Skip to content

Commit

Permalink
TEIID-4492 added ChildClasses option for configuring all pojos using …
Browse files Browse the repository at this point in the history
…protubuf annotations
  • Loading branch information
vhalbert committed Oct 4, 2016
1 parent 96d2f0e commit a383d23
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 16 deletions.
Expand Up @@ -81,7 +81,13 @@
<config-property-name>MessageDescriptor</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>


<config-property>
<description>{$display:"Child Class(s)",$description:"Child pojo classes, with annotations, that are accessible from the root class [className[;className];])",$required="false"}</description>
<config-property-name>ChildClasses</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>

<config-property>
<description>{$display:"Staging Cache Name",$description:"Cache name for the staging cache used in materialization",$required="false"}</description>
<config-property-name>StagingCacheName</config-property-name>
Expand Down
Expand Up @@ -78,6 +78,8 @@ private enum CACHE_TYPE {
private String messageMarshallers = null;
private String messageDescriptor = null;

private String childClasses= null;

private boolean usingAnnotations = false;

private RemoteCacheManager cacheContainer = null;
Expand Down Expand Up @@ -293,6 +295,26 @@ public void setMessageDescriptor(String messageDescriptor) {
this.messageDescriptor = messageDescriptor;
}

/**
* Returns a comma separated list of child class names that are
* registered in the JDG schema
*
* @return childClasses
*/
public String getChildClasses() {
return childClasses;
}

/**
* Sets a comma separated list of class names to register in the JDG schema
*
* @param childClasses Sets childClasses to the specified value.
*/
public void setChildClasses(String childClasses) {
this.childClasses = childClasses;
}


public String getStagingCacheName() {
return this.stagingCacheName;
}
Expand Down
Expand Up @@ -22,6 +22,9 @@
package org.teiid.resource.adapter.infinispan.hotrod.schema;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.resource.ResourceException;

Expand All @@ -31,6 +34,7 @@
import org.infinispan.protostream.annotations.ProtoSchemaBuilderException;
import org.infinispan.protostream.descriptors.Descriptor;
import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants;
import org.teiid.core.util.StringUtil;
import org.teiid.resource.adapter.infinispan.hotrod.InfinispanManagedConnectionFactory;
import org.teiid.resource.adapter.infinispan.hotrod.InfinispanSchemaDefinition;
import org.teiid.translator.TranslatorException;
Expand All @@ -44,10 +48,21 @@
*
*/
public class AnnotationSchema implements InfinispanSchemaDefinition {

private Set<Class> classes = new HashSet<Class>();

@Override
public void initialize(InfinispanManagedConnectionFactory config, ClassRegistry methodUtil) {
public void initialize(InfinispanManagedConnectionFactory config, ClassRegistry methodUtil) throws ResourceException {

if (config.getChildClasses() != null) {
List<String> clzzes = StringUtil.getTokens(config.getChildClasses(), ","); //$NON-NLS-1$
for (String clzName : clzzes) {
Class<?> ci = config.loadClass(clzName);

methodUtil.registerClass(ci);
classes.add(ci);
}
}

}

@Override
Expand All @@ -62,16 +77,18 @@ public void registerSchema(InfinispanManagedConnectionFactory config) throws Res
try {
Class<?> clzz = config.loadClass("org.infinispan.protostream.annotations.ProtoSchemaBuilder");
protoSchemaBuilder = (ProtoSchemaBuilder) clzz.newInstance();
String protoSchema = protoSchemaBuilder
.fileName(protoName)
.packageName(p)
.addClass(clzzType)
.build(config.getContext());
protoSchemaBuilder.fileName(protoName);
protoSchemaBuilder.packageName(p);
protoSchemaBuilder.addClass(clzzType);

RemoteCache<String, String> metadataCache = config.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put(protoName, protoSchema);

for(Class<?> c:classes) {
protoSchemaBuilder.addClass(c);
}
String protoSchema = protoSchemaBuilder.build(config.getContext());

RemoteCache<String, String> metadataCache = config.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put(protoName, protoSchema);

} catch (ProtoSchemaBuilderException e) {
throw new ResourceException(e);
} catch (IOException e) {
Expand All @@ -81,8 +98,7 @@ public void registerSchema(InfinispanManagedConnectionFactory config) throws Res
} catch (IllegalAccessException e) {
throw new ResourceException(e);
}
}

}

@Override
public Descriptor getDecriptor(InfinispanManagedConnectionFactory config, Class<?> clz) throws TranslatorException {
Expand Down
Expand Up @@ -28,11 +28,14 @@
import java.io.File;
import java.util.Properties;

import org.jboss.as.quickstarts.datagrid.hotrod.query.domain.Address;
import org.jboss.as.quickstarts.datagrid.hotrod.query.domain.PersonCacheSource;
import org.jboss.as.quickstarts.datagrid.hotrod.query.domain.PhoneNumber;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.translator.object.ObjectConnection;
import org.teiid.translator.infinispan.hotrod.InfinispanHotRodConnection;
import org.teiid.util.Version;


Expand All @@ -58,7 +61,7 @@ public static void beforeEachClass() throws Exception {

factory.setHotRodClientPropertiesFile("./target/hotrod-client.properties");
factory.setCacheTypeMap(RemoteInfinispanTestHelper.PERSON_CACHE_NAME + ":" + RemoteInfinispanTestHelper.PERSON_CLASS.getName()+ ";" + RemoteInfinispanTestHelper.PKEY_COLUMN);

factory.setChildClasses(PersonCacheSource.ADDRESSTYPE_CLASS_NAME + "," + PersonCacheSource.PHONENUMBER_CLASS_NAME);

}

Expand All @@ -71,7 +74,7 @@ public static void closeConnection() throws Exception {
@Test
public void testConnection() throws Exception {
try {
ObjectConnection conn = factory.createConnectionFactory().getConnection();
InfinispanHotRodConnection conn = factory.createConnectionFactory().getConnection();
Class<?> clz = conn.getCacheClassType();

assertEquals(RemoteInfinispanTestHelper.PERSON_CLASS, clz);
Expand All @@ -87,6 +90,8 @@ public void testConnection() throws Exception {
assertEquals("Support For Compare is false", conn.getVersion().compareTo(Version.getVersion("6.6")) >= 0, false );
// assertEquals("Version doesn't start with 7.2", conn.getVersion().startsWith("7.2"));

assertNotNull(conn.getDescriptor(Address.class));
assertNotNull(conn.getDescriptor(PhoneNumber.class));

conn.cleanUp();

Expand Down

0 comments on commit a383d23

Please sign in to comment.