Author: van.halbert
Date: 2012-09-12 15:04:53 -0400 (Wed, 12 Sep 2012)
New Revision: 4431
Added:
trunk/connectors/translator-object/
trunk/connectors/translator-object/.classpath
trunk/connectors/translator-object/.project
trunk/connectors/translator-object/.settings/
trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs
trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs
trunk/connectors/translator-object/pom.xml
trunk/connectors/translator-object/src/
trunk/connectors/translator-object/src/main/
trunk/connectors/translator-object/src/main/java/
trunk/connectors/translator-object/src/main/java/org/
trunk/connectors/translator-object/src/main/java/org/teiid/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchStrategy.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SelectProjections.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheSearchByKey.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java
trunk/connectors/translator-object/src/main/resources/
trunk/connectors/translator-object/src/main/resources/META-INF/
trunk/connectors/translator-object/src/main/resources/META-INF/services/
trunk/connectors/translator-object/src/main/resources/META-INF/services/org.teiid.translator.ExecutionFactory
trunk/connectors/translator-object/src/main/resources/org/
trunk/connectors/translator-object/src/main/resources/org/teiid/
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
trunk/connectors/translator-object/src/test/
trunk/connectors/translator-object/src/test/java/
trunk/connectors/translator-object/src/test/java/org/
trunk/connectors/translator-object/src/test/java/org/teiid/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/FakeStrategy.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestSelectProjections.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/RemoteInfinispanTestHelper.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Leg.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/MyFieldBridge.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Trade.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Transaction.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/VDBUtility.java
trunk/connectors/translator-object/src/test/resources/
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetAllTrades.expected
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetAllTradesAndLegs.expected
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetAllTradesLegsAndTransactions.expected
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetOneTrade.expected
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetOneTradeAndLegs.expected
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryInCriteria.expected
trunk/connectors/translator-object/src/test/resources/ObjectProject/
trunk/connectors/translator-object/src/test/resources/ObjectProject/.project
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade.vdb
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_Object.xmi
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_View.xmi
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryAnd.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryCompareEQBoolean.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryCompareNEBoolean.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryLikeCriteria1.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryLikeCriteria2.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryRangeAbove.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryRangeBelow.expected
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryRangeBetween.expected
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_config.xml
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_indexing_config.xml
trunk/connectors/translator-object/src/test/resources/infinispan_remote_config.xml
Log:
TEIID-1992 Committing the translator-project that will support connecting to an Infinispan
cache or a cache of type Map and perform searches on those caches. The OBJECTTABLE
function will need to be used to process the objects returned from the cache and produce
results in a tabular fashion.
Added: trunk/connectors/translator-object/.classpath
===================================================================
--- trunk/connectors/translator-object/.classpath (rev 0)
+++ trunk/connectors/translator-object/.classpath 2012-09-12 19:04:53 UTC (rev 4431)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes"
path="src/main/java"/>
+ <classpathentry excluding="**" kind="src"
output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry excluding="**" kind="src"
output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: trunk/connectors/translator-object/.project
===================================================================
--- trunk/connectors/translator-object/.project (rev 0)
+++ trunk/connectors/translator-object/.project 2012-09-12 19:04:53 UTC (rev 4431)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>translator-object</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++ trunk/connectors/translator-object/.settings/org.eclipse.jdt.core.prefs 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,6 @@
+#Wed Jan 25 12:40:49 CST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
Added: trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs
(rev 0)
+++ trunk/connectors/translator-object/.settings/org.maven.ide.eclipse.prefs 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,9 @@
+#Wed Jan 25 12:40:16 CST 2012
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
Added: trunk/connectors/translator-object/pom.xml
===================================================================
--- trunk/connectors/translator-object/pom.xml (rev 0)
+++ trunk/connectors/translator-object/pom.xml 2012-09-12 19:04:53 UTC (rev 4431)
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>connectors</artifactId>
+ <groupId>org.jboss.teiid</groupId>
+ <version>8.2.0.Alpha1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>translator-object</artifactId>
+ <groupId>org.jboss.teiid.connectors</groupId>
+ <name>Object Translator</name>
+ <description>This is the tranlator for API interfaces</description>
+
+ <properties>
+ <version.hibernate.search>4.1.1.Final</version.hibernate.search>
+ <mockito.all.version>1.8.4</mockito.all.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-client</artifactId>
+ <type>test-jar</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-metadata</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-metadata</artifactId>
+ <type>test-jar</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>${version.org.infinispan}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-query</artifactId>
+ <version>${version.org.infinispan}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-search</artifactId>
+ <version>${version.hibernate.search}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-client-hotrod</artifactId>
+ <version>${version.org.infinispan}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-server-hotrod</artifactId>
+ <version>${version.org.infinispan}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-server-hotrod</artifactId>
+ <version>${version.org.infinispan}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jgroups</groupId>
+ <artifactId>jgroups</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.marshalling</groupId>
+ <artifactId>jboss-marshalling-river</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>${mockito.all.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <outputDirectory>target/classes</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.properties</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ <excludes>
+ <exclude>**/*.xml</exclude>
+ <exclude>**/*.properties</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ </build>
+</project>
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,119 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.teiid.language.Select;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.DataNotAvailableException;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.TranslatorException;
+
+/**
+ * Execution of the SELECT Command
+ */
+public class ObjectExecution implements ResultSetExecution {
+
+ private Select query;
+ private Object connection;
+ private ObjectExecutionFactory config;
+
+ private Iterator<Object> resultsIt = null;
+
+ public ObjectExecution(Select query, RuntimeMetadata metadata,
+ ObjectExecutionFactory factory, Object connection) {
+ this.query = query;
+ this.connection = connection;
+ this.config = factory;
+ }
+
+ @Override
+ public void execute() throws TranslatorException {
+
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR,
+ "ObjectExecution command: " + query.toString()); //$NON-NLS-1$
+
+ SelectProjections projections = SelectProjections.create(config);
+ projections.parse(query);
+
+ List<Object> results = executeQuery(projections);
+
+ if (results != null && results.size() > 0) {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR,
+ "ObjectExecution number of returned objects is : " + results.size());
//$NON-NLS-1$
+
+ } else {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR,
+ "ObjectExecution number of objects returned is : 0"); //$NON-NLS-1$
+
+ results = Collections.emptyList();
+ }
+
+ this.resultsIt = results.iterator();
+ }
+
+ protected List<Object> executeQuery(SelectProjections projections)
+ throws TranslatorException {
+
+ SearchStrategy is = this.config.getSearchStrategy();
+ LogManager
+ .logTrace(
+ LogConstants.CTX_CONNECTOR,
+ "ObjectExecution calling search strategy : " + is.getClass().getName());
//$NON-NLS-1$
+
+ return is.performSearch((Select) query, projections, this.config,
+ this.connection);
+
+ }
+
+ @Override
+ public List<Object> next() throws TranslatorException,
+ DataNotAvailableException {
+ // create and return one row at a time for your resultset.
+ if (resultsIt.hasNext()) {
+ List<Object> r = new ArrayList<Object>(1);
+ r.add(resultsIt.next());
+ return r;
+ }
+ return null;
+ }
+
+ @Override
+ public void close() {
+ this.query = null;
+ this.connection = null;
+ this.config = null;
+ this.resultsIt = null;
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,244 @@
+/*
+ * 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 java.util.Collections;
+import java.util.List;
+
+import javax.resource.cci.ConnectionFactory;
+
+import org.teiid.language.QueryExpression;
+import org.teiid.language.Select;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TranslatorProperty;
+import org.teiid.translator.object.infinispan.search.SearchByKey;
+import org.teiid.translator.object.util.ObjectUtil;
+
+/**
+ * The ObjectExecutionFactory is a base implementation for connecting to an
+ * Object data source that's stored in a cache.
+ *
+ *
+ * @author vhalbert
+ *
+ */
+public abstract class ObjectExecutionFactory extends
+ ExecutionFactory<ConnectionFactory, Object> {
+
+ public static final int MAX_SET_SIZE = 1000;
+
+ /*
+ * SearchStrategy is the implementation that will perform a specific cache
+ * lookup algorithm
+ */
+ private SearchStrategy searchStrategy = null;
+ private String searchStrategyClassName = null;
+
+ // rootClassName identifies the name of the class that is identified by the
+ // unique key in the cache
+ private String rootClassName = null;
+ private Class<?> rootClass = null;
+
+ public ObjectExecutionFactory() {
+ super();
+
+ this.setSourceRequiredForMetadata(false);
+ this.setMaxInCriteriaSize(MAX_SET_SIZE);
+ this.setMaxDependentInPredicates(1);
+
+ this.setSupportsOrderBy(false);
+ this.setSupportsSelectDistinct(false);
+ this.setSupportsInnerJoins(false);
+ this.setSupportsFullOuterJoins(false);
+ this.setSupportsOuterJoins(false);
+
+ }
+
+ @Override
+ public void start() throws TranslatorException {
+ super.start();
+
+ if (this.getRootClassName() == null
+ || this.getRootClassName().trim().length() == -1) {
+ String msg = ObjectPlugin.Util.getString(
+ "ObjectExecutionFactory.rootClassNameNotDefined",
+ new Object[] {});
+ throw new TranslatorException(msg); //$NON-NLS-1$
+ }
+
+ try {
+ rootClass = Class.forName(rootClassName.trim(), true, getClass()
+ .getClassLoader());
+
+ searchStrategy = (SearchStrategy) ObjectUtil.createObject(
+ searchStrategyClassName, Collections.EMPTY_LIST, getClass()
+ .getClassLoader());
+
+ } catch (ClassNotFoundException e) {
+ String msg = ObjectPlugin.Util.getString(
+ "ObjectExecutionFactory.rootClassNotFound",
+ new Object[] { this.rootClassName });
+ throw new TranslatorException(msg); //$NON-NLS-1$
+ }
+
+ }
+
+ @Override
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Object connection) throws TranslatorException {
+
+ return new ObjectExecution((Select) command, metadata, this, connection);
+
+ }
+
+ public List getSupportedFunctions() {
+ return Collections.EMPTY_LIST;
+ }
+
+ @Override
+ public boolean supportsInnerJoins() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOuterJoins() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsFullOuterJoins() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsConvert(int fromType, int toType) {
+ return false;
+ }
+
+ public boolean supportsCompareCriteriaEquals() {
+ return true;
+ }
+
+ public boolean supportsInCriteria() {
+ return true;
+ }
+
+ public boolean supportsOrCriteria() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsLikeCriteria() {
+ // at this point, i've been unable to get the Like to work.
+ return false;
+ }
+
+ @Override
+ public boolean supportsNotCriteria() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSubqueryInOn() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOrderBy() {
+ return false;
+ }
+
+ /**
+ * Get the class name for the search strategy that will be used to perform
+ * object lookups in the cache.
+ *
+ * @return String class name
+ * @see #setSearchStrategyClassName(String)
+ */
+ public String getSearchStrategyClassName() {
+ return this.searchStrategyClassName;
+ }
+
+ /**
+ * Set the class name for the search strategy that will be used to perform
+ * object lookups in the cache.
+ * <p>
+ * Default is {@link SearchByKey}
+ *
+ * @param searchStrategyClassName
+ * @see #getSearchStrategyClassName()
+ */
+
+ public void setSearchStrategyClassName(String searchStrategyClassName) {
+ this.searchStrategyClassName = searchStrategyClassName;
+ }
+
+ protected SearchStrategy getSearchStrategy() {
+ return this.searchStrategy;
+ }
+
+
+ /**
+ * Call to get the class name of the root object in the cache. This
+ * identifies the name of the class that is identified by the unique key in
+ * the cache
+ *
+ * @return
+ */
+ @TranslatorProperty(display = "Root ClassName of Cached Object", advanced =
true)
+ public String getRootClassName() {
+ return this.rootClassName;
+ }
+
+ /**
+ * Call to set the root class name for the cache accessed by this factory
+ * instance.
+ * <p>
+ * If the root class name has already been set, subsequent calls will have
+ * no effect.
+ *
+ * @param rootClassName
+ */
+ public synchronized void setRootClassName(String rootClassName) {
+ if (this.rootClassName == null) {
+ this.rootClassName = rootClassName;
+
+ }
+ }
+
+ /**
+ * Call to get the class specified by calling
+ * {@link #setRootClassName(String)}
+ *
+ * @return Class
+ */
+ public Class<?> getRootClass() {
+ return this.rootClass;
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectPlugin.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,47 @@
+/*
+ * 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 java.util.ResourceBundle;
+
+import org.teiid.core.BundleUtil;
+
+
+/**
+ * ObjectPlugin
+ */
+public class ObjectPlugin {
+
+ public static final String PLUGIN_ID = "org.teiid.translator.object" ;
//$NON-NLS-1$
+
+ /**
+ * Provides access to the plugin's log and to it's resources.
+ */
+ public static final BundleUtil Util = new BundleUtil(PLUGIN_ID, PLUGIN_ID +
".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$
//$NON-NLS-2$
+
+ public static enum Event implements BundleUtil.Event {
+ TEIID12001, // unsupported capability
+ TEIID12005,
+ TEIID12006,
+ TEIID12007,
+ }
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchStrategy.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchStrategy.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SearchStrategy.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,20 @@
+package org.teiid.translator.object;
+
+import java.util.List;
+
+import org.teiid.language.Select;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.SelectProjections;
+
+/**
+ * Each SearchStrategy implementation is based on the data source language specifics for
searching its cache.
+ *
+ * @author vhalbert
+ *
+ */
+public interface SearchStrategy {
+
+ public List<Object> performSearch(Select command, SelectProjections projections,
+ ObjectExecutionFactory factory, Object connection) throws TranslatorException;
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SelectProjections.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SelectProjections.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/SelectProjections.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,118 @@
+/*
+ * 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 java.util.List;
+
+import org.teiid.language.Command;
+import org.teiid.language.NamedTable;
+import org.teiid.language.Select;
+import org.teiid.language.TableReference;
+import org.teiid.metadata.ForeignKey;
+import org.teiid.metadata.Table;
+
+/**
+ * The SelectProjections is responsible for parsing the select attributes from
+ * the {@link Command command} into usable information for translating result
+ * objects into rows.
+ *
+ * @author vhalbert
+ *
+ */
+public class SelectProjections {
+
+ private boolean isRootTableInSelect = false;
+
+ private Table rootTable = null;
+
+ private String rootClassName = null;
+
+ private SelectProjections(String rootClassName) {
+ this.rootClassName = rootClassName;
+ }
+
+ public static SelectProjections create(ObjectExecutionFactory factory) {
+ return new SelectProjections(factory.getRootClassName());
+ }
+
+ public String getRootTableName() {
+ return this.rootTable.getName();
+ }
+
+ 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 void parse(Select query) {
+ Table roottable = null;
+
+ List<TableReference> tables = query.getFrom();
+ Table lastGroup = null;
+ for (TableReference t : tables) {
+ if (t instanceof NamedTable) {
+ lastGroup = ((NamedTable) t).getMetadataObject();
+ if (lastGroup.getNameInSource().equals(rootClassName)) {
+ roottable = lastGroup;
+ this.isRootTableInSelect = true;
+ break;
+ }
+ }
+ }
+ // still need to find the roottable, even though its not part of the
+ // query
+ if (!this.isRootTableInSelect) {
+ roottable = determineRootTable(lastGroup);
+ }
+
+ this.rootTable = roottable;
+
+ }
+
+ private Table determineRootTable(Table t) {
+ if (t == null)
+ return null;
+
+ if (t.getForeignKeys() != null && !t.getForeignKeys().isEmpty()) {
+ List<ForeignKey> fks = t.getForeignKeys();
+ for (ForeignKey fk : fks) {
+ if (fk.getPrimaryKey() != null
+ && fk.getPrimaryKey().getParent() != t) {
+ return determineRootTable(fk.getPrimaryKey().getParent());
+ }
+ }
+ }
+
+ return t;
+ }
+
+ protected void cleanup() {
+ rootTable = null;
+
+ }
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanExecutionFactory.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,252 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.infinispan.Cache;
+import org.infinispan.api.BasicCache;
+import org.infinispan.api.BasicCacheContainer;
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.DefaultCacheManager;
+import org.teiid.language.QueryExpression;
+import org.teiid.language.Select;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TranslatorProperty;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.ObjectExecutionFactory;
+import org.teiid.translator.object.ObjectPlugin;
+import org.teiid.translator.object.infinispan.search.LuceneSearch;
+import org.teiid.translator.object.infinispan.search.SearchByKey;
+
+@Translator(name = "infinispanCache", description = "The Infinispan Cache
Translator")
+public class InfinispanExecutionFactory extends ObjectExecutionFactory {
+ public static final String PROPERTIES_FILE = "META-INF" + File.separator
+ + "datagrid.properties";
+
+ private boolean useLeceneSearching = false;
+ private String cacheName = null;
+ private String configurationFileName = null;
+
+ private BasicCacheContainer cacheContainer = null;
+
+ public InfinispanExecutionFactory() {
+ super();
+
+ this.setSearchStrategyClassName(SearchByKey.class.getName());
+ }
+
+ @Override
+ public void start() throws TranslatorException {
+
+ if (this.getCacheName() == null || this.getCacheName().isEmpty()) {
+ String msg = ObjectPlugin.Util.getString(
+ "InfinispanExecutionFactory.cacheNameNotDefined",
+ new Object[] {});
+ throw new TranslatorException(msg); //$NON-NLS-1$
+ }
+
+ super.start();
+
+ if (createCacheContainer()) {
+ cacheContainer = this.getCacheContainer();
+ }
+ }
+
+ @Override
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Object connection) throws TranslatorException {
+
+ return new ObjectExecution((Select) command, metadata, this,
+ (cacheContainer != null ? cacheContainer : connection));
+
+ }
+
+ protected boolean createCacheContainer() {
+ if (this.getConfigurationFileName() != null) {
+ return true;
+ }
+ return false;
+
+ }
+
+ /**
+ * 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.
+ *
+ * @return
+ * @see #setCacheName(String)
+ */
+ @TranslatorProperty(display = "CacheName", advanced = true)
+ public String getCacheName() {
+ return this.cacheName;
+ }
+
+ /**
+ * Set the cacheName that will be used to find the named cache.
+ *
+ * @param cacheName
+ * @see #getCacheName()
+ */
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ /**
+ * Indicates if Hibernate Search and Apache Lucene are used to index and
+ * search objects
+ *
+ * @since 6.1.0
+ */
+ @TranslatorProperty(display = "Use Lucene Searching", description =
"True, assumes objects have Hibernate Search annotations", advanced = true)
+ public boolean useLuceneSearching() {
+ return useLeceneSearching;
+ }
+
+ public void setUseLeceneSearching(boolean useLeceneSearching) {
+ this.useLeceneSearching = useLeceneSearching;
+ if (useLeceneSearching) {
+ this.setSearchStrategyClassName(LuceneSearch.class.getName());
+ } else {
+ this.setSearchStrategyClassName(SearchByKey.class.getName());
+ }
+ }
+
+ /**
+ * Get the name of the configuration resource or file that should be used if
+ * a {@link Cache cache} is to be created using the
+ * {@link DefaultCacheManager}. If not specified, a default configuration
+ * will be used.
+ *
+ * @return the name of the resource or file configuration that should be
+ * passed to the {@link CacheContainer}, or null if the default
+ * configuration should be used
+ * @see #setConfigurationFileName(String)
+ */
+ @TranslatorProperty(display = "ConfigurationFileName", advanced = true)
+ public String getConfigurationFileName() {
+ return configurationFileName;
+ }
+
+ /**
+ * Set the name of the configuration that should be used if a {@link Cache
+ * cache} is to be created using the {@link DefaultCacheManager}.
+ *
+ * @param configurationFileName
+ * the name of the configuration file that should be used to load
+ * the {@link CacheContainer}, or null if the default
+ * configuration should be used
+ * @see #getConfigurationFileName()
+ */
+ public synchronized void setConfigurationFileName(
+ String configurationFileName) {
+ if (this.configurationFileName == configurationFileName
+ || this.configurationFileName != null
+ && this.configurationFileName.equals(configurationFileName))
+ return; // unchanged
+ this.configurationFileName = configurationFileName;
+ }
+
+ public BasicCache<String, Object> getCache(Object connection)
+ throws TranslatorException {
+ BasicCache<String, Object> cache = null;
+ if (connection instanceof BasicCacheContainer) {
+ BasicCacheContainer bc = (BasicCacheContainer) connection;
+
+ if (this.getCacheName() != null) {
+ cache = bc.getCache(this.getCacheName());
+ } else {
+ cache = bc.getCache();
+ }
+ } else if (connection instanceof BasicCache) {
+ cache = (BasicCache) connection;
+ } else {
+ String msg = ObjectPlugin.Util.getString(
+ "InfinispanExecutionFactory.unsupportedConnectionType",
+ new Object[] { connection.getClass().getName(),
+ "either BasicCache or BasicCacheContainer" });
+ throw new TranslatorException(msg); //$NON-NLS-1$
+
+ }
+
+ if (cache == null) {
+ String msg = ObjectPlugin.Util.getString(
+ "InfinispanExecutionFactory.noCache", new Object[] { (this
+ .getCacheName() != null ? this.getCacheName()
+ : "DefaultCache") });
+ throw new TranslatorException(msg); //$NON-NLS-1$
+ }
+
+ return cache;
+
+ }
+
+ /**
+ * Method for obtaining the CacheContainer. This method will be called to
+ * create a container based on the <code>configurationFileName</code>
+ * specified.
+ *
+ * @return BasicCacheContainer
+ * @throws TranslatorException
+ * if there an issue obtaining the cache
+ * @see #getCache()
+ */
+ protected synchronized BasicCacheContainer getCacheContainer()
+ throws TranslatorException {
+ BasicCacheContainer container = null;
+
+ try {
+ container = new DefaultCacheManager(
+ this.getConfigurationFileName());
+ LogManager
+ .logInfo(LogConstants.CTX_CONNECTOR,
+ "=== Using DefaultCacheManager (loaded by configuration) ===");
//$NON-NLS-1$
+ } catch (IOException e) {
+ throw new TranslatorException(e);
+ }
+
+ return container;
+ }
+
+ protected String jdgProperty(String name) {
+ Properties props = new Properties();
+ try {
+ props.load(this.getClass().getClassLoader()
+ .getResourceAsStream(PROPERTIES_FILE));
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ return props.getProperty(name);
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanRemoteExecutionFactory.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,150 @@
+/*
+ * 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 org.infinispan.api.BasicCacheContainer;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.manager.CacheContainer;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.translator.Translator;
+
+/**
+ * The InfinispanRemoteExecutionFactory is used to obtain a remote
+ * {@link CacheContainer}. The {@link #getRemoteServerList() serverList} must
+ * provide 1 or more <code>host:port[;host:port...]</code> combinations that
+ * indicate where the remote server(s) are located.
+ *
+ * @author vhalbert
+ *
+ */
+
+@Translator(name = "infinispanRemoteCache", description = "The Execution
Factory for Remote Infinispan Cache")
+public class InfinispanRemoteExecutionFactory extends
+ InfinispanExecutionFactory {
+ // public static final String DATAGRID_HOST = "datagrid.host";
+ // public static final String HOTROD_PORT = "datagrid.hotrod.port";
+
+ private BasicCacheContainer manager;
+
+ private volatile String remoteServerList;
+
+ public InfinispanRemoteExecutionFactory() {
+ super();
+ this.setSourceRequired(false);
+ }
+
+
+ protected boolean createCacheContainer() {
+ if (this.getConfigurationFileName() != null) {
+ return true;
+ }
+
+ if (this.getRemoteServerList() != null
+ || this.getRemoteServerList().length() > 0) {
+ return true;
+ }
+
+ return false;
+
+ }
+
+ @Override
+ public boolean isSourceRequired() {
+ return true;
+ }
+
+ /**
+ * Get the list of remote servers that make up the Infinispan cluster. The
+ * servers must be Infinispan HotRod servers. The list must be in the
+ * appropriate format of <code>host:port[;host:port...]</code> that would
be
+ * used when defining an Infinispan {@link RemoteCacheManager} instance. If
+ * the value is missing, <code>localhost:11311</code> is assumed.
+ *
+ * @return the names of the remote servers
+ */
+ public String getRemoteServerList() {
+ return remoteServerList;
+ }
+
+ /**
+ * Set the list of remote servers that make up the Infinispan cluster. The
+ * servers must be Infinispan HotRod servers. The list must be in the
+ * appropriate format of <code>host:port[;host:port...]</code> that would
be
+ * used when defining an Infinispan {@link RemoteCacheManager} instance. If
+ * the value is missing, <code>localhost:11311</code> is assumed.
+ *
+ * @param remoteInfinispanServerList
+ * the server list in appropriate
+ * <code>server:port;server2:port2</code> format.
+ *
+ * @see #getRemoteServerList()
+ */
+ public synchronized void setRemoteServerList(
+ String remoteInfinispanServerList) {
+ if (this.remoteServerList == remoteInfinispanServerList
+ || this.remoteServerList != null
+ && this.remoteServerList.equals(remoteInfinispanServerList))
+ return; // unchanged
+ this.remoteServerList = remoteInfinispanServerList;
+ }
+
+ @Override
+ protected synchronized BasicCacheContainer getCacheContainer() {
+ RemoteCacheManager container = null;
+ if (this.getConfigurationFileName() != null) {
+ container = new RemoteCacheManager(this.getConfigurationFileName());
+
+ LogManager
+ .logInfo(LogConstants.CTX_CONNECTOR,
+ "=== Using RemoteCacheManager (loaded by configuration) ===");
//$NON-NLS-1$
+
+ } else {
+ if (this.getRemoteServerList() == null
+ || this.getRemoteServerList().isEmpty()
+ || this.getRemoteServerList().equals("")) {
+ container = new RemoteCacheManager();
+
+ LogManager
+ .logInfo(LogConstants.CTX_CONNECTOR,
+ "=== Using RemoteCacheManager (no serverlist defined) ===");
//$NON-NLS-1$
+
+ } else {
+ container = new RemoteCacheManager(this.getRemoteServerList());
+
+ LogManager
+ .logInfo(LogConstants.CTX_CONNECTOR,
+ "=== Using RemoteCacheManager (loaded by serverlist) ===");
//$NON-NLS-1$
+
+ }
+ }
+
+ return container;
+
+ }
+
+ public void cleanUp() {
+ manager.stop();
+ manager = null;
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,421 @@
+/*
+ * 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.search;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lucene.search.Query;
+import org.hibernate.search.query.dsl.BooleanJunction;
+import org.hibernate.search.query.dsl.QueryBuilder;
+import org.infinispan.Cache;
+import org.infinispan.query.CacheQuery;
+import org.infinispan.query.Search;
+import org.infinispan.query.SearchManager;
+import org.teiid.language.AndOr;
+import org.teiid.language.ColumnReference;
+import org.teiid.language.Comparison;
+import org.teiid.language.Condition;
+import org.teiid.language.Exists;
+import org.teiid.language.Expression;
+import org.teiid.language.In;
+import org.teiid.language.Like;
+import org.teiid.language.Literal;
+import org.teiid.language.Select;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectExecutionFactory;
+import org.teiid.translator.object.ObjectPlugin;
+import org.teiid.translator.object.SearchStrategy;
+import org.teiid.translator.object.SelectProjections;
+import org.teiid.translator.object.infinispan.InfinispanExecutionFactory;
+
+/**
+ * LuceneSearch will parse the WHERE criteria and build the search query(s)
+ * that's used to retrieve the results from an Infinispan cache.
+ *
+ * @author vhalbert
+ *
+ */
+public class LuceneSearch implements SearchStrategy {
+ protected List<String> exceptionMessages = new ArrayList<String>(2);
+
+ private QueryBuilder queryBuilder;
+
+ public LuceneSearch() {
+ }
+
+ public List<Object> performSearch(Select command,
+ SelectProjections projections,
+ ObjectExecutionFactory objectFactory, Object connection)
+ throws TranslatorException {
+
+ InfinispanExecutionFactory factory = (InfinispanExecutionFactory) objectFactory;
+
+ SearchManager searchManager = Search
+ .getSearchManager((Cache<?, ?>) factory.getCache(connection));
+
+ queryBuilder = searchManager.buildQueryBuilderForClass(
+ factory.getRootClass()).get();
+
+ BooleanJunction<BooleanJunction> junction = queryBuilder.bool();
+ boolean createdQueries = buildQueryFromWhereClause(command.getWhere(),
+ junction);
+
+ // check for errors
+ this.throwExceptionIfFound();
+
+ Query query = null;
+ if (createdQueries) {
+ query = junction.createQuery();
+ } else {
+ query = queryBuilder.all().createQuery();
+ }
+
+ CacheQuery cacheQuery = searchManager.getQuery(query,
+ factory.getRootClass()); // rootNodeType
+
+ List<Object> results = cacheQuery.list();
+ if (results == null || results.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ return results;
+ }
+
+ private boolean buildQueryFromWhereClause(Condition criteria,
+ BooleanJunction<BooleanJunction> junction)
+ throws TranslatorException {
+ boolean createdQueries = false;
+ BooleanJunction<BooleanJunction> inUse = junction;
+
+ if (criteria instanceof AndOr) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR,
+ "Parsing compound criteria."); //$NON-NLS-1$
+ AndOr crit = (AndOr) criteria;
+ AndOr.Operator op = crit.getOperator();
+
+ switch (op) {
+ case AND:
+
+ BooleanJunction<BooleanJunction> leftAnd = this.queryBuilder
+ .bool();
+ boolean andLeftHasQueries = buildQueryFromWhereClause(
+ crit.getLeftCondition(), leftAnd);
+
+ BooleanJunction<BooleanJunction> rightAnd = this.queryBuilder
+ .bool();
+ boolean andRightHasQueries = buildQueryFromWhereClause(
+ crit.getRightCondition(), rightAnd);
+
+ if (andLeftHasQueries && andRightHasQueries) {
+ leftAnd.must(rightAnd.createQuery());
+ inUse.should(leftAnd.createQuery());
+ } else if (andLeftHasQueries) {
+
+ inUse.should(leftAnd.createQuery());
+ } else if (andRightHasQueries) {
+ inUse.should(rightAnd.createQuery());
+ }
+
+ createdQueries = (andLeftHasQueries ? andLeftHasQueries
+ : andRightHasQueries);
+
+ break;
+
+ case OR:
+
+ boolean orLeftHasQueries = buildQueryFromWhereClause(
+ crit.getLeftCondition(), inUse);
+ boolean orRightHasQueries = buildQueryFromWhereClause(
+ crit.getRightCondition(), inUse);
+
+ createdQueries = (orLeftHasQueries ? orLeftHasQueries
+ : orRightHasQueries);
+
+ break;
+
+ default:
+ final String msg = ObjectPlugin.Util
+ .getString("LuceneSearch.invalidOperator", new Object[] { op, "And,
Or" }); //$NON-NLS-1$
+ throw new TranslatorException(msg);
+ }
+
+ } else if (criteria instanceof Comparison) {
+ createdQueries = visit((Comparison) criteria, inUse);
+
+ } else if (criteria instanceof Exists) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR,
+ "Parsing EXISTS criteria: NOT IMPLEMENTED YET"); //$NON-NLS-1$
+ // TODO Exists should be supported in a future release.
+
+ } else if (criteria instanceof Like) {
+ createdQueries = visit((Like) criteria, inUse);
+
+ } else if (criteria instanceof In) {
+ createdQueries = visit((In) criteria, inUse);
+
+ }
+ // else if (criteria instanceof Not) {
+ // LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing NOT
criteria."); //$NON-NLS-1$
+ // isNegated = true;
+ // filterList.addAll(getSearchFilterFromWhereClause(((Not)criteria).getCriteria(),
+ // new LinkedList<String>()));
+ // }
+
+ return createdQueries;
+ }
+
+ public boolean visit(Comparison obj,
+ BooleanJunction<BooleanJunction> junction) {
+
+ 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();
+
+ // joins between the objects in the same cache is not usable
+ if ((lhs instanceof ColumnReference && rhs instanceof ColumnReference)
+ || (lhs instanceof Literal && rhs instanceof Literal)) {
+ return false;
+ }
+
+ Object value = null;
+ Column mdIDElement = null;
+ Literal literal = null;
+ if (lhs instanceof ColumnReference) {
+
+ mdIDElement = ((ColumnReference) lhs).getMetadataObject();
+ literal = (Literal) rhs;
+ value = literal.getValue();
+
+ } else if (rhs instanceof ColumnReference ){
+ mdIDElement = ((ColumnReference) rhs).getMetadataObject();
+ literal = (Literal) lhs;
+ value = literal.getValue();
+ }
+
+ if (value == null) {
+ final String msg = ObjectPlugin.Util
+ .getString("LuceneSearch.unsupportedComparingByNull"); //$NON-NLS-1$
+ addException(msg);
+ return false;
+ }
+
+ value = escapeReservedChars(value);
+ switch (op) {
+ case NE:
+ createEqualsQuery(mdIDElement, value, false, true, junction);
+ break;
+
+ case EQ:
+ createEqualsQuery(mdIDElement, value, true, false, junction);
+ break;
+
+ case GT:
+ createRangeAboveQuery(mdIDElement, value, junction);
+ break;
+
+ case LT:
+ createRangeBelowQuery(mdIDElement, value, junction);
+ break;
+
+ default:
+ final String msg = ObjectPlugin.Util
+ .getString("LuceneSearch.unsupportedComparisonOperator"); //$NON-NLS-1$
+ addException(msg);
+ return false;
+ }
+ return true;
+
+ }
+
+ public boolean visit(In obj, BooleanJunction<BooleanJunction> junction) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria.");
//$NON-NLS-1$
+
+ Expression lhs = ((In) obj).getLeftExpression();
+
+ Column mdIDElement = ((ColumnReference) lhs).getMetadataObject();
+
+ List<Expression> rhsList = ((In) obj).getRightExpressions();
+ boolean createdQuery = false;
+ for (Expression expr : rhsList) {
+
+ if (expr instanceof Literal) {
+ Literal literal = (Literal) expr;
+
+ // add these as OR queries
+ createEqualsQuery(mdIDElement,
+ escapeReservedChars(literal.getValue()), false, false,
+ junction);
+ createdQuery = true;
+ } else {
+ String msg = ObjectPlugin.Util.getString(
+ "LuceneSearch.Unsupported_expression",
+ new Object[] { expr, "IN" });
+ this.addException(msg);
+ }
+ }
+ return createdQuery;
+ }
+
+ public boolean visit(Like obj, BooleanJunction<BooleanJunction> junction) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR,
+ "Parsing LIKE criteria."); //$NON-NLS-1$
+
+ Expression lhs = ((Like) obj).getLeftExpression();
+ Expression rhs = ((Like) obj).getRightExpression();
+
+ Column c = null;
+ Expression literalExp = null;
+ if (lhs instanceof ColumnReference) {
+ c = ((ColumnReference) lhs).getMetadataObject();
+ literalExp = rhs;
+ } else {
+ c = ((ColumnReference) rhs).getMetadataObject();
+ literalExp = lhs;
+ }
+
+ String value = null;
+ if (literalExp instanceof Literal) {
+
+ value = (String) escapeReservedChars(((Literal) literalExp)
+ .getValue());
+ createLikeQuery(c, value.replaceAll("%", ""), junction); //
"*"
+ return true;
+ } else {
+ final String msg = ObjectPlugin.Util.getString(
+ "LuceneSearch.Unsupported_expression",
+ new Object[] { literalExp.toString(), "LIKE" });
+ this.addException(msg);
+ return false;
+
+ }
+
+ }
+
+ protected static Object escapeReservedChars(final Object value) {
+ if (value instanceof String) {
+ } else {
+ return value;
+ }
+
+ String expr = (String) value;
+
+ 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 Query createEqualsQuery(Column column, Object value, boolean and,
+ boolean not, BooleanJunction<BooleanJunction> junction) {
+ Query queryKey = queryBuilder.keyword()
+ .onField(getNameInSourceFromColumn(column))
+ // .matching(value.toString() + "*")
+ .matching(value.toString()).createQuery();
+
+ if (not) {
+ junction.must(queryKey).not();
+ } else if (and) {
+ junction.must(queryKey);
+ } else {
+ junction.should(queryKey);
+ }
+ return queryKey;
+ }
+
+ private Query createRangeAboveQuery(Column column, Object value,
+ BooleanJunction<BooleanJunction> junction) {
+
+ Query queryKey = queryBuilder.range()
+ .onField(getNameInSourceFromColumn(column))
+ .above(value.toString()).excludeLimit().createQuery();
+ junction.must(queryKey);
+ return queryKey;
+ }
+
+ private Query createRangeBelowQuery(Column column, Object value,
+ BooleanJunction<BooleanJunction> junction) {
+
+ Query queryKey = queryBuilder.range()
+ .onField(getNameInSourceFromColumn(column))
+ .below(value.toString()).excludeLimit().createQuery();
+ junction.must(queryKey);
+ return queryKey;
+ }
+
+ private Query createLikeQuery(Column column, String value,
+ BooleanJunction<BooleanJunction> junction) {
+ Query queryKey = queryBuilder.phrase()
+ .onField(getNameInSourceFromColumn(column)).sentence(value)
+ .createQuery();
+ junction.should(queryKey);
+ return queryKey;
+ }
+
+ private String getNameInSourceFromColumn(Column c) {
+ String name = c.getNameInSource();
+ if (name == null || name.trim().equals("")) { //$NON-NLS-1$
+ return c.getName();
+ }
+ return name;
+ }
+
+ private void addException(String message) {
+
+ exceptionMessages.add(message);
+
+ }
+
+ protected void throwExceptionIfFound() throws TranslatorException {
+ if (!exceptionMessages.isEmpty())
+ throw new TranslatorException("LuceneSearch Exception(s): "
+ + exceptionMessages.toString());
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,145 @@
+/*
+ * 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.search;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.infinispan.api.BasicCache;
+import org.teiid.language.Select;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectExecutionFactory;
+import org.teiid.translator.object.SearchStrategy;
+import org.teiid.translator.object.SelectProjections;
+import org.teiid.translator.object.infinispan.InfinispanExecutionFactory;
+import org.teiid.translator.object.search.BasicKeySearchCriteria;
+import org.teiid.translator.object.search.SearchCriterion;
+
+/**
+ * SearchByKey is a simple SearchStrategy that enables querying the cache by
+ * the key, using EQUI and IN clauses on the SELECT statement.
+ */
+public class SearchByKey implements SearchStrategy {
+
+ public List<Object> performSearch(Select command,
+ SelectProjections projections,
+ ObjectExecutionFactory objectFactory, Object connection)
+ throws TranslatorException {
+
+ InfinispanExecutionFactory factory = (InfinispanExecutionFactory) objectFactory;
+ BasicCache<String, Object> cache = factory.getCache(connection);
+ BasicKeySearchCriteria bksc = BasicKeySearchCriteria.getInstance(
+ factory, projections, command);
+
+ return get(bksc.getCriterion(), cache, factory);
+
+ }
+
+ private List<Object> get(SearchCriterion criterion,
+ BasicCache<String, Object> cache, InfinispanExecutionFactory factory)
+ throws TranslatorException {
+ List<Object> results = null;
+
+ if (!criterion.isRootTableInSelect()) {
+ return Collections.EMPTY_LIST;
+ }
+
+ if (criterion.getOperator() == SearchCriterion.Operator.ALL) {
+ Set keys = cache.keySet();
+ results = new ArrayList<Object>();
+ for (Iterator it = keys.iterator(); it.hasNext();) {
+ Object v = cache.get(it.next());
+ addValue(v, results, factory.getRootClass());
+ }
+
+ return results;
+ }
+
+ if (criterion.getCriterion() != null) {
+ results = get(criterion.getCriterion(), cache, factory);
+ }
+
+ if (results == null) {
+ results = new ArrayList<Object>();
+ }
+
+ if (criterion.getOperator().equals(SearchCriterion.Operator.EQUALS)) {
+
+ Object value = criterion.getValue();
+
+ Object v = cache.get(value instanceof String ? value : value
+ .toString());
+ if (v != null) {
+ addValue(v, results, factory.getRootClass());
+ }
+ } else if (criterion.getOperator().equals(SearchCriterion.Operator.IN)) {
+
+ List<Object> parms = (List) criterion.getValue();
+ for (Iterator<Object> it = parms.iterator(); it.hasNext();) {
+ Object arg = it.next();
+ // the key is only supported in string format
+ Object v = cache.get(arg instanceof String ? arg : arg
+ .toString());
+ if (v != null) {
+ addValue(v, results, factory.getRootClass());
+ }
+ }
+
+ }
+
+ return results;
+
+ }
+
+ private void addValue(Object value, List<Object> results, Class rootNodeType) {
+ if (value != null && value.getClass().equals(rootNodeType)) {
+
+ if (value.getClass().isArray()) {
+ List<Object> listRows = Arrays.asList((Object[]) value);
+ results.addAll(listRows);
+ return;
+ }
+
+ if (value instanceof Collection) {
+ results.addAll((Collection) value);
+ return;
+ }
+
+ if (value instanceof Map) {
+ Map<?, Object> mapRows = (Map) value;
+ results.addAll(mapRows.values());
+ return;
+ }
+
+ results.add(value);
+ }
+
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,40 @@
+/*
+ * 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.mapcache;
+
+import org.teiid.translator.Translator;
+import org.teiid.translator.object.ObjectExecutionFactory;
+
+@Translator(name = "mapCache", description = "The Map Cache
Factory")
+public class MapCacheExecutionFactory extends ObjectExecutionFactory {
+
+ public MapCacheExecutionFactory() {
+ this.setSearchStrategyClassName(MapCacheSearchByKey.class.getName());
+ this.setSourceRequired(false);
+ }
+
+ @Override
+ public boolean supportsOnlyLiteralComparison() {
+ return true;
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheSearchByKey.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheSearchByKey.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheSearchByKey.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,155 @@
+/*
+ * 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.mapcache;
+
+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.language.Select;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectExecutionFactory;
+import org.teiid.translator.object.ObjectPlugin;
+import org.teiid.translator.object.SearchStrategy;
+import org.teiid.translator.object.SelectProjections;
+import org.teiid.translator.object.search.BasicKeySearchCriteria;
+import org.teiid.translator.object.search.SearchCriterion;
+
+/**
+ * The MapCacheSearchByKey provides simple key searches of the cache.
+ *
+ * @author vhalbert
+ *
+ */
+public class MapCacheSearchByKey implements SearchStrategy {
+
+ private BasicKeySearchCriteria visitor = null;
+
+ public List<Object> performSearch(Select command,
+ SelectProjections projections, ObjectExecutionFactory factory,
+ Object connection) throws TranslatorException {
+
+ Map<?, ?> cache = null;
+ if (connection instanceof Map) {
+ cache = (Map<?, ?>) connection;
+ } else {
+ String msg = ObjectPlugin.Util.getString(
+ "MapCacheSearchByKey.unexpectedCacheType",
+ new Object[] { connection.getClass().getName(), "Map" });
+ throw new TranslatorException(msg); //$NON-NLS-1$
+
+ }
+
+ visitor = BasicKeySearchCriteria.getInstance(factory, projections,
+ command);
+
+ return get(visitor.getCriterion(), cache, factory.getRootClass());
+ }
+
+ private List<Object> get(SearchCriterion criterion, Map<?, ?> cache,
+ Class<?> rootClass) throws TranslatorException {
+ List<Object> results = null;
+ if (criterion.getOperator() == SearchCriterion.Operator.ALL) {
+ results = new ArrayList<Object>();
+ for (Iterator<?> it = cache.keySet().iterator(); it.hasNext();) {
+ Object v = cache.get(it.next());
+ addValue(v, results, rootClass);
+
+ }
+
+ return results;
+ }
+
+ if (criterion.getCriterion() != null) {
+ results = get(criterion.getCriterion(), cache, rootClass);
+ }
+
+ if (results == null) {
+ results = new ArrayList<Object>();
+ }
+
+ if (criterion.getOperator().equals(SearchCriterion.Operator.EQUALS)) {
+
+ Object v = cache.get(criterion.getValue());
+ if (v != null) {
+ addValue(v, results, rootClass);
+ }
+ } else if (criterion.getOperator().equals(SearchCriterion.Operator.IN)) {
+
+ List<?> parms = (List<?>) criterion.getValue();
+ for (Iterator<?> it = parms.iterator(); it.hasNext();) {
+ Object arg = it.next();
+ Object v = cache.get(arg);
+ if (v != null) {
+ addValue(v, results, rootClass);
+ }
+ }
+
+ }
+
+ return results;
+
+ }
+
+ private void addValue(Object value, List<Object> results, Class<?>
rootClass)
+ throws TranslatorException {
+ // can only add objects of the same root class in the cache
+ if (value != null) {
+ if (value.getClass().equals(rootClass)) {
+
+ if (value.getClass().isArray()) {
+ List<Object> listRows = Arrays.asList((Object[]) value);
+ results.addAll(listRows);
+ return;
+ }
+
+ if (value instanceof Collection) {
+ results.addAll((Collection<?>) value);
+ return;
+ }
+
+ if (value instanceof Map) {
+ Map<?, ?> mapRows = (Map<?, ?>) value;
+ results.addAll(mapRows.values());
+ return;
+ }
+
+ results.add(value);
+ } else {
+ // the object obtained from the cache has to be of the same root
+ // class type, otherwise, the modeling
+ // structure won't correspond correctly
+ String msg = ObjectPlugin.Util.getString(
+ "MapCacheSearchByKey.unexpectedObjectTypeInCache",
+ new Object[] { value.getClass().getName(),
+ rootClass.getName() });
+
+ throw new TranslatorException(msg);
+ }
+ }
+
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,289 @@
+/*
+ * 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.search;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.core.util.Assertion;
+import org.teiid.language.AggregateFunction;
+import org.teiid.language.ColumnReference;
+import org.teiid.language.Command;
+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.Literal;
+import org.teiid.language.ScalarSubquery;
+import org.teiid.language.SearchedCase;
+import org.teiid.language.Select;
+import org.teiid.language.visitor.HierarchyVisitor;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectExecutionFactory;
+import org.teiid.translator.object.ObjectPlugin;
+import org.teiid.translator.object.SelectProjections;
+
+/**
+ * The BasicKeySearchCriteria parses the {@link Command select} and creates
+ * {@link SearchCriterion searchCriteria} to support basic key searching on a
+ * cache. The EQUALS or IN clauses in the SQL command are the only supported
+ * options at this time, with the assumption of OR is used, not AND.
+ *
+ * @author vhalbert
+ *
+ */
+public class BasicKeySearchCriteria extends HierarchyVisitor {
+
+ // search criteria based on the WHERE clause
+ private SearchCriterion criterion;
+ private SelectProjections projections;
+
+ private List<String> exceptionMessages = new ArrayList<String>(2);
+
+ private BasicKeySearchCriteria(ObjectExecutionFactory factory,
+ SelectProjections projections) {
+ this.projections = projections;
+ }
+
+ public static BasicKeySearchCriteria getInstance(
+ ObjectExecutionFactory factory, SelectProjections projections,
+ Select command) throws TranslatorException {
+ BasicKeySearchCriteria visitor = new BasicKeySearchCriteria(factory,
+ projections);
+ visitor.visitNode(command);
+ visitor.throwExceptionIfFound();
+ return visitor;
+ }
+
+ private String getRootNodePrimaryKeyColumnName() {
+ return this.projections.getRootNodePrimaryKeyColumnName();
+ }
+
+ private boolean isRootTableInFrom() {
+ return this.projections.isRootTableInFrom();
+ }
+
+ /**
+ * Call to get the {@link SearchCriterion Criterion}. If the command
+ * specified no criteria, then a {@link SearchCriterion Criterion} that
+ * indicates to retrieve "ALL" will be returned.
+ *
+ * @return
+ */
+ public SearchCriterion getCriterion() {
+ if (this.criterion != null) {
+
+ } else {
+ this.criterion = new SearchCriterion();
+
+ }
+ this.criterion.setRootTableInSelect(isRootTableInFrom());
+
+ return this.criterion;
+ }
+
+ @Override
+ 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;
+ }
+
+ Object value = null;
+ Column mdIDElement = null;
+ Literal literal = null;
+ if (lhs instanceof ColumnReference && isValidExpression(rhs)) {
+ mdIDElement = ((ColumnReference) lhs).getMetadataObject();
+ literal = (Literal) rhs;
+ value = literal.getValue();
+
+ } else if (rhs instanceof ColumnReference && isValidExpression(lhs)) {
+ mdIDElement = ((ColumnReference) rhs).getMetadataObject();
+ literal = (Literal) lhs;
+ value = literal.getValue();
+
+ }
+
+ if (mdIDElement == null || value == null) {
+ Assertion.assertTrue(false,
+ "BasicKeySearchCriteria.missingComparisonExpression");
+ }
+
+ addCompareCriteria(mdIDElement,
+ escapeReservedChars(literal.getValue()), op);
+
+ }
+
+ public void visit(In obj) {
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria.");
//$NON-NLS-1$
+
+ Expression lhs = ((In) obj).getLeftExpression();
+ isValidExpression(lhs);
+
+ Column mdIDElement = ((ColumnReference) lhs).getMetadataObject();
+
+ List<Expression> rhsList = ((In) obj).getRightExpressions();
+
+ Class<?> type = lhs.getType();
+ List<Object> parms = new ArrayList<Object>(rhsList.size());
+ for (Expression expr : rhsList) {
+
+ if (expr instanceof Literal) {
+ Literal literal = (Literal) expr;
+
+ parms.add(escapeReservedChars(literal.getValue()));
+
+ type = literal.getType();
+
+ } else {
+ Assertion
+ .assertTrue(false,
+ "BasicKeySearchCriteria.Unsupported_expression "
+ + expr);
+ }
+
+ }
+ addInCriteria(mdIDElement, parms, type);
+
+ }
+
+ private void addCompareCriteria(Column column, Object value, Operator op) {
+ SearchCriterion sc = new SearchCriterion(column, value, op.toString(),
+ SearchCriterion.Operator.EQUALS, column.getRuntimeType());
+
+ addSearchCriterion(sc);
+ }
+
+ private void addInCriteria(Column column, List<Object> parms, Class<?> type)
{
+ SearchCriterion sc = new SearchCriterion(column, parms, "in",
+ SearchCriterion.Operator.IN, column.getRuntimeType());
+
+ addSearchCriterion(sc);
+
+ }
+
+ private boolean isValidExpression(Expression e) {
+ if (e instanceof ColumnReference) {
+ return true;
+ } else if (e instanceof Literal) {
+ return true;
+
+ } else {
+ String msg = null;
+ if (e instanceof AggregateFunction) {
+ msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12001);
+ } else if (e instanceof Function) {
+ msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12005);
+ } else if (e instanceof ScalarSubquery) {
+ msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12006);
+ } else if (e instanceof SearchedCase) {
+ msg = ObjectPlugin.Util.gs(ObjectPlugin.Event.TEIID12007);
+ }
+ LogManager.logError(LogConstants.CTX_CONNECTOR, msg + e.toString());
+ addException(msg + e.toString());
+ }
+ return false;
+
+ }
+
+ 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 (searchCriteria.getField() != null);
+ assert (getRootNodePrimaryKeyColumnName() != null);
+
+ // must be a key column in order to perform search
+ if (searchCriteria.getTableName().equalsIgnoreCase(
+ this.projections.getRootTableName())
+ && searchCriteria.getField().equalsIgnoreCase(
+ getRootNodePrimaryKeyColumnName())) {
+
+ if (this.criterion != null) {
+ searchCriteria.addOrCriterion(this.criterion);
+ }
+
+ this.criterion = searchCriteria;
+ }
+
+ this.criterion = searchCriteria;
+ }
+
+ protected static Object escapeReservedChars(final Object value) {
+ if (value instanceof String) {
+ String expr = (String) value;
+ 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();
+ }
+ return value;
+ }
+
+ private void addException(String msg) {
+ exceptionMessages.add(msg);
+ }
+
+ protected void throwExceptionIfFound() throws TranslatorException {
+ if (!exceptionMessages.isEmpty())
+ throw new TranslatorException("ObjectProjections Exception: "
+ + exceptionMessages.toString());
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,160 @@
+/*
+ * 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.search;
+
+import org.teiid.metadata.Column;
+import org.teiid.metadata.Table;
+
+public class SearchCriterion {
+
+ public enum Operator {
+ AND, // used to group conditional criterial
+ 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 String runtimeType;
+ private boolean isRootTableInSelect = false;
+
+ public SearchCriterion() {
+ this.operator = Operator.ALL;
+ }
+
+ public SearchCriterion(Column column, Object value, String operaterString,
+ String type) {
+ this.column = column;
+ this.value = value;
+ this.operatorString = operaterString;
+ this.runtimeType = type;
+ this.operator = Operator.EQUALS;
+
+ }
+
+ public SearchCriterion(Column column, Object value, String operaterString,
+ Operator operator, String 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 String getRuntimeType() {
+ return this.runtimeType;
+ }
+
+ public void setRuntimeType(String type) {
+ this.runtimeType = type;
+ }
+
+ public int getCriteriaCount() {
+ return 1 + (this.addCondition != null ? this.addCondition
+ .getCriteriaCount() : 0);
+ }
+
+ public void addAndCriterion(SearchCriterion condition) {
+ this.addCondition = condition;
+ this.isAnd = true;
+ }
+
+ public void addOrCriterion(SearchCriterion condition) {
+ this.addCondition = condition;
+ this.isAnd = false;
+ }
+
+ public SearchCriterion getCriterion() {
+ 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;
+ }
+
+}
Added:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java
===================================================================
---
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java
(rev 0)
+++
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/ObjectUtil.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,42 @@
+/*
+ * 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.util;
+
+import java.util.Collection;
+
+import org.teiid.core.util.ReflectionHelper;
+import org.teiid.translator.TranslatorException;
+
+public class ObjectUtil {
+
+ public static Object createObject(String objectClassName,
+ Collection<?> ctors, ClassLoader loader) throws TranslatorException {
+ try {
+
+ return ReflectionHelper.create(objectClassName, ctors.toArray(), null, loader);
+ } catch (Exception e1) {
+ throw new TranslatorException(e1.getCause());
+ }
+ }
+
+
+}
Added:
trunk/connectors/translator-object/src/main/resources/META-INF/services/org.teiid.translator.ExecutionFactory
===================================================================
---
trunk/connectors/translator-object/src/main/resources/META-INF/services/org.teiid.translator.ExecutionFactory
(rev 0)
+++
trunk/connectors/translator-object/src/main/resources/META-INF/services/org.teiid.translator.ExecutionFactory 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,4 @@
+org.teiid.translator.object.infinispan.InfinispanExecutionFactory
+org.teiid.translator.object.infinispan.InfinispanRemoteExecutionFactory
+org.teiid.translator.object.mapcache.MapCacheExecutionFactory
+
Added:
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
===================================================================
---
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
(rev 0)
+++
trunk/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+xTEIID12001=Received IAggregate, but it is not supported. Check capabilities.
+xTEIID12005=Received IFunction, but it is not supported. Check capabilities.
+xTEIID12006=Received IScalarSubquery, but it is not supported. Check capabilities.
+xTEIID12007=Received ISearchedCaseExpression, but it is not supported. Check
capabilities.
+
+ObjectExecutionFactory.rootClassNameNotDefined=RootClassName is undefined
+ObjectExecutionFactory.rootClassNotFound=RootClass {0} not found to load
+
+LuceneSearch.invalidOperator=Unsupported operator {0} was encountered, only {1} are
supported
+LuceneSearch.unsupportedComparingByNull=Comparing using a NULL is not currently
supported.
+LuceneSearch.Unsupported_expression=Unsupported expression of {0} when performing [1}
+
+InfinispanBaseExecutionFactory.cacheNameNotDefined=CacheName is not defined
+InfinispanBaseExecutionFactory.noCache=No cache was found for {0} in Infinispan
+InfinispanExecutionFactory.unsupportedConnectionType=Connection type {0} is not currently
supported when connecting to Infinispan, must be {1}
+
+MapCacheSearchByKey.unexpectedObjectTypeInCache=Unexpected root object type in the cache
is {0}, expected {1}
+MapCacheSearchByKey.unexpectedCacheType=Unable to process object in cache of type {0},
expected type {1}
\ No newline at end of file
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,217 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.jdbc.util.ResultSetUtil;
+
+
+/**
+ * Base Testing class that's extended to reuse the reading/writing/comparing expected
results
+ *
+ */
+public abstract class BaseObjectTest {
+
+ protected static boolean REPLACE_EXPECTED = false;
+ protected static boolean WRITE_ACTUAL_RESULTS_TO_FILE = false;
+ protected static boolean PRINT_RESULTSETS_TO_CONSOLE = false;
+
+ private static final int MAX_COL_WIDTH = 65;
+
+ protected static boolean print = false;
+
+ public void compareResultSet(ResultSet... rs) throws IOException, SQLException {
+
+ StackTraceElement ste = new Exception().getStackTrace()[1];
+ String testName = ste.getMethodName();
+ String className = this.getClass().getName();
+ //ste.getClassName();
+ className = className.substring(className.lastIndexOf('.') + 1);
+ testName = className + "/" + testName; //$NON-NLS-1$
+ compareResultSet(testName, rs);
+ }
+
+ public void compareResultSet(String testName, ResultSet... rs)
+ throws FileNotFoundException, SQLException, IOException {
+ FileOutputStream actualOut = null;
+ BufferedReader expectedIn = null;
+ PrintStream stream = null;
+ try {
+ if (REPLACE_EXPECTED) {
+ File actual = new File(UnitTestUtil.getTestDataPath() + "/"
+testName+".expected"); //$NON-NLS-1$ //$NON-NLS-2$
+ actualOut = new FileOutputStream(actual);
+ } else {
+ if (WRITE_ACTUAL_RESULTS_TO_FILE) {
+ File actual = new File(UnitTestUtil.getTestDataPath() + "/"
+testName+".actual"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (!actual.getParentFile().exists()) {
+ actual.getParentFile().mkdir();
+ }
+ actualOut = new FileOutputStream(actual);
+
+
+ } else {
+ File expected = new File(UnitTestUtil.getTestDataPath() +
"/"+testName+".expected"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedIn = new BufferedReader(new FileReader(expected));
+ }
+
+
+ }
+ PrintStream defaultStream = null;
+ if (PRINT_RESULTSETS_TO_CONSOLE) {
+ defaultStream = new PrintStream(System.out) {
+ // SYS.out should be protected from being closed.
+ public void close() {}
+ };
+ }
+ stream = ResultSetUtil.getPrintStream(actualOut, expectedIn, defaultStream);
+ for (int i = 0; i < rs.length; i++) {
+ ResultSetUtil.printResultSet(rs[i], MAX_COL_WIDTH, true, stream);
+ }
+ assertEquals("Actual data did not match expected", //$NON-NLS-1$
+ Collections.EMPTY_LIST,
+ ResultSetUtil.getUnequalLines(stream));
+ } finally {
+ if (stream != null) {
+ stream.close();
+ }
+ if (actualOut != null) {
+ actualOut.close();
+ }
+ if (expectedIn != null) {
+ expectedIn.close();
+ }
+ }
+ }
+
+ public 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 void compareResultSet(String testName, List<Object> rs)
+ throws FileNotFoundException, SQLException, IOException {
+ FileOutputStream actualOut = null;
+ BufferedReader expectedIn = null;
+ PrintStream stream = null;
+ try {
+ if (REPLACE_EXPECTED) {
+ File actual = new File(UnitTestUtil.getTestDataPath()
+ + "/" + testName + ".expected"); //$NON-NLS-1$ //$NON-NLS-2$
+ actualOut = new FileOutputStream(actual);
+ } else {
+ if (WRITE_ACTUAL_RESULTS_TO_FILE) {
+ File actual = new File(UnitTestUtil.getTestDataPath()
+ + "/" + testName + ".actual"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (!actual.getParentFile().exists()) {
+ actual.getParentFile().mkdir();
+ }
+ actualOut = new FileOutputStream(actual);
+
+// ObjectOutput oo = null;
+// oo = new ObjectOutputStream(actualOut);
+
+ 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();
+ actualOut.write( o.toString().getBytes());
+ actualOut.write( new String("\t").getBytes());
+ }
+ //ExternalizeUtil.writeList(oo, rs[i]);
+ }
+
+ return;
+
+
+ } else {
+ File expected = new File(UnitTestUtil.getTestDataPath()
+ + "/" + testName + ".expected"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedIn = new BufferedReader(new FileReader(expected));
+ }
+
+ }
+ PrintStream defaultStream = null;
+ if (PRINT_RESULTSETS_TO_CONSOLE) {
+ defaultStream = new PrintStream(System.out) {
+ // SYS.out should be protected from being closed.
+ public void close() {
+ }
+ };
+ }
+ stream = ResultSetUtil.getPrintStream(actualOut, expectedIn,
+ defaultStream);
+// for (int i = 0; i < rs.length; i++) {
+// ResultSetUtil.printResultSet(rs[i], MAX_COL_WIDTH, true, stream);
+// }
+ assertEquals(
+ "Actual data did not match expected", //$NON-NLS-1$
+ Collections.EMPTY_LIST,
+ ResultSetUtil.getUnequalLines(stream));
+ } finally {
+ if (stream != null) {
+ stream.close();
+ }
+ if (actualOut != null) {
+ actualOut.close();
+ }
+ if (expectedIn != null) {
+ expectedIn.close();
+ }
+ }
+ }
+
+ 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;
+ }
+
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,103 @@
+/*
+ * 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 java.util.List;
+
+import org.junit.Test;
+import org.teiid.language.Select;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+/**
+ * BasicSearchTest represent a common core set of test that are run for all the
configuration/search combinations.
+ * @author vhalbert
+ *
+ */
+
+@SuppressWarnings("nls")
+public abstract class BasicSearchTest extends BaseObjectTest {
+
+ @Test public void testQueryGetAllTrades() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade as T"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, TradesCacheSource.NUMTRADES);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryGetAllTradesAndLegs() 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$
+
+ List<Object> rows = performTest(command, TradesCacheSource.NUMTRADES);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryGetAllTradesLegsAndTransactions() 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$
+
+ List<Object> rows = performTest(command, TradesCacheSource.NUMTRADES);
+
+ compareResultSet(rows);
+
+ }
+
+
+ @Test public void testQueryGetOneTrade() 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$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryGetOneTradeAndLegs() 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'");
//$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+
+
+ @Test public void testQueryInCriteria() 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 in
('1', '3')"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 2);
+
+ compareResultSet(rows);
+
+ }
+
+ protected abstract List<Object> performTest(Select command, int rowcnt) throws
Exception;
+
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/FakeStrategy.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/FakeStrategy.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/FakeStrategy.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,39 @@
+/*
+ * 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 java.util.List;
+
+import org.teiid.language.Select;
+import org.teiid.translator.TranslatorException;
+
+public class FakeStrategy implements SearchStrategy {
+
+ public static List<Object> RESULTS = null;
+
+ @Override
+ public List<Object> performSearch(Select command, SelectProjections projections,
+ ObjectExecutionFactory factory, Object connection) throws TranslatorException{
+ return RESULTS;
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,143 @@
+/*
+ * 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 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.translator.ExecutionContext;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+@SuppressWarnings("nls")
+public class TestObjectExecution {
+
+
+ private static TradesCacheSource source = TradesCacheSource.loadCache();
+ private static ObjectExecutionFactory factory;
+
+ @Mock
+ private ExecutionContext context;
+
+ @Before public void beforeEach() throws Exception{
+
+ MockitoAnnotations.initMocks(this);
+
+ factory = new ObjectExecutionFactory() { };
+ factory.setSearchStrategyClassName(FakeStrategy.class.getName());
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+
+ factory.start();
+
+ FakeStrategy.RESULTS = source.getAll();
+
+
+ }
+
+
+ @Test public void testQueryRootObject() throws Exception {
+ execute( createExecution("select * From Trade_Object.Trade"), 3, 1);
+ }
+
+ @Test public void testQueryIncludeLegs() throws Exception {
+ execute( createExecution("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"),
+ 3, 1);
+
+ }
+
+ @Test public void testQueryGetAllTransactions() throws Exception {
+ execute( createExecution("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
N " +
+ " Where T.TradeId = L.TradeId and L.LegId = N.LegId"),3, 1);
+ }
+
+
+ @Test public void testAtomicSelects() throws Exception {
+
+ Thread[] threads = new Thread[20];
+ for (int i = 0; i < threads.length; i++) {
+ threads[i] = new Thread() {
+ public void run() {
+ for (int i=0; i<1000; i++) {
+ test();
+ }
+ }
+ public void test() {
+ ObjectExecution exec = null;
+ try {
+ exec = createExecution("select * From Trade_Object.Trade");
+ execute(exec, 3, 1);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (exec != null) exec.close();
+ }
+ }
+ };
+
+ threads[i].start();
+ }
+ for (int i = 0; i < threads.length; i++) {
+ try {
+ threads[i].join();
+ } catch (InterruptedException ignore) {}
+ }
+ }
+
+ private ObjectExecution createExecution(String sql) throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand(sql);
//$NON-NLS-1$
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
+
+ return exec;
+
+ }
+
+ private void execute(ObjectExecution exec, int expected, int columns) throws Exception
{
+
+ exec.execute();
+
+ int cnt = 0;
+ List<?> row = exec.next();
+
+ // check the number of columns
+ assertEquals("Number of columns is incorrect", columns, row.size());
+
+
+ while (row != null) {
+ ++cnt;
+ row = exec.next();
+ }
+ assertEquals("Did not get expected number of rows", expected, cnt);
//$NON-NLS-1$
+
+
+ exec.close();
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,101 @@
+/*
+ * 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.assertNotNull;
+
+import java.util.Properties;
+
+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.MetadataFactory;
+import org.teiid.query.metadata.SystemMetadata;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.object.testdata.Trade;
+import org.teiid.translator.object.util.VDBUtility;
+
+@SuppressWarnings("nls")
+public class TestObjectExecutionFactory {
+
+ public class TestFactory extends ObjectExecutionFactory {
+ public TestFactory() {
+
+ }
+
+ }
+
+ @Mock
+ private ExecutionContext context;
+
+ @Mock
+ private Select command;
+
+ private ObjectExecutionFactory factory;
+
+ @Before public void beforeEach() throws Exception{
+
+ MockitoAnnotations.initMocks(this);
+
+ factory = new TestFactory();
+ factory.setSearchStrategyClassName(FakeStrategy.class.getName());
+
+ }
+
+ @Test public void testFactory() throws Exception {
+ factory.setRootClassName(Trade.class.getName());
+
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
+
+ assertNotNull(exec);
+ }
+
+ @Test public void testFactoryLoadingJarClassNames() throws Exception {
+
+
+ factory.setRootClassName(Trade.class.getName());
+
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
+
+ assertNotNull(exec);
+
+ }
+
+ @Test public void testGetMetadata() throws Exception {
+
+ MetadataFactory mfactory = new MetadataFactory("TestVDB", 1,
"Trade", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(),
null);
+
+ factory.setRootClassName(Trade.class.getName());
+
+ factory.start();
+
+ factory.getMetadata(mfactory, null);
+
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestSelectProjections.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestSelectProjections.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestSelectProjections.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,126 @@
+/*
+ * 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 org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.teiid.language.Select;
+import org.teiid.translator.object.mapcache.MapCacheSearchByKey;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+
+@SuppressWarnings("nls")
+public class TestSelectProjections {
+
+ private ObjectExecutionFactory factory;
+
+ @Before public void beforeEach() throws Exception{
+
+ MockitoAnnotations.initMocks(this);
+
+ factory = new ObjectExecutionFactory() {};
+
+ factory.setSearchStrategyClassName(MapCacheSearchByKey.class.getName());
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+
+ factory.start();
+
+ }
+
+
+ @Test public void testQueryRootObject() throws Exception {
+
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade"); //$NON-NLS-1$
+ SelectProjections visitor = createSelectProjections(command);
+
+ validateResults(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$
+ SelectProjections visitor = createSelectProjections(command);
+ validateResults( 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$
+ SelectProjections visitor = createSelectProjections(command);
+ validateResults( 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$
+ SelectProjections visitor = createSelectProjections(command);
+ validateResults(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$
+ SelectProjections visitor = createSelectProjections(command);
+ validateResults(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$
+ SelectProjections visitor = createSelectProjections(command);
+ validateResults(true, visitor);
+
+ }
+
+
+ @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$
+ SelectProjections visitor = createSelectProjections(command);
+
+ validateResults(true, visitor);
+
+ }
+
+ private SelectProjections createSelectProjections(Select command) {
+ SelectProjections visitor = SelectProjections.create(factory);
+ visitor.parse(command);
+ return visitor;
+
+ }
+
+ private void validateResults( boolean rootNodeInQuery, SelectProjections visitor) throws
Exception {
+
+ assertEquals(rootNodeInQuery, visitor.isRootTableInFrom());
+ assertNotNull(visitor.getRootNodePrimaryKeyColumnName());
+ assertNotNull(visitor.getRootTableName());
+
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/RemoteInfinispanTestHelper.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/RemoteInfinispanTestHelper.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/RemoteInfinispanTestHelper.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,90 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.Properties;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.server.core.Main;
+import org.infinispan.server.hotrod.HotRodServer;
+
+/**
+ */
+public class RemoteInfinispanTestHelper {
+ protected static final int PORT = 11311;
+ protected static final int TIMEOUT = 0;
+ protected static final String CONFIG_FILE =
"src/test/resources/infinispan_remote_config.xml";
+ private static HotRodServer server = null;
+ private static int count = 0;
+
+ public static synchronized HotRodServer createServer() throws IOException {
+ count++;
+ if (server == null) {
+ DefaultCacheManager cacheManager = new DefaultCacheManager(CONFIG_FILE);
+ // This doesn't work on IPv6, because the util assumes
"127.0.0.1" ...
+ // server = HotRodTestingUtil.startHotRodServer(cacheManager, HOST, PORT);
+ server = new HotRodServer();
+ String hostAddress = hostAddress();
+ String hostPort = Integer.toString(hostPort());
+ String timeoutStr = Integer.toString(TIMEOUT);
+ Properties props = new Properties();
+ props.setProperty(Main.PROP_KEY_HOST(), hostAddress);
+ props.setProperty(Main.PROP_KEY_PORT(), hostPort);
+ props.setProperty(Main.PROP_KEY_IDLE_TIMEOUT(), timeoutStr);
+ props.setProperty(Main.PROP_KEY_PROXY_HOST(), hostAddress);
+ props.setProperty(Main.PROP_KEY_PROXY_PORT(), hostPort);
+ // System.out.println("Starting HotRot Server at " + hostAddress +
":" + hostPort);
+ server.start(props, cacheManager);
+ }
+ return server;
+ }
+
+ public static int hostPort() {
+ return PORT;
+ }
+
+ /**
+ * Return the IP address of this host, in either IPv4 or IPv6 format.
+ *
+ * @return the IP address as a string
+ */
+ public static String hostAddress() {
+ try {
+ return InetAddress.getLocalHost().getHostAddress();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static synchronized void releaseServer() {
+ --count;
+ if (count <= 0) {
+ try {
+ // System.out.println("Stopping HotRot Server at " +
hostAddress() + ":" + hostPort());
+ server.stop();
+ } finally {
+ server = null;
+ }
+ }
+ }
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,94 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.teiid.language.Select;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.object.BasicSearchTest;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.infinispan.search.SearchByKey;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+@SuppressWarnings("nls")
+public class TestInfinispanConfigFileKeySearch extends BasicSearchTest {
+
+ private static ExecutionContext context;
+
+
+ private static InfinispanExecutionFactory factory = null;
+
+
+ @BeforeClass
+ public static void beforeEachClass() throws Exception {
+ // Set up the mock JNDI ...
+
+ context = mock(ExecutionContext.class);
+
+ factory = new InfinispanExecutionFactory();
+
+ factory.setConfigurationFileName("./src/test/resources/infinispan_persistent_config.xml");
+
+ factory.setCacheName(TradesCacheSource.TRADES_CACHE_NAME);
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.setSearchStrategyClassName(SearchByKey.class.getName());
+ factory.start();
+
+ TradesCacheSource.loadCache(factory.getCacheContainer().getCache(TradesCacheSource.TRADES_CACHE_NAME));
+
+
+ }
+
+
+ @Override
+ protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+
+ 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();
+
+ while (row != null) {
+ rows.add(row);
+ ++cnt;
+ row = exec.next();
+ }
+
+ assertEquals("Did not get expected number of rows", rowcnt, cnt);
//$NON-NLS-1$
+
+ exec.close();
+ return rows;
+ }
+
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,166 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.DefaultCacheManager;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.teiid.language.Select;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.object.BasicSearchTest;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.infinispan.search.LuceneSearch;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+@SuppressWarnings("nls")
+public class TestInfinispanJndiILuceneSearch extends BasicSearchTest {
+ private static CacheContainer container = null;
+ private static ExecutionContext context;
+
+ private InfinispanExecutionFactory factory = null;
+
+ @BeforeClass
+ public static void beforeEachClass() throws Exception {
+ // Create the cache manager ...
+ container = new
DefaultCacheManager("infinispan_persistent_indexing_config.xml");
+
+ TradesCacheSource.loadCache(container.getCache(TradesCacheSource.TRADES_CACHE_NAME));
+ context = mock(ExecutionContext.class);
+ }
+
+ @Before public void beforeEachTest() throws Exception{
+
+ factory = new InfinispanExecutionFactory();
+
+ factory.setCacheName(TradesCacheSource.TRADES_CACHE_NAME);
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.setSearchStrategyClassName(LuceneSearch.class.getName());
+ factory.start();
+
+
+ }
+
+ @Override
+ protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, container);
+
+ 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", rowcnt, cnt);
//$NON-NLS-1$
+
+ exec.close();
+ return rows;
+ }
+
+ @Test public void testQueryLikeCriteria1() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name From Trade_Object.Trade as T WHERE T.Name like
'TradeName%'"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 3);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryLikeCriteria2() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name From Trade_Object.Trade as T WHERE T.Name like 'TradeName
2%'"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryCompareEQBoolean() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name, T.Settled From Trade_Object.Trade as T WHERE T.Settled =
'false'"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 2);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryCompareNEBoolean() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
T.TradeId, T.Name, T.Settled From Trade_Object.Trade as T WHERE T.Settled <>
'false'"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryRangeBetween() 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' and T.TradeId < '3'"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryRangeAbove() 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$
+
+ List<Object> rows = performTest(command, 2);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryRangeBelow() 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 <
'2'"); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+
+ @Test public void testQueryAnd() 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' and T.Settled = 'false' "); //$NON-NLS-1$
+
+ List<Object> rows = performTest(command, 1);
+
+ compareResultSet(rows);
+
+ }
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,95 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.DefaultCacheManager;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.teiid.language.Select;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.object.BasicSearchTest;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.infinispan.search.SearchByKey;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+@SuppressWarnings("nls")
+public class TestInfinispanJndiKeySearch extends BasicSearchTest {
+ private static CacheContainer container = null;
+ private static ExecutionContext context;
+
+ private InfinispanExecutionFactory factory = null;
+
+ @BeforeClass
+ public static void beforeEachClass() throws Exception {
+ // Create the cache manager ...
+ container = new DefaultCacheManager("infinispan_persistent_config.xml");
+
+ TradesCacheSource.loadCache(container.getCache(TradesCacheSource.TRADES_CACHE_NAME));
+ context = mock(ExecutionContext.class);
+ }
+
+ @Before public void beforeEachTest() throws Exception{
+
+ factory = new InfinispanExecutionFactory();
+
+ factory.setCacheName(TradesCacheSource.TRADES_CACHE_NAME);
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.setSearchStrategyClassName(SearchByKey.class.getName());
+ factory.start();
+
+
+ }
+
+ @Override
+ protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, container);
+
+ 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", rowcnt, cnt);
//$NON-NLS-1$
+
+ exec.close();
+ return rows;
+ }
+
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,120 @@
+/*
+ * 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 static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.Context;
+
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.mockito.Mock;
+import org.teiid.language.Select;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.object.BasicSearchTest;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+@SuppressWarnings("nls")
+@Ignore
+public class TestInfinispanRemoteJndiKeySearch extends BasicSearchTest {
+ protected static final String JNDI_NAME = "java/MyCacheManager";
+
+ private static RemoteCacheManager container = null;
+ private static ExecutionContext context;
+
+
+ private InfinispanExecutionFactory factory = null;
+
+ @Mock
+ private static Context jndi;
+
+ @BeforeClass
+ public static void beforeEachClass() throws Exception {
+ RemoteInfinispanTestHelper.createServer();
+ // Create the cache manager ...
+
+ // Set up the mock JNDI ...
+ jndi = mock(Context.class);
+ when(jndi.lookup(anyString())).thenReturn(null);
+ when(jndi.lookup(JNDI_NAME)).thenReturn(container);
+
+ context = mock(ExecutionContext.class);
+
+
+ }
+
+ @Before public void beforeEachTest() throws Exception{
+
+ factory = new InfinispanExecutionFactory();
+
+ factory.setCacheName(TradesCacheSource.TRADES_CACHE_NAME);
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.start();
+
+ }
+
+ @AfterClass
+ public static void closeConnection() throws Exception {
+ RemoteInfinispanTestHelper.releaseServer();
+ }
+
+
+ @Override
+ protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+ container = new RemoteCacheManager("infinispan_remote_config.xml");
+
+ TradesCacheSource.loadCache(container.getCache(TradesCacheSource.TRADES_CACHE_NAME));
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, container);
+
+ 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", rowcnt, cnt);
//$NON-NLS-1$
+
+ exec.close();
+ return rows;
+ }
+
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,93 @@
+/*
+ * 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.mapcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.teiid.language.Select;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.object.BasicSearchTest;
+import org.teiid.translator.object.ObjectExecution;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+
+@SuppressWarnings("nls")
+public class TestMapCacheKeySearch extends BasicSearchTest {
+
+ private static TradesCacheSource source = TradesCacheSource.loadCache();
+ private static ExecutionContext context;
+
+ private MapCacheExecutionFactory factory = null;
+
+
+ protected static boolean print = false;
+
+ @BeforeClass
+ public static void beforeEachClass() throws Exception {
+
+ context = mock(ExecutionContext.class);
+
+ }
+
+ @Before public void beforeEach() throws Exception{
+
+ factory = new MapCacheExecutionFactory();
+
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+ factory.start();
+
+ }
+
+ @Override
+ protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, source);
+
+ 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", rowcnt, cnt);
//$NON-NLS-1$
+
+ exec.close();
+ return rows;
+ }
+
+
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,176 @@
+/*
+ * 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.search;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.teiid.language.Select;
+import org.teiid.translator.object.ObjectExecutionFactory;
+import org.teiid.translator.object.SelectProjections;
+import org.teiid.translator.object.util.TradesCacheSource;
+import org.teiid.translator.object.util.VDBUtility;
+
+
+@SuppressWarnings("nls")
+public class TestBasicKeySearchCriteria {
+
+
+ private ObjectExecutionFactory factory;
+
+ @Before public void beforeEach() throws Exception {
+
+ factory = new ObjectExecutionFactory() {};
+
+ factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
+
+ }
+
+ private SelectProjections createSelectProjections(Select command) {
+ SelectProjections visitor = SelectProjections.create(factory);
+ visitor.parse(command);
+ return visitor;
+
+ }
+
+ private BasicKeySearchCriteria createVisitor(Select command, SelectProjections
projections) throws Exception {
+ return BasicKeySearchCriteria.getInstance(factory, projections, command);
+ }
+
+
+ @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$
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, true);
+
+ }
+
+ @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$
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, true);
+
+ }
+
+ @Test public void test2Equals() throws Exception {
+
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade where Trade_Object.Trade.Name = 'MyName' and
(Trade_Object.Trade.TradeId = '2' or Trade_Object.Trade.Settled = 'true')
or (Trade_Object.Trade.Settled = 'false' and Trade_Object.Trade.TradeId = 3)
"); //$NON-NLS-1$
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 2, false, true);
+ }
+
+
+ @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$
+
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, true);
+
+ assertEquals(criteria.getCriterion().getOperator(), SearchCriterion.Operator.ALL);
+ }
+
+ @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$
+
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, true);
+ }
+
+ @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$
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, true);
+
+ assertEquals(criteria.getCriterion().getOperator(), SearchCriterion.Operator.ALL);
+
+
+ }
+ @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$
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, true);
+
+ }
+
+ @Test public void testQueryLegsWithCriteria() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select
L.Name as LegName From Trade_Object.Leg as L Where L.Name='MyLeg'");
//$NON-NLS-1$
+
+ SelectProjections visitor = createSelectProjections(command);
+
+ BasicKeySearchCriteria criteria = createVisitor(command, visitor);
+ validateSearchCriteria(criteria.getCriterion(), 1, false, false);
+ }
+
+ private void validateSearchCriteria(SearchCriterion criteria, int cnt, boolean isAnd,
boolean isRootInSelect) {
+ if (cnt == 0) {
+ assertNull("Criteria should be null", criteria);
+ return;
+ }
+
+
+ assertNotNull(criteria);
+ assertEquals(cnt, criteria.getCriteriaCount());
+
+ if (criteria.getOperator() != SearchCriterion.Operator.ALL) {
+
+ assertNotNull(criteria.getColumn());
+ assertNotNull(criteria.getField());
+ assertNotNull(criteria.getOperator());
+ assertNotNull(criteria.getOperatorString());
+ assertNotNull(criteria.getTableName());
+ assertNotNull(criteria.getRuntimeType());
+ assertNotNull(criteria.getValue());
+
+ assertEquals(isAnd, criteria.isAndCondition());
+
+ }
+
+ assertEquals(isRootInSelect, criteria.isRootTableInSelect());
+
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Leg.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Leg.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Leg.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,119 @@
+/*
+ * 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.testdata;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+import org.hibernate.search.annotations.DateBridge;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Resolution;
+
+@Indexed @ProvidedId
+public class Leg implements Serializable {
+
+ // 4 attributes, transactions is not selectable
+ public static int NUM_ATTRIBUTES = 4;
+
+ private static final long serialVersionUID = 7683272638393477962L;
+
+private @Field double notational;
+private @Field long id;
+private @Field String legName;
+private @Field @DateBridge(resolution=Resolution.MINUTE) Date createdDateTime;
+
+private @IndexedEmbedded List<Transaction> transactions = null;
+
+ public Leg() {
+ super();
+ }
+
+ public Leg(long legId, String name, double notional, Date date) {
+ this.notational = notional;
+ this.id=legId;
+ this.legName=name;
+ this.createdDateTime=date;
+ }
+
+ @Field
+ public String getLegName() {
+ return this.legName;
+ }
+
+ public void setLegName(String name) {
+ this.legName = name;
+ }
+
+ @Field
+ public long getLegId() {
+ return id;
+ }
+
+ public void setLegId(long id) {
+ this.id = id;
+ }
+
+
+ public void setNotational(double notional) {
+ this.notational = notional;
+ }
+
+ @Field
+ public double getNotational() {
+ return notational;
+ }
+
+ public void setCreatedDateTime(Date ts) {
+ this.createdDateTime = ts;
+ }
+
+ @Field
+ public Date getCreatedDateTime() {
+ return this.createdDateTime;
+ }
+
+ public void setTransations(List<Transaction> transactions) {
+ this.transactions = transactions;
+ }
+
+ @IndexedEmbedded
+ public List<Transaction> getTransactions() {
+ return this.transactions;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("Leg:");
+ sb.append(" id " + getLegId());
+ sb.append(" name " + getLegName());
+ sb.append(" notational " + getNotational());
+ sb.append(" createdDate " + getCreatedDateTime());
+ sb.append(" numTransactions " + getTransactions());
+
+
+
+ return sb.toString();
+ }
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/MyFieldBridge.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/MyFieldBridge.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/MyFieldBridge.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,33 @@
+/*
+ * 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.testdata;
+
+import org.hibernate.search.bridge.StringBridge;
+
+//The bride for LineItem bridge
+public class MyFieldBridge implements StringBridge {
+
+ @Override
+ public String objectToString(final Object object) {
+ return object.toString();
+ }
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Trade.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Trade.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Trade.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,126 @@
+/*
+ * 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.testdata;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.Entity;
+
+import org.hibernate.search.annotations.DateBridge;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Resolution;
+
+@Entity
+@Indexed @ProvidedId
+public class Trade implements Serializable {
+
+ // 4 attributes, legs is not selectable
+ public static int NUM_ATTRIBUTES = 4;
+
+ private static final long serialVersionUID = 8611785625511714561L;
+
+
+protected @IndexedEmbedded List<Leg> legs = new ArrayList<Leg>();
+protected @Field(index=Index.YES) long tradeId;
+protected @Field String name;
+protected @Field @DateBridge(resolution=Resolution.MINUTE) Date tradeDate;
+protected @Field boolean settled;
+
+ public Trade() {
+ }
+
+ public Trade(long tradeId, String name, List<Leg> legs, Date tradeDate) {
+ this.legs = legs;
+ this.tradeId = tradeId;
+ this.name = name;
+ this.tradeDate=tradeDate;
+ }
+
+ @Field
+ public long getTradeId() {
+ return tradeId;
+ }
+
+ public void setTradeId(long id) {
+ this.tradeId = id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public String getName() {
+ return this.name;
+ }
+
+ @Field
+ public Date getTradeDate() {
+ return this.tradeDate;
+ }
+
+ @Field
+ public boolean isSettled() {
+ return this.settled;
+ }
+
+ // @IndexedEmbedded
+ public List<Leg> getLegs() {
+ if (legs == null) {
+ return Collections.EMPTY_LIST;
+ }
+ return legs;
+ }
+
+ public void setTradeDate(Date date) {
+ this.tradeDate = date;
+ }
+
+ public void setLegs(List<Leg> legs) {
+ this.legs = legs;
+ }
+
+ public void setSettled(boolean isSettled) {
+ this.settled = isSettled;
+ }
+
+ public String toString() {
+
+ StringBuffer sb = new StringBuffer("Trade:");
+ sb.append(" id " + getTradeId());
+ sb.append(" name " + getName());
+ sb.append(" settled " + isSettled());
+ sb.append(" tradeDate " + getTradeDate());
+ sb.append(" numLegs " + getLegs().size());
+
+ return sb.toString();
+ }
+
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Transaction.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Transaction.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/testdata/Transaction.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,69 @@
+/*
+ * 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.testdata;
+
+import java.io.Serializable;
+
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.FieldBridge;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.ProvidedId;
+
+@Indexed @ProvidedId
+public class Transaction implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private @Field @FieldBridge(impl = MyFieldBridge.class) LineItem li = null;
+
+ @Indexed @ProvidedId
+ final class LineItem implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ @Field String description = null;
+
+
+ public String toString() {
+ return description;
+ }
+ }
+
+
+
+
+ public void setLineItem(Object description) {
+ LineItem item = new LineItem();
+ item.description = description.toString();
+ li = item;
+ }
+
+ public Object getLineItem() {
+ return li;
+ }
+
+}
+
+
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/TradesCacheSource.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,149 @@
+/*
+ * 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.util;
+
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.infinispan.api.BasicCache;
+import org.teiid.translator.object.testdata.Leg;
+import org.teiid.translator.object.testdata.Trade;
+import org.teiid.translator.object.testdata.Transaction;
+
+
+/**
+ * Sample cache of objects
+ *
+ * @author vhalbert
+ *
+ */
+@SuppressWarnings("rawtypes")
+public class TradesCacheSource extends HashMap <Object, Object> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -727553658250070494L;
+
+ public static final String TRADES_CACHE_NAME = "Trades";
+ public static final String TRADES_CACHE_KEYS = "TradeKeys";
+
+ public static final String TRADE_CLASS_NAME = Trade.class.getName();
+ public static final String LEG_CLASS_NAME = Leg.class.getName();
+ public static final String TRANSACTION_CLASS_NAME = Transaction.class.getName();
+
+
+ public static final int NUMLEGS = 10;
+ public static final int NUMTRADES = 3;
+ public static final int NUMTRANSACTIONS = 5;
+
+ public static void loadCache( BasicCache<String, Object> cache) {
+
+ for (int i = 1; i <= NUMTRADES; i++) {
+
+ List<Leg> legs = new ArrayList<Leg>();
+ double d = 0;
+ for (int j = 1; j <= NUMLEGS; j++) {
+
+ Leg leg = new Leg(j, "LegName " + j, d * j * 3.14, new Date());
+
+ List<Transaction> trans = new ArrayList<Transaction>(NUMTRANSACTIONS);
+ for (int x = 1; x <= NUMTRANSACTIONS; x++) {
+ Transaction t = new Transaction();
+ t.setLineItem("Leg " + j + ", transaction line item " + x);
+ trans.add(t);
+ }
+
+ leg.setTransations(trans);
+ leg.setNotational(i * 7 / 3.14);
+
+ legs.add(leg);
+ }
+
+ Trade trade = new Trade(i, "TradeName " + i, legs, new Date());
+
+ // even trades set settled to true
+ if ( i % 2 == 0) {
+ trade.setSettled(true);
+ }
+
+ cache.put(String.valueOf(trade.getTradeId()), trade);
+
+ }
+
+
+ }
+
+ public static void loadCache(Map<Object, Object> cache) {
+ for (int i = 1; i <= NUMTRADES; i++) {
+
+ List<Leg> legs = new ArrayList<Leg>();
+ double d = 0;
+ for (int j = 1; j <= NUMLEGS; j++) {
+
+ Leg leg = new Leg(j, "LegName " + j, d * j * 3.14, new Date());
+
+ List trans = new ArrayList(NUMTRANSACTIONS);
+ for (int x = 1; x <= NUMTRANSACTIONS; x++) {
+ Transaction t = new Transaction();
+ t.setLineItem("Leg " + j + ", transaction line item " + x);
+ trans.add(t);
+ }
+
+ leg.setTransations(trans);
+ leg.setNotational(i * 7 / 3.14);
+
+ legs.add(leg);
+ }
+
+ Trade trade = new Trade(i, "TradeName " + i, legs, new Date());
+
+ // even trades set settled to true
+ if ( i % 2 == 0) {
+ trade.setSettled(true);
+ }
+
+ cache.put(String.valueOf(i), trade);
+
+ }
+ }
+
+ public static TradesCacheSource loadCache() {
+ TradesCacheSource tcs = new TradesCacheSource();
+ loadCache(tcs);
+ return tcs;
+ }
+
+ public List<Object> getAll() {
+ return new ArrayList<Object>(this.values());
+ }
+
+ public List<Object> get(int key) {
+ List<Object> objs = new ArrayList<Object>(1);
+ objs.add(super.get(key));
+ return objs;
+ }
+}
Added:
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/VDBUtility.java
===================================================================
---
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/VDBUtility.java
(rev 0)
+++
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/util/VDBUtility.java 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,52 @@
+/*
+ * 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.util;
+
+import java.io.File;
+
+import org.teiid.cdk.api.TranslationUtility;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.metadata.RuntimeMetadata;
+
+
+public class VDBUtility {
+
+ public static TranslationUtility TRANSLATION_UTILITY = null;
+
+ public static RuntimeMetadata RUNTIME_METADATA = null;
+
+ static {
+ File f = new File(UnitTestUtil.getTestDataPath() + File.separatorChar +
"ObjectProject" + File.separatorChar + "Trade.vdb");
+ System.out.println("TestDataPath " + f.getAbsolutePath());
+ try {
+ TRANSLATION_UTILITY = new TranslationUtility("Trade.vdb",
f.toURI().toURL());
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ RUNTIME_METADATA = VDBUtility.TRANSLATION_UTILITY.createRuntimeMetadata();
+ }
+
+
+}
Added:
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetAllTrades.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetAllTradesAndLegs.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetAllTradesLegsAndTransactions.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetOneTrade.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryGetOneTradeAndLegs.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/testQueryInCriteria.expected
===================================================================
Added: trunk/connectors/translator-object/src/test/resources/ObjectProject/.project
===================================================================
--- trunk/connectors/translator-object/src/test/resources/ObjectProject/.project
(rev 0)
+++
trunk/connectors/translator-object/src/test/resources/ObjectProject/.project 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Object</name>
+ <comment>No Product Application, version
7.4.2.v20111104-1235-H672-Final</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.teiid.designer.core.modelBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.teiid.designer.core.modelNature</nature>
+ </natures>
+</projectDescription>
Added: trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade.vdb
===================================================================
(Binary files differ)
Property changes on:
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade.vdb
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_Object.xmi
===================================================================
--- trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_Object.xmi
(rev 0)
+++
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_Object.xmi 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="ASCII"?>
+<xmi:XMI xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:diagram="http://www.metamatrix.com/metamodels/Diagram"
xmlns:jdbc="http://www.metamatrix.com/metamodels/JDBC"
xmlns:mmcore="http://www.metamatrix.com/metamodels/Core"
xmlns:relational="http://www.metamatrix.com/metamodels/Relational&qu...
+ <mmcore:ModelAnnotation
xmi:uuid="mmuuid:abbd65a2-2896-4819-9428-fa8ba13a1b71"
primaryMetamodelUri="http://www.metamatrix.com/metamodels/Relational...
modelType="PHYSICAL" ProducerName="Teiid Designer"
ProducerVersion="7.7.1.v20120703-2229-H8-CR2-SOA">
+ <modelImports xmi:uuid="mmuuid:7c40d324-5eca-472f-a7a8-c20b01f5d848"
name="SimpleDatatypes-instance"
modelLocation="http://www.metamatrix.com/metamodels/SimpleDatatypes-...
modelType="TYPE"
primaryMetamodelUri="http://www.eclipse.org/xsd/2002/XSD"/>
+ <modelImports xmi:uuid="mmuuid:ec47f017-3602-4c78-b25f-64d1611529f2"
name="XMLSchema"
modelLocation="http://www.w3.org/2001/XMLSchema"
modelType="TYPE"
primaryMetamodelUri="http://www.eclipse.org/xsd/2002/XSD"/>
+ </mmcore:ModelAnnotation>
+ <diagram:DiagramContainer
xmi:uuid="mmuuid:060329df-f071-436c-91d8-8de84f4a38b3">
+ <diagram xmi:uuid="mmuuid:0d512295-f6e7-418d-8409-f7e689137c68"
type="packageDiagramType"
target="mmuuid/abbd65a2-2896-4819-9428-fa8ba13a1b71">
+ <diagramEntity xmi:uuid="mmuuid:0556cf27-0b7f-4670-ba1d-f958c70d1619"
name="Trade" modelObject="mmuuid/5b23705c-0091-412a-9e79-c61ed02bd618"
xPosition="131" yPosition="57"/>
+ <diagramEntity xmi:uuid="mmuuid:ada12275-d21b-4036-bcc9-c869229899ab"
name="Leg" modelObject="mmuuid/3c3beef7-0a75-4bbb-9aaa-7ea240da41f3"
xPosition="495" yPosition="69"/>
+ <diagramEntity xmi:uuid="mmuuid:38199303-f03d-43ea-b506-a3d7e0be856b"
modelObject="mmuuid/6c111154-eb05-4aca-ae33-d5a7d0c67e46"/>
+ </diagram>
+ </diagram:DiagramContainer>
+ <relational:BaseTable
xmi:uuid="mmuuid:5b23705c-0091-412a-9e79-c61ed02bd618" name="Trade"
nameInSource="org.teiid.translator.object.testdata.Trade">
+ <columns xmi:uuid="mmuuid:1a601c6c-979c-4a8a-9128-ac1c9cf853a8"
name="TradeDate" nameInSource="tradeDate"
nativeType="java.util.Date" fixedLength="true"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL"
caseSensitive="false" searchability="ALL_EXCEPT_LIKE">
+ <type
href="http://www.w3.org/2001/XMLSchema#date"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:139a5ee2-44dc-4b5f-b3d0-68a269ffd7a1"
name="Name" nameInSource="name"
nativeType="java.lang.String" length="4000"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:9ac8e953-1818-4ce6-a9d8-14d1a8539370"
name="TradeId" nameInSource="tradeId" nativeType="String"
fixedLength="true" nullable="NULLABLE_UNKNOWN"
defaultValue="NULL" caseSensitive="false"
searchability="ALL_EXCEPT_LIKE"
uniqueKeys="mmuuid/ac210048-f093-4ed3-9af4-90669fc99c3c">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:6aa63e1e-d16b-4d6c-b927-ca19a96cb619"
name="Legs" nameInSource="Legs" nativeType="java.util.Map"
fixedLength="true" nullable="NULLABLE_UNKNOWN"
defaultValue="NULL" selectable="false" updateable="false"
caseSensitive="false" searchability="UNSEARCHABLE">
+ <type
href="http://www.metamatrix.com/metamodels/SimpleDatatypes-instance#...
+ </columns>
+ <columns xmi:uuid="mmuuid:7f3823ba-96f9-43d6-9155-e2e707babccc"
name="Settled" nameInSource="settled" nativeType="boolean"
fixedLength="true" nullable="NULLABLE_UNKNOWN"
defaultValue="NULL" caseSensitive="false"
searchability="ALL_EXCEPT_LIKE">
+ <type
href="http://www.w3.org/2001/XMLSchema#boolean"/>
+ </columns>
+ <primaryKey xmi:uuid="mmuuid:ac210048-f093-4ed3-9af4-90669fc99c3c"
name="TradeId_PK"
columns="mmuuid/9ac8e953-1818-4ce6-a9d8-14d1a8539370"
foreignKeys="mmuuid/3a3196cd-3e6c-48bf-aa02-e6c99fb1fafe"/>
+ </relational:BaseTable>
+ <relational:BaseTable
xmi:uuid="mmuuid:3c3beef7-0a75-4bbb-9aaa-7ea240da41f3" name="Leg"
nameInSource="org.teiid.translator.object.testdata.Leg">
+ <columns xmi:uuid="mmuuid:3ad9207c-b90f-4aca-bd66-8cd9b3a0e2a3"
name="LegId" nameInSource="legId" nativeType="String"
fixedLength="true" nullable="NULLABLE_UNKNOWN"
defaultValue="NULL" caseSensitive="false"
searchability="ALL_EXCEPT_LIKE"
uniqueKeys="mmuuid/ea715b26-57e0-4245-b3a4-d326dcde47aa">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:19abbb02-6270-4e16-8daa-539e4d024808"
name="Name" nameInSource="legName"
nativeType="java.lang.String" length="4000"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:90f53b02-1ff3-4275-ab86-20465b5e0b77"
name="Transactions" nameInSource="Transactions"
nativeType="java.util.List" fixedLength="true"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL"
selectable="false" updateable="false" caseSensitive="false"
searchability="UNSEARCHABLE">
+ <type
href="http://www.metamatrix.com/metamodels/SimpleDatatypes-instance#...
+ </columns>
+ <columns xmi:uuid="mmuuid:e542a4df-c982-42b7-9f15-ccda9006762c"
name="CreatedDateTime" nameInSource="createdDateTime"
nativeType="java.util.Calendar" fixedLength="true"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL"
caseSensitive="false" searchability="ALL_EXCEPT_LIKE">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:3ef7317b-0b54-4bbe-b634-aee7910cc5ca"
name="Notational" nameInSource="notational"
nativeType="double" fixedLength="true"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL"
caseSensitive="false" searchability="ALL_EXCEPT_LIKE">
+ <type
href="http://www.w3.org/2001/XMLSchema#double"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:e08030b0-2255-4f9e-a61f-f3d3a419f9f9"
name="TradeId" nameInSource="tradeId" nativeType="String"
fixedLength="true" nullable="NULLABLE_UNKNOWN"
defaultValue="NULL" selectable="false" updateable="false"
caseSensitive="false" searchability="UNSEARCHABLE"
foreignKeys="mmuuid/3a3196cd-3e6c-48bf-aa02-e6c99fb1fafe">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <foreignKeys xmi:uuid="mmuuid:3a3196cd-3e6c-48bf-aa02-e6c99fb1fafe"
name="LegToTrade_FK" nameInSource="Legs"
primaryKeyMultiplicity="ZERO_TO_MANY"
columns="mmuuid/e08030b0-2255-4f9e-a61f-f3d3a419f9f9"
uniqueKey="mmuuid/ac210048-f093-4ed3-9af4-90669fc99c3c"/>
+ <primaryKey xmi:uuid="mmuuid:ea715b26-57e0-4245-b3a4-d326dcde47aa"
name="LegID_PK" columns="mmuuid/3ad9207c-b90f-4aca-bd66-8cd9b3a0e2a3"
foreignKeys="mmuuid/63d1f569-9637-421f-b1c1-489cbd759315"/>
+ </relational:BaseTable>
+ <mmcore:AnnotationContainer
xmi:uuid="mmuuid:146acc5c-ec00-4c47-b40f-bcde7a260d72">
+ <annotations xmi:uuid="mmuuid:01b2c46c-61f1-416d-8fea-e21204a8b5d0"
description="NULL"
annotatedObject="mmuuid/3c3beef7-0a75-4bbb-9aaa-7ea240da41f3"/>
+ <annotations xmi:uuid="mmuuid:a6eeddb2-f866-4e9d-8fce-d81ac06fd133"
description="NULL"
annotatedObject="mmuuid/6c111154-eb05-4aca-ae33-d5a7d0c67e46"/>
+ <annotations xmi:uuid="mmuuid:be09e12b-a29d-491e-9819-e968dc67eb38"
description="NULL"
annotatedObject="mmuuid/5b23705c-0091-412a-9e79-c61ed02bd618"/>
+ </mmcore:AnnotationContainer>
+ <relational:BaseTable
xmi:uuid="mmuuid:6c111154-eb05-4aca-ae33-d5a7d0c67e46"
name="Transaction" nameInSource=""Transaction"">
+ <columns xmi:uuid="mmuuid:ed5c696c-a021-4a05-b5d1-61e398931773"
name="LineItem" nameInSource="LineItem"
nativeType="java.lang.Object" fixedLength="true"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL"
caseSensitive="false" searchability="UNSEARCHABLE">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:4065954d-91fc-45e2-8893-8221644a7719"
name="LegId" nameInSource="TradeId" nativeType="String"
fixedLength="true" nullable="NULLABLE_UNKNOWN"
defaultValue="NULL" selectable="false" updateable="false"
caseSensitive="false" searchability="UNSEARCHABLE"
foreignKeys="mmuuid/63d1f569-9637-421f-b1c1-489cbd759315">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <foreignKeys xmi:uuid="mmuuid:63d1f569-9637-421f-b1c1-489cbd759315"
name="TransToLeg_FK" nameInSource="Transactions"
primaryKeyMultiplicity="ZERO_TO_MANY"
columns="mmuuid/4065954d-91fc-45e2-8893-8221644a7719"
uniqueKey="mmuuid/ea715b26-57e0-4245-b3a4-d326dcde47aa"/>
+ </relational:BaseTable>
+ <jdbc:JdbcSource xmi:uuid="mmuuid:700653fe-5c8f-46f2-abb5-343af1927615"
name="Object JDBC" driverName="Object JDBC Driver"
driverClass="org.teiid.translator.object.jdbcdriver.ObjectDriver"
username="user"
url="jdbc:object:classNames=org.teiid.translator.object.testdata.Trade,org.teiid.translator.object.testdata.Leg,org.teiid.translator.object.testdata.Transaction">
+ <importSettings xmi:uuid="mmuuid:2d204a81-1586-4bee-aedf-0bb09155a701"
createCatalogsInModel="false" createSchemasInModel="false"
includeIndexes="false" includeApproximateIndexes="false">
+ <includedTableTypes>TABLE</includedTableTypes>
+ </importSettings>
+ </jdbc:JdbcSource>
+</xmi:XMI>
Added: trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_View.xmi
===================================================================
--- trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_View.xmi
(rev 0)
+++
trunk/connectors/translator-object/src/test/resources/ObjectProject/Trade_View.xmi 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="ASCII"?>
+<xmi:XMI xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:diagram="http://www.metamatrix.com/metamodels/Diagram"
xmlns:mmcore="http://www.metamatrix.com/metamodels/Core"
xmlns:relational="http://www.metamatrix.com/metamodels/Relational"
xmlns:transformation="http://www.metamatrix.com/metamodels/Transform...
+ <mmcore:ModelAnnotation
xmi:uuid="mmuuid:5a3d4831-477f-42b8-bb8e-62a895f62365"
primaryMetamodelUri="http://www.metamatrix.com/metamodels/Relational...
modelType="VIRTUAL" ProducerName="Teiid Designer"
ProducerVersion="7.7.1.v20120703-2229-H8-CR2-SOA">
+ <modelImports xmi:uuid="mmuuid:d3b3585d-b97d-4f9f-885f-b653f01daddc"
name="Trade_Object" modelLocation="Trade_Object.xmi"
uuid="mmuuid:abbd65a2-2896-4819-9428-fa8ba13a1b71"
modelType="PHYSICAL"
primaryMetamodelUri="http://www.metamatrix.com/metamodels/Relational...
+ <modelImports xmi:uuid="mmuuid:48862877-960f-45c6-90fe-d97b49508ddd"
name="XMLSchema"
modelLocation="http://www.w3.org/2001/XMLSchema"
modelType="TYPE"
primaryMetamodelUri="http://www.eclipse.org/xsd/2002/XSD"/>
+ </mmcore:ModelAnnotation>
+ <mmcore:AnnotationContainer
xmi:uuid="mmuuid:376f12cd-a07c-430a-89f6-72c21a43f334"/>
+ <transformation:TransformationContainer
xmi:uuid="mmuuid:82fc8a9d-fa7a-4f42-bd2c-435128e99bf2">
+ <transformationMappings
xsi:type="transformation:SqlTransformationMappingRoot"
xmi:uuid="mmuuid:e1683238-ae62-4ea5-9862-d89aa6a618c1"
outputs="mmuuid/d1202de2-c370-42ad-851b-5cfb89fb19de"
target="mmuuid/d1202de2-c370-42ad-851b-5cfb89fb19de">
+ <helper xsi:type="transformation:SqlTransformation"
xmi:uuid="mmuuid:e347fd3e-3a26-4942-82cc-e219f8f90d5f">
+ <nested xsi:type="transformation:SqlTransformation"
xmi:uuid="mmuuid:c1e16e72-4ca7-4c2d-9eea-8554bd7bc304"
selectSql="SELECT
		Trade_Object.Trade.TradeId,
Trade_Object.Trade.Name, Trade_Object.Leg.LegId, Trade_Object.Leg.Notational,
Trade_Object.Leg.Name AS LegName,
Trade_Object.Trade.Settled
	FROM
		Trade_Object.Trade,
Trade_Object.Leg"/>
+ <aliases xmi:uuid="mmuuid:4e39271e-ea0b-4419-ab90-75aa072e4475"
alias="Trade">
+ <aliasedObject
href="Trade_Object.xmi#mmuuid/5b23705c-0091-412a-9e79-c61ed02bd618"/>
+ </aliases>
+ <aliases xmi:uuid="mmuuid:60a538ba-5ecd-4ccc-afd7-0a359d2a8180"
alias="Leg">
+ <aliasedObject
href="Trade_Object.xmi#mmuuid/3c3beef7-0a75-4bbb-9aaa-7ea240da41f3"/>
+ </aliases>
+ </helper>
+ <nested xsi:type="transformation:TransformationMapping"
xmi:uuid="mmuuid:21b5cb8c-f40e-4b98-b6f1-1a53c2dfb568"
outputs="mmuuid/6a07d2c3-b0ee-4b29-85ee-bfc9e874cb10">
+ <inputs
href="Trade_Object.xmi#mmuuid/9ac8e953-1818-4ce6-a9d8-14d1a8539370"/>
+ </nested>
+ <nested xsi:type="transformation:TransformationMapping"
xmi:uuid="mmuuid:01039342-1945-4db0-b0f2-bfbe8488dc71"
outputs="mmuuid/7a44decb-8083-4a9c-acfa-8ed71d1cc308">
+ <inputs
href="Trade_Object.xmi#mmuuid/139a5ee2-44dc-4b5f-b3d0-68a269ffd7a1"/>
+ </nested>
+ <nested xsi:type="transformation:TransformationMapping"
xmi:uuid="mmuuid:245d2337-8396-43f0-a75e-ac6037d22baf"
outputs="mmuuid/0fb2cad2-eaee-4b73-8411-994eb7eb3fd0">
+ <inputs
href="Trade_Object.xmi#mmuuid/3ad9207c-b90f-4aca-bd66-8cd9b3a0e2a3"/>
+ </nested>
+ <nested xsi:type="transformation:TransformationMapping"
xmi:uuid="mmuuid:7101182e-04c9-4d12-8141-ca2fdaa90ad1"
outputs="mmuuid/77da2470-3fc1-4fdf-94b4-de43b30b5f25">
+ <inputs
href="Trade_Object.xmi#mmuuid/3ef7317b-0b54-4bbe-b634-aee7910cc5ca"/>
+ </nested>
+ <nested xsi:type="transformation:TransformationMapping"
xmi:uuid="mmuuid:bd02fb13-86c7-4af7-a439-d76739b85bb9"
outputs="mmuuid/e62074a4-0366-4332-b6a4-8fbe855a96ca">
+ <inputs
href="Trade_Object.xmi#mmuuid/19abbb02-6270-4e16-8daa-539e4d024808"/>
+ </nested>
+ <nested xsi:type="transformation:TransformationMapping"
xmi:uuid="mmuuid:411dcb19-5da1-4ecc-9980-fe4e1b6f63fc"
outputs="mmuuid/c4fe20fa-2936-4131-9df1-79f0347e19ca">
+ <inputs
href="Trade_Object.xmi#mmuuid/7f3823ba-96f9-43d6-9155-e2e707babccc"/>
+ </nested>
+ <inputs
href="Trade_Object.xmi#mmuuid/5b23705c-0091-412a-9e79-c61ed02bd618"/>
+ <inputs
href="Trade_Object.xmi#mmuuid/3c3beef7-0a75-4bbb-9aaa-7ea240da41f3"/>
+ </transformationMappings>
+ </transformation:TransformationContainer>
+ <diagram:DiagramContainer
xmi:uuid="mmuuid:e3ea76b1-8edd-4f68-8fea-346d5ceb2a0c">
+ <diagram xmi:uuid="mmuuid:cd1589b7-71af-4fba-bbac-15c75732b75a"
type="packageDiagramType"
target="mmuuid/5a3d4831-477f-42b8-bb8e-62a895f62365">
+ <diagramEntity xmi:uuid="mmuuid:3927d9a9-77fd-4662-8029-4127e7b0f87c"
modelObject="mmuuid/d1202de2-c370-42ad-851b-5cfb89fb19de"/>
+ </diagram>
+ <diagram xmi:uuid="mmuuid:e009ec34-e8c3-419d-bb0c-c4ab6fc9511a"
type="transformationDiagramType"
target="mmuuid/d1202de2-c370-42ad-851b-5cfb89fb19de">
+ <diagramEntity xmi:uuid="mmuuid:aaa3adb9-255e-4b77-a560-69eb0d65de26"
name="Trades_View"
modelObject="mmuuid/d1202de2-c370-42ad-851b-5cfb89fb19de"
xPosition="30" yPosition="50"/>
+ <diagramEntity xmi:uuid="mmuuid:a403e12c-a40a-48fc-8677-31f0b0319c60"
name="T" modelObject="mmuuid/e1683238-ae62-4ea5-9862-d89aa6a618c1"
xPosition="211" yPosition="50"/>
+ <diagramEntity xmi:uuid="mmuuid:8db4da4d-2983-463a-a929-44fd158c1c37"
xPosition="261" yPosition="50">
+ <modelObject
href="Trade_Object.xmi#mmuuid/5b23705c-0091-412a-9e79-c61ed02bd618"/>
+ </diagramEntity>
+ <diagramEntity xmi:uuid="mmuuid:74af4ac8-e4ae-4853-8d45-638b1b5813bc"
xPosition="434" yPosition="50">
+ <modelObject
href="Trade_Object.xmi#mmuuid/3c3beef7-0a75-4bbb-9aaa-7ea240da41f3"/>
+ </diagramEntity>
+ </diagram>
+ </diagram:DiagramContainer>
+ <relational:BaseTable
xmi:uuid="mmuuid:d1202de2-c370-42ad-851b-5cfb89fb19de"
name="Trades_View" supportsUpdate="false">
+ <columns xmi:uuid="mmuuid:6a07d2c3-b0ee-4b29-85ee-bfc9e874cb10"
name="TradeID">
+ <type
href="http://www.w3.org/2001/XMLSchema#long"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:7a44decb-8083-4a9c-acfa-8ed71d1cc308"
name="Name" length="4000" caseSensitive="false">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:0fb2cad2-eaee-4b73-8411-994eb7eb3fd0"
name="LegID">
+ <type
href="http://www.w3.org/2001/XMLSchema#long"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:77da2470-3fc1-4fdf-94b4-de43b30b5f25"
name="Notational">
+ <type
href="http://www.w3.org/2001/XMLSchema#double"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:e62074a4-0366-4332-b6a4-8fbe855a96ca"
name="LegName" length="4000">
+ <type
href="http://www.w3.org/2001/XMLSchema#string"/>
+ </columns>
+ <columns xmi:uuid="mmuuid:c4fe20fa-2936-4131-9df1-79f0347e19ca"
name="Settled" fixedLength="true"
nullable="NULLABLE_UNKNOWN" defaultValue="NULL"
caseSensitive="false" searchability="ALL_EXCEPT_LIKE">
+ <type
href="http://www.w3.org/2001/XMLSchema#boolean"/>
+ </columns>
+ </relational:BaseTable>
+</xmi:XMI>
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryAnd.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryCompareEQBoolean.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryCompareNEBoolean.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryLikeCriteria1.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryLikeCriteria2.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryRangeAbove.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryRangeBelow.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/TestInfinispanJndiILuceneSearch/testQueryRangeBetween.expected
===================================================================
Added:
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_config.xml
===================================================================
---
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_config.xml
(rev 0)
+++
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_config.xml 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:infinispan:config:5.0">
+ <global />
+ <default>
+ <loaders shared="false" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="false"
+ ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location"
value="target/localcache"/>
+ </properties>
+ </loader>
+ </loaders>
+ </default>
+ <namedCache name="Trades">
+ <loaders shared="false" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="true"
+ ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location"
value="./target/localcache/persistent/trades"/>
+ </properties>
+ </loader>
+ </loaders>
+ </namedCache>
+</infinispan>
\ No newline at end of file
Added:
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_indexing_config.xml
===================================================================
---
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_indexing_config.xml
(rev 0)
+++
trunk/connectors/translator-object/src/test/resources/infinispan_persistent_indexing_config.xml 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:infinispan:config:5.0">
+ <global />
+ <default>
+ <loaders shared="false" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="false"
+ ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location"
value="target/localcache"/>
+ </properties>
+ </loader>
+ </loaders>
+ <indexing enabled="true" indexLocalOnly="true">
+ <properties>
+ <property name="hibernate.search.default.directory_provider"
value="ram" />
+ </properties>
+ </indexing>
+ </default>
+ <namedCache name="Trades">
+ <loaders shared="false" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="true"
+ ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location"
value="./target/localcache/indexing/trades"/>
+ </properties>
+ </loader>
+ </loaders>
+ </namedCache>
+</infinispan>
\ No newline at end of file
Added: trunk/connectors/translator-object/src/test/resources/infinispan_remote_config.xml
===================================================================
--- trunk/connectors/translator-object/src/test/resources/infinispan_remote_config.xml
(rev 0)
+++
trunk/connectors/translator-object/src/test/resources/infinispan_remote_config.xml 2012-09-12
19:04:53 UTC (rev 4431)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:infinispan:config:5.0">
+ <global />
+ <default>
+ <loaders shared="false" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="false"
+ ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location"
value="./target/localcache/remote/default"/>
+ </properties>
+ </loader>
+ </loaders>
+ </default>
+ <namedCache name="Trades">
+ <loaders shared="false" preload="true">
+ <loader class="org.infinispan.loaders.file.FileCacheStore"
+ fetchPersistentState="true"
+ ignoreModifications="false"
+ purgeOnStartup="false">
+ <properties>
+ <property name="location"
value="./target/localcache/remote/Trades"/>
+ </properties>
+ </loader>
+ </loaders>
+ </namedCache>
+</infinispan>