Author: rareddy
Date: 2010-12-23 13:22:52 -0500 (Thu, 23 Dec 2010)
New Revision: 2794
Added:
trunk/connectors/translator-delegate/
trunk/connectors/translator-delegate/pom.xml
trunk/connectors/translator-delegate/src/
trunk/connectors/translator-delegate/src/main/
trunk/connectors/translator-delegate/src/main/java/
trunk/connectors/translator-delegate/src/main/java/org/
trunk/connectors/translator-delegate/src/main/java/org/teiid/
trunk/connectors/translator-delegate/src/main/java/org/teiid/translator/
trunk/connectors/translator-delegate/src/main/java/org/teiid/translator/delegate/
trunk/connectors/translator-delegate/src/main/java/org/teiid/translator/delegate/DelegateExecutionFactory.java
trunk/connectors/translator-delegate/src/main/resources/
trunk/connectors/translator-delegate/src/main/resources/META-INF/
trunk/connectors/translator-delegate/src/main/resources/META-INF/jboss-beans.xml
trunk/connectors/translator-delegate/src/test/
trunk/connectors/translator-delegate/src/test/java/
trunk/connectors/translator-delegate/src/test/java/org/
trunk/connectors/translator-delegate/src/test/java/org/teiid/
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/Delegatee.java
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/TestDelegateExecutionFactory.java
Modified:
trunk/connectors/pom.xml
Log:
TEIID-1330: adding delegating translator
Modified: trunk/connectors/pom.xml
===================================================================
--- trunk/connectors/pom.xml 2010-12-23 17:46:42 UTC (rev 2793)
+++ trunk/connectors/pom.xml 2010-12-23 18:22:52 UTC (rev 2794)
@@ -80,6 +80,7 @@
<module>translator-loopback</module>
<module>translator-file</module>
<module>translator-salesforce</module>
+ <module>translator-delegate</module>
<module>connector-file</module>
<module>connector-salesforce</module>
Property changes on: trunk/connectors/translator-delegate
___________________________________________________________________
Name: svn:ignore
+ .project
.classpath
.settings
Added: trunk/connectors/translator-delegate/pom.xml
===================================================================
--- trunk/connectors/translator-delegate/pom.xml (rev 0)
+++ trunk/connectors/translator-delegate/pom.xml 2010-12-23 18:22:52 UTC (rev 2794)
@@ -0,0 +1,53 @@
+<?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>7.3.0.Alpha2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>translator-delegate</artifactId>
+ <groupId>org.jboss.teiid.connectors</groupId>
+ <name>Delegate Translator</name>
+ <description>Delegate Translator</description>
+
+ <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>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <scope>provided</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-delegate/src/main/java/org/teiid/translator/delegate/DelegateExecutionFactory.java
===================================================================
---
trunk/connectors/translator-delegate/src/main/java/org/teiid/translator/delegate/DelegateExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-delegate/src/main/java/org/teiid/translator/delegate/DelegateExecutionFactory.java 2010-12-23
18:22:52 UTC (rev 2794)
@@ -0,0 +1,399 @@
+/*
+ * 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.delegate;
+
+import java.util.List;
+
+import org.teiid.language.Call;
+import org.teiid.language.Command;
+import org.teiid.language.LanguageFactory;
+import org.teiid.language.QueryExpression;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.Execution;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ProcedureExecution;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TranslatorProperty;
+import org.teiid.translator.TypeFacility;
+import org.teiid.translator.UpdateExecution;
+
+/**
+ * Delegate translator. User can define a {@link ExecutionFactory} of their own and have
this translator
+ * delegate all the calls to that class. This will help user to avoid packing their
translator in the required
+ * jar packaging and lets the user intercept the calls for their needs. Please note that
your 'vdb.xml' file contains
+ * the following xml fragment to configure this translator to delegate calls to custom
translator.
+ * <pre>
+ * {@code
+ <translator type="delegate" name="my-translator"
description="custom translator">
+ <property value="delegateClassName" name="name of class that
implements custom execution factory"/>
+ </translator>
+ }
+ * </pre>
+ *
+ */
+@Translator(name="delegate", description="A translator that acts as
delegator to the another translator")
+public class DelegateExecutionFactory<F, C> extends ExecutionFactory {
+
+ private String delegateClassName;
+ private ExecutionFactory delegate;
+
+ @TranslatorProperty(display="Delegatee class name", required = true)
+ public String getDelegateClassName() {
+ return this.delegateClassName;
+ }
+
+ public void setDelegateClassName(String delegateName) {
+ this.delegateClassName = delegateName;
+ }
+
+ /**
+ * For testing only
+ */
+ ExecutionFactory getDelegatee() {
+ return this.delegate;
+ }
+
+ @Override
+ public void start() throws TranslatorException {
+ this.delegate = getInstance(ExecutionFactory.class, this.delegateClassName,null,
null);
+ this.delegate.start();
+ }
+ @Override
+ public boolean areLobsUsableAfterClose() {
+ return delegate.areLobsUsableAfterClose();
+ }
+ @Override
+ public void closeConnection(Object connection, Object factory) {
+ delegate.closeConnection(connection, factory);
+ }
+ @Override
+ public Execution createExecution(Command command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Object connection) throws TranslatorException {
+ return delegate.createExecution(command, executionContext, metadata,
+ connection);
+ }
+ @Override
+ public ProcedureExecution createProcedureExecution(Call command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Object connection) throws TranslatorException {
+ return delegate.createProcedureExecution(command, executionContext,
+ metadata, connection);
+ }
+ @Override
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Object connection) throws TranslatorException {
+ return delegate.createResultSetExecution(command, executionContext,
+ metadata, connection);
+ }
+ @Override
+ public UpdateExecution createUpdateExecution(Command command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Object connection) throws TranslatorException {
+ return delegate.createUpdateExecution(command, executionContext,
+ metadata, connection);
+ }
+ @Override
+ public Object getConnection(Object factory) throws TranslatorException {
+ return delegate.getConnection(factory);
+ }
+ @Override
+ public NullOrder getDefaultNullOrder() {
+ return delegate.getDefaultNullOrder();
+ }
+ @Override
+ public LanguageFactory getLanguageFactory() {
+ return delegate.getLanguageFactory();
+ }
+ @Override
+ public int getMaxFromGroups() {
+ return delegate.getMaxFromGroups();
+ }
+ @Override
+ public int getMaxInCriteriaSize() {
+ return delegate.getMaxInCriteriaSize();
+ }
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory, Object conn)
+ throws TranslatorException {
+ delegate.getMetadata(metadataFactory, conn);
+ }
+ @Override
+ public List getPushDownFunctions() {
+ return delegate.getPushDownFunctions();
+ }
+ @Override
+ public List getSupportedFunctions() {
+ return delegate.getSupportedFunctions();
+ }
+ @Override
+ public TypeFacility getTypeFacility() {
+ return delegate.getTypeFacility();
+ }
+ @Override
+ public boolean isImmutable() {
+ return delegate.isImmutable();
+ }
+ @Override
+ public boolean isSourceRequired() {
+ return delegate.isSourceRequired();
+ }
+ @Override
+ public void setImmutable(boolean arg0) {
+ delegate.setImmutable(arg0);
+ }
+ @Override
+ public void setRequiresCriteria(boolean requiresCriteria) {
+ delegate.setRequiresCriteria(requiresCriteria);
+ }
+ @Override
+ public void setSourceRequired(boolean value) {
+ delegate.setSourceRequired(value);
+ }
+ @Override
+ public void setSupportedJoinCriteria(
+ SupportedJoinCriteria supportedJoinCriteria) {
+ delegate.setSupportedJoinCriteria(supportedJoinCriteria);
+ }
+ @Override
+ public void setSupportsFullOuterJoins(boolean supportsFullOuterJoins) {
+ delegate.setSupportsFullOuterJoins(supportsFullOuterJoins);
+ }
+ @Override
+ public void setSupportsInnerJoins(boolean supportsInnerJoins) {
+ delegate.setSupportsInnerJoins(supportsInnerJoins);
+ }
+ @Override
+ public void setSupportsOrderBy(boolean supportsOrderBy) {
+ delegate.setSupportsOrderBy(supportsOrderBy);
+ }
+ @Override
+ public void setSupportsOuterJoins(boolean supportsOuterJoins) {
+ delegate.setSupportsOuterJoins(supportsOuterJoins);
+ }
+ @Override
+ public void setSupportsSelectDistinct(boolean supportsSelectDistinct) {
+ delegate.setSupportsSelectDistinct(supportsSelectDistinct);
+ }
+ @Override
+ public boolean supportsAggregatesAvg() {
+ return delegate.supportsAggregatesAvg();
+ }
+ @Override
+ public boolean supportsAggregatesCount() {
+ return delegate.supportsAggregatesCount();
+ }
+ @Override
+ public boolean supportsAggregatesCountStar() {
+ return delegate.supportsAggregatesCountStar();
+ }
+ @Override
+ public boolean supportsAggregatesDistinct() {
+ return delegate.supportsAggregatesDistinct();
+ }
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return delegate.supportsAggregatesEnhancedNumeric();
+ }
+ @Override
+ public boolean supportsAggregatesMax() {
+ return delegate.supportsAggregatesMax();
+ }
+ @Override
+ public boolean supportsAggregatesMin() {
+ return delegate.supportsAggregatesMin();
+ }
+ @Override
+ public boolean supportsAggregatesSum() {
+ return delegate.supportsAggregatesSum();
+ }
+ @Override
+ public boolean supportsAliasedTable() {
+ return delegate.supportsAliasedTable();
+ }
+ @Override
+ public boolean supportsBatchedUpdates() {
+ return delegate.supportsBatchedUpdates();
+ }
+ @Override
+ public boolean supportsBetweenCriteria() {
+ return delegate.supportsBetweenCriteria();
+ }
+ @Override
+ public boolean supportsBulkUpdate() {
+ return delegate.supportsBulkUpdate();
+ }
+ @Override
+ public boolean supportsCaseExpressions() {
+ return delegate.supportsCaseExpressions();
+ }
+ @Override
+ public boolean supportsCommonTableExpressions() {
+ return delegate.supportsCommonTableExpressions();
+ }
+ @Override
+ public boolean supportsCompareCriteriaEquals() {
+ return delegate.supportsCompareCriteriaEquals();
+ }
+ @Override
+ public boolean supportsCompareCriteriaOrdered() {
+ return delegate.supportsCompareCriteriaOrdered();
+ }
+ @Override
+ public boolean supportsCorrelatedSubqueries() {
+ return delegate.supportsCorrelatedSubqueries();
+ }
+ @Override
+ public boolean supportsExcept() {
+ return delegate.supportsExcept();
+ }
+ @Override
+ public boolean supportsExistsCriteria() {
+ return delegate.supportsExistsCriteria();
+ }
+ @Override
+ public boolean supportsFunctionsInGroupBy() {
+ return delegate.supportsFunctionsInGroupBy();
+ }
+ @Override
+ public boolean supportsGroupBy() {
+ return delegate.supportsGroupBy();
+ }
+ @Override
+ public boolean supportsHaving() {
+ return delegate.supportsHaving();
+ }
+ @Override
+ public boolean supportsInCriteria() {
+ return delegate.supportsInCriteria();
+ }
+ @Override
+ public boolean supportsInCriteriaSubquery() {
+ return delegate.supportsInCriteriaSubquery();
+ }
+ @Override
+ public boolean supportsInlineViews() {
+ return delegate.supportsInlineViews();
+ }
+ @Override
+ public boolean supportsInsertWithIterator() {
+ return delegate.supportsInsertWithIterator();
+ }
+ @Override
+ public boolean supportsInsertWithQueryExpression() {
+ return delegate.supportsInsertWithQueryExpression();
+ }
+ @Override
+ public boolean supportsIntersect() {
+ return delegate.supportsIntersect();
+ }
+ @Override
+ public boolean supportsIsNullCriteria() {
+ return delegate.supportsIsNullCriteria();
+ }
+ @Override
+ public boolean supportsLikeCriteria() {
+ return delegate.supportsLikeCriteria();
+ }
+ @Override
+ public boolean supportsLikeCriteriaEscapeCharacter() {
+ return delegate.supportsLikeCriteriaEscapeCharacter();
+ }
+ @Override
+ public boolean supportsNotCriteria() {
+ return delegate.supportsNotCriteria();
+ }
+ @Override
+ public boolean supportsOrCriteria() {
+ return delegate.supportsOrCriteria();
+ }
+ @Override
+ public boolean supportsOrderByNullOrdering() {
+ return delegate.supportsOrderByNullOrdering();
+ }
+ @Override
+ public boolean supportsOrderByUnrelated() {
+ return delegate.supportsOrderByUnrelated();
+ }
+ @Override
+ public boolean supportsQuantifiedCompareCriteriaAll() {
+ return delegate.supportsQuantifiedCompareCriteriaAll();
+ }
+ @Override
+ public boolean supportsQuantifiedCompareCriteriaSome() {
+ return delegate.supportsQuantifiedCompareCriteriaSome();
+ }
+ @Override
+ public boolean supportsRowLimit() {
+ return delegate.supportsRowLimit();
+ }
+ @Override
+ public boolean supportsRowOffset() {
+ return delegate.supportsRowOffset();
+ }
+ @Override
+ public boolean supportsScalarSubqueries() {
+ return delegate.supportsScalarSubqueries();
+ }
+ @Override
+ public boolean supportsSearchedCaseExpressions() {
+ return delegate.supportsSearchedCaseExpressions();
+ }
+ @Override
+ public boolean supportsSelectExpression() {
+ return delegate.supportsSelectExpression();
+ }
+ @Override
+ public boolean supportsSelfJoins() {
+ return delegate.supportsSelfJoins();
+ }
+ @Override
+ public boolean supportsSetQueryOrderBy() {
+ return delegate.supportsSetQueryOrderBy();
+ }
+ @Override
+ public boolean supportsUnions() {
+ return delegate.supportsUnions();
+ }
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+ @Override
+ public boolean useAnsiJoin() {
+ return delegate.useAnsiJoin();
+ }
+ @Override
+ public boolean equals(Object obj) {
+ return delegate.equals(obj);
+ }
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+}
Added: trunk/connectors/translator-delegate/src/main/resources/META-INF/jboss-beans.xml
===================================================================
--- trunk/connectors/translator-delegate/src/main/resources/META-INF/jboss-beans.xml
(rev 0)
+++
trunk/connectors/translator-delegate/src/main/resources/META-INF/jboss-beans.xml 2010-12-23
18:22:52 UTC (rev 2794)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="translator-delegate-template"
class="org.teiid.templates.TranslatorDeploymentTemplate">
+ <property name="info"><inject
bean="translator-delegate"/></property>
+ <property name="managedObjectFactory"><inject
bean="ManagedObjectFactory"/></property>
+ </bean>
+
+ <bean name="translator-delegate"
class="org.teiid.templates.TranslatorTemplateInfo">
+ <constructor factoryMethod="createTemplateInfo">
+ <factory bean="TranslatorDeploymentTemplateInfoFactory"/>
+ <parameter
class="java.lang.Class">org.teiid.templates.TranslatorTemplateInfo</parameter>
+ <parameter
class="java.lang.Class">org.teiid.translator.delegate.DelegateExecutionFactory</parameter>
+ <parameter
class="java.lang.String">translator-delegate</parameter>
+ <parameter class="java.lang.String">Delegate
Translator</parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added:
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/Delegatee.java
===================================================================
---
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/Delegatee.java
(rev 0)
+++
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/Delegatee.java 2010-12-23
18:22:52 UTC (rev 2794)
@@ -0,0 +1,55 @@
+/*
+ * 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.delegate;
+
+import java.sql.Connection;
+
+import javax.sql.DataSource;
+
+import org.teiid.language.Command;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.Execution;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.TranslatorException;
+
+public class Delegatee extends ExecutionFactory<DataSource, Connection>{
+ public boolean connectionInvoked = false;
+ public boolean executionInvoked = false;
+
+ @Override
+ public Connection getConnection(DataSource factory)
+ throws TranslatorException {
+ connectionInvoked = true;
+ return null;
+ }
+
+ @Override
+ public Execution createExecution(Command command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Connection connection) throws TranslatorException {
+ executionInvoked = true;
+ return null;
+ }
+
+
+}
\ No newline at end of file
Added:
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/TestDelegateExecutionFactory.java
===================================================================
---
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/TestDelegateExecutionFactory.java
(rev 0)
+++
trunk/connectors/translator-delegate/src/test/java/org/teiid/translator/delegate/TestDelegateExecutionFactory.java 2010-12-23
18:22:52 UTC (rev 2794)
@@ -0,0 +1,48 @@
+/*
+ * 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.delegate;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.sql.DataSource;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+@SuppressWarnings("nls")
+public class TestDelegateExecutionFactory {
+
+ @Test
+ public void testDeleteTranslator() throws Exception {
+
+ DelegateExecutionFactory def = new DelegateExecutionFactory();
+ def.setDelegateClassName("org.teiid.translator.delegate.Delegatee");
+ def.start();
+
+ def.getConnection(Mockito.mock(DataSource.class));
+ Delegatee delegatee = (Delegatee)def.getDelegatee();
+ assertTrue(delegatee.connectionInvoked);
+
+ def.createExecution(null, null, null, null);
+ assertTrue(delegatee.executionInvoked);
+ }
+}
\ No newline at end of file