teiid SVN: r4134 - in branches/7.7.x/connectors/translator-object: src/main/java/org/teiid/translator/object and 9 other directories.
by teiid-commits@lists.jboss.org
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)
12 years, 7 months
teiid SVN: r4133 - in branches/7.4.x/engine/src: main/java/org/teiid/query/processor/relational and 3 other directories.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2012-05-22 08:44:18 -0400 (Tue, 22 May 2012)
New Revision: 4133
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
Log:
TEIID-1956 WHERE clause throws org.teiid.jdbc.TeiidSQLException: Index: 2, Size: 1
TEIID-2048 Error during dependent procedure execution
Combined patch.
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -34,6 +34,7 @@
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.query.analysis.AnalysisRecord;
@@ -44,6 +45,7 @@
import org.teiid.query.optimizer.relational.plantree.NodeConstants;
import org.teiid.query.optimizer.relational.plantree.NodeEditor;
import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.IsNullCriteria;
@@ -137,6 +139,10 @@
return false;
}
+ if (tgtCrit instanceof IsNullCriteria && ((IsNullCriteria)tgtCrit).isNegated()) {
+ return false;
+ }
+
int endGroups = GroupsUsedByElementsVisitor.getGroups(tgtCrit).size();
if (checkForGroupReduction) {
@@ -210,17 +216,23 @@
Set<Criteria> toCopy = criteriaInfo[0];
Set<Criteria> allCriteria = criteriaInfo[1];
-
- if (!toCopy.isEmpty()) {
- Map<Expression, Expression> srcToTgt = buildElementMap(joinCrits);
-
+
+ if (joinCrits != null && !joinCrits.isEmpty()) {
List<Criteria> newJoinCrits = new LinkedList<Criteria>();
-
- changedTree |= createCriteria(false, toCopy, combinedCriteria, srcToTgt, newJoinCrits, metadata);
+
+ //we don't want to continue discovery since that could be recursive
+ Map<Expression, Expression> srcToTgt = buildElementMap(joinCrits, node.hasBooleanProperty(NodeConstants.Info.IS_COPIED)?null:newJoinCrits, combinedCriteria, metadata);
- srcToTgt = buildElementMap(allCriteria);
-
- changedTree |= createCriteria(true, joinCrits, combinedCriteria, srcToTgt, newJoinCrits, metadata);
+ changedTree |= !newJoinCrits.isEmpty();
+
+ if (!toCopy.isEmpty()) {
+
+ changedTree |= createCriteria(false, toCopy, combinedCriteria, srcToTgt, newJoinCrits, metadata);
+
+ srcToTgt = buildElementMap(allCriteria, null, null, metadata);
+
+ changedTree |= createCriteria(true, joinCrits, combinedCriteria, srcToTgt, newJoinCrits, metadata);
+ }
joinCrits.addAll(newJoinCrits);
}
@@ -345,11 +357,14 @@
* Construct a mapping of element symbol to value map based upon equality CompareCriteria in crits
*
* @param crits
+ * @param newJoinCrits
+ * @param metadata
* @return
*/
- Map<Expression, Expression> buildElementMap(Collection<Criteria> crits) {
+ Map<Expression, Expression> buildElementMap(Collection<Criteria> crits, List<Criteria> newJoinCrits, Set<Criteria> allCriteria, QueryMetadataInterface metadata) {
Map<Expression, Expression> srcToTgt = null;
- for (Criteria theCrit : crits) {
+ for (Iterator<Criteria> iter = crits.iterator(); iter.hasNext();) {
+ Criteria theCrit = iter.next();
if (theCrit instanceof IsNullCriteria) {
IsNullCriteria isNull = (IsNullCriteria)theCrit;
if (!isNull.isNegated() && isNull.getExpression() instanceof ElementSymbol) {
@@ -368,8 +383,16 @@
if (srcToTgt == null) {
srcToTgt = new HashMap<Expression, Expression>();
}
- srcToTgt.put(crit.getLeftExpression(), crit.getRightExpression());
- srcToTgt.put(crit.getRightExpression(), crit.getLeftExpression());
+ Expression oldValue = srcToTgt.put(crit.getLeftExpression(), crit.getRightExpression());
+ boolean removed = false;
+ if (checkWithinJoin(crit, newJoinCrits, allCriteria, oldValue, crit.getRightExpression(), metadata)) {
+ iter.remove();
+ removed = true;
+ }
+ oldValue = srcToTgt.put(crit.getRightExpression(), crit.getLeftExpression());
+ if (checkWithinJoin(crit, newJoinCrits, allCriteria, oldValue, crit.getLeftExpression(), metadata) && !removed) {
+ iter.remove();
+ }
}
}
if (srcToTgt == null) {
@@ -377,6 +400,34 @@
}
return srcToTgt;
}
+
+ /**
+ * @return true if the original crit can be removed
+ */
+ private boolean checkWithinJoin(CompareCriteria crit, List<Criteria> newJoinCrits, Set<Criteria> allCriteria,
+ Expression oldValue, Expression left, QueryMetadataInterface metadata) {
+ if (newJoinCrits == null || oldValue == null) {
+ return false;
+ }
+ if (oldValue.equals(left)) {
+ return true;
+ }
+ Criteria newCrit = new CompareCriteria((Expression)left.clone(), CompareCriteria.EQ, (Expression)oldValue.clone());
+ try {
+ newCrit = QueryRewriter.rewriteCriteria(newCrit, null, null, metadata);
+ } catch (TeiidException e) {
+ LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, e, "Could not remap target criteria in RuleCopyCriteria"); //$NON-NLS-1$
+ return false;
+ }
+ if (allCriteria.add(newCrit)) {
+ newJoinCrits.add(newCrit);
+ }
+ if (!GroupsUsedByElementsVisitor.getGroups(crit.getLeftExpression()).isEmpty() && !GroupsUsedByElementsVisitor.getGroups(crit.getRightExpression()).isEmpty()
+ && (GroupsUsedByElementsVisitor.getGroups(left).isEmpty() || GroupsUsedByElementsVisitor.getGroups(oldValue).isEmpty())) {
+ crit.setOptional(true); //the original has been simplified
+ }
+ return false;
+ }
public String toString() {
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -573,6 +573,15 @@
}
FrameUtil.convertNode(copyNode, sourceGroup, null, symbolMap.asMap(), metadata, true);
+
+ //any proc relational criteria that is not input criteria should stay above the source
+ if (sourceGroup.isProcedure() && !copyNode.getGroups().isEmpty()) {
+ if (this.createdNodes != null) {
+ this.createdNodes.remove(this.createdNodes.size() - 1);
+ }
+ return false;
+ }
+
PlanNode intermediateParent = NodeEditor.findParent(projectNode, NodeConstants.Types.ACCESS, NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP);
if (intermediateParent != null) {
intermediateParent.addAsParent(copyNode);
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -24,9 +24,8 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Set;
import org.teiid.common.buffer.IndexedTupleSource;
import org.teiid.common.buffer.STree;
@@ -107,16 +106,17 @@
* TODO: reuse existing temp table indexes
*/
public void createIndex(SourceState state, boolean sorted) throws TeiidComponentException, TeiidProcessingException {
- int keyLength = state.getExpressionIndexes().length;
+ int[] expressionIndexes = state.getExpressionIndexes();
+ int keyLength = expressionIndexes.length;
List elements = state.getSource().getOutputElements();
//TODO: minimize reordering, or at least detect when it's not necessary
- int[] reorderedSortIndex = Arrays.copyOf(state.getExpressionIndexes(), elements.size());
- Set<Integer> used = new HashSet<Integer>();
- for (int i : state.getExpressionIndexes()) {
+ LinkedHashSet<Integer> used = new LinkedHashSet<Integer>();
+ for (int i : expressionIndexes) {
used.add(i);
}
- int j = state.getExpressionIndexes().length;
+ int[] reorderedSortIndex = Arrays.copyOf(expressionIndexes, keyLength + elements.size() - used.size());
+ int j = keyLength;
for (int i = 0; i < elements.size(); i++) {
if (!used.contains(i)) {
reorderedSortIndex[j++] = i;
@@ -145,12 +145,12 @@
//detect if sorted and distinct
List<?> originalTuple = its.nextTuple();
//remove the tuple if it has null
- for (int i : state.getExpressionIndexes()) {
+ for (int i : expressionIndexes) {
if (originalTuple.get(i) == null) {
continue outer;
}
}
- if (sortedDistinct && lastTuple != null && this.compare(lastTuple, originalTuple, state.getExpressionIndexes(), state.getExpressionIndexes()) == 0) {
+ if (sortedDistinct && lastTuple != null && this.compare(lastTuple, originalTuple, expressionIndexes, expressionIndexes) == 0) {
sortedDistinct = false;
}
lastTuple = originalTuple;
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -27,19 +27,7 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.*;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.FunctionExecutionException;
@@ -76,80 +64,12 @@
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.LanguageObject.Util;
-import org.teiid.query.sql.lang.AbstractSetCriteria;
-import org.teiid.query.sql.lang.ArrayTable;
-import org.teiid.query.sql.lang.BatchedUpdateCommand;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.DependentSetCriteria;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.ExpressionCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.FromClause;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.Into;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.lang.SetClauseList;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.TextTable;
-import org.teiid.query.sql.lang.TranslatableProcedureContainer;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
-import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.PredicateCriteria.Negatable;
import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
import org.teiid.query.sql.navigator.PostOrderNavigator;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.ExpressionStatement;
-import org.teiid.query.sql.proc.HasCriteria;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.TranslateCriteria;
-import org.teiid.query.sql.proc.TriggerAction;
-import org.teiid.query.sql.proc.WhileStatement;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.proc.*;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -1540,6 +1460,17 @@
if (isNull(leftExpr) || isNull(rightExpr)) {
return UNKNOWN_CRITERIA;
}
+
+ if (leftExpr.equals(rightExpr)) {
+ switch(criteria.getOperator()) {
+ case CompareCriteria.LE:
+ case CompareCriteria.GE:
+ case CompareCriteria.EQ:
+ return getSimpliedCriteria(criteria, criteria.getLeftExpression(), true, true);
+ default:
+ return getSimpliedCriteria(criteria, criteria.getLeftExpression(), false, true);
+ }
+ }
boolean rightConstant = false;
if(EvaluatableVisitor.willBecomeConstant(rightExpr)) {
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -286,7 +286,7 @@
TestOptimizer.helpPlan(sql, metadata,
new String[] {
- "SELECT g_0.e2, g_0.e1 FROM pm5.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", //$NON-NLS-1$
+ "SELECT g_0.e2, g_0.e1 FROM pm5.g1 AS g_0 WHERE (g_0.e1 IN (<dependent values>)) AND (g_0.e1 IN (<dependent values>))", //$NON-NLS-1$
"SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0", //$NON-NLS-1$
"SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)" }, TestOptimizer.getGenericFinder(false), ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -757,7 +757,7 @@
"SELECT table1comp.IntKey, table1comp.key1, BQT1.SmallA.StringKey FROM (SELECT t1.*, (STRINGKEY || STRINGNUM) AS key1 FROM BQT2.SmallA AS t1) AS table1comp, BQT1.SmallA WHERE table1comp.key1 = BQT1.SmallA.StringKey AND table1comp.key1 = BQT1.SmallA.StringNum", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT g_0.STRINGKEY, g_0.STRINGNUM, g_0.IntKey FROM BQT2.SmallA AS g_0", "SELECT g_0.StringKey, g_0.StringNum FROM BQT1.SmallA AS g_0 WHERE (g_0.StringKey IN (<dependent values>)) AND (g_0.StringNum IN (<dependent values>))"}, //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT g_0.STRINGKEY, g_0.STRINGNUM, g_0.IntKey FROM BQT2.SmallA AS g_0", "SELECT g_0.StringKey, g_0.StringNum FROM BQT1.SmallA AS g_0 WHERE (g_0.StringNum = g_0.StringKey) AND (g_0.StringKey IN (<dependent values>)) AND (g_0.StringNum IN (<dependent values>))"}, //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
TestOptimizer.checkNodeTypes(plan, new int[] {
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -1038,12 +1038,12 @@
RealMetadataFactory.setCardinality("bqt2.smallb", 15662, metadata); //$NON-NLS-1$
TestOptimizer.helpPlan(
- "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallB, BQT1.Smalla, bqt2.smallb where bqt2.smallb.intkey = bqt1.smallb.intkey and bqt2.smallb.intkey = bqt1.smalla.intkey", //$NON-NLS-1$
+ "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallB, BQT1.Smalla, bqt2.smallb where bqt2.smallb.intkey = bqt1.smallb.intkey and bqt2.smallb.stringkey = bqt1.smalla.stringkey", //$NON-NLS-1$
metadata,
null, capFinder,
- new String[] {"SELECT g_0.intkey AS c_0 FROM BQT1.Smalla AS g_0 ORDER BY c_0",
+ new String[] {"SELECT g_0.stringkey AS c_0, g_0.intkey AS c_1 FROM bqt2.smallb AS g_0 ORDER BY c_0",
"SELECT g_0.intkey AS c_0 FROM BQT1.SmallB AS g_0 ORDER BY c_0",
- "SELECT g_0.intkey AS c_0 FROM bqt2.smallb AS g_0 ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
+ "SELECT g_0.stringkey AS c_0, g_0.IntKey AS c_1 FROM BQT1.Smalla AS g_0 ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
ComparisonMode.EXACT_COMMAND_STRING );
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -236,6 +236,28 @@
TestProcessor.helpProcess(plan, dataManager, expected);
}
+ @Test public void testProcAsTableInJoinWithOutJoinPredicate(){
+ String sql = "select param1, param2, pm1.vsp26.e2, pm1.g1.e2 from pm1.vsp26, pm1.g1 where pm1.vsp26.e2 = pm1.g1.e2 and param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, pm1.vsp26.e2"; //$NON-NLS-1$
+
+ // Create expected results
+ List<?>[] expected = new List[] {
+ Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), 0}), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), 0}), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), 0}), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), 0}), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(1), "c", new Integer(1), 1}), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(2), "b", new Integer(2), 2}), //$NON-NLS-1$
+ Arrays.asList(new Object[] { new Integer(3), "a", new Integer(3), 3}), //$NON-NLS-1$
+ };
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData1(dataManager);
+ // Plan query
+ ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
+ // Run query
+ TestProcessor.helpProcess(plan, dataManager, expected);
+ }
+
@Test public void testProcAsTableInSubquery(){
String sql = "select param1, param2, pm1.vsp26.e2, (select count(e1) from pm1.vsp26 where param1 = 1 and param2 = 'a') x from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -6973,10 +6973,6 @@
helpProcess(plan, manager, expected);
}
- /**
- * Here a merge join will be used since there is at least one equi join predicate.
- * TODO: this can be optimized further
- */
@Test public void testCase6193_1() throws Exception {
// Create query
String sql = "select a.INTKEY, b.intkey from bqt1.smalla a LEFT OUTER JOIN bqt2.SMALLA b on a.intkey=b.intkey and a.intkey=5 where a.intkey <10 "; //$NON-NLS-1$
@@ -7014,12 +7010,12 @@
0, // DependentProject
0, // DupRemove
0, // Grouping
- 0, // NestedLoopJoinStrategy
- 1, // MergeJoinStrategy
+ 1, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
1, // Project
- 1, // Select
+ 2, // Select
0, // Sort
0 // UnionAll
});
@@ -7585,5 +7581,23 @@
Arrays.asList(3)});
}
+ @Test public void testDupCriteria() {
+ String sql = "select * from pm1.g1 a left outer join pm1.g2 b on a.e1 = b.e1 where b.e2 = a.e1"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached());
+ FakeDataManager fdm = new FakeDataManager();
+ sampleData1(fdm);
+ helpProcess(plan, fdm, new List[0]);
+ }
+
+ @Test public void testDupCriteria1() {
+ String sql = "select count(*) from pm1.g1 a left outer join pm1.g2 b on a.e1 = b.e1 where b.e1 = a.e1"; //$NON-NLS-1$
+
+ ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached());
+ FakeDataManager fdm = new FakeDataManager();
+ sampleData1(fdm);
+ helpProcess(plan, fdm, new List[] {Arrays.asList(11)});
+ }
+
private static final boolean DEBUG = false;
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2012-05-21 19:03:10 UTC (rev 4132)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2012-05-22 12:44:18 UTC (rev 4133)
@@ -569,7 +569,7 @@
}
@Test public void testVirtualAccessVirtualDep() throws Exception {
- String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e2) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
+ String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e0) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
@@ -577,8 +577,8 @@
finder.addCapabilities("test", caps); //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, finder,
- new String[] {"SELECT g_0.e2 AS c_0 FROM test.\"group\" AS g_0 WHERE (g_0.e0 = 1) AND (g_0.e1 = '2') ORDER BY c_0", //$NON-NLS-1$
- "SELECT g_0.e0 AS c_0, g_0.e1 AS c_1, g_0.e0 AS c_2 FROM test.\"group\" AS g_0 WHERE (g_0.e0 IN (<dependent values>)) AND (g_0.e1 IN (<dependent values>)) ORDER BY c_2, c_1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ new String[] {"SELECT g_0.e0 AS c_0, g_0.e0 AS c_1 FROM test.\"group\" AS g_0 WHERE (g_0.e1 = '1') AND (g_0.e0 IN (<dependent values>)) ORDER BY c_1",
+ "SELECT g_0.e2 AS c_0 FROM test.\"group\" AS g_0 WHERE (g_0.e0 = 1) AND (g_0.e1 = '2') ORDER BY c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, new int[] {
1, // Access
@@ -603,7 +603,7 @@
*
*/
@Test public void testVirtualAccessVirtualDep2() {
- String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a makenotdep inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e2) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
+ String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a makenotdep inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e0) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
12 years, 7 months
teiid SVN: r4132 - in branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc: oracle and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-05-21 15:03:10 -0400 (Mon, 21 May 2012)
New Revision: 4132
Modified:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
Log:
TEIID-2056 fix for oracle lob handling
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-05-21 19:02:53 UTC (rev 4131)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-05-21 19:03:10 UTC (rev 4132)
@@ -24,14 +24,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Timestamp;
+import java.sql.*;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Calendar;
@@ -47,34 +40,14 @@
import javax.sql.DataSource;
import org.teiid.core.util.PropertiesUtils;
-import org.teiid.language.Argument;
-import org.teiid.language.Call;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Command;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Limit;
-import org.teiid.language.Literal;
-import org.teiid.language.QueryExpression;
-import org.teiid.language.SQLConstants;
-import org.teiid.language.SetQuery;
+import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
import org.teiid.language.SetQuery.Operation;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.ProcedureExecution;
-import org.teiid.translator.ResultSetExecution;
-import org.teiid.translator.SourceSystemFunctions;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.TranslatorProperty;
-import org.teiid.translator.TypeFacility;
-import org.teiid.translator.UpdateExecution;
+import org.teiid.translator.*;
/**
@@ -841,6 +814,19 @@
stmt.setBigDecimal(i, (BigDecimal)param);
return;
}
+
+ if (useStreamsForLobs()) {
+ if (param instanceof Blob) {
+ Blob blob = (Blob)param;
+ stmt.setBinaryStream(i, blob.getBinaryStream(), blob.length());
+ return;
+ }
+ if (param instanceof Clob) {
+ Clob clob = (Clob)param;
+ stmt.setCharacterStream(i, clob.getCharacterStream(), clob.length());
+ return;
+ }
+ }
//convert these the following to jdbc safe values
if (TypeFacility.RUNTIME_TYPES.BIG_INTEGER.equals(paramType)) {
param = new BigDecimal((BigInteger)param);
@@ -853,6 +839,14 @@
stmt.setObject(i, param, type);
}
+ /**
+ * If streams should be used for Blob/Clob sets on {@link PreparedStatement}s
+ * @return
+ */
+ public boolean useStreamsForLobs() {
+ return false;
+ }
+
/**
* Retrieve the value on the current resultset row for the given column index.
* @param results
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2012-05-21 19:02:53 UTC (rev 4131)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2012-05-21 19:03:10 UTC (rev 4132)
@@ -449,6 +449,11 @@
}
@Override
+ public boolean useStreamsForLobs() {
+ return true;
+ }
+
+ @Override
public NullOrder getDefaultNullOrder() {
return NullOrder.HIGH;
}
12 years, 7 months
teiid SVN: r4131 - in trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc: oracle and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-05-21 15:02:53 -0400 (Mon, 21 May 2012)
New Revision: 4131
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
Log:
TEIID-2056 fix for oracle lob handling
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-05-21 15:54:43 UTC (rev 4130)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2012-05-21 19:02:53 UTC (rev 4131)
@@ -24,15 +24,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
+import java.sql.*;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Calendar;
@@ -811,6 +803,19 @@
stmt.setBigDecimal(i, (BigDecimal)param);
return;
}
+
+ if (useStreamsForLobs()) {
+ if (param instanceof Blob) {
+ Blob blob = (Blob)param;
+ stmt.setBinaryStream(i, blob.getBinaryStream(), blob.length());
+ return;
+ }
+ if (param instanceof Clob) {
+ Clob clob = (Clob)param;
+ stmt.setCharacterStream(i, clob.getCharacterStream(), clob.length());
+ return;
+ }
+ }
//convert these the following to jdbc safe values
if (TypeFacility.RUNTIME_TYPES.BIG_INTEGER.equals(paramType)) {
param = new BigDecimal((BigInteger)param);
@@ -825,6 +830,14 @@
stmt.setObject(i, param, type);
}
+ /**
+ * If streams should be used for Blob/Clob sets on {@link PreparedStatement}s
+ * @return
+ */
+ public boolean useStreamsForLobs() {
+ return false;
+ }
+
/**
* Retrieve the value on the current resultset row for the given column index.
* @param results
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2012-05-21 15:54:43 UTC (rev 4130)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2012-05-21 19:02:53 UTC (rev 4131)
@@ -449,6 +449,11 @@
}
@Override
+ public boolean useStreamsForLobs() {
+ return true;
+ }
+
+ @Override
public NullOrder getDefaultNullOrder() {
return NullOrder.HIGH;
}
12 years, 7 months
teiid SVN: r4130 - in trunk: engine/src/main/java/org/teiid/query/analysis and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-05-21 11:54:43 -0400 (Mon, 21 May 2012)
New Revision: 4130
Modified:
trunk/client/src/main/java/org/teiid/client/plan/Annotation.java
trunk/engine/src/main/java/org/teiid/query/analysis/AnalysisRecord.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java
Log:
TEIID-2043 condensing plan size and also converting many debug statements to annotations
Modified: trunk/client/src/main/java/org/teiid/client/plan/Annotation.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/plan/Annotation.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/client/src/main/java/org/teiid/client/plan/Annotation.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -35,6 +35,7 @@
public static final String MATERIALIZED_VIEW = "Materialized View"; //$NON-NLS-1$
public static final String CACHED_PROCEDURE = "Cached Procedure"; //$NON-NLS-1$
public static final String HINTS = "Hints"; //$NON-NLS-1$
+ public static final String RELATIONAL_PLANNER = "Relational Planner"; //$NON-NLS-1$
public enum Priority {
LOW,
Modified: trunk/engine/src/main/java/org/teiid/query/analysis/AnalysisRecord.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/analysis/AnalysisRecord.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/analysis/AnalysisRecord.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -32,6 +32,7 @@
import org.teiid.client.plan.Annotation;
import org.teiid.client.plan.PlanNode;
+import org.teiid.client.plan.Annotation.Priority;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.logging.LogConstants;
@@ -159,6 +160,10 @@
return this.recordDebug;
}
+ public void addAnnotation(String category, String annotation, String resolution, Priority priority) {
+ addAnnotation(new Annotation(category, annotation, resolution, priority));
+ }
+
/**
* Add an annotation. This can only be used if {@link #recordAnnotations}
* returns true.
@@ -166,6 +171,9 @@
*/
public void addAnnotation(Annotation annotation) {
this.annotations.add(annotation);
+ if (this.recordDebug()) {
+ this.println(annotation.getPriority() + " " + annotation.getCategory() + " " + annotation.getAnnotation() + " - " + annotation.getResolution()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/PlanNode.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -22,19 +22,14 @@
package org.teiid.query.optimizer.relational.plantree;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.client.plan.Annotation;
+import org.teiid.client.plan.Annotation.Priority;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.SubqueryContainer;
@@ -54,6 +49,8 @@
/** The type of node, as defined by NodeConstants.Types. */
private int type;
+
+ private boolean modified;
/** The parent of this node, null if root. */
private PlanNode parent;
@@ -98,6 +95,7 @@
if (this.parent != null) {
this.parent.children.remove(this);
}
+ this.modified = true;
this.parent = parent;
}
@@ -112,6 +110,7 @@
childIter.remove();
child.parent = null;
}
+ this.modified = true;
return childrenCopy;
}
@@ -134,11 +133,13 @@
}
public void addFirstChild(PlanNode child) {
+ this.modified = true;
this.children.addFirst(child);
child.setParent(this);
}
public void addLastChild(PlanNode child) {
+ this.modified = true;
this.children.addLast(child);
child.setParent(this);
}
@@ -150,6 +151,7 @@
}
public PlanNode removeFromParent() {
+ this.modified = true;
PlanNode result = this.parent;
if (result != null) {
result.removeChild(this);
@@ -161,6 +163,7 @@
boolean result = this.children.remove(child);
if (result) {
child.parent = null;
+ modified = true;
}
return result;
}
@@ -169,13 +172,18 @@
if(nodeProperties == null) {
return null;
}
- return nodeProperties.get(propertyID);
+ Object result = nodeProperties.get(propertyID);
+ if (result != null) {
+ modified = true;
+ }
+ return result;
}
public Object setProperty(NodeConstants.Info propertyID, Object value) {
if(nodeProperties == null) {
nodeProperties = new LinkedHashMap<NodeConstants.Info, Object>();
}
+ modified = true;
return nodeProperties.put(propertyID, value);
}
@@ -183,6 +191,7 @@
if(nodeProperties == null) {
return null;
}
+ modified = true;
return nodeProperties.remove(propertyID);
}
@@ -210,10 +219,12 @@
}
public void addGroup(GroupSymbol groupID) {
+ modified = true;
groups.add(groupID);
}
public void addGroups(Collection<GroupSymbol> newGroups) {
+ modified = true;
this.groups.addAll(newGroups);
}
@@ -230,7 +241,7 @@
* @return String representing this node and all children under this node
*/
public String toString() {
- StringBuffer str = new StringBuffer();
+ StringBuilder str = new StringBuilder();
getRecursiveString(str, 0);
return str.toString();
}
@@ -240,7 +251,7 @@
* @return String representing just this node
*/
public String nodeToString() {
- StringBuffer str = new StringBuffer();
+ StringBuilder str = new StringBuilder();
getNodeString(str);
return str.toString();
}
@@ -248,13 +259,13 @@
// Define a single tab
private static final String TAB = " "; //$NON-NLS-1$
- private void setTab(StringBuffer str, int tabStop) {
+ private void setTab(StringBuilder str, int tabStop) {
for(int i=0; i<tabStop; i++) {
str.append(TAB);
}
}
- void getRecursiveString(StringBuffer str, int tabLevel) {
+ void getRecursiveString(StringBuilder str, int tabLevel) {
setTab(str, tabLevel);
getNodeString(str);
str.append(")\n"); //$NON-NLS-1$
@@ -265,13 +276,20 @@
}
}
- void getNodeString(StringBuffer str) {
+ void getNodeString(StringBuilder str) {
str.append(NodeConstants.getNodeTypeString(this.type));
str.append("(groups="); //$NON-NLS-1$
str.append(this.groups);
- if(nodeProperties != null) {
- str.append(", props="); //$NON-NLS-1$
- str.append(nodeProperties);
+ if (modified) {
+ if(nodeProperties != null) {
+ str.append(", props="); //$NON-NLS-1$
+ String props = nodeProperties.toString();
+ if (props.length() > 100000) {
+ props = props.substring(0, 100000) + "..."; //$NON-NLS-1$
+ }
+ str.append(props);
+ }
+ modified = false;
}
}
@@ -280,6 +298,7 @@
}
public void replaceChild(PlanNode child, PlanNode replacement) {
+ modified = true;
int i = this.children.indexOf(child);
this.children.set(i, replacement);
child.setParent(null);
@@ -292,6 +311,7 @@
* @param node
*/
public void addAsParent(PlanNode node) {
+ modified = true;
if (this.parent != null) {
this.parent.replaceChild(this, node);
}
@@ -395,5 +415,14 @@
}
return cardinality;
}
+
+ public void recordDebugAnnotation(String annotation, Object modelID, String resolution, AnalysisRecord record, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
+ if (record != null && record.recordAnnotations()) {
+ boolean current = this.modified;
+ this.modified = true;
+ record.addAnnotation(Annotation.RELATIONAL_PLANNER, annotation + (modelID != null?" " + metadata.getModelID(modelID):""), resolution + " " + this.nodeToString(), Priority.LOW); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ this.modified = current;
+ }
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -27,6 +27,8 @@
import java.util.HashSet;
import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.client.plan.Annotation;
+import org.teiid.client.plan.Annotation.Priority;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.FunctionMethod.PushDown;
@@ -649,9 +651,9 @@
private void markInvalid(LanguageObject object, String reason) {
this.valid = false;
setAbort(true);
- if (analysisRecord != null && analysisRecord.recordDebug()) {
+ if (analysisRecord != null && analysisRecord.recordAnnotations()) {
try {
- analysisRecord.println(reason + " " + this.metadata.getName(this.modelID) + ": " + object); //$NON-NLS-1$ //$NON-NLS-2$
+ analysisRecord.addAnnotation(Annotation.RELATIONAL_PLANNER, reason + " " + this.metadata.getName(this.modelID), object + " was not pushed", Priority.LOW); //$NON-NLS-1$ //$NON-NLS-2$
} catch (QueryMetadataException e) {
} catch (TeiidComponentException e) {
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -130,8 +130,10 @@
* @param metadata Metadata implementation
* @param node Root node to search
* @param matches Collection to accumulate matches in
+ * @throws TeiidComponentException
+ * @throws QueryMetadataException
*/
- List<CandidateJoin> findCandidate(PlanNode root, QueryMetadataInterface metadata, AnalysisRecord analysisRecord) {
+ List<CandidateJoin> findCandidate(PlanNode root, QueryMetadataInterface metadata, AnalysisRecord analysisRecord) throws QueryMetadataException, TeiidComponentException {
List<CandidateJoin> candidates = new ArrayList<CandidateJoin>();
@@ -170,53 +172,45 @@
* @param sourceNode The access node being considered
* @param analysisRecord TODO
* @return True if valid for making dependent
+ * @throws TeiidComponentException
+ * @throws QueryMetadataException
*/
- boolean isValidJoin(PlanNode joinNode, PlanNode sourceNode, AnalysisRecord analysisRecord) {
+ boolean isValidJoin(PlanNode joinNode, PlanNode sourceNode, AnalysisRecord analysisRecord) throws QueryMetadataException, TeiidComponentException {
JoinType jtype = (JoinType) joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);
// Check that join is not a CROSS join or FULL OUTER join
if(jtype.equals(JoinType.JOIN_CROSS) || jtype.equals(JoinType.JOIN_FULL_OUTER)) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Rejecting dependent access node as parent join is CROSS or FULL OUTER: "+ sourceNode.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode.recordDebugAnnotation("parent join is CROSS or FULL OUTER", null, "Rejecting dependent join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
if (!joinNode.getExportedCorrelatedReferences().isEmpty()) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Rejecting dependent access node as parent join has a correlated nested table: "+ sourceNode.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode.recordDebugAnnotation("parent join has a correlated nested table", null, "Rejecting dependent join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
// Check that join criteria exist
List jcrit = (List) joinNode.getProperty(NodeConstants.Info.JOIN_CRITERIA);
if(jcrit == null || jcrit.size() == 0) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Rejecting dependent access node as parent join has no join criteria: "+ sourceNode.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode.recordDebugAnnotation("parent join has has no join criteria", null, "Rejecting dependent join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
if(joinNode.getProperty(NodeConstants.Info.LEFT_EXPRESSIONS) == null) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Rejecting dependent access node as parent join has no equality expressions: "+ sourceNode.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode.recordDebugAnnotation("parent join has no equa-join predicates", null, "Rejecting dependent join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
// Check that for a left or right outer join the dependent side must be the inner
if(jtype.isOuter() && JoinUtil.getInnerSideJoinNodes(joinNode)[0] != sourceNode) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Rejecting dependent access node as it is on outer side of a join: "+ sourceNode.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode.recordDebugAnnotation("node is on outer side of the join", null, "Rejecting dependent join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
return true;
}
- PlanNode chooseDepWithoutCosting(PlanNode rootNode1, PlanNode rootNode2, AnalysisRecord analysisRecord) {
+ PlanNode chooseDepWithoutCosting(PlanNode rootNode1, PlanNode rootNode2, AnalysisRecord analysisRecord) throws QueryMetadataException, TeiidComponentException {
PlanNode sourceNode1 = FrameUtil.findJoinSourceNode(rootNode1);
PlanNode sourceNode2 = null;
@@ -227,41 +221,30 @@
if (sourceNode2 != null && sourceNode2.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS) ) {
//Return null - query planning should fail because both access nodes
//have unsatisfied access patterns
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Neither access node can be made dependent because both have unsatisfied access patterns: " + sourceNode1.nodeToString() + "\n" + sourceNode2.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ rootNode1.getParent().recordDebugAnnotation("both children have unsatisfied access patterns", null, "Neither node can be made dependent", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
+ rootNode1.recordDebugAnnotation("unsatisfied access pattern detected", null, "marking as dependent side of join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return rootNode1;
} else if (sourceNode2 != null && sourceNode2.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS) ) {
//Access node 2 has unsatisfied access pattern,
//so try to make node 2 dependent
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Making access node dependent to satisfy access pattern: "+ sourceNode2.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode2.recordDebugAnnotation("unsatisfied access pattern detected", null, "marking as dependent side of join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return rootNode2;
}
// Check for hints, which over-rule heuristics
if(sourceNode1.hasBooleanProperty(NodeConstants.Info.MAKE_DEP)) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Making access node dependent due to hint: "+ sourceNode1.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode1.recordDebugAnnotation("MAKE_DEP hint detected", null, "marking as dependent side of join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return rootNode1;
} else if(sourceNode2 != null && sourceNode2.hasBooleanProperty(NodeConstants.Info.MAKE_DEP)) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Making access node dependent due to hint: "+ sourceNode2.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode2.recordDebugAnnotation("MAKE_DEP hint detected", null, "marking as dependent side of join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return rootNode2;
} else if (sourceNode1.hasBooleanProperty(NodeConstants.Info.MAKE_IND) && sourceNode2 != null) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Making access node dependent due to hint: "+ sourceNode2.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode2.recordDebugAnnotation("MAKE_IND hint detected", null, "marking as dependent side of join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return rootNode2;
} else if (sourceNode2 != null && sourceNode2.hasBooleanProperty(NodeConstants.Info.MAKE_IND)) {
- if (analysisRecord.recordDebug()) {
- analysisRecord.println("Making access node dependent due to hint: "+ sourceNode1.nodeToString()); //$NON-NLS-1$
- }
+ sourceNode1.recordDebugAnnotation("MAKE_IND hint detected", null, "marking as dependent side of join", analysisRecord, null); //$NON-NLS-1$ //$NON-NLS-2$
return rootNode1;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -168,7 +168,7 @@
// Walk to end of the chain and change recurse root
while(recurseRoot.getType() == NodeConstants.Types.SELECT) {
// Look for opportunities to replace with a semi-join
- recurseRoot = planMergeJoin(recurseRoot, root, analysisRecord);
+ recurseRoot = planMergeJoin(recurseRoot, root);
if (root.getChildCount() == 0) {
root = recurseRoot.getFirstChild();
if (root.getType() != NodeConstants.Types.SELECT) {
@@ -240,10 +240,8 @@
* IN ( ) / SOME ( )
*
* and replace with a semi join
- *
- * TODO: it would be good to have a hint to force
*/
- private PlanNode planMergeJoin(PlanNode current, PlanNode root, AnalysisRecord analysisRecord) throws QueryMetadataException,
+ private PlanNode planMergeJoin(PlanNode current, PlanNode root) throws QueryMetadataException,
TeiidComponentException {
float sourceCost = NewCalculateCostUtil.computeCostForTree(current.getFirstChild(), metadata);
Criteria crit = (Criteria)current.getProperty(NodeConstants.Info.SELECT_CRITERIA);
@@ -270,7 +268,7 @@
if (!planQuery(leftGroups, false, plannedResult)) {
if (plannedResult.mergeJoin && analysisRecord != null && analysisRecord.recordAnnotations()) {
- this.analysisRecord.addAnnotation(new Annotation(Annotation.HINTS, "could not plan as a merge join: " + crit, "ignoring hint", Priority.MEDIUM)); //$NON-NLS-1$ //$NON-NLS-2$
+ this.analysisRecord.addAnnotation(new Annotation(Annotation.HINTS, "Could not plan as a merge join: " + crit, "ignoring MJ hint", Priority.HIGH)); //$NON-NLS-1$ //$NON-NLS-2$
}
return current;
}
@@ -287,9 +285,6 @@
List<Expression> projectedSymbols = LanguageObject.Util.deepClone(plannedResult.query.getProjectedSymbols(), Expression.class);
//NOTE: we could tap into the relationalplanner at a lower level to get this in a plan node form,
//the major benefit would be to reuse the dependent join planning logic if possible.
- if (analysisRecord != null && analysisRecord.recordDebug()) {
- analysisRecord.println("Attempting to plan " + crit + " as a merge join"); //$NON-NLS-1$ //$NON-NLS-2$
- }
RelationalPlan subPlan = (RelationalPlan)QueryOptimizer.optimizePlan(plannedResult.query, metadata, idGenerator, capFinder, analysisRecord, context);
Number planCardinality = subPlan.getRootNode().getEstimateNodeCardinality();
@@ -301,12 +296,14 @@
|| (sourceCost != NewCalculateCostUtil.UNKNOWN_VALUE && sourceCost * originalCardinality.floatValue() < planCardinality.floatValue() / (100 * Math.log(Math.max(4, sourceCost))))) {
//bail-out if both are unknown or the new plan is too large
if (analysisRecord != null && analysisRecord.recordDebug()) {
- analysisRecord.println("Failed to use mege join, as the cost was not favorable. Use the MJ hint to force."); //$NON-NLS-1$
+ current.recordDebugAnnotation("cost of merge join plan was not favorable", null, "semi merge join will not be used", analysisRecord, metadata); //$NON-NLS-1$ //$NON-NLS-2$
}
return current;
}
}
+ current.recordDebugAnnotation("Conditions met (hint or cost)", null, "Converting to a semi merge join", analysisRecord, metadata); //$NON-NLS-1$ //$NON-NLS-2$
+
PlanNode semiJoin = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
semiJoin.addGroups(current.getGroups());
semiJoin.setProperty(NodeConstants.Info.JOIN_STRATEGY, JoinStrategyType.MERGE);
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -232,9 +232,7 @@
Expression limit = (Expression)parentNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
if (limit != null && !CapabilitiesUtil.supportsRowLimit(modelID, metadata, capFinder)) {
- if (analysisRecord != null && analysisRecord.recordDebug()) {
- analysisRecord.println("limit not supported by source " + metadata.getName(modelID)); //$NON-NLS-1$
- }
+ parentNode.recordDebugAnnotation("limit not supported by source", modelID, "limit node not pushed", analysisRecord, metadata); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -144,13 +144,13 @@
{
// If model supports the support constant parameter, then move access node
if(!CapabilitiesUtil.supportsSelectDistinct(modelID, metadata, capFinder)) {
- recordDebug("cannot push dupremove, since distinct is not supported by source", parentNode, record); //$NON-NLS-1$
+ parentNode.recordDebugAnnotation("distinct is not supported by source", modelID, "cannot push dupremove", record, metadata); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
//TODO: this check is too specific the columns could be used in expressions that are comparable
if (!CapabilitiesUtil.checkElementsAreSearchable((List)NodeEditor.findNodePreOrder(parentNode, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS), metadata, SupportConstants.Element.SEARCHABLE_COMPARE)) {
- recordDebug("cannot push dupremove, since not all columns are comparable at the source", parentNode, record); //$NON-NLS-1$
+ parentNode.recordDebugAnnotation("not all columns are comparable at the source", modelID, "cannot push dupremove", record, metadata); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
@@ -310,12 +310,12 @@
}
List<Expression> groupCols = (List<Expression>)groupNode.getProperty(NodeConstants.Info.GROUP_COLS);
if(!CapabilitiesUtil.supportsAggregates(groupCols, modelID, metadata, capFinder)) {
- recordDebug("cannot push group by, since group by is not supported by source", groupNode, record); //$NON-NLS-1$
+ groupNode.recordDebugAnnotation("group by is not supported by source", modelID, "cannot push group by", record, metadata); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
if (CapabilitiesUtil.supports(Capability.QUERY_ONLY_SINGLE_TABLE_GROUP_BY, modelID, metadata, capFinder)
&& !NodeEditor.findAllNodes(groupNode, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE).isEmpty()) {
- recordDebug("cannot push group by, since joined group by is not supported by source", groupNode, record); //$NON-NLS-1$
+ groupNode.recordDebugAnnotation("joined group by is not supported by source", modelID, "cannot push group by", record, metadata); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
if (groupCols != null) {
@@ -335,13 +335,7 @@
return CapabilitiesUtil.checkElementsAreSearchable(groupCols, metadata, SupportConstants.Element.SEARCHABLE_COMPARE);
}
- private static void recordDebug(String message, PlanNode node, AnalysisRecord record) {
- if (record != null && record.recordDebug()) {
- record.println(message + " " + node.nodeToString()); //$NON-NLS-1$
- }
- }
-
- static boolean canRaiseOverSort(PlanNode accessNode,
+ static boolean canRaiseOverSort(PlanNode accessNode,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder,
PlanNode parentNode, AnalysisRecord record, boolean compensateForUnrelated) throws QueryMetadataException,
@@ -421,7 +415,7 @@
}
if (parentNode.hasBooleanProperty(NodeConstants.Info.IS_HAVING) && !CapabilitiesUtil.supports(Capability.QUERY_HAVING, modelID, metadata, capFinder)) {
- recordDebug("cannot push having, since having is not supported by source", parentNode, record); //$NON-NLS-1$
+ parentNode.recordDebugAnnotation("having is not supported by source", modelID, "cannot push having", record, metadata); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -161,10 +161,7 @@
joinNode.removeChild(optionalNode);
joinNode.getFirstChild().setProperty(NodeConstants.Info.OUTPUT_COLS, joinNode.getProperty(NodeConstants.Info.OUTPUT_COLS));
NodeEditor.removeChildNode(parentNode, joinNode);
- if (record != null && record.recordDebug()) {
- record.println("Removing join node since " + (isOptional?"it was marked as optional ":"it will not affect the results") + joinNode); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
+ joinNode.recordDebugAnnotation((isOptional?"node was marked as optional ":"node will not affect the results"), null, "Removing join node", record, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
while (parentNode.getType() != NodeConstants.Types.PROJECT) {
PlanNode current = parentNode;
parentNode = parentNode.getParent();
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -35,6 +35,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.client.plan.Annotation.Priority;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.QueryPlugin;
@@ -482,25 +483,25 @@
ProcessorPlan plan = null;
- boolean debug = planEnv.analysisRecord.recordDebug();
+ boolean debug = planEnv.analysisRecord.recordAnnotations();
- if (debug) {
- planEnv.analysisRecord.println("Attempting to create plan for staging table " + srcGroupName); //$NON-NLS-1$
- }
-
try {
// register with env
plan = optimizePlan(cmd, planEnv);
} catch (QueryPlannerException e) {
if (implicit) {
if (debug) {
- planEnv.analysisRecord.println("Failed to create plan for staging table " + srcGroupName + " due to " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ planEnv.analysisRecord.addAnnotation("XML Planning", "Planning failded for staging otable " + srcGroupName + " due to " + e.getMessage(), "Implicit staging table will not be used", Priority.LOW); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
return false;
}
throw e;
}
+ if (debug) {
+ planEnv.analysisRecord.addAnnotation("XML Planning", "Planning succeeded for staging of " + srcGroupName, (implicit?"Implicit ":"") + "staging table will be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+
int cardinality = QueryMetadataInterface.UNKNOWN_CARDINALITY;
if (plan instanceof RelationalPlan) {
Modified: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -68,6 +68,7 @@
import net.sf.saxon.value.SequenceType;
import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.client.plan.Annotation.Priority;
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -90,6 +91,7 @@
@SuppressWarnings("serial")
public class SaxonXQueryExpression {
+ private static final String XQUERY_PLANNING = "XQuery Planning"; //$NON-NLS-1$
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
static final String DEFAULT_PREFIX = "-"; //$NON-NLS-1$
@@ -237,8 +239,8 @@
try {
streamingPath = StreamingUtils.getStreamingPath(xQueryString, namespaceMap);
} catch (IllegalArgumentException e) {
- if (record.recordDebug()) {
- record.println("Document streaming will not be used: " + e.getMessage()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "Invalid streaming path " + xQueryString + " "+ e.getMessage(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
this.contextRoot = null;
@@ -253,16 +255,16 @@
try {
parentRoot = map.getContextRoot();
} catch (IllegalStateException e) {
- if (record.recordDebug()) {
- record.println("Document projection will not be used, since multiple context item exist."); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "Multiple context items exist " + xQueryString, "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return;
}
if (parentRoot == null) {
//TODO: this seems like we could omit the context item altogether
//this.xQuery.usesContextItem() should also be false
- if (record.recordDebug()) {
- record.println("Document projection will not be used, since no context item reference was found in the XQuery"); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "No context item reference was found in the XQuery " + xQueryString, "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return;
}
@@ -272,8 +274,8 @@
if (!finalNodes.isEmpty()) {
if (columns != null && !columns.isEmpty()) {
if (finalNodes.size() != 1) {
- if (record.recordDebug()) {
- record.println("Document projection will not be used, since multiple return items exist"); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "multiple return items exist " + xQueryString, "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return;
}
@@ -289,15 +291,18 @@
}
}
if (parentRoot.hasUnknownDependencies()) {
- if (record.recordDebug()) {
- record.println("Document projection will not be used since there are unknown dependencies (most likely a user defined function)."); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "There are unknown dependencies (most likely a user defined function) in " + xQueryString, "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return;
}
- if (record.recordDebug()) {
- StringBuilder sb = new StringBuilder();
- showArcs(sb, parentRoot, 0);
- record.println("Using path filtering for XQuery context item: \n" + sb.toString()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ StringBuilder sb = null;
+ if (record.recordDebug()) {
+ sb = new StringBuilder();
+ showArcs(sb, parentRoot, 0);
+ }
+ record.addAnnotation(XQUERY_PLANNING, "Projection conditions met for " + xQueryString, "Document projection will be used" + (sb != null ? "\n" +sb.toString():""), Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
this.contextRoot = parentRoot;
}
@@ -331,8 +336,8 @@
for (PathMapRoot root : subMap.getPathMapRoots()) {
if (root.getRootExpression() instanceof ContextItemExpression || root.getRootExpression() instanceof RootExpression) {
if (subContextRoot != null) {
- if (record.recordDebug()) {
- record.println("Document projection will not be used, since multiple context items exist in column path " + xmlColumn.getPath()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "Multiple context items exist in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return null;
}
@@ -387,15 +392,15 @@
if (ancestor) {
if (current.getTarget().isReturnable()) {
if (axis != Axis.NAMESPACE && axis != Axis.ATTRIBUTE) {
- if (record.recordDebug()) {
- record.println("Document streaming will not be used, since the column path contains an invalid reverse axis " + xmlColumn.getPath()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return false;
}
}
if (!isValidAncestorAxis[axis]) {
- if (record.recordDebug()) {
- record.println("Document streaming will not be used, since the column path contains an invalid reverse axis " + xmlColumn.getPath()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return false;
}
@@ -404,15 +409,15 @@
|| axis == Axis.ANCESTOR
|| axis == Axis.ANCESTOR_OR_SELF) {
if (current.getTarget().isReturnable()) {
- if (record.recordDebug()) {
- record.println("Document streaming will not be used, since the column path contains an invalid reverse axis " + xmlColumn.getPath()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return false;
}
ancestor = true;
} else {
- if (record.recordDebug()) {
- record.println("Document streaming will not be used, since the column path may not reference an ancestor or subtree " + xmlColumn.getPath()); //$NON-NLS-1$
+ if (record.recordAnnotations()) {
+ record.addAnnotation(XQUERY_PLANNING, "The column path may not reference an ancestor or subtree " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM); //$NON-NLS-1$ //$NON-NLS-2$
}
return false;
}
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java 2012-05-21 15:16:44 UTC (rev 4129)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java 2012-05-21 15:54:43 UTC (rev 4130)
@@ -47,17 +47,7 @@
import org.teiid.query.processor.relational.JoinNode.JoinStrategyType;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.rewriter.QueryRewriter;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -162,7 +152,7 @@
return query;
}
- public void helpTestValidJoin(PlanNode joinNode, PlanNode accessNode, boolean expectedValid) {
+ public void helpTestValidJoin(PlanNode joinNode, PlanNode accessNode, boolean expectedValid) throws QueryMetadataException, TeiidComponentException {
RuleChooseDependent rule = new RuleChooseDependent();
RuleChooseJoinStrategy.chooseJoinStrategy(joinNode, metadata);
boolean isValid = rule.isValidJoin(joinNode, accessNode, AnalysisRecord.createNonRecordingRecord());
12 years, 7 months
teiid SVN: r4129 - in trunk: engine/src/main/java/org/teiid/dqp/service and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-05-21 11:16:44 -0400 (Mon, 21 May 2012)
New Revision: 4129
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
trunk/engine/src/main/java/org/teiid/dqp/service/SessionService.java
trunk/engine/src/main/java/org/teiid/security/SecurityHelper.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java
trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java
Log:
TEIID-2055 forward merge with minor changes
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -103,13 +103,13 @@
}
public static void setWorkContext(DQPWorkContext context) {
- CONTEXTS.set(context);
+ if (context == null) {
+ CONTEXTS.remove();
+ } else {
+ CONTEXTS.set(context);
+ }
}
- public static void releaseWorkContext() {
- CONTEXTS.set(null);
- }
-
private SessionMetadata session = new SessionMetadata();
private String clientAddress;
private String clientHostname;
@@ -236,29 +236,21 @@
public void runInContext(final Runnable runnable) {
DQPWorkContext previous = DQPWorkContext.getWorkContext();
- boolean associated = attachDQPWorkContext();
+ DQPWorkContext.setWorkContext(this);
+ Object previousSecurityContext = null;
+ if (securityHelper != null) {
+ previousSecurityContext = securityHelper.associateSecurityContext(this.getSecurityContext());
+ }
try {
runnable.run();
} finally {
- if (associated) {
- securityHelper.clearSecurityContext();
+ if (securityHelper != null) {
+ securityHelper.associateSecurityContext(previousSecurityContext);
}
- DQPWorkContext.releaseWorkContext();
- if (previous != null) {
- previous.attachDQPWorkContext();
- }
+ DQPWorkContext.setWorkContext(previous);
}
}
- private boolean attachDQPWorkContext() {
- DQPWorkContext.setWorkContext(this);
- boolean associated = false;
- if (securityHelper != null && this.getSubject() != null) {
- associated = securityHelper.associateSecurityContext(this.getSecurityContext());
- }
- return associated;
- }
-
public HashMap<String, DataPolicy> getAllowedDataPolicies() {
if (this.policies == null) {
this.policies = new HashMap<String, DataPolicy>();
Modified: trunk/engine/src/main/java/org/teiid/dqp/service/SessionService.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/service/SessionService.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/engine/src/main/java/org/teiid/dqp/service/SessionService.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -25,7 +25,6 @@
import java.util.Collection;
import java.util.Properties;
-import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
@@ -34,6 +33,7 @@
import org.teiid.dqp.internal.process.DQPCore;
import org.teiid.net.socket.AuthenticationType;
import org.teiid.security.Credentials;
+import org.teiid.security.SecurityHelper;
/**
@@ -148,9 +148,5 @@
String getGssSecurityDomain();
- boolean associateSubjectInContext(String securityDomain, Subject subject);
-
- Subject getSubjectInContext(String securityDomain);
-
- public void clearSubjectInContext();
+ SecurityHelper getSecurityHelper();
}
Modified: trunk/engine/src/main/java/org/teiid/security/SecurityHelper.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/security/SecurityHelper.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/engine/src/main/java/org/teiid/security/SecurityHelper.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -28,7 +28,7 @@
public interface SecurityHelper {
- boolean associateSecurityContext(Object context);
+ Object associateSecurityContext(Object context);
void clearSecurityContext();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -22,29 +22,25 @@
package org.teiid.dqp.internal.process;
+import static org.junit.Assert.*;
+
+import java.security.Principal;
import java.util.Map;
+import javax.security.auth.Subject;
+
+import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.adminapi.DataPolicy;
import org.teiid.adminapi.impl.DataPolicyMetadata;
import org.teiid.adminapi.impl.SessionMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.core.util.UnitTestUtil;
+import org.teiid.security.SecurityHelper;
-import junit.framework.TestCase;
+public class TestDQPWorkContext {
-public class TestDQPWorkContext extends TestCase {
-
- /**
- * Constructor for TestRequestMessage.
- *
- * @param name
- */
- public TestDQPWorkContext(String name) {
- super(name);
- }
-
public static DQPWorkContext example() {
DQPWorkContext message = new DQPWorkContext();
message.getSession().setVDBName("vdbName"); //$NON-NLS-1$
@@ -55,7 +51,7 @@
return message;
}
- public void testSerialize() throws Exception {
+ @Test public void testSerialize() throws Exception {
DQPWorkContext copy = UnitTestUtil.helpSerialize(example());
assertEquals("5", copy.getSessionId()); //$NON-NLS-1$
@@ -64,9 +60,8 @@
assertEquals(1, copy.getVdbVersion());
assertEquals("querybuilder", copy.getAppName()); //$NON-NLS-1$
}
-
- public void testClearPolicies() {
+ @Test public void testClearPolicies() {
DQPWorkContext message = new DQPWorkContext();
message.setSession(Mockito.mock(SessionMetadata.class));
Mockito.stub(message.getSession().getVdb()).toReturn(new VDBMetaData());
@@ -80,7 +75,7 @@
assertTrue(map.isEmpty());
}
- public void testAnyAuthenticated() {
+ @Test public void testAnyAuthenticated() {
DQPWorkContext message = new DQPWorkContext();
message.setSession(Mockito.mock(SessionMetadata.class));
VDBMetaData vdb = new VDBMetaData();
@@ -92,4 +87,62 @@
Map<String, DataPolicy> map = message.getAllowedDataPolicies();
assertEquals(1, map.size());
}
+
+ @Test public void testRestoreSecurityContext() {
+ final SecurityHelper sc = new SecurityHelper() {
+ Object mycontext = null;
+
+ @Override
+ public boolean sameSubject(String securityDomain, Object context, Subject subject) {
+ return mycontext == context;
+ }
+ @Override
+ public Subject getSubjectInContext(String securityDomain) {
+ return null;
+ }
+ @Override
+ public Object getSecurityContext(String securityDomain) {
+ return this.mycontext;
+ }
+ @Override
+ public Object createSecurityContext(String securityDomain, Principal p,Object credentials, Subject subject) {
+ return securityDomain+"SC"; //$NON-NLS-1$
+ }
+ @Override
+ public void clearSecurityContext() {
+ this.mycontext = null;
+ }
+ @Override
+ public Object associateSecurityContext(Object context) {
+ Object old = mycontext;
+ this.mycontext = context;
+ return old;
+ }
+ };
+ Object previousSC = sc.createSecurityContext("test", null, null, null); //$NON-NLS-1$
+ sc.associateSecurityContext(previousSC);
+
+ DQPWorkContext message = new DQPWorkContext() {
+ public Subject getSubject() {
+ return new Subject();
+ }
+ };
+ message.setSecurityHelper(sc);
+ message.setSession(Mockito.mock(SessionMetadata.class));
+ final String currentSC = "teiid-security-context"; //$NON-NLS-1$
+ Mockito.stub(message.getSession().getSecurityContext()).toReturn(currentSC);
+
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ assertEquals(currentSC, sc.getSecurityContext(null));
+ }
+ };
+
+ message.runInContext(r);
+
+ assertEquals(previousSC, sc.getSecurityContext(null));
+ }
+
+
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -36,13 +36,12 @@
private static final long serialVersionUID = 3598997061994110254L;
@Override
- public boolean associateSecurityContext(Object newContext) {
+ public Object associateSecurityContext(Object newContext) {
SecurityContext context = SecurityActions.getSecurityContext();
- if (context == null || (newContext != null && newContext != context)) {
+ if (newContext != context) {
SecurityActions.setSecurityContext((SecurityContext)newContext);
- return true;
}
- return false;
+ return context;
}
@Override
Modified: trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -24,7 +24,6 @@
import java.io.IOException;
-import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -387,21 +386,7 @@
this.dqp = dqp;
}
- @Override
- public boolean associateSubjectInContext(String securityDomain, Subject subject) {
- Principal principal = null;
- for(Principal p:subject.getPrincipals()) {
- principal = p;
- break;
- }
- return this.securityHelper.associateSecurityContext(this.securityHelper.createSecurityContext(securityDomain, principal, null, subject));
- }
- @Override
- public Subject getSubjectInContext(String securityDomain) {
- return this.securityHelper.getSubjectInContext(securityDomain);
- }
-
public void setGssSecurityDomain(String domain) {
this.gssSecurityDomain = domain;
}
@@ -410,12 +395,12 @@
public String getGssSecurityDomain(){
return this.gssSecurityDomain;
}
-
- @Override
- public void clearSubjectInContext() {
- this.securityHelper.clearSecurityContext();
- }
+ @Override
+ public SecurityHelper getSecurityHelper() {
+ return securityHelper;
+ }
+
protected Collection<String> getDomainsForUser(List<String> domains, String username) {
// If username is null, return all domains
if (username == null) {
Modified: trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2012-05-21 14:56:10 UTC (rev 4128)
+++ trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2012-05-21 15:16:44 UTC (rev 4129)
@@ -22,6 +22,7 @@
package org.teiid.transport;
+import java.security.Principal;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.Properties;
@@ -53,6 +54,7 @@
import org.teiid.net.socket.AuthenticationType;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.security.Credentials;
+import org.teiid.security.SecurityHelper;
public class LogonImpl implements ILogon {
@@ -67,7 +69,7 @@
public LogonResult logon(Properties connProps) throws LogonException, TeiidComponentException, CommunicationException {
if (this.service.getGssSecurityDomain() != null && connProps.get(ILogon.KRB5TOKEN) != null) {
- Subject user = this.service.getSubjectInContext(this.service.getGssSecurityDomain());
+ Subject user = this.service.getSecurityHelper().getSubjectInContext(this.service.getGssSecurityDomain());
if (user == null) {
throw new LogonException(RuntimePlugin.Event.TEIID40054, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40054));
}
@@ -80,7 +82,6 @@
return logon(connProps, null);
}
-
private LogonResult logon(Properties connProps, byte[] krb5ServiceTicket) throws LogonException {
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
String oldSessionId = workContext.getSessionId();
@@ -158,6 +159,7 @@
String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME);
String password = connProps.getProperty(TeiidURL.CONNECTION.PASSWORD);
+ Object previous = null;
boolean associated = false;
try {
String securityDomain = service.getGssSecurityDomain();
@@ -174,7 +176,15 @@
}
if (result.context.isEstablished()) {
- associated = service.associateSubjectInContext(securityDomain, subject);
+ Principal principal = null;
+ for(Principal p:subject.getPrincipals()) {
+ principal = p;
+ break;
+ }
+ SecurityHelper securityHelper = service.getSecurityHelper();
+ Object securityContext = securityHelper.createSecurityContext(securityDomain, principal, null, subject);
+ previous = securityHelper.associateSecurityContext(securityContext);
+ associated = true;
}
if (!result.context.isEstablished() || !createSession) {
@@ -192,7 +202,7 @@
throw new LogonException(RuntimePlugin.Event.TEIID40061, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40061));
} finally {
if (associated) {
- service.clearSubjectInContext();
+ service.getSecurityHelper().associateSecurityContext(previous);
}
}
}
12 years, 7 months
teiid SVN: r4128 - in branches/7.4.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2012-05-21 10:56:10 -0400 (Mon, 21 May 2012)
New Revision: 4128
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
Log:
TEIID-2045 fix for insert with query expression
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2012-05-21 14:05:09 UTC (rev 4127)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2012-05-21 14:56:10 UTC (rev 4128)
@@ -22,16 +22,7 @@
package org.teiid.query.optimizer.relational.rules;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
@@ -501,7 +492,7 @@
if(sourceNode.getType() != NodeConstants.Types.SOURCE) {
sourceNode = sourceNode.getFirstChild();
}
- if(sourceNode != null && sourceNode.getType() == NodeConstants.Types.SOURCE) {
+ if(sourceNode != null && sourceNode.getType() == NodeConstants.Types.SOURCE && sourceNode.getChildCount() == 0) {
Command command = (Command) sourceNode.getProperty(NodeConstants.Info.VIRTUAL_COMMAND);
if(! (command instanceof QueryCommand)) {
return command;
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2012-05-21 14:05:09 UTC (rev 4127)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2012-05-21 14:56:10 UTC (rev 4128)
@@ -112,7 +112,11 @@
addDistinct(metadata, capFinder, accessNode, queryCommand);
command = queryCommand;
if (intoGroup != null) {
- Insert insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
+ Insert insertCommand = (Insert)commandRoot.getParent().getProperty(NodeConstants.Info.VIRTUAL_COMMAND);
+ if (insertCommand == null) {
+ //TODO: this is probably no longer needed as we rewrite select into
+ insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
+ }
insertCommand.setQueryExpression(queryCommand);
command = insertCommand;
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java 2012-05-21 14:05:09 UTC (rev 4127)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java 2012-05-21 14:56:10 UTC (rev 4128)
@@ -15,6 +15,7 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.TestOptimizer;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
import org.teiid.query.sql.lang.BatchedUpdateCommand;
@@ -367,7 +368,7 @@
// if not doBulkInsert and is doBatching,
// check the command hist to ensure it contains the expected commands
if ( !doBulkInsert && doBatching ) {
- BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(2);
+ BatchedUpdateCommand bu = (BatchedUpdateCommand)dataManager.getCommandHistory().get(2);
assertEquals(2, bu.getUpdateCommands().size());
assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() ); //$NON-NLS-1$
assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() ); //$NON-NLS-1$
@@ -390,5 +391,41 @@
// Run query
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testInsertQueryExpression() throws Exception {
+ String sql = "insert into pm1.g1 select * from pm1.g2"; //$NON-NLS-1$
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION, true);
+ DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(caps);
+
+ QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
+
+ Command command = helpParse(sql);
+ ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+
+ HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
+ List<?>[] expected = new List<?>[] {Arrays.asList(1)};
+ dataManager.addData("INSERT INTO g1 (e1, e2, e3, e4) SELECT g2.e1, g2.e2, g2.e3, g2.e4 FROM g2", expected);
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test public void testInsertQueryExpression1() throws Exception {
+ String sql = "insert into pm1.g1 (e1) select e1 from pm1.g2"; //$NON-NLS-1$
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION, true);
+ DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(caps);
+
+ QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
+
+ Command command = helpParse(sql);
+
+ ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+
+ HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
+ List<?>[] expected = new List<?>[] {Arrays.asList(1)};
+ dataManager.addData("INSERT INTO g1 (e1) SELECT g2.e1 FROM g2", expected);
+ helpProcess(plan, dataManager, expected);
+ }
+
}
12 years, 7 months
teiid SVN: r4127 - trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-05-21 10:05:09 -0400 (Mon, 21 May 2012)
New Revision: 4127
Modified:
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
Log:
TEIID-2011: fixing for metadata changes
Modified: trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
===================================================================
--- trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-05-21 13:14:32 UTC (rev 4126)
+++ trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-05-21 14:05:09 UTC (rev 4127)
@@ -99,13 +99,13 @@
// take a second swipe and add Foreign Keys
for (EntityType<?> entity:entities) {
- Table t = mf.getTable(entity.getName());
+ Table t = mf.getSchema().getTable(entity.getName());
addForeignKeys(mf, model, entity, t);
}
}
private Table addEntity(MetadataFactory mf, Metamodel model, EntityType<?> entity) throws TranslatorException {
- Table table = mf.getTable(entity.getName());
+ Table table = mf.getSchema().getTable(entity.getName());
if (table == null) {
table = mf.addTable(entity.getName());
table.setSupportsUpdate(true);
@@ -218,7 +218,7 @@
for (EntityType et:model.getEntities()) {
if (et.getJavaType().equals(pa.getElementType().getJavaType())) {
- forignTable = mf.getTable(et.getName());
+ forignTable = mf.getSchema().getTable(et.getName());
break;
}
}
12 years, 7 months
teiid SVN: r4126 - in branches/7.7.x: engine/src/main/java/org/teiid/dqp/service and 5 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-05-21 09:14:32 -0400 (Mon, 21 May 2012)
New Revision: 4126
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java
branches/7.7.x/engine/src/main/java/org/teiid/security/SecurityHelper.java
branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java
branches/7.7.x/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java
branches/7.7.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
branches/7.7.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java
Log:
TEIID-2055: Restore the previous security context on the thread explicitly after the task is finished.
Modified: branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -227,12 +227,13 @@
public void runInContext(final Runnable runnable) {
DQPWorkContext previous = DQPWorkContext.getWorkContext();
+ Object previousSC = getSecurityContextOnThread();
boolean associated = attachDQPWorkContext();
try {
runnable.run();
} finally {
if (associated) {
- securityHelper.clearSecurityContext(this.getSecurityDomain());
+ securityHelper.clearSecurityContext(previousSC);
}
DQPWorkContext.releaseWorkContext();
if (previous != null) {
@@ -241,11 +242,18 @@
}
}
+ private Object getSecurityContextOnThread() {
+ if (securityHelper != null) {
+ return securityHelper.getSecurityContextOnThread();
+ }
+ return null;
+ }
+
private boolean attachDQPWorkContext() {
DQPWorkContext.setWorkContext(this);
boolean associated = false;
if (securityHelper != null && this.getSubject() != null) {
- associated = securityHelper.associateSecurityContext(this.getSecurityDomain(), this.getSecurityContext());
+ associated = securityHelper.associateSecurityContext(this.getSecurityContext());
}
return associated;
}
Modified: branches/7.7.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/service/SessionService.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -152,5 +152,7 @@
Subject getSubjectInContext(String securityDomain);
- public void clearSubjectInContext();
+ public void clearSubjectInContext(Object prevSecurityContext);
+
+ Object getSecurityContextOnThread();
}
Modified: branches/7.7.x/engine/src/main/java/org/teiid/security/SecurityHelper.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/security/SecurityHelper.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/engine/src/main/java/org/teiid/security/SecurityHelper.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -28,10 +28,12 @@
public interface SecurityHelper {
- boolean associateSecurityContext(String securityDomain, Object context);
+ boolean associateSecurityContext(Object context);
- void clearSecurityContext(String securityDomain);
+ void clearSecurityContext(Object prevContext);
+ Object getSecurityContextOnThread();
+
Object getSecurityContext(String securityDomain);
Object createSecurityContext(String securityDomain, Principal p, Object credentials, Subject subject);
Modified: branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -22,14 +22,18 @@
package org.teiid.dqp.internal.process;
+import java.security.Principal;
import java.util.Map;
+import javax.security.auth.Subject;
+
import org.mockito.Mockito;
import org.teiid.adminapi.DataPolicy;
import org.teiid.adminapi.impl.DataPolicyMetadata;
import org.teiid.adminapi.impl.SessionMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.core.util.UnitTestUtil;
+import org.teiid.security.SecurityHelper;
import junit.framework.TestCase;
@@ -92,4 +96,65 @@
Map<String, DataPolicy> map = message.getAllowedDataPolicies();
assertEquals(1, map.size());
}
+
+ public void testRestoreSecurityContext() {
+ final SecurityHelper sc = new SecurityHelper() {
+ Object mycontext = null;
+
+ @Override
+ public boolean sameSubject(String securityDomain, Object context, Subject subject) {
+ return mycontext == context;
+ }
+ @Override
+ public Subject getSubjectInContext(String securityDomain) {
+ return null;
+ }
+ @Override
+ public Object getSecurityContextOnThread() {
+ return this.mycontext;
+ }
+ @Override
+ public Object getSecurityContext(String securityDomain) {
+ return this.mycontext;
+ }
+ @Override
+ public Object createSecurityContext(String securityDomain, Principal p,Object credentials, Subject subject) {
+ return securityDomain+"SC"; //$NON-NLS-1$
+ }
+ @Override
+ public void clearSecurityContext(Object prevContext) {
+ this.mycontext = prevContext;
+ }
+ @Override
+ public boolean associateSecurityContext(Object context) {
+ this.mycontext = context;
+ return true;
+ }
+ };
+ Object previousSC = sc.createSecurityContext("test", null, null, null); //$NON-NLS-1$
+ sc.associateSecurityContext(previousSC);
+
+ DQPWorkContext message = new DQPWorkContext() {
+ public Subject getSubject() {
+ return new Subject();
+ }
+ };
+ message.setSecurityHelper(sc);
+ message.setSession(Mockito.mock(SessionMetadata.class));
+ final String currentSC = "teiid-security-context"; //$NON-NLS-1$
+ Mockito.stub(message.getSession().getSecurityContext()).toReturn(currentSC);
+
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ assertEquals(currentSC, sc.getSecurityContextOnThread());
+ }
+ };
+
+ message.runInContext(r);
+
+ assertEquals(previousSC, sc.getSecurityContextOnThread());
+ }
+
+
}
Modified: branches/7.7.x/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java
===================================================================
--- branches/7.7.x/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -36,7 +36,7 @@
private static final long serialVersionUID = 3598997061994110254L;
@Override
- public boolean associateSecurityContext(String securityDomain, Object newContext) {
+ public boolean associateSecurityContext(Object newContext) {
SecurityContext context = SecurityActions.getSecurityContext();
if (context == null || (newContext != null && newContext != context)) {
SecurityActions.setSecurityContext((SecurityContext)newContext);
@@ -46,11 +46,19 @@
}
@Override
- public void clearSecurityContext(String context) {
+ public void clearSecurityContext(Object prevContext) {
SecurityActions.clearSecurityContext();
+ if (prevContext != null) {
+ SecurityActions.setSecurityContext((SecurityContext)prevContext);
+ }
}
@Override
+ public Object getSecurityContextOnThread() {
+ return SecurityActions.getSecurityContext();
+ }
+
+ @Override
public Object getSecurityContext(String securityDomain) {
SecurityContext sc = SecurityActions.getSecurityContext();
if (sc != null && sc.getSecurityDomain().equals(securityDomain)) {
Modified: branches/7.7.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
===================================================================
--- branches/7.7.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -430,7 +430,7 @@
principal = p;
break;
}
- return this.securityHelper.associateSecurityContext(securityDomain, this.securityHelper.createSecurityContext(securityDomain, principal, null, subject));
+ return this.securityHelper.associateSecurityContext(this.securityHelper.createSecurityContext(securityDomain, principal, null, subject));
}
@Override
@@ -438,6 +438,11 @@
return this.securityHelper.getSubjectInContext(securityDomain);
}
+ @Override
+ public Object getSecurityContextOnThread() {
+ return this.securityHelper.getSecurityContextOnThread();
+ }
+
public void setGssSecurityDomain(String domain) {
this.gssSecurityDomain = domain;
}
@@ -448,7 +453,7 @@
}
@Override
- public void clearSubjectInContext() {
- this.securityHelper.clearSecurityContext(null);
+ public void clearSubjectInContext(Object previousSC) {
+ this.securityHelper.clearSecurityContext(previousSC);
}
}
Modified: branches/7.7.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java
===================================================================
--- branches/7.7.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2012-05-20 13:12:16 UTC (rev 4125)
+++ branches/7.7.x/runtime/src/main/java/org/teiid/transport/LogonImpl.java 2012-05-21 13:14:32 UTC (rev 4126)
@@ -160,6 +160,7 @@
String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME);
String password = connProps.getProperty(TeiidURL.CONNECTION.PASSWORD);
boolean assosiated = false;
+ Object previousSC = null;
try {
String securityDomain = service.getGssSecurityDomain();
if (securityDomain == null) {
@@ -175,6 +176,7 @@
}
if (result.context.isEstablished()) {
+ previousSC = service.getSecurityContextOnThread();
assosiated = service.associateSubjectInContext(securityDomain, subject);
}
@@ -192,7 +194,7 @@
throw new LogonException(e, RuntimePlugin.Util.getString("krb5_login_failed")); //$NON-NLS-1$
} finally {
if (assosiated) {
- this.service.clearSubjectInContext();
+ this.service.clearSubjectInContext(previousSC);
}
}
}
12 years, 7 months