Author: van.halbert
Date: 2012-04-25 19:47:29 -0400 (Wed, 25 Apr 2012)
New Revision: 4036
Modified:
branches/7.7.x/connectors/translator-object/Notes.txt
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java
branches/7.7.x/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java
Log:
TEIID-1992 add logic to executionfactoy to load classes based on a comma separated list of
packages, cleanup and added some new test
Modified: branches/7.7.x/connectors/translator-object/Notes.txt
===================================================================
--- branches/7.7.x/connectors/translator-object/Notes.txt 2012-04-25 20:54:00 UTC (rev
4035)
+++ branches/7.7.x/connectors/translator-object/Notes.txt 2012-04-25 23:47:29 UTC (rev
4036)
@@ -1,3 +1,10 @@
+To add a new data source implementation, implement the following:
+
+- Either extend ObjectExecutionFactory or create your own.
+- Implement ObjectSourceProxy, adding vendor specific logic for executing a query and
returning a List of Objects
+
+
+
Notes:
Limitations -
@@ -8,6 +15,7 @@
+
Modeling -
- JavaBean convention is used. The column name (or nameinsource if used) are used in
finding the get/is method.
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -43,15 +43,14 @@
private Select query;
private ObjectSourceProxy proxy;
- private ObjectExecutionFactory factory;
+ private ObjectMethodManager methodManager;
- @SuppressWarnings("rawtypes")
- private Iterator resultsIt = null;
+ private Iterator<List<Object>> resultsIt = null;
- public ObjectExecution(Command query, RuntimeMetadata metadata, ObjectSourceProxy
connproxy, ObjectExecutionFactory factory) {
+ public ObjectExecution(Command query, RuntimeMetadata metadata, ObjectSourceProxy
connproxy, ObjectMethodManager methodManager) {
this.query = (Select) query;
this.proxy = connproxy;
- this.factory = factory;
+ this.methodManager = methodManager;
}
@Override
@@ -61,13 +60,13 @@
List<Object> objects = executeQuery();
- List<List<?>> results = null;
+ List<List<Object>> results = null;
if (objects != null && objects.size() > 0) {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ObjectExecution number of
objects from proxy is : " + objects.size()); //$NON-NLS-1$
ObjectProjections op = new ObjectProjections(query);
- results = ObjectTranslator.translateObjects(objects, op,
factory.getObjectMethodManager());
+ results = ObjectTranslator.translateObjects(objects, op, methodManager);
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ObjectExecution number of rows
from translation : " + results.size()); //$NON-NLS-1$
@@ -102,8 +101,10 @@
@Override
public void close() {
- this.proxy.close();
+ if (this.proxy != null) this.proxy.close();
this.proxy = null;
+ this.methodManager = null;
+ this.query = null;
}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecutionFactory.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -22,11 +22,17 @@
package org.teiid.translator.object;
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.teiid.language.QueryExpression;
import org.teiid.language.Select;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.ExecutionContext;
@@ -56,7 +62,7 @@
private ObjectMethodManager objectMethods=null;
private boolean columnNameFirstLetterUpperCase = true;
-
+ private String packageNamesOfCachedObjects = null;
public ObjectExecutionFactory() {
super();
@@ -76,13 +82,13 @@
@Override
public void start() throws TranslatorException {
- objectMethods = ObjectMethodManager.initialize(isColumnNameFirstLetterUpperCase(),
this.getClass().getClassLoader());
+ createObjectMethodManager();
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, Object connection)
throws TranslatorException {
- return new ObjectExecution((Select)command, metadata, createProxy(connection),
this);
+ return new ObjectExecution((Select)command, metadata, createProxy(connection),
objectMethods);
}
public List getSupportedFunctions() {
@@ -96,6 +102,28 @@
/**
* <p>
+ * Returns a comma separated list of package names for the cached objects.
+ * </p>
+ * @return String comma separated package names
+ */
+ @TranslatorProperty(display="PackageNamesOfCachedObjects (CSV)",
advanced=true)
+ public String getPackageNamesOfCachedObjects() {
+ return this.packageNamesOfCachedObjects;
+ }
+
+ /**
+ * <p>
+ * Call to set package names for the cached objects
+ * </p>
+ * @param String commo separated list of package names
+ */
+ public void setPackageNamesOfCachedObjects(String packageNamesOfCachedObjects) {
+ this.packageNamesOfCachedObjects = packageNamesOfCachedObjects;
+ }
+
+
+ /**
+ * <p>
* The {@link #getColumnNameFirstLetterUpperCase() option, when
<code>false</code>, indicates that the column name (or nameInSource when
specified)
* will start with a lower case. This is an option because some users prefer (or
standardize) on names being lower case or have a
* different case naming structure.
@@ -138,9 +166,7 @@
@Override
public void getMetadata(MetadataFactory metadataFactory, Object conn)
throws TranslatorException {
- if (objectMethods != null) {
- objectMethods = ObjectMethodManager.initialize(isColumnNameFirstLetterUpperCase(),
this.getClass().getClassLoader());
- }
+
}
@@ -157,6 +183,57 @@
* @throws TranslatorException
*/
protected abstract ObjectSourceProxy createProxy(Object connection) throws
TranslatorException ;
+
+ protected void createObjectMethodManager() throws TranslatorException {
+ if (objectMethods == null) {
+ objectMethods =
ObjectMethodManager.initialize(getClassesForPackage(this.packageNamesOfCachedObjects),
+ isColumnNameFirstLetterUpperCase(), this.getClass().getClassLoader());
+ }
+ }
+ protected List<String> getClassesForPackage(String pkgname) throws
TranslatorException {
+ if (pkgname == null) return Collections.EMPTY_LIST;
+ ArrayList<String> classes = new ArrayList<String>();
+ // Get a File object for the package
+ File directory = null;
+ String fullPath;
+ String relPath = pkgname.replace('.', '/');
+ URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);
+ if (resource == null) {
+ throw new TranslatorException(ObjectPlugin.Util
+ .getString(
+ "ObjectExecutionFactory.noResourceFound", new Object[] { relPath }));
//$NON-NLS-1$
+ }
+ fullPath = resource.getFile();
+
+ try {
+ directory = new File(resource.toURI());
+ } catch (URISyntaxException e) {
+ throw new TranslatorException(ObjectPlugin.Util
+ .getString(
+ "ObjectExecutionFactory.invalidResource", new Object[] { pkgname,
resource })); //$NON-NLS-1$
+
+ } catch (IllegalArgumentException e) {
+ directory = null;
+ }
+
+ if (directory != null && directory.exists()) {
+ // Get the list of the files contained in the package
+ String[] files = directory.list();
+ for (int i = 0; i < files.length; i++) {
+ // we are only interested in .class files
+ if (files[i].endsWith(".class") &&
!files[i].contains("$") ) {
+ // removes the .class extension
+ String className = pkgname + '.' + files[i].substring(0,
files[i].length() - 6);
+ classes.add(className);
+
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ClassDiscovery",
className); //$NON-NLS-1$
+
+ }
+ }
+ }
+ return classes;
+ }
+
}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectMethodManager.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -93,13 +94,12 @@
Method getIsMethod(String name) {
return this.is.get(name);
- }
-
+ }
}
@SuppressWarnings("unchecked")
public static ObjectMethodManager initialize(boolean firstLetterUpperCaseInColumName,
ClassLoader classloader) throws TranslatorException {
- return loadClassMethods(Collections.EMPTY_LIST, firstLetterUpperCaseInColumName,
classloader);
+ return initialize(Collections.EMPTY_LIST, firstLetterUpperCaseInColumName,
classloader);
}
@SuppressWarnings("unchecked")
@@ -110,18 +110,22 @@
} else {
classNames = Collections.EMPTY_LIST;
}
- return loadClassMethods(classNames, firstLetterUpperCaseInColumName, classloader);
+ return initialize(classNames, firstLetterUpperCaseInColumName, classloader);
}
- public static ObjectMethodManager loadClassMethods(List<String> classNames,
boolean firstLetterUpperCaseInColumName, ClassLoader classloader) throws
TranslatorException {
+ public static ObjectMethodManager initialize(List<String> classNames, boolean
firstLetterUpperCaseInColumName, ClassLoader classloader) throws TranslatorException {
+ if (classNames == null) classNames = Collections.EMPTY_LIST;
ObjectMethodManager osmm = new ObjectMethodManager(firstLetterUpperCaseInColumName);
+ osmm.loadClassNames(classNames, classloader);
+ return osmm;
+ }
+
+ public void loadClassNames(List<String> classNames, ClassLoader classloader)
throws TranslatorException {
for (String clzName: classNames) {
- osmm.loadClassByName(clzName, classloader);
+ loadClassByName(clzName, classloader);
}
-
- return osmm;
}
public Class<?> loadClassByName(String className, ClassLoader classLoader) throws
TranslatorException {
@@ -143,25 +147,6 @@
this.firstLetterUpperCaseInColumName = firstLetterUpperCaseInColumName;
}
- private ClassMethods loadClassMethods(Class<?> clzz) {
- Method[] methods = clzz.getDeclaredMethods();
- ClassMethods clzMethods = new ClassMethods(clzz);
-
- for (int i=0; i<methods.length; i++) {
- Method m = methods[i];
- if (m.getName().startsWith(GET)) {
- clzMethods.addGetter(m.getName(), m);
- // commenting out the caching of the setter methods
-// } else if (m.getName().startsWith(SET)) {
-// clzMethods.addSetter(m.getName(), m);
- } else if (m.getName().startsWith(IS)) {
- clzMethods.addIsMethod(m.getName(), m);
- }
- }
- this.put(clzz.getName(), clzMethods);
- return clzMethods;
- }
-
public Object getIsValue(String methodName, Object object)
throws TranslatorException {
@@ -237,7 +222,7 @@
return this.firstLetterUpperCaseInColumName;
}
- public static final Class<?> loadClass(final String className,
+ public static synchronized final Class<?> loadClass(final String className,
final ClassLoader classLoader) throws TranslatorException {
try {
Class<?> cls = null;
@@ -270,6 +255,27 @@
return clzMethods;
}
+
+
+ private synchronized ClassMethods loadClassMethods(Class<?> clzz) {
+ Method[] methods = clzz.getDeclaredMethods();
+ ClassMethods clzMethods = new ClassMethods(clzz);
+
+ for (int i=0; i<methods.length; i++) {
+ Method m = methods[i];
+ if (m.getName().startsWith(GET)) {
+ clzMethods.addGetter(m.getName(), m);
+ // commenting out the caching of the setter methods
+// } else if (m.getName().startsWith(SET)) {
+// clzMethods.addSetter(m.getName(), m);
+ } else if (m.getName().startsWith(IS)) {
+ clzMethods.addIsMethod(m.getName(), m);
+ }
+ }
+ this.put(clzz.getName(), clzMethods);
+ return clzMethods;
+ }
+
private boolean firstLetterUpperCaseInColumName = true;
}
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectProjections.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -99,10 +99,12 @@
private void addException(String columnNameToUse1,
String columnNameToUse2, String table) {
+
exceptionMessages.add(
- "Query Error: multiple collections found between columns "
- + columnNameToUse1 + " and " + columnNameToUse2
- + " (table: " + table + " ) ");
+ ObjectPlugin.Util
+ .getString(
+ "ObjectProjections.unsupportedMultipleContainers", new Object[] {
columnNameToUse1, columnNameToUse2, table }));
+
}
protected void throwExceptionIfFound() throws TranslatorException {
Modified:
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectTranslator.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -86,11 +86,11 @@
* obtaining the data from an object
* @return List<List<?>> that represent the rows and columns in the result
set
*/
- public static List<List<?>> translateObjects(List<Object> objects,
ObjectProjections projections, ObjectMethodManager objectManager) throws
TranslatorException {
+ public static List<List<Object>> translateObjects(List<Object>
objects, ObjectProjections projections, ObjectMethodManager objectManager) throws
TranslatorException {
projections.throwExceptionIfFound();
- List<List<?>> rows = new
ArrayList<List<?>>(objects.size());
+ List<List<Object>> rows = new
ArrayList<List<Object>>(objects.size());
// if no container objects required in the results, then
// perform simple logic for building a row
@@ -144,8 +144,9 @@
int level, ObjectProjections projections, ObjectMethodManager objectManager) throws
TranslatorException {
List<List<Object>> containerRows = new
ArrayList<List<Object>>();
- // if there another container depth, then process it first
- // this will be recursive
+ // if there is another container depth, then process it first
+ // this will be recursive to get to the bottom child and return
+ // back up the chain, expanding the rows for each child
if (level < projections.childrenDepth) {
String containerMethodName = projections.childrenNodes.get(level);
@@ -230,6 +231,7 @@
if (projections.nodeDepth[col] == level) {
+ // this should not happen, but just in case
if (colObject != null) throw new TranslatorException("Program Error: column
object was not null for column " + projections.columnNamesToUse[col] + " at
level " + level);
final Object value = getValue(parentObject, col, level, projections,
objectManager);
Modified:
branches/7.7.x/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties
===================================================================
---
branches/7.7.x/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/main/resources/org/teiid/translator/object/i18n.properties 2012-04-25
23:47:29 UTC (rev 4036)
@@ -20,15 +20,14 @@
# 02110-1301 USA.
#
+ObjectExecutionFactory.noResourceFound=Unable to discover class, no resource found for
{0}
+ObjectExecutionFactory.invalidResource={0} ( {1} ) does not appear to be a valid URL /
URI.
-ObjectDriver.urlFormat=The required url format is
jdbc:object:classNames=name1[,name2,...n]
+ObjectMethodManager.noMethodFound=Method {0} was not found for class {1}
+ObjectMethodManager.objectClassNotFound=Class {0} not found to load
+ObjectProjections.unsupportedMultipleContainers=Query Error: multiple collections found
between columns {0} and {1} (table: {2})
-ObjectExecutionFactory.rootClassNameUndefined=ObjectExecutionFatory is invalid,
RootClassName is not defined
-
ObjectVisitor.missingComparisonExpression=Missing either left or right expression in
comparison
ObjectVisitor.Unsupported_expressionr=Unsupported element {0}
-ObjectMethodManager.noMethodFound=Method {0} was not found for class {1}
-
-ObjectMethodManager.objectClassNotFound=Class {0} not found to load
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -28,12 +28,10 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
+import org.teiid.language.Command;
import org.teiid.language.Select;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.object.ObjectExecution;
-import org.teiid.translator.object.ObjectExecutionFactory;
-import org.teiid.translator.object.ObjectSourceProxy;
import org.teiid.translator.object.testdata.TradesCacheSource;
import org.teiid.translator.object.testdata.VDBUtility;
@@ -49,54 +47,110 @@
@Test public void testQueryRootObject() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select *
From Trade_Object.Trade"); //$NON-NLS-1$
- this.runCommand(command, 3);
-
+ execute( createExecution("select * From Trade_Object.Trade"), 3, 4);
}
@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$
- runCommand(command, 30);
+ 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"),
+ 30, 3);
}
- private void runCommand(Select command, int expected) throws Exception {
+ @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"),150, 4);
+ }
+
- ExecutionContext context = Mockito.mock(ExecutionContext.class);
+ @Test public void testAtomicSelects() throws Exception {
- ObjectSourceProxy proxy = Mockito.mock(ObjectSourceProxy.class);
-
- Mockito.stub(proxy.get(command)).toReturn(source.getAll());
+ 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, 4);
+ } 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$
+ ExecutionContext context = Mockito.mock(ExecutionContext.class);
- ObjectExecutionFactory factory = new ObjectExecutionFactory() {
+ final ObjectExecutionFactory factory = new ObjectExecutionFactory() {
@Override
protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
- return (ObjectSourceProxy) connection;
+ return new ObjectSourceProxy() {
+
+ @Override
+ public List<Object> get(Command command) throws TranslatorException {
+ return source.getAll();
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ };
}
};
factory.start();
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, proxy);
+ 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();
-
}
}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecutionFactory.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -24,8 +24,11 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
+import java.io.File;
+
import org.junit.Test;
import org.mockito.Mockito;
+import org.teiid.core.util.UnitTestUtil;
import org.teiid.language.Select;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
@@ -43,7 +46,7 @@
ExecutionContext context = Mockito.mock(ExecutionContext.class);
- ObjectSourceProxy proxy = Mockito.mock(ObjectSourceProxy.class);
+ final ObjectSourceProxy proxy = Mockito.mock(ObjectSourceProxy.class);
ObjectExecutionFactory factory = new ObjectExecutionFactory() {
@@ -51,7 +54,7 @@
protected ObjectSourceProxy createProxy(Object connection)
throws TranslatorException {
- return (ObjectSourceProxy) connection;
+ return proxy;
}
};
@@ -60,7 +63,7 @@
factory.start();
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, proxy);
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
assertNotNull(exec);
assertNotNull(factory.getObjectMethodManager());
@@ -68,6 +71,45 @@
}
+ @Test public void testFactoryLoadingJarClassNames() throws Exception {
+
+ // File testjar = new File(UnitTestUtil.getTestScratchPath() + "/../" +
"translator-object-7.7.1-tests.jar");
+// File testjar = new File("target/" +
"translator-object-7.7.1-tests.jar");
+
+// assertEquals("Testjar doesn't exist " + testjar.getAbsolutePath(),
true, testjar.exists());
+
+ Select command = Mockito.mock(Select.class);
+
+ ExecutionContext context = Mockito.mock(ExecutionContext.class);
+
+ final ObjectSourceProxy proxy = Mockito.mock(ObjectSourceProxy.class);
+
+ ObjectExecutionFactory factory = new ObjectExecutionFactory() {
+
+ @Override
+ protected ObjectSourceProxy createProxy(Object connection)
+ throws TranslatorException {
+
+ return proxy;
+ }
+
+ };
+
+ factory.setColumnNameFirstLetterUpperCase(false);
+
+ factory.setPackageNamesOfCachedObjects("org.teiid.translator.object.testdata");
+
+ factory.start();
+
+ ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context,
VDBUtility.RUNTIME_METADATA, null);
+
+ assertNotNull(exec);
+ assertNotNull(factory.getObjectMethodManager());
+ assertEquals(factory.isColumnNameFirstLetterUpperCase(), false);
+
+ }
+
+
}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectProjections.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -68,7 +68,6 @@
// confirm the arrays match
for (int i = 0; i < op.getColumns().length; i++) {
assertEquals(op.getColumnNamesToUse()[i],
op.getColumnNameToUse(op.getColumns()[i]));
- System.out.println("ColumnToUse: " + op.getColumnNamesToUse()[i]);
}
}
Modified:
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java
===================================================================
---
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java 2012-04-25
20:54:00 UTC (rev 4035)
+++
branches/7.7.x/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectTranslator.java 2012-04-25
23:47:29 UTC (rev 4036)
@@ -69,7 +69,7 @@
ObjectMethodManager omm = ObjectMethodManager.initialize(true,
this.getClass().getClassLoader());
- List<List<?>> results = ObjectTranslator.translateObjects(source.getAll(),
op, omm);
+ List<List<Object>> results =
ObjectTranslator.translateObjects(source.getAll(), op, omm);
assertEquals(rows, results.size());