Author: van.halbert
Date: 2012-05-22 10:51:03 -0400 (Tue, 22 May 2012)
New Revision: 4134
Added:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectVisitor.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchCriterion.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanCacheConnection.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectVisitor.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanIntegration.java
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegs.expected
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegsWithFilter.expected
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeAndLegsWithFilter.expected
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeID.expected
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTrades.expected
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTransaction.expected
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryIncludeLegs.expected
Removed:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectCacheConnection.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanObjectVisitor.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheVisitor.java
branches/7.7.x/connectors/translator-object/src/test/resources/ObjectDatabaseMetaDataTest/
branches/7.7.x/connectors/translator-object/src/test/resources/ObjectDriverIntegrationTest/
branches/7.7.x/connectors/translator-object/src/test/resources/testQueryIncludeLegs.expected
Modified:
branches/7.7.x/connectors/translator-object/Notes.txt
branches/7.7.x/connectors/translator-object/pom.xml
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectSourceProxy.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheExecutionFactory.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheProxy.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanProxy.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheIntegration.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java
Log:
TEIID-1992 this include several things; added the ability to filter rows when no vendor
specific query implementation available, refactored the connection implementation to
support remote infinispan connection, added more tests and cleanup
Modified: branches/7.7.x/connectors/translator-object/Notes.txt
===================================================================
--- branches/7.7.x/connectors/translator-object/Notes.txt 2012-05-22 12:44:18 UTC (rev
4133)
+++ branches/7.7.x/connectors/translator-object/Notes.txt 2012-05-22 14:51:03 UTC (rev
4134)
@@ -15,6 +15,7 @@
2. Default, columns that are of type object are NOT Selectable or Searchable. Its
assumed that if object types like
Map, Collection, or Array, there needs to be a related child table that has a foreign
key defined.
+3. When using filtering and adding criteria, the column must also be in the SELECT
CLAUSE
Modeling -
Modified: branches/7.7.x/connectors/translator-object/pom.xml
===================================================================
--- branches/7.7.x/connectors/translator-object/pom.xml 2012-05-22 12:44:18 UTC (rev
4133)
+++ branches/7.7.x/connectors/translator-object/pom.xml 2012-05-22 14:51:03 UTC (rev
4134)
@@ -13,6 +13,7 @@
<properties>
<version.infinispan>5.1.2.FINAL</version.infinispan>
<version.hibernate.search>3.1.1.GA</version.hibernate.search>
+ <mockito.all.version>1.8.4</mockito.all.version>
</properties>
<dependencies>
@@ -44,38 +45,11 @@
<scope>provided</scope>
</dependency>
- <!-- dependency>
- <groupId>org.jboss.teiid.connectors</groupId>
- <artifactId>connector-infinispan</artifactId>
- <classifier>lib</classifier>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency-->
-
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>${version.infinispan}</version>
- </dependency>
-
- <!-- dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-core</artifactId>
- <version>${version.infinispan}</version>
- </dependency>
- <dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-client-hotrod</artifactId>
- <version>${version.infinispan}</version>
- </dependency-->
-
-<!--
- <dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-query</artifactId>
- <version>${version.infinispan}</version>
- </dependency>
- -->
+ </dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -88,6 +62,13 @@
<artifactId>connector-api</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>${mockito.all.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
Deleted:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectCacheConnection.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectCacheConnection.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectCacheConnection.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -1,14 +0,0 @@
-package org.teiid.translator.object;
-
-import java.util.List;
-
-/**
- * This is the interface the connection is exposed as.
- * @author vhalbert
- *
- */
-public interface ObjectCacheConnection {
-
- List<Object> get(List<Object> args, String cacheName, Class<?>
rootNodeType) throws Exception ;
-
-}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -45,30 +45,33 @@
private ObjectSourceProxy proxy;
private ObjectMethodManager methodManager;
private ObjectExecutionFactory config;
- private ObjectProjections op;
+ private RuntimeMetadata metadata;
private Iterator<List<Object>> resultsIt = null;
public ObjectExecution(Command query, RuntimeMetadata metadata, ObjectSourceProxy
proxy, ObjectMethodManager methodManager, ObjectExecutionFactory factory) {
this.query = (Select) query;
- this.op = new ObjectProjections(this.query);
this.proxy = proxy;
this.methodManager = methodManager;
this.config = factory;
+ this.metadata = metadata;
}
@Override
public void execute() throws TranslatorException {
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Object executing command:
" + query.toString()); //$NON-NLS-1$
+ ObjectVisitor visitor = getObjectVisitor();
- List<Object> objects = executeQuery();
+ visitor.visitNode(query);
+ List<Object> objects = executeQuery(visitor);
+
List<List<Object>> results = null;
if (objects != null && objects.size() > 0) {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ObjectExecution number of
objects from proxy is : " + objects.size()); //$NON-NLS-1$
- results = ObjectTranslator.translateObjects(objects, op, methodManager);
+ results = ObjectTranslator.translateObjects(objects, visitor, methodManager);
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ObjectExecution number of rows
from translation : " + results.size()); //$NON-NLS-1$
@@ -78,19 +81,22 @@
results = Collections.emptyList();
}
-
this.resultsIt = results.iterator();
}
- protected List<Object> executeQuery()
+ protected List<Object> executeQuery(ObjectVisitor op)
throws TranslatorException {
- LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ObjectExecution calling
proxy : " + this.proxy.getClass().getName()); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ObjectExecution calling proxy
: " + this.proxy.getClass().getName()); //$NON-NLS-1$
- return this.proxy.get(query, config.getCacheName(), op.rootNodeClassName);
+ return this.proxy.get(query, config.getCacheName(), op);
}
+ protected ObjectVisitor getObjectVisitor() {
+ return new ObjectVisitor(this.config,this.metadata);
+ }
+
@Override
public List<Object> next() throws TranslatorException,
DataNotAvailableException {
// create and return one row at a time for your resultset.
@@ -107,7 +113,7 @@
this.proxy = null;
this.methodManager = null;
this.query = null;
-
+ this.metadata = null;
}
@Override
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -33,8 +33,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import javax.resource.cci.ConnectionFactory;
-
import org.teiid.core.util.StringUtil;
import org.teiid.language.QueryExpression;
import org.teiid.language.Select;
@@ -56,9 +54,10 @@
* @author vhalbert
*
*/
+//public abstract class ObjectExecutionFactory extends
ExecutionFactory<ConnectionFactory, ObjectCacheConnection > {
-public abstract class ObjectExecutionFactory extends
ExecutionFactory<ConnectionFactory, ObjectCacheConnection > {
- public static final int MAX_SET_SIZE = 100;
+public abstract class ObjectExecutionFactory extends ExecutionFactory {
+ public static final int MAX_SET_SIZE = 1000;
/*
* ObjectMethodManager is the cache of methods used on the objects.
@@ -70,7 +69,7 @@
private String packageNamesOfCachedObjects = null;
private String classNamesOfCachedObjects = null;
private String cacheName = null;
- private String objectRelationShips = null;
+ private boolean supportFilters = true;
public ObjectExecutionFactory() {
super();
@@ -85,7 +84,8 @@
this.setSupportsSelectDistinct(false);
this.setSupportsInnerJoins(true);
this.setSupportsFullOuterJoins(false);
- this.setSupportsOuterJoins(true);
+ this.setSupportsOuterJoins(false);
+
}
@Override
@@ -96,8 +96,9 @@
}
@Override
- public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, ObjectCacheConnection
connection)
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Object connection)
throws TranslatorException {
+
return new ObjectExecution((Select)command, metadata, createProxy(connection),
objectMethods, this);
}
@@ -110,7 +111,13 @@
return true;
}
-
+ public boolean supportsInCriteria() {
+ return true;
+ }
+
+ public boolean supportsOrCriteria() {
+ return true;
+ }
/**
* Get the cacheName that will be used by this factory instance to access the named
cache.
* However, if not specified a default configuration will be created.
@@ -132,25 +139,58 @@
this.cacheName = cacheName;
}
+
+ // TODO: implement the code that supports this option for non-annotated classes
+// /**
+// * Get the object relationships.
+// * @return
+// * @see #setObjectRelationships(String)
+// */
+// @TranslatorProperty(display="ObjectRelationships", advanced=true)
+// public String getObjectRelationships() {
+// return this.objectRelationShips;
+// }
+//
+// /**
+// * Set the object relationships so that the metadata relationships can be built.
Specify the
+// * relationships using the format: <parent
classname>.<getMethod>:<child classname>
+// * @param cacheName
+// * @see #getObjectRelationships()
+// */
+//
+// public void setObjectRelationships(String objectRelationships) {
+// this.objectRelationShips = objectRelationships;
+// }
+
/**
- * Get the object relationships.
+ * <p>
+ * Call to get the indicator if object filtering will be used to help determine if
+ * an object is included in the results. This option can be used when the criteria
+ * cannot be used by the vendor specific querying capabilities.
+ * </p>
+ * This doesn't apply to the primary key when used in the criteria.
+ * <p>
+ * Note, the use of this option will be slower because the filtering is done
post-retrieval
+ * of the objects from the cache.
+ * </p>
+ *
* @return
- * @see #setObjectRelationships(String)
+ * @see #setSupportFilters(boolean)
*/
- @TranslatorProperty(display="ObjectRelationShips", advanced=true)
- public String getObjectRelationships() {
- return this.objectRelationShips;
+ @TranslatorProperty(display="SupportFilters", advanced=true)
+ public boolean isSupportFilters() {
+ return this.supportFilters;
}
/**
- * Set the object relationships so that the metadata relationships can be built.
Specify the
- * relationships using the format: <simple
classname>.<getMethod>:<simple classname>
- * @param cacheName
- * @see #getObjectRelationships()
+ * Set to <code>true</code> when the criteria will be used to filter the
objects to be
+ * returned in the results.
+ * @param supportFilters
+ * @see #isSupportFilters()
*/
- public void setObjectRelationships(String objectRelationships) {
- this.objectRelationShips = objectRelationships;
+ public void setSupportFilters(boolean supportFilters) {
+ this.supportFilters = supportFilters;
}
/**
@@ -236,7 +276,7 @@
@Override
- public void getMetadata(MetadataFactory metadataFactory, ObjectCacheConnection conn)
+ public void getMetadata(MetadataFactory metadataFactory, Object conn)
throws TranslatorException {
createObjectMethodManager();
ObjectMetadataProcessor processor = new ObjectMetadataProcessor(metadataFactory,
this);
@@ -256,7 +296,7 @@
* @return IObjectConnectionProxy
* @throws TranslatorException
*/
- protected abstract ObjectSourceProxy createProxy(ObjectCacheConnection connection)
throws TranslatorException ;
+ protected abstract ObjectSourceProxy createProxy(Object connection) throws
TranslatorException ;
protected void createObjectMethodManager() throws TranslatorException {
if (objectMethods == null) {
@@ -323,12 +363,9 @@
classes.addAll(findClasses(directory, packageName, regex));
}
ArrayList<String> classNames = new ArrayList<String>();
-// ArrayList<Class> classList = new ArrayList<Class>();
for (String clazz : classes) {
classNames.add(clazz);
}
-// return classList.toArray(new Class[classes.size()]);
-//
return classNames;
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -55,7 +55,7 @@
this.clz = clzz;
}
- public Class getClassIdentifier() {
+ public Class<?> getClassIdentifier() {
return this.clz;
}
public String getClassName() {
Deleted:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -1,227 +0,0 @@
-package org.teiid.translator.object;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.core.util.StringUtil;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Select;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.ForeignKey;
-import org.teiid.metadata.KeyRecord;
-import org.teiid.metadata.Table;
-import org.teiid.translator.TranslatorException;
-
-public class ObjectProjections {
- // Columns that are in the select clause
- protected Column[] columns = null; // columnNameToUse, Column in select
- // The columnNameToUse could be either
- // - name in source
- // - if its a child column, then it will be {FK name in source}.{name in source}
- protected String[] columnNamesToUse = null;
-
- protected List<String>[] nameNodes = null;
- protected int[] nodeDepth = null; // values are zero based, anything greater than zero
indicates there children involved
-
- // this is the number of children deep this query is requesting information
- protected int childrenDepth = -1; //
- // this is the path of method calls to traverse the children
- protected List<String> childrenNodes = null;
-
- protected List<String> exceptionMessages = new ArrayList<String>(2);
-
- protected String rootNodeClassName = null;
-
-
- public ObjectProjections(Select query) {
- parse(query);
- }
-
- public Column[] getColumns() {
- return this.columns;
- }
-
- public String[] getColumnNamesToUse() {
- return this.columnNamesToUse;
- }
-
- public boolean hasChildren() {
- return (childrenDepth > -1);
- }
-
- @SuppressWarnings("unchecked")
- private void parse(Select query) {
- columns = getSelectableColumns(query);
- columnNamesToUse = new String[columns.length];
- nameNodes = new ArrayList[columns.length];
- nodeDepth = new int[columns.length];
-
- String maxDepthColumnNameToUse = null;
-
- for (int i=0; i<columns.length; ++i) {
- columnNamesToUse[i] = getColumnNameToUse(columns[i]);
-
- nameNodes[i] = StringUtil.getTokens(columnNamesToUse[i], ".");
- nodeDepth[i] = nameNodes[i].size() - 1; // if one node name, then depth is zero, and
incremented from there
-
- // only when there are multiple node names will a container/child be involved
- if (nodeDepth[i] > 0) {
- if (childrenDepth == -1) {
- childrenDepth = nodeDepth[i];
- // strip off the the child node names (excluding the last node, which is the value
call)
- maxDepthColumnNameToUse = columnNamesToUse[i].substring(0,
columnNamesToUse[i].lastIndexOf("."));
- childrenNodes = nameNodes[i];
- } else {
- // if the columns are not on the same path, then this is an error,
- // can only support one child path per query
- if (!columnNamesToUse[i].startsWith(maxDepthColumnNameToUse)) {
- addException(maxDepthColumnNameToUse, columnNamesToUse[i],
columns[i].getParent().getName());
- }
-
- if ( nodeDepth[i] > childrenDepth) {
- childrenDepth = nodeDepth[i];
- childrenNodes = nameNodes[i];
- }
-
- }
- }
-
- }
-
- }
-
- private Column[] getSelectableColumns(Select query) {
- Column[] interimColumns = new Column[query.getDerivedColumns().size()];
-
- Iterator<DerivedColumn> selectSymbolItr = query.getDerivedColumns().iterator();
- int i=0;
- while(selectSymbolItr.hasNext()) {
- Column c = getColumnFromSymbol(selectSymbolItr.next());
- if (!c.isSelectable()) continue;
-
- interimColumns[i] = c;
- ++i;
- }
-
- // if all columns are included, then return, no need to rebuild the array
- if (interimColumns.length == i+1) {
- return interimColumns;
- }
-
- Column[] columns = new Column[i];
- for (int x=0; x<i; ++x) {
- columns[x] = interimColumns[x];
- }
- return columns;
-
- }
-
- private void addException(String columnNameToUse1,
- String columnNameToUse2, String table) {
-
- exceptionMessages.add(
- ObjectPlugin.Util
- .getString(
- "ObjectProjections.unsupportedMultipleContainers", new Object[] {
columnNameToUse1, columnNameToUse2, table }));
-
- }
-
- protected void throwExceptionIfFound() throws TranslatorException {
- if (!exceptionMessages.isEmpty())
- throw new TranslatorException("ObjectProjections Exception: " +
exceptionMessages.toString());
- }
-
- public String getColumnNameToUse(Column column) {
- String nis = getNameInSourceForObjectHierarchy(column);
- if (nis == null) return column.getName();
- return nis;
- }
-
- /**
- * Method to build the nameInSource nodes to be used to lookup a value, starting with
the root object.
- * If the column is associated with a table that has a foreign key (i.e, is contained
within), use the nameInSource
- * of the foreign key as a prefix node in the nameInSource. The process will climb the
foreign key hierarchy tree to
- * combine to make the NameInSource for the column.
- * Example: Object hierarchy: "A" = getLegs => "B" =
getTransactions => "C"
- * The column object would start with "C" and find a foreign key to
"B", having nameInSource of "Transactions"
- * current nodes in the name are: Transactions."C"
- *
- * The process then takes object "B" and determines it has a foreign key to
"A", its nameInSource is "Legs", which is prefixed on the nodes
names.
- * current nodes in the name are: Legs.Transactions."C"
- *
- * The node name structure will allow the object reflection process to traverse the root
object to get to "C" by taking the first node, Legs,
- * and calling "A".getLegs(), and then processing each object in the
collection by calling "B".getTransations().
- *
- * @param e the supplied Element
- * @return the name
- */
- // GHH 20080326 - found that code to fall back on Name if NameInSource
- // was null wasn't working properly, so replaced with tried and true
- // code from another custom connector.
- protected String getNameInSourceForObjectHierarchy(Column e) {
- String nis = getNameInSourceFromColumn(e);
-
- Object p = e.getParent();
- // if the column comes from a table that has a foreign key, then
- // preprend the nameInSource with the foreign key nameInSource
- //NOTE: the foreign key NIS should be the name of the container method to find the
column
- String parentNodeName = null;
- if (p instanceof Table) {
- parentNodeName = getForeignKeyNodeName((Table) p);
- }
-
- return (parentNodeName != null ? parentNodeName + "." : "") + nis;
- }
-
- protected void setRootClassName(Table t) {
- if (this.rootNodeClassName != null) return;
-
- if (t.getNameInSource() != null) {
- this.rootNodeClassName = t.getNameInSource();
- }
- }
-
-
- protected String getNameInSourceFromColumn(Column c) {
- String name = c.getNameInSource();
- if(name == null || name.equals("")) { //$NON-NLS-1$
- return c.getName();
- }
- return name;
- }
-
-
- protected String getForeignKeyNodeName(Table t) {
- if (t == null) return null;
-
- setRootClassName(t);
-
- if (t.getForeignKeys() != null && !t.getForeignKeys().isEmpty()) {
- ForeignKey fk = (ForeignKey) t.getForeignKeys().get(0);
- String fk_nis = fk.getNameInSource();
-
- KeyRecord kr = fk.getPrimaryKey();
- if (kr.getParent() != null) {
- String parentNIS = getForeignKeyNodeName(kr.getParent());
-
- return (parentNIS != null ? parentNIS + "." : "") + fk_nis;
- }
- return fk_nis;
- }
-
- return null;
- }
-
- /**
- * Helper method for getting {@link org.teiid.metadata.Column} from a
- * {@link org.teiid.language.DerivedColumn}.
- * @param symbol Input ISelectSymbol
- * @return Element returned metadata runtime Element
- */
- protected Column getColumnFromSymbol(DerivedColumn symbol) {
- ColumnReference expr = (ColumnReference) symbol.getExpression();
- return expr.getMetadataObject();
- }
-}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectSourceProxy.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectSourceProxy.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectSourceProxy.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -46,11 +46,11 @@
* to data source query syntax.
* @param command is the SELECT command to query the data source
* @param cacheName is the name of the cache to query
- * @param rootClassName is the class type of the object in the cache
+ * @param visitor represents the source tables and columns being queried
* @return List of objects found in the cache.
* @throws TranslatorException is thrown if there are issues querying the data source
*/
- List<Object> get(Command command, String cacheName, String rootClassName) throws
TranslatorException;
+ List<Object> get(Command command, String cacheName, ObjectVisitor visitor) throws
TranslatorException;
/**
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -33,6 +33,7 @@
import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
import org.teiid.core.types.DataTypeManager.DefaultTypeCodes;
import org.teiid.core.types.TransformationException;
+import org.teiid.metadata.Column;
import org.teiid.translator.TranslatorException;
/**
@@ -63,56 +64,82 @@
* if table or view is defined to have multiple container objects (ie., Maps, List,
etc.) returned
* in the same source query.
* <p> Example:
- * Object X
- * Attributes: Name
+ * Object Person
+ * Attributes: Name
* Addresses (List)
* Phones (List)
- * Object X is mapped to Table A
- * Name
+ *
+ * Addresses contained Address Object(s)
* Street
* City
* State
+ * Zip
+ *
+ * Phones contained Phone Object(s)
* Phone_Number
*
- * To model this correctly, you would create 2 Tables (A and B):
- * Table A
- * Name, Street, City, State
- * Table B
- * Name, Phone_Number
*
+ * To model this correctly, you would create 3 Tables (Person, Address, Phone):
+ * Table Person
+ * Name (String)
+ * Addresses (Object)
+ * Phones (Object)
+ * PK-Name
+ * Table Address
+ * Name,
+ * Street
+ * City
+ * State
+ * Zip
+ * FK-PersonName
+ *
+ * Table Phone
+ * Name
+ * Phone_Number
+ * FK-PersonName
+ *
+ *
+ * The recommendation now is to create a view for each logical set (i.e.,
PersonAddresses and PersonPhoneNumbers).
+ *
* If the user wants a cross-product result, then allow the Teiid engine to perform
that logic, but the Translator
* will only traverse one container path per result set. I say container path,
because it will be possible for
* an object in a container to define another container object, and so on.
Theoretically, there is no depth limit.
* <li></li>
* @param objects is the List of objects from the cache
- * @param projections are the columns to be returned in the result set
+ * @param visitor are the columns to be returned in the result set
* @param objectManager is responsible for providing the object methods used for
traversing an object and/or
* obtaining the data from an object
* @return List<List<?>> that represent the rows and columns in the result
set
*/
- public static List<List<Object>> translateObjects(List<Object>
objects, ObjectProjections projections, ObjectMethodManager objectManager) throws
TranslatorException {
+ public static List<List<Object>> translateObjects(List<Object>
objects, ObjectVisitor visitor, ObjectMethodManager objectManager) throws
TranslatorException {
- projections.throwExceptionIfFound();
+ visitor.throwExceptionIfFound();
List<List<Object>> rows = new
ArrayList<List<Object>>(objects.size());
// if no container objects required in the results, then
// perform simple logic for building a row
- int numCols = projections.columnNamesToUse.length;
+ int numCols = visitor.columnNamesToUse.length;
- if (!projections.hasChildren()) {
+ if (!visitor.hasChildren()) {
for (Iterator<Object> it = objects.iterator(); it.hasNext();) {
// each object represent 1 row
Object o = (Object) it.next();
+ boolean includeRow = true;
+
List<Object> row = new ArrayList<Object>(numCols);
- for (int i = 0; i < numCols; i++) {
- Object value = getValue(o, i, 0, projections, objectManager);
-
- row.add(value);
+ for (int i = 0; i < numCols; i++) {
+ includeRow = addValueToRow(o, i, 0, visitor, objectManager, row);
+ if (!includeRow) {
+ row.clear();
+ break;
+ }
}
- rows.add(row);
+ if (includeRow) {
+ rows.add(row);
+ }
}
return rows;
@@ -123,7 +150,7 @@
// collection is found in its results
Object o = (Object) it.next();
- List<List<Object>> containerRows = processContainer(o, 0, projections,
objectManager);
+ List<List<Object>> containerRows = processContainer(o, 0, visitor,
objectManager);
rows.addAll(containerRows);
}
@@ -145,7 +172,7 @@
*/
@SuppressWarnings("unchecked")
private static List<List<Object>> processContainer(Object parentObject,
- int level, ObjectProjections projections, ObjectMethodManager objectManager) throws
TranslatorException {
+ int level, ObjectVisitor projections, ObjectMethodManager objectManager) throws
TranslatorException {
List<List<Object>> containerRows = new
ArrayList<List<Object>>();
// if there is another container depth, then process it first
@@ -201,22 +228,29 @@
}
+ // if no children object were needed,which would expand the number of rows,
+ // then this one object will be the one row returned
if (containerRows.isEmpty()) {
- containerRows = new ArrayList<List<Object>>(1);
List<Object> row = new
ArrayList<Object>(projections.columnNamesToUse.length);
+ boolean includeRow = true;
for (int i = 0; i < projections.columnNamesToUse.length; i++) {
// the column must have as many nodes as the level being processed
// in order to obtain the value at the current level
if (projections.nameNodes[i].size() >= (level + 1)) { // level is zero based
- Object value = getValue(parentObject, i, level, projections, objectManager);
-
- row.add(value);
+ includeRow = addValueToRow(parentObject, i, level, projections, objectManager,
row);
+ if (!includeRow) {
+ row.clear();
+ break;
+ }
+
} else {
row.add(null);
}
}
- containerRows.add(row);
+ if (includeRow) {
+ containerRows.add(row);
+ }
return containerRows;
}
@@ -227,6 +261,7 @@
List<Object> newrow = new
ArrayList<Object>(projections.columnNamesToUse.length);
+ boolean includeRow = true;
for (int col=0; col<projections.columnNamesToUse.length; ++col) {
// only make method calls for columns that are being processed at the same level,
// columns at other node depths will be loaded when its level is processed
@@ -237,10 +272,12 @@
// this should not happen, but just in case
if (colObject != null) throw new TranslatorException("Program Error: column
object was not null for column " + projections.columnNamesToUse[col] + " at
level " + level);
-
- final Object value = getValue(parentObject, col, level, projections,
objectManager);
-
- newrow.add(value);
+
+ includeRow = addValueToRow(parentObject, col, level, projections, objectManager,
newrow);
+ if (!includeRow) {
+ newrow.clear();
+ break;
+ }
} else {
newrow.add(colObject);
@@ -248,37 +285,85 @@
}
- expandedRows.add(newrow);
+ if (includeRow) {
+ expandedRows.add(newrow);
+ }
}
return expandedRows;
}
- private static Object getValue(Object cachedObject, int columnIdx, int methodIdx,
ObjectProjections projections, ObjectMethodManager objectManager) throws
TranslatorException {
- Object value = null;
+ /*
+ * Return false when the row should be excluded from the results
+ */
+ private static boolean addValueToRow(Object cachedObject, int columnIdx, int methodIdx,
ObjectVisitor visitor, ObjectMethodManager objectManager, List<Object> row) throws
TranslatorException {
// only the last parsed name can be where the boolean call can be made
// example: x.y.z z will be where "is" is called
// or x x could be where "is" is called
- Class<?> clzType = projections.columns[columnIdx].getJavaType();
+ Column c = visitor.columns[columnIdx];
+ Class<?> clzType = c.getJavaType();
+ Object value = getValue(cachedObject, visitor.nameNodes[columnIdx].get(methodIdx),
clzType, objectManager);
+
+ if (visitor.hasFilters()) {
+ SearchCriterion sc = visitor.getFilters().get(c.getFullName());
+
+ while (sc != null) {
+ Object searchValue = null;
+ try {
+ if (sc.getValue().getClass().equals(clzType) ) {
+ searchValue = sc.getValue();
+
+ if (searchValue != null && searchValue.equals(value)) {
+ } else {
+ return false;
+ }
+ } else if (DataTypeManager.isTransformable(sc.getValue().getClass(), clzType)) {
+ searchValue = DataTypeManager.getTransform(sc.getValue().getClass(),
clzType).transform(sc.getValue());
+ // if the filter matches, then return false to indicate this row is excluded
+ if (searchValue.equals(value)) {
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } catch (TransformationException e) {
+ // TODO Auto-generated catch block
+ throw new TranslatorException(e);
+ }
+
+ sc = sc.getAddCondition();
+
+ }
+
+ }
+ row.add(value);
+
+ return true;
+ }
+
+
+ private static Object getValue(Object cachedObject, String columnName, Class<?>
clzType, ObjectMethodManager objectManager) throws TranslatorException {
+ Object value = null;
+ Class<?> dataTypeClass =
DataTypeManager.getDataTypeClass(cachedObject.getClass().getName());
+
if (cachedObject.getClass().equals(clzType)) {
return cachedObject;
}
- Class dataTypeClass =
DataTypeManager.getDataTypeClass(cachedObject.getClass().getName());
-
// if the class is not a native type, but the POJO object, then
// call the method on the class to get the value
if (dataTypeClass == DefaultDataClasses.OBJECT) {
if (clzType != null && clzType == Boolean.class) {
final String methodName = objectManager.formatMethodName(
- ObjectMethodManager.IS, projections.nameNodes[columnIdx].get(methodIdx) );
+ ObjectMethodManager.IS, columnName );
value = objectManager.getIsValue(
methodName, cachedObject);
} else {
final String methodName = objectManager.formatMethodName(
- ObjectMethodManager.GET, projections.nameNodes[columnIdx].get(methodIdx) );
+ ObjectMethodManager.GET, columnName );
value = objectManager.getGetValue(
methodName, cachedObject);
@@ -312,9 +397,8 @@
}
}
-
return value;
- }
+ }
private static CONTAINER_TYPE getContainerType(Object o) {
Added:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectVisitor.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectVisitor.java
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectVisitor.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1,488 @@
+package org.teiid.translator.object;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.teiid.core.util.StringUtil;
+import org.teiid.language.ColumnReference;
+import org.teiid.language.Comparison;
+import org.teiid.language.Comparison.Operator;
+import org.teiid.language.DerivedColumn;
+import org.teiid.language.Expression;
+import org.teiid.language.In;
+import org.teiid.language.Literal;
+import org.teiid.language.NamedTable;
+import org.teiid.language.Select;
+import org.teiid.language.TableReference;
+import org.teiid.language.visitor.HierarchyVisitor;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ForeignKey;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.translator.TranslatorException;
+
+public class ObjectVisitor extends HierarchyVisitor {
+ // Columns that are in the select clause
+ protected Column[] columns = null;
+ // The columnNameToUse could be either
+ // - name in source
+ // - if its a child column, then it will be {FK name in source}.{name in source}
+ protected String[] columnNamesToUse = null;
+
+ // tokenized version of the column name
+ protected List<String>[] nameNodes = null;
+ protected int[] nodeDepth = null; // values are zero based, anything greater than zero
indicates there children involved
+
+ // this is the number of children deep this query is requesting information
+ protected int childrenDepth = -1; //
+ // this is the longest path of method calls to traverse the children
+ protected List<String> childrenNodes = null;
+
+ protected List<String> exceptionMessages = new ArrayList<String>(2);
+
+ protected boolean isRootTableInSelect = false;
+
+ private Table rootTable = null;
+
+ private Map<String, String> fkNames; // tablename, childNodePath
+
+ // key search criteria
+ private SearchCriterion criterion;
+ // non-key search criteria
+ private Map<String, SearchCriterion> filters; // columnName, criteria
+ private boolean useFilters;
+
+ private RuntimeMetadata metadata;
+
+
+ public ObjectVisitor(ObjectExecutionFactory factory, RuntimeMetadata metadata) {
+ this.useFilters = factory.isSupportFilters();
+ this.metadata = metadata;
+ }
+
+ public Column[] getColumns() {
+ return this.columns;
+ }
+
+ public String[] getColumnNamesToUse() {
+ return this.columnNamesToUse;
+ }
+
+ public boolean hasChildren() {
+ return (childrenDepth > -1);
+ }
+
+ public boolean hasFilters() {
+ return (useFilters && filters != null && filters.size() > 0);
+ }
+
+ public Table getRootTable() {
+ return this.rootTable;
+ }
+
+ public String getRootNodeClassName() {
+ return this.rootTable.getNameInSource();
+ }
+
+ public String getRootNodePrimaryKeyColumnName() {
+ if (this.rootTable.getPrimaryKey()!= null) {
+ return this.rootTable.getPrimaryKey().getColumns().get(0).getName();
+ }
+ return null;
+ }
+
+ public boolean isRootTableInFrom() {
+ return this.isRootTableInSelect;
+ }
+
+ public SearchCriterion getCriterion() {
+ if (this.criterion == null) {
+ this.criterion = new SearchCriterion();
+ }
+
+ this.criterion.setRootTableInSelect(isRootTableInFrom());
+
+ return this.criterion;
+ }
+
+ public Map<String, SearchCriterion> getFilters() {
+ return this.filters;
+ }
+
+ @Override
+ public void visit(Select query) {
+ columns = getSelectableColumns(query);
+
+
+ columnNamesToUse = new String[columns.length];
+ nameNodes = new ArrayList[columns.length];
+ nodeDepth = new int[columns.length];
+
+ this.fkNames = new HashMap(query.getFrom().size());
+
+ String maxDepthColumnNameToUse = null;
+
+ for (int i=0; i<columns.length; ++i) {
+ columnNamesToUse[i] = getColumnNameToUse(columns[i]);
+
+ nameNodes[i] = StringUtil.getTokens(columnNamesToUse[i], ".");
+ nodeDepth[i] = nameNodes[i].size() - 1; // if one node name, then depth is zero, and
incremented from there
+
+ // only when there are multiple node names will a container/child be involved
+ if (nodeDepth[i] > 0) {
+ if (childrenDepth == -1) {
+ childrenDepth = nodeDepth[i];
+ // strip off the the child node names (excluding the last node, which is the value
call)
+ maxDepthColumnNameToUse = columnNamesToUse[i].substring(0,
columnNamesToUse[i].lastIndexOf("."));
+ childrenNodes = nameNodes[i];
+ } else {
+ // if the columns are not on the same path, then this is an error,
+ // can only support one child path per query
+ if (!columnNamesToUse[i].startsWith(maxDepthColumnNameToUse)) {
+ addException(maxDepthColumnNameToUse, columnNamesToUse[i],
columns[i].getParent().getName());
+ }
+
+ if ( nodeDepth[i] > childrenDepth) {
+ childrenDepth = nodeDepth[i];
+ childrenNodes = nameNodes[i];
+ }
+
+ }
+ }
+
+ }
+
+
+ List <TableReference> tables = query.getFrom();
+ for (TableReference t:tables) {
+ if(t instanceof NamedTable) {
+ Table group = ((NamedTable)t).getMetadataObject();
+ if (group.equals(this.rootTable)) {
+ this.isRootTableInSelect = true;
+ }
+ }
+ }
+
+ if (this.useFilters) {
+ this.filters = new HashMap<String, SearchCriterion>(getColumns().length);
+ }
+
+ super.visit(query);
+
+
+ }
+
+ public void visit(Comparison obj) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison
criteria."); //$NON-NLS-1$
+ Comparison.Operator op = ((Comparison) obj).getOperator();
+
+ Expression lhs = ((Comparison) obj).getLeftExpression();
+ Expression rhs = ((Comparison) obj).getRightExpression();
+
+ // comparison between the ojbects is not usable, because the nameInSource and its
parent(s)
+ // will be how the child objects are obtained
+ if ((lhs instanceof ColumnReference && rhs instanceof ColumnReference) ||
+ (lhs instanceof Literal && rhs instanceof Literal) ) {
+ return;
+ }
+
+ String value = null;
+ Column mdIDElement = null;
+ Literal literal = null;
+ if(lhs instanceof ColumnReference) {
+ mdIDElement = ((ColumnReference)lhs).getMetadataObject();
+ literal = (Literal) rhs;
+ value = literal.getValue().toString();
+
+ } else {
+ mdIDElement = ((ColumnReference)rhs).getMetadataObject();
+ literal = (Literal) lhs;
+ value = literal.getValue().toString();
+ }
+
+ if(mdIDElement == null || value == null) {
+ final String msg =
ObjectPlugin.Util.getString("ObjectVisitor.missingComparisonExpression");
//$NON-NLS-1$
+ addException(msg);
+ }
+
+ value = escapeReservedChars(value);
+
+ addCompareCriteria(mdIDElement, escapeReservedChars(value), op, literal.getType());
+
+ }
+
+ public void visit(In obj) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria.");
//$NON-NLS-1$
+// isNegated = ((In) criteria).isNegated();
+
+ Expression lhs = ((In)obj).getLeftExpression();
+
+ Column mdIDElement = ((ColumnReference)lhs).getMetadataObject();
+
+ List<Expression> rhsList = ((In)obj).getRightExpressions();
+
+ Class<?> type = lhs.getType();
+ List parms = new ArrayList(rhsList.size());
+ Iterator iter = rhsList.iterator();
+ while(iter.hasNext()) {
+
+ Expression expr = (Expression) iter.next();
+ if(expr instanceof Literal) {
+ Literal literal = (Literal) expr;
+
+ parms.add(literal.getValue());
+
+ type = literal.getType();
+
+ } else {
+ this.addException("ObjectVisitor.Unsupported_expression " + expr);
+ }
+
+ }
+ addInCriteria(mdIDElement, parms, type);
+
+ }
+
+ private void addCompareCriteria(Column column, Object value, Operator op,
Class<?> type) {
+ SearchCriterion sc = new SearchCriterion(column, value, op.toString(),
SearchCriterion.Operator.EQUALS, type);
+
+ addSearchCriterion(sc);
+ }
+
+ private void addInCriteria(Column column,
+ List<Object> parms, Class<?> type) {
+ SearchCriterion sc = new SearchCriterion(
+ column, parms, "in", SearchCriterion.Operator.IN, type);
+
+ addSearchCriterion( sc);
+
+ }
+
+ private void addSearchCriterion(SearchCriterion searchCriteria) {
+ // only searching on primary key is part of the criteria sent for cache lookup
+ // all other criteria will be used to filter the rows
+ assert(searchCriteria.getTableName() != null);
+ assert(getRootTable() != null);
+ assert(searchCriteria.getField() != null);
+ assert(getRootNodePrimaryKeyColumnName() != null);
+ if (searchCriteria.getTableName().equalsIgnoreCase(getRootTable().getName())
&&
+ searchCriteria.getField().equalsIgnoreCase(getRootNodePrimaryKeyColumnName())) {
+
+ if (this.criterion != null) {
+ searchCriteria.addOrCondition(this.criterion);
+ }
+
+ this.criterion = searchCriteria;
+ } else if (useFilters) {
+
+ if (this.filters.containsKey(searchCriteria.getColumn().getFullName())) {
+ SearchCriterion sc = this.filters.get(searchCriteria.getColumn().getFullName());
+ sc.addOrCondition(searchCriteria);
+ } else {
+ this.filters.put(searchCriteria.getColumn().getFullName(), searchCriteria);
+ }
+
+ }
+ }
+
+ protected static String escapeReservedChars(final String expr) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < expr.length(); i++) {
+ char curChar = expr.charAt(i);
+ switch (curChar) {
+ case '\\':
+ sb.append("\\5c"); //$NON-NLS-1$
+ break;
+ case '*':
+ sb.append("\\2a"); //$NON-NLS-1$
+ break;
+ case '(':
+ sb.append("\\28"); //$NON-NLS-1$
+ break;
+ case ')':
+ sb.append("\\29"); //$NON-NLS-1$
+ break;
+ case '\u0000':
+ sb.append("\\00"); //$NON-NLS-1$
+ break;
+ default:
+ sb.append(curChar);
+ }
+ }
+ return sb.toString();
+ }
+
+
+ private Column[] getSelectableColumns(Select query) {
+ int s = query.getDerivedColumns().size();
+ Column[] interimColumns = new Column[s];
+
+ Iterator<DerivedColumn> selectSymbolItr = query.getDerivedColumns().iterator();
+ int i=0;
+ while(selectSymbolItr.hasNext()) {
+ Column c = getColumnFromSymbol(selectSymbolItr.next());
+ if (!c.isSelectable()) continue;
+
+ interimColumns[i] = c;
+ ++i;
+ }
+
+ // if all columns are included, then return, no need to rebuild the array
+ if (s == i) {
+ return interimColumns;
+ }
+
+ Column[] columns = new Column[i];
+ for (int x=0; x<i; ++x) {
+ columns[x] = interimColumns[x];
+ }
+ return columns;
+
+ }
+
+ private void addException(String columnNameToUse1,
+ String columnNameToUse2, String table) {
+
+ exceptionMessages.add(
+ ObjectPlugin.Util
+ .getString(
+ "ObjectProjections.unsupportedMultipleContainers", new Object[] {
columnNameToUse1, columnNameToUse2, table }));
+
+ }
+
+ private void addException(String message) {
+
+ exceptionMessages.add(
+ ObjectPlugin.Util
+ .getString(
+ "ObjectProjections.errorProcessingVisitor", new Object[] { message
}));
+
+ }
+
+ protected void throwExceptionIfFound() throws TranslatorException {
+ if (!exceptionMessages.isEmpty())
+ throw new TranslatorException("ObjectProjections Exception: " +
exceptionMessages.toString());
+ }
+
+ public String getColumnNameToUse(Column column) {
+ String nis = getNameInSourceForObjectHierarchy(column);
+ if (nis == null) return column.getName();
+ return nis;
+ }
+
+ /**
+ * Method to build the nameInSource nodes to be used to lookup a value, starting with
the root object.
+ * If the column is associated with a table that has a foreign key (i.e, is contained
within), use the nameInSource
+ * of the foreign key as a prefix node in the nameInSource. The process will climb the
foreign key hierarchy tree to
+ * combine to make the NameInSource for the column.
+ * Example: Object hierarchy: "A" = getLegs => "B" =
getTransactions => "C"
+ * The column object would start with "C" and find a foreign key to
"B", having nameInSource of "Transactions"
+ * current nodes in the name are: Transactions."C"
+ *
+ * The process then takes object "B" and determines it has a foreign key to
"A", its nameInSource is "Legs", which is prefixed on the nodes
names.
+ * current nodes in the name are: Legs.Transactions."C"
+ *
+ * The node name structure will allow the object reflection process to traverse the root
object to get to "C" by taking the first node, Legs,
+ * and calling "A".getLegs(), and then processing each object in the
collection by calling "B".getTransations().
+ *
+ * @param e the supplied Element
+ * @return the name
+ */
+ // GHH 20080326 - found that code to fall back on Name if NameInSource
+ // was null wasn't working properly, so replaced with tried and true
+ // code from another custom connector.
+ protected String getNameInSourceForObjectHierarchy(Column e) {
+ String nis = getNameInSourceFromColumn(e);
+
+ Object p = e.getParent();
+ // if the column comes from a table that has a foreign key, then
+ // prepend the nameInSource with the foreign key nameInSource
+ //NOTE: the foreign key NIS should be the name of the container method to find the
column
+ String parentNodeName = null;
+ if (p instanceof Table) {
+ parentNodeName = getForeignKeyNodeName((Table) p);
+ }
+
+ return (parentNodeName != null ? parentNodeName + "." : "") + nis;
+ }
+
+ protected void setRootClassName(Table t) {
+ if (this.rootTable != null) return;
+
+ if (t.getNameInSource() != null) {
+ this.rootTable = t;
+ }
+ }
+
+
+ protected String getNameInSourceFromColumn(Column c) {
+ String name = c.getNameInSource();
+ if(name == null || name.equals("")) { //$NON-NLS-1$
+ return c.getName();
+ }
+ return name;
+ }
+
+
+ protected String getForeignKeyNodeName(Table t) {
+ String fkName = buildForeignKeyName(t);
+ if (fkName != null) {
+ this.fkNames.put(t.getName(), fkName);
+ }
+
+ return fkName;
+ }
+
+ protected String buildForeignKeyName(Table t) {
+ if (t == null) return null;
+
+ if (this.fkNames.containsKey(t.getName()) ) {
+ return this.fkNames.get(t.getName());
+ }
+
+ if (t.getForeignKeys() != null && !t.getForeignKeys().isEmpty()) {
+ ForeignKey fk = (ForeignKey) t.getForeignKeys().get(0);
+ String fk_nis = fk.getNameInSource();
+
+ if (fk.getPrimaryKey() != null && fk.getPrimaryKey().getParent() != t) {
+ String parentNIS = buildForeignKeyName(fk.getPrimaryKey().getParent());
+
+ return (parentNIS != null ? parentNIS + "." : "") + fk_nis;
+ }
+ return fk_nis;
+ } else {
+ setRootClassName(t);
+
+ }
+
+ return null;
+ }
+
+ /**
+ * Helper method for getting {@link org.teiid.metadata.Column} from a
+ * {@link org.teiid.language.DerivedColumn}.
+ * @param symbol Input ISelectSymbol
+ * @return Element returned metadata runtime Element
+ */
+ protected Column getColumnFromSymbol(DerivedColumn symbol) {
+ ColumnReference expr = (ColumnReference) symbol.getExpression();
+ return expr.getMetadataObject();
+ }
+
+ protected void cleanup() {
+ metadata = null;
+ columns = null;
+ columnNamesToUse = null;
+ nameNodes = null;
+ nodeDepth = null;
+ childrenNodes = null;
+ exceptionMessages = null;
+ rootTable = null;
+
+ }
+}
Added:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchCriterion.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchCriterion.java
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchCriterion.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1,149 @@
+package org.teiid.translator.object;
+
+import org.teiid.metadata.Column;
+import org.teiid.metadata.Table;
+
+
+public class SearchCriterion {
+
+ public enum Operator {
+
+ EQUALS,
+ IN,
+ ALL // no criteria, select all objects
+
+ }
+
+ private SearchCriterion addCondition;
+ private boolean isAnd = false;
+
+ private Operator operator;
+ private String operatorString;
+ private Column column;
+ private Object value;
+ private Class<?> type;
+ private boolean isRootTableInSelect = false;
+
+ public SearchCriterion() {
+ this.operator = Operator.ALL;
+ }
+
+
+ public SearchCriterion(Column column, Object value, String operaterString,
Class<?> type) {
+ this.column = column;
+ this.value = value;
+ this.operatorString = operaterString;
+ this.operator = Operator.EQUALS;
+ this.type = type;
+
+ }
+
+ public SearchCriterion(Column column, Object value, String operaterString, Operator
operator, Class<?> type) {
+ this(column, value, operaterString, type);
+ this.operator = operator;
+
+ }
+
+ public Column getColumn() {
+ return column;
+ }
+
+
+ public String getTableName() {
+ Object p = column.getParent();
+ if (p instanceof Table) {
+ Table t = (Table)p;
+ return t.getName();
+ } else {
+ // don't this would happen, but just in case at the moment
+ assert(p.getClass().getName() != null);
+ }
+
+ return null;
+ }
+
+ public String getField() {
+ return getNameInSourceFromColumn(this.column);
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public String getOperatorString() {
+ return this.operatorString;
+ }
+
+ public void setOperatorString(String operatorString){
+ this.operatorString = operatorString;
+
+ }
+
+ public Class<?> getType()
+ {
+ return this.type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+ public void addAndCondition(SearchCriterion condition) {
+ this.addCondition = condition;
+ this.isAnd = true;
+ }
+
+ public void addOrCondition(SearchCriterion condition) {
+ this.addCondition = condition;
+ this.isAnd = false;
+ }
+
+ public SearchCriterion getAddCondition() {
+ return this.addCondition;
+ }
+
+ public boolean isAndCondition() {
+ return this.isAnd;
+ }
+
+ public boolean isRootTableInSelect() {
+ return isRootTableInSelect;
+ }
+
+ public void setRootTableInSelect(boolean isRootTableInSelect) {
+ this.isRootTableInSelect = isRootTableInSelect;
+ }
+
+ private String getNameInSourceFromColumn(Column c) {
+ String name = c.getNameInSource();
+ if(name == null || name.equals("")) { //$NON-NLS-1$
+ return c.getName();
+ }
+ return name;
+ }
+
+
+//
+// public String getAuxValue() {
+// return auxValue;
+// }
+//
+// public void setAuxValue(String auxValue) {
+// this.auxValue = auxValue;
+// }
+//
+
+
+}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheExecutionFactory.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheExecutionFactory.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -31,7 +31,6 @@
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
-import org.teiid.translator.object.ObjectCacheConnection;
import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.ObjectMethodManager;
import org.teiid.translator.object.ObjectSourceProxy;
@@ -102,7 +101,7 @@
}
@Override
- protected ObjectSourceProxy createProxy(ObjectCacheConnection connection)
+ protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
return new MapCacheProxy(connection, this);
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheProxy.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheProxy.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/example/MapCacheProxy.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -28,16 +28,15 @@
import org.teiid.language.Command;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectVisitor;
import org.teiid.translator.object.ObjectSourceProxy;
public class MapCacheProxy implements ObjectSourceProxy {
private MapCacheObjectVisitor visitor = new MapCacheObjectVisitor();
-// private Object connection;
private MapCacheExecutionFactory factory;
public MapCacheProxy(Object connection, MapCacheExecutionFactory factory) {
-// this.connection = connection;
this.factory = factory;
}
@@ -48,8 +47,7 @@
@Override
- public List<Object> get(Command command, String cache, String rootClassName)
throws TranslatorException {
- visitor.visitNode(command);
+ public List<Object> get(Command command, String cache, ObjectVisitor
sourceProjections) throws TranslatorException {
List<Object> results = null;
if (visitor.compare) {
Added:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanCacheConnection.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanCacheConnection.java
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanCacheConnection.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1,12 @@
+package org.teiid.translator.object.infinispan;
+
+import java.util.List;
+
+import org.teiid.translator.object.SearchCriterion;
+
+
+public interface InfinispanCacheConnection {
+
+ List<Object> get(SearchCriterion criterion, String cacheName, Class<?>
rootNodeType) throws Exception ;
+
+}
Deleted:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanObjectVisitor.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanObjectVisitor.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanObjectVisitor.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -1,348 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.object.infinispan;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Comparison.Operator;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.In;
-import org.teiid.language.Like;
-import org.teiid.language.Literal;
-import org.teiid.language.ScalarSubquery;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.visitor.HierarchyVisitor;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.Table;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.object.ObjectPlugin;
-
-
-/**
- * This is an example of extending ObjectVisitor, providing query access to a local Map
object cache
- */
-public class InfinispanObjectVisitor extends HierarchyVisitor {
-
- protected TranslatorException exception;
- public String tableName;
- public String columnName;
- public Object value;
- public Class<?> classType;
- public List<Object> parms;
- public Operator op;
-
- public boolean like = false;
- public boolean compare = false;
- public boolean in = false;
-
- /**
- *
- */
- public InfinispanObjectVisitor() {
- super();
- }
-
-
-
- public List<Object> getKeyCriteria() {
- // TODO Auto-generated method stub
- if (parms != null) return parms;
-
- if (value == null) return Collections.EMPTY_LIST;
-
- List result = new ArrayList(1);
- result.add(value);
- return result;
- }
-
-
-
-
- public void addCompareCriteria(String tableName,
- String columnName, Object value, Operator op,
- Class<?> type) throws TranslatorException {
- this.tableName = tableName;
- this.columnName = columnName;
- this.op = op;
- this.value = value;
- this.compare = true;
- this.classType = type;
- }
-
- public void addLikeCriteria(String tableName,
- String columnName, Object value)
- throws TranslatorException {
- this.tableName = tableName;
- this.columnName = columnName;
- this.value = value;
- this.like = true;
- }
-
- public void addInCriteria(String tableName, String columnName,
- List<Object> parms, Class<?> type)
- throws TranslatorException {
- this.tableName = tableName;
- this.columnName = columnName;
- this.parms = parms;
- this.in = true;
- this.classType = type;
- }
-
- public TranslatorException getException() {
- return this.exception;
- }
-
-
- public void visit(Comparison obj) {
- LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison
criteria."); //$NON-NLS-1$
- try {
-
- Comparison.Operator op = ((Comparison) obj).getOperator();
-
- Expression lhs = ((Comparison) obj).getLeftExpression();
- Expression rhs = ((Comparison) obj).getRightExpression();
-
- // comparison between the ojbects is not usable, because the nameInSource and its
parent(s)
- // will be how the child objects are obtained
- if (lhs instanceof ColumnReference && rhs instanceof ColumnReference) {
- return;
- }
-
-
- String lhsString = getExpressionString(lhs);
- String rhsString = getExpressionString(rhs);
- if(lhsString == null || rhsString == null) {
- final String msg =
ObjectPlugin.Util.getString("ObjectVisitor.missingComparisonExpression");
//$NON-NLS-1$
- exception = new TranslatorException(msg);
- }
-
- if (rhs instanceof Literal || lhs instanceof Literal) {
- if(rhs instanceof Literal) {
- Literal literal = (Literal) rhs;
- String tableName = getTableNameFromColumnObject(lhs);
- addCompareCriteria(tableName, lhsString, literal.getValue(), op,
literal.getType());
-
- } else {
- Literal literal = (Literal) lhs;
- String tableName = getTableNameFromColumnObject(rhs);
- addCompareCriteria(tableName, rhsString, literal.getValue(), op,
literal.getType());
-
-
- }
- }
- }catch (TranslatorException t) {
- exception = t;
- }
- }
-
-
- public void visit(Like obj) {
-
- LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing LIKE criteria.");
//$NON-NLS-1$
-// isNegated = ((Like) criteria).isNegated();
- // Convert LIKE to Equals, where any "%" symbol is replaced with
"*".
- try {
-
- Comparison.Operator op = Operator.EQ;
- Expression lhs = ((Like) obj).getLeftExpression();
- Expression rhs = ((Like) obj).getRightExpression();
-
- String tableName = getTableNameFromColumnObject(lhs);
- if (tableName == null) {
- tableName = getTableNameFromColumnObject(rhs);
- }
-
- String lhsString = getExpressionString(lhs);
- String rhsString = getExpressionString(rhs);
-
- addLikeCriteria(tableName, lhsString, rhsString);
-
- }catch (TranslatorException t) {
- exception = t;
- }
- }
-
-
- public void visit(In obj) {
- LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria.");
//$NON-NLS-1$
-// isNegated = ((In) criteria).isNegated();
- try {
-
- Expression lhs = ((In)obj).getLeftExpression();
-
- String tableName = getTableNameFromColumnObject(lhs);
- String colName = getExpressionString(lhs);
-
- List<Expression> rhsList = ((In)obj).getRightExpressions();
-
- Class type = lhs.getType();
- List parms = new ArrayList(rhsList.size());
- Iterator iter = rhsList.iterator();
- while(iter.hasNext()) {
-
- Expression expr = (Expression) iter.next();
- type = addParmFromExpression(expr, parms);
-
- }
- addInCriteria(tableName, colName, parms, type);
-
- }catch (TranslatorException t) {
- exception = t;
- }
-
- }
-
- protected String getTableNameFromColumnObject(Object e) {
- Column col = null;
- if(e instanceof ColumnReference) {
- col = ((ColumnReference)e).getMetadataObject();
- } else if (e instanceof Column) {
- col = (Column) e;
- }
-
- Object p = col.getParent();
- if (p instanceof Table) {
- Table t = (Table)p;
- return t.getName();
- }
-
- return null;
-
- }
-
- protected Class addParmFromExpression(Expression expr, List parms ) {
- Class type = null;
- if(expr instanceof Literal) {
- Long longparm = null;
- Literal literal = (Literal) expr;
-
- parms.add(literal);
-
- type = literal.getType();
-
- } else {
- this.exception = new
TranslatorException("ObjectVisitor.Unsupported_expression" + expr);
//$NON-NLS-1$
- }
-
- return type;
-
- }
-
-
- // GHH 20080326 - found that code to fall back on Name if NameInSource
- // was null wasn't working properly, so replaced with tried and true
- // code from another custom connector.
- private String getExpressionString(Expression e) throws TranslatorException {
- String expressionName = null;
- // GHH 20080326 - changed around the IElement handling here
- // - the rest of this method is unchanged
- if(e instanceof ColumnReference) {
- Column mdIDElement = ((ColumnReference)e).getMetadataObject();
- expressionName = getNameInSourceFromColumn(mdIDElement);
-// expressionName = mdIDElement.getNameInSource();
-// if(expressionName == null || expressionName.equals("")) { //$NON-NLS-1$
-// expressionName = mdIDElement.getName();
-// }
- } else if(e instanceof Literal) {
-// try {
-// if(((Literal)e).getType().equals(Class.forName(Timestamp.class.getName()))) {
-// LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Found an expression that
uses timestamp; converting to LDAP string format."); //$NON-NLS-1$
-// Timestamp ts = (Timestamp)((Literal)e).getValue();
-// Date dt = new Date(ts.getTime());
-// //TODO: Fetch format if provided.
-// SimpleDateFormat sdf = new
SimpleDateFormat(LDAPConnectorConstants.ldapTimestampFormat);
-// expressionName = sdf.format(dt);
-// LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Timestamp to stsring is:
" + expressionName); //$NON-NLS-1$
-// }
-// else {
-// expressionName = ((Literal)e).getValue().toString();
-// }
-
- expressionName = ((Literal)e).getValue().toString();
-// } catch (ClassNotFoundException cce) {
-// final String msg =
LDAPPlugin.Util.getString("IQueryToLdapSearchParser.timestampClassNotFoundError");
//$NON-NLS-1$
-// throw new TranslatorException(cce, msg);
-// }
-//
- } else {
- if(e instanceof AggregateFunction) {
- LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IAggregate, but it is
not supported. Check capabilities."); //$NON-NLS-1$
- } else if(e instanceof Function) {
- LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IFunction, but it is
not supported. Check capabilties."); //$NON-NLS-1$
- } else if(e instanceof ScalarSubquery) {
- LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IScalarSubquery, but
it is not supported. Check capabilties."); //$NON-NLS-1$
- } else if (e instanceof SearchedCase) {
- LogManager.logError(LogConstants.CTX_CONNECTOR, "Received
ISearchedCaseExpression, but it is not supported. Check capabilties.");
//$NON-NLS-1$
- }
- final String msg =
ObjectPlugin.Util.getString("ObjectVisitor.unsupportedElementError" ,
e.toString()); //$NON-NLS-1$
- throw new TranslatorException(msg);
- }
- expressionName = escapeReservedChars(expressionName);
- return expressionName;
- }
-
- protected String getNameInSourceFromColumn(Column c) {
- String name = c.getNameInSource();
- if(name == null || name.equals("")) { //$NON-NLS-1$
- return c.getName();
- }
- return name;
- }
-
- protected static String escapeReservedChars(final String expr) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < expr.length(); i++) {
- char curChar = expr.charAt(i);
- switch (curChar) {
- case '\\':
- sb.append("\\5c"); //$NON-NLS-1$
- break;
- case '*':
- sb.append("\\2a"); //$NON-NLS-1$
- break;
- case '(':
- sb.append("\\28"); //$NON-NLS-1$
- break;
- case ')':
- sb.append("\\29"); //$NON-NLS-1$
- break;
- case '\u0000':
- sb.append("\\00"); //$NON-NLS-1$
- break;
- default:
- sb.append(curChar);
- }
- }
- return sb.toString();
- }
-
-}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanProxy.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanProxy.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanProxy.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -22,17 +22,12 @@
package org.teiid.translator.object.infinispan;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.teiid.core.BundleUtil;
import org.teiid.language.Command;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.object.ObjectCacheConnection;
+import org.teiid.translator.object.ObjectVisitor;
import org.teiid.translator.object.ObjectSourceProxy;
/**
@@ -42,11 +37,10 @@
public static final BundleUtil UTIL = BundleUtil.getBundleUtil(InfinispanProxy.class);
- private InfinispanObjectVisitor visitor = new InfinispanObjectVisitor();
private InfinispanRemoteExecutionFactory factory;
- private ObjectCacheConnection connection;
+ private InfinispanCacheConnection connection;
- public InfinispanProxy(ObjectCacheConnection connection,
InfinispanRemoteExecutionFactory factory) {
+ public InfinispanProxy(InfinispanCacheConnection connection,
InfinispanRemoteExecutionFactory factory) {
this.factory = factory;
this.connection = connection;
}
@@ -54,23 +48,22 @@
@Override
public void close() {
- this.visitor = null;
this.factory = null;
+ this.connection = null;
}
@Override
- public List<Object> get(Command command, String cache, String rootClassName)
throws TranslatorException {
- visitor.visitNode(command);
+ public List<Object> get(Command command, String cache, ObjectVisitor visitor)
throws TranslatorException {
Class<?> rootClass = null;
- if (this.factory.getObjectMethodManager().getClassMethods(rootClassName) == null) {
- rootClass = this.factory.getObjectMethodManager().loadClassByName(rootClassName,
null);
+ if
(this.factory.getObjectMethodManager().getClassMethods(visitor.getRootNodeClassName()) ==
null) {
+ rootClass =
this.factory.getObjectMethodManager().loadClassByName(visitor.getRootNodeClassName(),
null);
} else {
- rootClass =
this.factory.getObjectMethodManager().getClassMethods(rootClassName).getClassIdentifier();
+ rootClass =
this.factory.getObjectMethodManager().getClassMethods(visitor.getRootNodeClassName()).getClassIdentifier();
}
try {
- return connection.get(visitor.getKeyCriteria(), cache, rootClass);
+ return connection.get(visitor.getCriterion(), cache, rootClass);
} catch (Exception e) {
throw new TranslatorException(e.getMessage());
}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -3,11 +3,11 @@
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.object.ObjectCacheConnection;
import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.ObjectSourceProxy;
@Translator(name="infinispanRemote", description="The Execution Factory
for Remote Infinispan Cache")
+
public class InfinispanRemoteExecutionFactory extends ObjectExecutionFactory {
public InfinispanRemoteExecutionFactory() {
@@ -21,9 +21,9 @@
}
- protected ObjectSourceProxy createProxy(ObjectCacheConnection connection)
+ protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
- return new InfinispanProxy(connection, this);
+ return new InfinispanProxy((InfinispanCacheConnection) connection, this);
}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -48,6 +48,8 @@
private static final int MAX_COL_WIDTH = 65;
+ protected static boolean print = false;
+
public static void writeActualResultsToFile(boolean write) {
WRITE_ACTUAL_RESULTS_TO_FILE = write;
}
@@ -113,9 +115,18 @@
}
}
}
+
+ public static void compareResultSet(List<Object> rs) throws IOException,
SQLException {
+ StackTraceElement ste = new Exception().getStackTrace()[1];
+ String testName = ste.getMethodName();
+ String className = ste.getClassName();
+ className = className.substring(className.lastIndexOf('.') + 1);
+ testName = className + "/" + testName; //$NON-NLS-1$
+ compareResultSet(testName, rs);
+ }
- public static void compareResultSet(String testName, List<Object>... rs)
+ public static void compareResultSet(String testName, List<Object> rs)
throws FileNotFoundException, SQLException, IOException {
FileOutputStream actualOut = null;
BufferedReader expectedIn = null;
@@ -137,8 +148,8 @@
// ObjectOutput oo = null;
// oo = new ObjectOutputStream(actualOut);
- for (int i = 0; i < rs.length; i++) {
- List<Object> r = rs[i];
+ for (int i = 0; i < rs.size(); i++) {
+ List<Object> r = (List) rs.get(i);
actualOut.write( new String("ROW_" + i).getBytes());
for (Iterator it=r.iterator(); it.hasNext();) {
Object o = it.next();
@@ -188,4 +199,18 @@
}
}
+ protected void printRow(int rownum, List<?> row) {
+ if (!print) return;
+ if (row == null) {
+ System.out.println("Row " + rownum + " is null");
+ return;
+ }
+ int i = 0;
+ for(Object o:row) {
+ System.out.println("Row " + rownum + " Col " + i + " - "
+ o.toString());
+ ++i;
+ }
+
+ }
+
}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -22,12 +22,16 @@
package org.teiid.translator.object;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
import java.util.List;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.teiid.language.Command;
import org.teiid.language.Select;
import org.teiid.translator.ExecutionContext;
@@ -40,25 +44,29 @@
private static TradesCacheSource source;
private static ObjectExecutionFactory factory;
- private static ExecutionContext context;
+
+ @Mock
+ private ExecutionContext context;
+
+ @Mock
+ private ObjectVisitor visitor;
-
- @BeforeClass
- public static void beforeEach() throws Exception {
+ @Before public void beforeEach() throws Exception{
+
+ MockitoAnnotations.initMocks(this);
+
source = TradesCacheSource.loadCache();
-
- context = Mockito.mock(ExecutionContext.class);
factory = new ObjectExecutionFactory() {
@Override
- protected ObjectSourceProxy createProxy(ObjectCacheConnection connection)
+ protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
return new ObjectSourceProxy() {
@Override
- public List<Object> get(Command command, String cacheName, String className)
throws TranslatorException {
+ public List<Object> get(Command command, String cacheName, ObjectVisitor
visitor) throws TranslatorException {
return source.getAll();
}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -24,21 +24,18 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
-
-
import org.junit.Test;
import org.mockito.Mockito;
-import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl;
import org.teiid.language.Select;
import org.teiid.metadata.Datatype;
import org.teiid.metadata.MetadataFactory;
-import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.index.VDBMetadataFactory;
-import org.teiid.query.metadata.CompositeMetadataStore;
-import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.util.VDBUtility;
@@ -57,7 +54,7 @@
ObjectExecutionFactory factory = new ObjectExecutionFactory() {
@Override
- protected ObjectSourceProxy createProxy(ObjectCacheConnection connection)
+ protected ObjectSourceProxy createProxy( Object connection)
throws TranslatorException {
return proxy;
@@ -89,7 +86,7 @@
ObjectExecutionFactory factory = new ObjectExecutionFactory() {
@Override
- protected ObjectSourceProxy createProxy(ObjectCacheConnection connection)
+ protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
return proxy;
@@ -126,7 +123,7 @@
ObjectExecutionFactory factory = new ObjectExecutionFactory() {
@Override
- protected ObjectSourceProxy createProxy(ObjectCacheConnection connection)
+ protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
return proxy;
Deleted:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -1,85 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.translator.object;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.teiid.language.Select;
-import org.teiid.translator.object.testdata.Trade;
-import org.teiid.translator.object.util.VDBUtility;
-
-@SuppressWarnings("nls")
-public class TestObjectProjections {
-
-
- @Test public void testQueryRootObject() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade"); //$NON-NLS-1$
-
- ObjectProjections op = new ObjectProjections(command);
-
- validateResults(4, 0, op);
-
-
- }
-
- @Test public void testQueryIncludeLegs() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
-
- ObjectProjections op = new ObjectProjections(command);
- validateResults(3, 1, op);
- }
-
- @Test public void testQueryGetAllTransactions() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName, " +
- " N.LineItem " +
- " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction
as N " +
- " Where T.TradeId = L.TradeId and L.LegId = N.LegId"); //$NON-NLS-1$
- ObjectProjections op = new ObjectProjections(command);
- validateResults(4, 2, op);
-
-
- }
-
- private void validateResults(int size, int depth, ObjectProjections op) throws Exception
{
- op.throwExceptionIfFound();
-
- assertEquals(Trade.class.getName(), op.rootNodeClassName);
- assertEquals(size, op.getColumnNamesToUse().length);
- assertEquals(size, op.getColumns().length);
-
- int d = (op.childrenDepth > -1 ? op.childrenDepth : 0 );
-
- assertEquals(depth, d);
-
- //if children, then there should always be one more child node than the depth
- assertEquals(depth, (op.childrenNodes == null ? 0 : op.childrenNodes.size() - 1) );
- assertEquals(size, op.nameNodes.length);
- assertEquals(size, op.nodeDepth.length);
-
- // confirm the arrays match
- for (int i = 0; i < op.getColumns().length; i++) {
- assertEquals(op.getColumnNamesToUse()[i],
op.getColumnNameToUse(op.getColumns()[i]));
- }
- }
-
-}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -22,11 +22,15 @@
package org.teiid.translator.object;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
import java.util.List;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.teiid.language.Select;
import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
@@ -36,10 +40,17 @@
private static TradesCacheSource source;
- @BeforeClass
- public static void beforeEach() throws Exception {
+ @Mock
+ private ObjectExecutionFactory factory;
+
+ @Before public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
+
+ when(factory.isSupportFilters()).thenReturn(true);
+
source = TradesCacheSource.loadCache();
- }
+
+ }
@Test public void testQueryGetAllTrades() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade"); //$NON-NLS-1$
@@ -64,12 +75,13 @@
private void runTest(Select command, int rows, int columns) throws Exception {
- ObjectProjections op = new ObjectProjections(command);
+ ObjectVisitor visitor = new ObjectVisitor(factory, VDBUtility.RUNTIME_METADATA);
+ visitor.visit(command);
ObjectMethodManager omm = ObjectMethodManager.initialize(true,
this.getClass().getClassLoader());
- List<List<Object>> results =
ObjectTranslator.translateObjects(source.getAll(), op, omm);
+ List<List<Object>> results =
ObjectTranslator.translateObjects(source.getAll(), visitor, omm);
assertEquals(rows, results.size());
Added:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectVisitor.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectVisitor.java
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectVisitor.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1,258 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.object;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.teiid.language.Select;
+import org.teiid.metadata.Column;
+import org.teiid.translator.object.testdata.Trade;
+import org.teiid.translator.object.util.VDBUtility;
+
+
+@SuppressWarnings("nls")
+public class TestObjectVisitor {
+
+
+ @Mock
+ private ObjectExecutionFactory factory;
+
+ @Before public void beforeEach() {
+
+ MockitoAnnotations.initMocks(this);
+
+ when(factory.isSupportFilters()).thenReturn(true);
+
+ }
+
+
+ @Test public void testQueryRootObject() throws Exception {
+
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+ validateResults(4, 0, true, visitor);
+
+ }
+
+ @Test public void testQueryWithNonSearchableColumn() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
L.Name as LegName, L.TradeId as ID From Trade_Object.Leg as L"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+ validateResults(1, 1, false, visitor);
+ }
+
+
+ @Test public void testQuery1LevelDownWithRootNotInSelect() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
L.Name as LegName From Trade_Object.Leg as L"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+ validateResults(1, 1, false, visitor);
+ }
+
+ @Test public void testQuery2LevelDownWithRootNotInSelect() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
N.LineItem " +
+ " From Trade_Object.Transaction as N "); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+ validateResults(1, 2, false, visitor);
+
+ }
+
+ @Test public void testQueryIncludeLegs() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+ validateResults(3, 1, true, visitor);
+ }
+
+ @Test public void testQueryGetAllTransactions() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName, " +
+ " N.LineItem " +
+ " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction
as N " +
+ " Where T.TradeId = L.TradeId and L.LegId = N.LegId"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+ validateResults(4, 2, true, visitor);
+
+ }
+
+ private ObjectVisitor createVisitor(Select command) {
+ ObjectVisitor visitor = new ObjectVisitor(factory, VDBUtility.RUNTIME_METADATA);
+ visitor.visitNode(command);
+ return visitor;
+
+ }
+
+
+ private void validateResults(int size, int depth, boolean rootNodeInQuery, ObjectVisitor
visitor) throws Exception {
+ visitor.throwExceptionIfFound();
+
+ assertEquals(Trade.class.getName(), visitor.getRootTable().getNameInSource());
+ assertEquals(size, visitor.getColumnNamesToUse().length);
+ assertEquals(size, visitor.getColumns().length);
+ assertEquals(rootNodeInQuery, visitor.isRootTableInFrom());
+
+ int d = (visitor.childrenDepth > -1 ? visitor.childrenDepth : 0 );
+
+ assertEquals(depth, d);
+
+ //if children, then there should always be one more child node than the depth
+ assertEquals(depth, (visitor.childrenNodes == null ? 0 :
visitor.childrenNodes.size() - 1) );
+ assertEquals(size, visitor.nameNodes.length);
+ assertEquals(size, visitor.nodeDepth.length);
+
+ // confirm the arrays match
+ for (int i = 0; i < visitor.getColumns().length; i++) {
+ assertEquals(visitor.getColumnNamesToUse()[i],
visitor.getColumnNameToUse(visitor.getColumns()[i]));
+ }
+ }
+
+
+ @Test public void testIN() throws Exception {
+
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.TradeID IN (1,2,3)"); //$NON-NLS-1$
+
+ ObjectVisitor visitor = createVisitor(command);
+
+ validateResults(4, 0, true, visitor);
+// validateSelectVisitorAllRootTableColumns(visitor, null, 4);
+
+ assertNotNull("Key Column In Search", visitor.getCriterion());
+
+ assertEquals("Filters", visitor.getFilters().size(), 0);
+
+ }
+
+ @Test public void test1Equals() throws Exception {
+
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.TradeID = 1"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+
+ validateSelectVisitorAllRootTableColumns(visitor, null, 4);
+
+ assertNotNull("Key Column In Search", visitor.getCriterion());
+
+ assertEquals("Filters", visitor.getFilters().size(), 0);
+
+ }
+
+ @Test public void test1EqualsFilter() throws Exception {
+
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.Name = 'MyName'");
//$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+
+ List<String> names = new ArrayList(1);
+ names.add("Name");
+ validateSelectVisitorAllRootTableColumns(visitor, names, 4);
+
+ assertNotNull("Key Column In Search", visitor.getCriterion());
+
+ assertEquals("Filters", visitor.getFilters().size(), 1);
+
+ }
+
+
+ @Test public void testQueryIncludeLegsNoCriteria() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
+
+ ObjectVisitor visitor = createVisitor(command);
+ validateSelectVisitorAllRootTableColumns(visitor, null, 3);
+
+ assertEquals("Filters", visitor.getFilters().size(), 0);
+
+ }
+
+ @Test public void testQueryIncludeLegsWithCriteria() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId and L.Name='MyLeg'");
//$NON-NLS-1$
+
+ ObjectVisitor visitor = createVisitor(command);
+ List<String> names = new ArrayList(1);
+ names.add("Name");
+ validateSelectVisitorAllRootTableColumns(visitor, names, 3);
+
+ assertEquals("Filters", visitor.getFilters().size(), 1);
+
+ }
+
+ @Test public void testQueryGetAllTransactionsNoCriteria() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName, " +
+ " N.LineItem " +
+ " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction
as N " +
+ " Where T.TradeId = L.TradeId and L.LegId = N.LegId "); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+
+ validateSelectVisitorAllRootTableColumns(visitor, null, 4);
+
+ assertEquals("Filters", visitor.getFilters().size(), 0);
+
+
+ }
+ @Test public void testQueryGetTransactionsUseKeyCriteria() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName, " +
+ " N.LineItem " +
+ " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction
as N " +
+ " Where T.TradeId = L.TradeId and L.LegId = N.LegId and T.TradeId in (1,2,3)
"); //$NON-NLS-1$
+ ObjectVisitor visitor = createVisitor(command);
+
+ validateSelectVisitorAllRootTableColumns(visitor, null, 4);
+
+ assertNotNull("Key Column In Search", visitor.getCriterion());
+ assertEquals("Filters", visitor.getFilters().size(), 0);
+
+ }
+
+ private void validateSelectVisitorAllRootTableColumns(ObjectVisitor visitor,
List<String> columnFilters, int numOfColumns) throws Exception {
+
+ Column[] columns = visitor.getColumns();
+ String[] columnNamesToUse = visitor.getColumnNamesToUse();
+
+ assertNotNull("ColumnNames", columns);
+ assertEquals("Column Names", numOfColumns, columns.length);
+ assertEquals("Column Names", columnNamesToUse.length, columns.length);
+
+
+ boolean hasName = false;
+ boolean hasTradeId = false;
+ for (int i=0; i<columns.length; i++) {
+ Column col = columns[i];
+ if (col.getName().equalsIgnoreCase("Name")) hasName = true;
+ else if (col.getName().equalsIgnoreCase("TradeId")) hasTradeId = true;
+ assertNotNull("Column Type", col.getDatatype());
+ assertNotNull("Column Java Type", col.getJavaType());
+ assertNotNull("Column Name to Use", columnNamesToUse[i]);
+ assertNotNull("Column Native Type", col.getNativeType());
+
+ assertNotNull("Column Table Name", col.getParent().getName());
+
+
+ }
+
+ assertTrue("Missing NAME column", hasName);
+ assertTrue("Missing TRADEID column", hasTradeId);
+ }
+
+}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheIntegration.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheIntegration.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheIntegration.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -23,6 +23,7 @@
import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
@@ -31,130 +32,117 @@
import org.teiid.language.Select;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.object.BaseObjectTest;
-import org.teiid.translator.object.ObjectCacheConnection;
import org.teiid.translator.object.ObjectExecution;
-import org.teiid.translator.object.example.MapCacheExecutionFactory;
+import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
@SuppressWarnings("nls")
public class TestMapCacheIntegration extends BaseObjectTest {
+
- private static boolean print = false;
+ protected static boolean print = false;
@Test public void testQueryIncludeLegs() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
ExecutionContext context = Mockito.mock(ExecutionContext.class);
-
- ObjectCacheConnection connection = Mockito.mock(ObjectCacheConnection.class);
MapCacheExecutionFactory factory = new MapCacheExecutionFactory();
factory.setCacheLoaderClassName("org.teiid.translator.object.util.TradesCacheSource");
factory.start();
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
exec.execute();
+ List<Object> rows = new ArrayList<Object>();
int cnt = 0;
List<Object> row = exec.next();
-
-// BaseObjectTest.compareResultSet("testQueryIncludeLegs", row);
while (row != null) {
+ rows.add(row);
++cnt;
row = exec.next();
printRow(cnt, row);
- }
+ }
+
+ assertEquals("Did not get expected number of rows",
TradesCacheSource.NUMTRADES * TradesCacheSource.NUMLEGS, cnt); //$NON-NLS-1$
+ this.compareResultSet(rows);
- assertEquals("Did not get expected number of rows", 30, cnt); //$NON-NLS-1$
-
exec.close();
}
- @Ignore
@Test public void testQueryGetTrades() throws Exception {
- WRITE_ACTUAL_RESULTS_TO_FILE = true;
+
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade"); //$NON-NLS-1$
ExecutionContext context = Mockito.mock(ExecutionContext.class);
- ObjectCacheConnection connection = Mockito.mock(ObjectCacheConnection.class);
MapCacheExecutionFactory factory = new MapCacheExecutionFactory();
- factory.setCacheLoaderClassName("org.teiid.translator.object.testdata.TradesCacheSource");
+ factory.setCacheLoaderClassName("org.teiid.translator.object.util.TradesCacheSource");
factory.start();
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
exec.execute();
+ List<Object> rows = new ArrayList<Object>();
int cnt = 0;
List<Object> row = exec.next();
-
-// BaseObjectTest.compareResultSet("testQueryIncludeLegs", row);
while (row != null) {
+ rows.add(row);
++cnt;
row = exec.next();
printRow(cnt, row);
}
-
- assertEquals("Did not get expected number of rows", 30, cnt); //$NON-NLS-1$
+ assertEquals("Did not get expected number of rows",
TradesCacheSource.NUMTRADES, cnt); //$NON-NLS-1$
+
+ this.compareResultSet(rows);
exec.close();
}
- @Ignore
@Test public void testQueryGetTransaction() throws Exception {
- WRITE_ACTUAL_RESULTS_TO_FILE = true;
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Transaction"); //$NON-NLS-1$
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName, " +
+ " N.LineItem " +
+ " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction
as N " +
+ " Where T.TradeId = L.TradeId and L.LegId = N.LegId"); //$NON-NLS-1$
ExecutionContext context = Mockito.mock(ExecutionContext.class);
- ObjectCacheConnection connection = Mockito.mock(ObjectCacheConnection.class);
MapCacheExecutionFactory factory = new MapCacheExecutionFactory();
- factory.setCacheLoaderClassName("org.teiid.translator.object.testdata.TradesCacheSource");
+ factory.setCacheLoaderClassName("org.teiid.translator.object.util.TradesCacheSource");
factory.start();
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
exec.execute();
+ List<Object> rows = new ArrayList<Object>();
int cnt = 0;
List<Object> row = exec.next();
-
-// BaseObjectTest.compareResultSet("testQueryIncludeLegs", row);
while (row != null) {
+ rows.add(row);
++cnt;
row = exec.next();
printRow(cnt, row);
}
-
- assertEquals("Did not get expected number of rows", 50, cnt); //$NON-NLS-1$
+ int total = TradesCacheSource.NUMTRADES * TradesCacheSource.NUMLEGS *
TradesCacheSource.NUMTRANSACTIONS;
+ assertEquals("Did not get expected number of rows", total, cnt);
//$NON-NLS-1$
+
+ this.compareResultSet(rows);
exec.close();
}
- private void printRow(int rownum, List<?> row) {
- if (!print) return;
- if (row == null) {
- System.out.println("Row " + rownum + " is null");
- return;
- }
- int i = 0;
- for(Object o:row) {
- System.out.println("Row " + rownum + " Col " + i + " - "
+ o.toString());
- ++i;
- }
-
- }
}
Deleted:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheVisitor.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheVisitor.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/example/TestMapCacheVisitor.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -1,154 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.translator.object.example;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.teiid.language.Comparison.Operator;
-import org.teiid.language.Select;
-import org.teiid.metadata.Column;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.object.ObjectProjections;
-import org.teiid.translator.object.testdata.Trade;
-import org.teiid.translator.object.util.VDBUtility;
-
-
-@SuppressWarnings("nls")
-public class TestMapCacheVisitor {
-
- private static int CNT = 0;
- @Before public void setup() {
- CNT = 0;
- }
-
- @Test public void testIN() throws Exception {
-
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.TradeID IN (1,2,3)"); //$NON-NLS-1$
- ObjectProjections op = new ObjectProjections(command);
-
- MapCacheObjectVisitor visitor =new MapCacheObjectVisitor() {
- @Override
- public void addInCriteria(String objectName, String attributeName,
- List<Object> parms, Class<?> type)
- throws TranslatorException {
- CNT+=parms.size();
- }
-
- };
-
- visitor.visit(command);
-
- validateSelectVisitorAllRootTableColumns(op);
- assertEquals("In Criteria", 3, CNT);
-
- }
-
- @Test public void test1Equals() throws Exception {
-
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.TradeID = 1"); //$NON-NLS-1$
- ObjectProjections op = new ObjectProjections(command);
-
- MapCacheObjectVisitor visitor =new MapCacheObjectVisitor() {
-
- @Override
- public void addCompareCriteria(String objectName,
- String attributeName, Object value, Operator op,
- Class<?> type) throws TranslatorException {
-
- if (value.toString().equals("1")) {
- ++CNT;
- }
- }
-
- };
-
- visitor.visit(command);
-
- validateSelectVisitorAllRootTableColumns(op);
- assertEquals("Equals Criteria", 1, CNT);
- }
-
- @Test public void testLike() throws Exception {
-
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.Name like 'Test%'");
//$NON-NLS-1$
- ObjectProjections op = new ObjectProjections(command);
- MapCacheObjectVisitor visitor =new MapCacheObjectVisitor() {
-
- @Override
- public void addLikeCriteria(String objectName,
- String attributeName, Object value)
- throws TranslatorException {
-
- if (value.toString().equals("Test%")) {
- ++CNT;
- }
- }
-
- };
-
- visitor.visit(command);
-
- validateSelectVisitorAllRootTableColumns(op);
- assertEquals("Like Criteria", 1, CNT);
- }
-
- private void validateSelectVisitorAllRootTableColumns(ObjectProjections visitor) throws
Exception {
-
- Column[] columns = visitor.getColumns();
- String[] columnNamesToUse = visitor.getColumnNamesToUse();
-
-// String[] colnames = visitor.getColumnNames();
-
- assertNotNull("ColumnNames", columns);
- assertEquals("Column Names", Trade.NUM_ATTRIBUTES, columns.length);
- assertEquals("Column Names", columnNamesToUse.length, columns.length);
-
-
- boolean hasName = false;
- boolean hasTradeId = false;
- for (int i=0; i<columns.length; i++) {
- Column col = columns[i];
- if (col.getName().equalsIgnoreCase("Name")) hasName = true;
- else if (col.getName().equalsIgnoreCase("TradeId")) hasTradeId = true;
- // don't validate NIS, because it can be null
-// assertNotNull("Column NIS", visitor.getColumnNameInSource(colnames[i]));
- assertNotNull("Column Type", col.getDatatype());
- assertNotNull("Column Java Type", col.getJavaType());
- assertNotNull("Column Name to Use", columnNamesToUse[i]);
- assertNotNull("Column Native Type", col.getNativeType());
-
- assertNotNull("Column Table Name", col.getParent().getName());
-
-
- }
-
- assertTrue("Missing NAME column", hasName);
- assertTrue("Missing TRADEID column", hasTradeId);
- }
-
-}
Added:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanIntegration.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanIntegration.java
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanIntegration.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1,233 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.object.infinispan;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.language.Select;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.BaseObjectTest;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.SearchCriterion;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+
+@SuppressWarnings("nls")
+public class TestInfinispanIntegration extends BaseObjectTest {
+
+ private static ExecutionContext context;
+
+
+ @BeforeClass
+ public static void beforeEach() throws Exception {
+ //print = true;
+ context = Mockito.mock(ExecutionContext.class);
+ }
+
+ @Test public void testQueryIncludeLegs() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
+
+ InfinispanCacheConnection connection = new InfinispanCacheConnection() {
+
+ @Override
+ public List<Object> get(SearchCriterion criterion, String cacheName,
Class<?> rootNodeType)
+ throws TranslatorException {
+
+ return TradesCacheSource.loadCache().getAll();
+ }
+
+ };
+
+ InfinispanRemoteExecutionFactory factory = new InfinispanRemoteExecutionFactory();
+ factory.setCacheName("Trades");
+ factory.setClassNamesOfCachedObjects(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+
+ exec.execute();
+
+ List<Object> rows = new ArrayList<Object>();
+
+ int cnt = 0;
+ List<Object> row = exec.next();
+
+
+ while (row != null) {
+ rows.add(row);
+ ++cnt;
+ row = exec.next();
+
+ }
+
+
+ assertEquals("Did not get expected number of rows", 30, cnt); //$NON-NLS-1$
+
+ this.compareResultSet(rows);
+
+ exec.close();
+
+ }
+
+ @Test public void testQueryIncludeLegsWithFilter() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId and L.Name = 'LegName 1'");
//$NON-NLS-1$
+
+ InfinispanCacheConnection connection = new InfinispanCacheConnection() {
+
+ @Override
+ public List<Object> get(SearchCriterion criterion, String cacheName,
Class<?> rootNodeType)
+ throws TranslatorException {
+
+ return TradesCacheSource.loadCache().getAll();
+ }
+
+ };
+ InfinispanRemoteExecutionFactory factory = new InfinispanRemoteExecutionFactory();
+ factory.setCacheName("Trades");
+ factory.setClassNamesOfCachedObjects(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.setSupportFilters(true);
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+
+ exec.execute();
+
+ List<Object> rows = new ArrayList<Object>();
+
+ int cnt = 0;
+ List<Object> row = exec.next();
+
+
+ while (row != null) {
+ rows.add(row);
+ ++cnt;
+ row = exec.next();
+ }
+
+
+ assertEquals("Did not get expected number of rows", 3, cnt); //$NON-NLS-1$
+
+ this.compareResultSet(rows);
+
+ exec.close();
+
+ }
+
+ @Test public void testQueryIncludeTradeAndLegsWithFilter() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T,
Trade_Object.Leg as L Where T.TradeId = L.TradeId and T.TradeId = '1' and L.Name
= 'LegName 1'"); //$NON-NLS-1$
+
+ InfinispanCacheConnection connection = new InfinispanCacheConnection() {
+
+ @Override
+ public List<Object> get(SearchCriterion criterion, String cacheName,
Class<?> rootNodeType)
+ throws TranslatorException {
+
+ return TradesCacheSource.loadCache().get(1);
+ }
+
+ };
+ InfinispanRemoteExecutionFactory factory = new InfinispanRemoteExecutionFactory();
+ factory.setCacheName("Trades");
+ factory.setClassNamesOfCachedObjects(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.setSupportFilters(true);
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+
+ exec.execute();
+
+ List<Object> rows = new ArrayList<Object>();
+
+ int cnt = 0;
+ List<Object> row = exec.next();
+
+
+ while (row != null) {
+ rows.add(row);
+ ++cnt;
+ row = exec.next();
+ printRow(cnt, row);
+ }
+
+
+ assertEquals("Did not get expected number of rows", 1, cnt); //$NON-NLS-1$
+
+ this.compareResultSet(rows);
+
+ exec.close();
+
+ }
+
+ // when using key, no filter is applied
+ @Test public void testQueryIncludeTradeID() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId = 1");
//$NON-NLS-1$
+
+ InfinispanCacheConnection connection = new InfinispanCacheConnection() {
+
+ @Override
+ public List<Object> get(SearchCriterion criterion, String cacheName,
Class<?> rootNodeType)
+ throws TranslatorException {
+
+ return TradesCacheSource.loadCache().getAll();
+ }
+
+ };
+ InfinispanRemoteExecutionFactory factory = new InfinispanRemoteExecutionFactory();
+ factory.setCacheName("Trades");
+ factory.setClassNamesOfCachedObjects(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.setSupportFilters(true);
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, connection);
+
+ exec.execute();
+
+ List<Object> rows = new ArrayList<Object>();
+
+ int cnt = 0;
+ List<Object> row = exec.next();
+
+
+ while (row != null) {
+ rows.add(row);
+ ++cnt;
+ row = exec.next();
+ }
+
+
+ assertEquals("Did not get expected number of rows", 3, cnt); //$NON-NLS-1$
+
+ this.compareResultSet(rows);
+
+ exec.close();
+
+ }
+
+}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java 2012-05-22
12:44:18 UTC (rev 4133)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java 2012-05-22
14:51:03 UTC (rev 4134)
@@ -105,7 +105,7 @@
public List<Object> get(int key) {
List<Object> objs = new ArrayList<Object>(1);
- objs.add(this.get(key));
+ objs.add(super.get(key));
return objs;
}
}
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegs.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegs.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegs.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_01 TradeName 1 LegName 1 ROW_11 TradeName 1 LegName 2 ROW_21 TradeName 1 LegName
3 ROW_31 TradeName 1 LegName 4 ROW_41 TradeName 1 LegName 5 ROW_51 TradeName 1 LegName
6 ROW_61 TradeName 1 LegName 7 ROW_71 TradeName 1 LegName 8 ROW_81 TradeName 1 LegName
9 ROW_91 TradeName 1 LegName 10 ROW_102 TradeName 2 LegName 1 ROW_112 TradeName 2 LegName
2 ROW_122 TradeName 2 LegName 3 ROW_132 TradeName 2 LegName 4 ROW_142 TradeName 2 LegName
5 ROW_152 TradeName 2 LegName 6 ROW_162 TradeName 2 LegName 7 ROW_172 TradeName 2 LegName
8 ROW_182 TradeName 2 LegName 9 ROW_192 TradeName 2 LegName 10 ROW_203 TradeName 3 LegName
1 ROW_213 TradeName 3 LegName 2 ROW_223 TradeName 3 LegName 3 ROW_233 TradeName 3 LegName
4 ROW_243 TradeName 3 LegName 5 ROW_253 TradeName 3 LegName 6 ROW_263 TradeName 3 LegName
7 ROW_273 TradeName 3 LegName 8 ROW_283 TradeName 3 LegName 9 ROW_293 TradeName 3 LegName
10
\ No newline at end of file
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegsWithFilter.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegsWithFilter.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeLegsWithFilter.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_01 TradeName 1 LegName 1 ROW_12 TradeName 2 LegName 1 ROW_23 TradeName 3 LegName 1
\ No newline at end of file
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeAndLegsWithFilter.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeAndLegsWithFilter.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeAndLegsWithFilter.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_01 TradeName 1 LegName 1
\ No newline at end of file
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeID.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeID.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestInfinispanIntegration/testQueryIncludeTradeID.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_01 TradeName 1 ROW_12 TradeName 2 ROW_23 TradeName 3
\ No newline at end of file
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTrades.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTrades.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTrades.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_0Tue May 22 09:39:08 CDT 2012 TradeName 1 1 false ROW_1Tue May 22 09:39:08 CDT
2012 TradeName 2 2 true ROW_2Tue May 22 09:39:08 CDT 2012 TradeName 3 3 false
\ No newline at end of file
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTransaction.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTransaction.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryGetTransaction.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_01 TradeName 1 LegName 1 Leg 1, transaction line item 1 ROW_11 TradeName 1 LegName
1 Leg 1, transaction line item 2 ROW_21 TradeName 1 LegName 1 Leg 1, transaction line item
3 ROW_31 TradeName 1 LegName 1 Leg 1, transaction line item 4 ROW_41 TradeName 1 LegName
1 Leg 1, transaction line item 5 ROW_51 TradeName 1 LegName 2 Leg 2, transaction line item
1 ROW_61 TradeName 1 LegName 2 Leg 2, transaction line item 2 ROW_71 TradeName 1 LegName
2 Leg 2, transaction line item 3 ROW_81 TradeName 1 LegName 2 Leg 2, transaction line item
4 ROW_91 TradeName 1 LegName 2 Leg 2, transaction line item 5 ROW_101 TradeName 1 LegName
3 Leg 3, transaction line item 1 ROW_111 TradeName 1 LegName 3 Leg 3, transaction line
item 2 ROW_121 TradeName 1 LegName 3 Leg 3, transaction line item 3 ROW_131 TradeName
1 LegName 3 Leg 3, transaction line item 4 ROW_141 TradeName 1 LegName 3 Leg 3,
transaction line item 5 ROW_151 TradeName 1 LegName 4 Leg 4, transaction line item
1 ROW_161 TradeName 1 Le!
gName 4 Leg 4, transaction line item 2 ROW_171 TradeName 1 LegName 4 Leg 4, transaction
line item 3 ROW_181 TradeName 1 LegName 4 Leg 4, transaction line item 4 ROW_191 TradeName
1 LegName 4 Leg 4, transaction line item 5 ROW_201 TradeName 1 LegName 5 Leg 5,
transaction line item 1 ROW_211 TradeName 1 LegName 5 Leg 5, transaction line item
2 ROW_221 TradeName 1 LegName 5 Leg 5, transaction line item 3 ROW_231 TradeName 1 LegName
5 Leg 5, transaction line item 4 ROW_241 TradeName 1 LegName 5 Leg 5, transaction line
item 5 ROW_251 TradeName 1 LegName 6 Leg 6, transaction line item 1 ROW_261 TradeName
1 LegName 6 Leg 6, transaction line item 2 ROW_271 TradeName 1 LegName 6 Leg 6,
transaction line item 3 ROW_281 TradeName 1 LegName 6 Leg 6, transaction line item
4 ROW_291 TradeName 1 LegName 6 Leg 6, transaction line item 5 ROW_301 TradeName 1 LegName
7 Leg 7, transaction line item 1 ROW_311 TradeName 1 LegName 7 Leg 7, transaction line
item 2 ROW_321 TradeName 1 LegName 7 Leg !
7, transaction line item 3 ROW_331 TradeName 1 LegName 7 Leg 7!
, transa
ction line item 4 ROW_341 TradeName 1 LegName 7 Leg 7, transaction line item
5 ROW_351 TradeName 1 LegName 8 Leg 8, transaction line item 1 ROW_361 TradeName 1 LegName
8 Leg 8, transaction line item 2 ROW_371 TradeName 1 LegName 8 Leg 8, transaction line
item 3 ROW_381 TradeName 1 LegName 8 Leg 8, transaction line item 4 ROW_391 TradeName
1 LegName 8 Leg 8, transaction line item 5 ROW_401 TradeName 1 LegName 9 Leg 9,
transaction line item 1 ROW_411 TradeName 1 LegName 9 Leg 9, transaction line item
2 ROW_421 TradeName 1 LegName 9 Leg 9, transaction line item 3 ROW_431 TradeName 1 LegName
9 Leg 9, transaction line item 4 ROW_441 TradeName 1 LegName 9 Leg 9, transaction line
item 5 ROW_451 TradeName 1 LegName 10 Leg 10, transaction line item 1 ROW_461 TradeName
1 LegName 10 Leg 10, transaction line item 2 ROW_471 TradeName 1 LegName 10 Leg 10,
transaction line item 3 ROW_481 TradeName 1 LegName 10 Leg 10, transaction line item
4 ROW_491 TradeName 1 LegName 10 Leg 10, transacti!
on line item 5 ROW_502 TradeName 2 LegName 1 Leg 1, transaction line item
1 ROW_512 TradeName 2 LegName 1 Leg 1, transaction line item 2 ROW_522 TradeName 2 LegName
1 Leg 1, transaction line item 3 ROW_532 TradeName 2 LegName 1 Leg 1, transaction line
item 4 ROW_542 TradeName 2 LegName 1 Leg 1, transaction line item 5 ROW_552 TradeName
2 LegName 2 Leg 2, transaction line item 1 ROW_562 TradeName 2 LegName 2 Leg 2,
transaction line item 2 ROW_572 TradeName 2 LegName 2 Leg 2, transaction line item
3 ROW_582 TradeName 2 LegName 2 Leg 2, transaction line item 4 ROW_592 TradeName 2 LegName
2 Leg 2, transaction line item 5 ROW_602 TradeName 2 LegName 3 Leg 3, transaction line
item 1 ROW_612 TradeName 2 LegName 3 Leg 3, transaction line item 2 ROW_622 TradeName
2 LegName 3 Leg 3, transaction line item 3 ROW_632 TradeName 2 LegName 3 Leg 3,
transaction line item 4 ROW_642 TradeName 2 LegName 3 Leg 3, transaction line item
5 ROW_652 TradeName 2 LegName 4 Leg 4, transaction line item!
1 ROW_662 TradeName 2 LegName 4 Leg 4, transaction line item !
2 ROW_67
2 TradeName 2 LegName 4 Leg 4, transaction line item 3 ROW_682 TradeName 2 LegName 4 Leg
4, transaction line item 4 ROW_692 TradeName 2 LegName 4 Leg 4, transaction line item
5 ROW_702 TradeName 2 LegName 5 Leg 5, transaction line item 1 ROW_712 TradeName 2 LegName
5 Leg 5, transaction line item 2 ROW_722 TradeName 2 LegName 5 Leg 5, transaction line
item 3 ROW_732 TradeName 2 LegName 5 Leg 5, transaction line item 4 ROW_742 TradeName
2 LegName 5 Leg 5, transaction line item 5 ROW_752 TradeName 2 LegName 6 Leg 6,
transaction line item 1 ROW_762 TradeName 2 LegName 6 Leg 6, transaction line item
2 ROW_772 TradeName 2 LegName 6 Leg 6, transaction line item 3 ROW_782 TradeName 2 LegName
6 Leg 6, transaction line item 4 ROW_792 TradeName 2 LegName 6 Leg 6, transaction line
item 5 ROW_802 TradeName 2 LegName 7 Leg 7, transaction line item 1 ROW_812 TradeName
2 LegName 7 Leg 7, transaction line item 2 ROW_822 TradeName 2 LegName 7 Leg 7,
transaction line item 3 ROW_832 TradeName 2!
LegName 7 Leg 7, transaction line item 4 ROW_842 TradeName 2 LegName 7 Leg 7,
transaction line item 5 ROW_852 TradeName 2 LegName 8 Leg 8, transaction line item
1 ROW_862 TradeName 2 LegName 8 Leg 8, transaction line item 2 ROW_872 TradeName 2 LegName
8 Leg 8, transaction line item 3 ROW_882 TradeName 2 LegName 8 Leg 8, transaction line
item 4 ROW_892 TradeName 2 LegName 8 Leg 8, transaction line item 5 ROW_902 TradeName
2 LegName 9 Leg 9, transaction line item 1 ROW_912 TradeName 2 LegName 9 Leg 9,
transaction line item 2 ROW_922 TradeName 2 LegName 9 Leg 9, transaction line item
3 ROW_932 TradeName 2 LegName 9 Leg 9, transaction line item 4 ROW_942 TradeName 2 LegName
9 Leg 9, transaction line item 5 ROW_952 TradeName 2 LegName 10 Leg 10, transaction line
item 1 ROW_962 TradeName 2 LegName 10 Leg 10, transaction line item 2 ROW_972 TradeName
2 LegName 10 Leg 10, transaction line item 3 ROW_982 TradeName 2 LegName 10 Leg 10,
transaction line item 4 ROW_992 TradeName 2 Leg!
Name 10 Leg 10, transaction line item 5 ROW_1003 TradeName 3 L!
egName 1
Leg 1, transaction line item 1 ROW_1013 TradeName 3 LegName 1 Leg 1, transaction line
item 2 ROW_1023 TradeName 3 LegName 1 Leg 1, transaction line item 3 ROW_1033 TradeName
3 LegName 1 Leg 1, transaction line item 4 ROW_1043 TradeName 3 LegName 1 Leg 1,
transaction line item 5 ROW_1053 TradeName 3 LegName 2 Leg 2, transaction line item
1 ROW_1063 TradeName 3 LegName 2 Leg 2, transaction line item 2 ROW_1073 TradeName
3 LegName 2 Leg 2, transaction line item 3 ROW_1083 TradeName 3 LegName 2 Leg 2,
transaction line item 4 ROW_1093 TradeName 3 LegName 2 Leg 2, transaction line item
5 ROW_1103 TradeName 3 LegName 3 Leg 3, transaction line item 1 ROW_1113 TradeName
3 LegName 3 Leg 3, transaction line item 2 ROW_1123 TradeName 3 LegName 3 Leg 3,
transaction line item 3 ROW_1133 TradeName 3 LegName 3 Leg 3, transaction line item
4 ROW_1143 TradeName 3 LegName 3 Leg 3, transaction line item 5 ROW_1153 TradeName
3 LegName 4 Leg 4, transaction line item 1 ROW_1163 TradeName 3 LegNam!
e 4 Leg 4, transaction line item 2 ROW_1173 TradeName 3 LegName 4 Leg 4, transaction line
item 3 ROW_1183 TradeName 3 LegName 4 Leg 4, transaction line item 4 ROW_1193 TradeName
3 LegName 4 Leg 4, transaction line item 5 ROW_1203 TradeName 3 LegName 5 Leg 5,
transaction line item 1 ROW_1213 TradeName 3 LegName 5 Leg 5, transaction line item
2 ROW_1223 TradeName 3 LegName 5 Leg 5, transaction line item 3 ROW_1233 TradeName
3 LegName 5 Leg 5, transaction line item 4 ROW_1243 TradeName 3 LegName 5 Leg 5,
transaction line item 5 ROW_1253 TradeName 3 LegName 6 Leg 6, transaction line item
1 ROW_1263 TradeName 3 LegName 6 Leg 6, transaction line item 2 ROW_1273 TradeName
3 LegName 6 Leg 6, transaction line item 3 ROW_1283 TradeName 3 LegName 6 Leg 6,
transaction line item 4 ROW_1293 TradeName 3 LegName 6 Leg 6, transaction line item
5 ROW_1303 TradeName 3 LegName 7 Leg 7, transaction line item 1 ROW_1313 TradeName
3 LegName 7 Leg 7, transaction line item 2 ROW_1323 TradeName 3 Le!
gName 7 Leg 7, transaction line item 3 ROW_1333 TradeName 3 Le!
gName 7
Leg 7, transaction line item 4 ROW_1343 TradeName 3 LegName 7 Leg 7, transaction line item
5 ROW_1353 TradeName 3 LegName 8 Leg 8, transaction line item 1 ROW_1363 TradeName
3 LegName 8 Leg 8, transaction line item 2 ROW_1373 TradeName 3 LegName 8 Leg 8,
transaction line item 3 ROW_1383 TradeName 3 LegName 8 Leg 8, transaction line item
4 ROW_1393 TradeName 3 LegName 8 Leg 8, transaction line item 5 ROW_1403 TradeName
3 LegName 9 Leg 9, transaction line item 1 ROW_1413 TradeName 3 LegName 9 Leg 9,
transaction line item 2 ROW_1423 TradeName 3 LegName 9 Leg 9, transaction line item
3 ROW_1433 TradeName 3 LegName 9 Leg 9, transaction line item 4 ROW_1443 TradeName
3 LegName 9 Leg 9, transaction line item 5 ROW_1453 TradeName 3 LegName 10 Leg 10,
transaction line item 1 ROW_1463 TradeName 3 LegName 10 Leg 10, transaction line item
2 ROW_1473 TradeName 3 LegName 10 Leg 10, transaction line item 3 ROW_1483 TradeName
3 LegName 10 Leg 10, transaction line item 4 ROW_1493 TradeName 3!
LegName 10 Leg 10, transaction line item 5
\ No newline at end of file
Added:
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryIncludeLegs.expected
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryIncludeLegs.expected
(rev 0)
+++
branches/7.7.x/connectors/translator-object/src/test/resources/TestMapCacheIntegration/testQueryIncludeLegs.expected 2012-05-22
14:51:03 UTC (rev 4134)
@@ -0,0 +1 @@
+ROW_01 TradeName 1 LegName 1 ROW_11 TradeName 1 LegName 2 ROW_21 TradeName 1 LegName
3 ROW_31 TradeName 1 LegName 4 ROW_41 TradeName 1 LegName 5 ROW_51 TradeName 1 LegName
6 ROW_61 TradeName 1 LegName 7 ROW_71 TradeName 1 LegName 8 ROW_81 TradeName 1 LegName
9 ROW_91 TradeName 1 LegName 10 ROW_102 TradeName 2 LegName 1 ROW_112 TradeName 2 LegName
2 ROW_122 TradeName 2 LegName 3 ROW_132 TradeName 2 LegName 4 ROW_142 TradeName 2 LegName
5 ROW_152 TradeName 2 LegName 6 ROW_162 TradeName 2 LegName 7 ROW_172 TradeName 2 LegName
8 ROW_182 TradeName 2 LegName 9 ROW_192 TradeName 2 LegName 10 ROW_203 TradeName 3 LegName
1 ROW_213 TradeName 3 LegName 2 ROW_223 TradeName 3 LegName 3 ROW_233 TradeName 3 LegName
4 ROW_243 TradeName 3 LegName 5 ROW_253 TradeName 3 LegName 6 ROW_263 TradeName 3 LegName
7 ROW_273 TradeName 3 LegName 8 ROW_283 TradeName 3 LegName 9 ROW_293 TradeName 3 LegName
10
\ No newline at end of file
Deleted:
branches/7.7.x/connectors/translator-object/src/test/resources/testQueryIncludeLegs.expected
===================================================================
(Binary files differ)