Author: rareddy
Date: 2009-12-15 12:41:34 -0500 (Tue, 15 Dec 2009)
New Revision: 1667
Added:
branches/JCA/connectors/sandbox/connector-template/
branches/JCA/connectors/sandbox/connector-template/src/
branches/JCA/connectors/sandbox/connector-template/src/main/
branches/JCA/connectors/sandbox/connector-template/src/main/java/
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java
branches/JCA/connectors/sandbox/connector-template/src/main/rar/
branches/JCA/connectors/sandbox/connector-template/src/main/rar/META-INF/
branches/JCA/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml
branches/JCA/connectors/sandbox/connector-template/src/main/resources/
branches/JCA/connectors/sandbox/connector-template/src/test/
branches/JCA/connectors/sandbox/connector-template/src/test/java/
branches/JCA/connectors/sandbox/connector-template/src/test/resources/
Log:
TEIID-907: Adding a sample connector template for the purposes of custom CDK development.
Added:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java
===================================================================
---
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java 2009-12-15
17:41:34 UTC (rev 1667)
@@ -0,0 +1,21 @@
+/*
+ * ${license}
+ */
+package ${package-name};
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.basic.BasicConnectorCapabilities;
+
+
+/**
+ * Specifies the capabilities of this connector.
+ */
+public class ${connector-name}Capabilities extends BasicConnectorCapabilities {
+
+ // TODO: override "supports*" methods from the BaseConnectorCapabilities to
+ // extend the capabilities of your connector. By specifying the correct capabilities
+ // Teiid will push certain commands and joins etc to be handled by the connector,
+ // which is more performent.
+}
Property changes on:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java
===================================================================
---
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java 2009-12-15
17:41:34 UTC (rev 1667)
@@ -0,0 +1,33 @@
+/*
+ * ${license}
+ */
+package ${package-name};
+
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.Execution;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.basic.BasicConnection;
+import org.teiid.connector.language.ICommand;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+
+/**
+ * Connection to the resource.
+ */
+public class ${connector-name}Connection extends BasicConnection {
+
+ private ${connector-name}ManagedConnectionFactory config;
+
+ public ${connector-name}Connection(${connector-name}ManagedConnectionFactory env) {
+ this.config = env;
+ }
+
+ @Override
+ public Execution createExecution(ICommand command, ExecutionContext executionContext,
RuntimeMetadata metadata) throws ConnectorException {
+ return new ${connector-name}Execution(command, config, metadata);
+ }
+
+ @Override
+ public void close() {
+
+ }
+}
Property changes on:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java
===================================================================
---
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java 2009-12-15
17:41:34 UTC (rev 1667)
@@ -0,0 +1,38 @@
+/*
+ * ${license}
+ */
+package ${package-name};
+
+import org.teiid.connector.api.Connection;
+import org.teiid.connector.api.ConnectorCapabilities;
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ConnectorLogger;
+import org.teiid.connector.basic.BasicConnector;
+
+
+public class ${connector-name}Connector extends BasicConnector {
+
+ private ${connector-name}ManagedConnectionFactory config;
+
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+
+ this.config = (${connector-name}ManagedConnectionFactory)env;
+
+ // TODO: do connector initialization here..
+ }
+
+
+ public Connection getConnection() throws ConnectorException {
+ // TODO: create the connector connection here.
+ return new ${connector-name}Connection(this.config);
+ }
+
+ @Override
+ public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
+ // TODO: if you not already defined the Capabilities class in "ra.xml"
define it here.
+ return ${connector-name}Capabilities.class;
+ }
+}
Property changes on:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java
===================================================================
---
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java 2009-12-15
17:41:34 UTC (rev 1667)
@@ -0,0 +1,189 @@
+/*
+ * ${license}
+ */
+package ${package-name};
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Random;
+
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.DataNotAvailableException;
+import org.teiid.connector.api.ProcedureExecution;
+import org.teiid.connector.api.TypeFacility;
+import org.teiid.connector.api.UpdateExecution;
+import org.teiid.connector.basic.BasicExecution;
+import org.teiid.connector.language.IBatchedUpdates;
+import org.teiid.connector.language.ICommand;
+import org.teiid.connector.language.IDelete;
+import org.teiid.connector.language.IInsert;
+import org.teiid.connector.language.IParameter;
+import org.teiid.connector.language.IProcedure;
+import org.teiid.connector.language.IQueryCommand;
+import org.teiid.connector.language.IUpdate;
+import org.teiid.connector.language.IParameter.Direction;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+
+import com.metamatrix.query.optimizer.relational.rules.NewCalculateCostUtil;
+
+
+/**
+ * Execution of a command. This may be select, update or procedure command.
+ */
+public class ${connector-name}Execution extends BasicExecution implements
UpdateExecution, ProcedureExecution {
+
+ // Connector resources
+ private ${connector-name}ManagedConnectionFactory config;
+ private ICommand command;
+ private RuntimeMetadata metadata;
+
+ private List<Object> row;
+
+ public ${connector-name}Execution(ICommand command,
${connector-name}ManagedConnectionFactory config, RuntimeMetadata metadata) {
+ this.config = config;
+ this.command = command;
+ this.metadata = metadata;
+ }
+
+ @Override
+ public void execute() throws ConnectorException {
+
+ // Log our command
+ this.config.getLogger().logTrace("executing command: " + command);
//$NON-NLS-1$
+
+ // Note that a connector does not have support all types of commands always. If
you are
+ // writing read-only then "query" may be sufficient.
+ if (command instanceof IQueryCommand) {
+ IQueryCommand queryCommand = (IQueryCommand)command;
+ // TODO: execute and produce results for "select" command
+ }
+ else if (command instanceof IInsert) {
+ // TODO: fill in for "insert" command support
+ }
+ else if (command instanceof IUpdate) {
+ // TODO: fill in for "update" command support
+ }
+ else if (command instanceof IDelete) {
+ // TODO: fill in for "delete" command support
+ }
+ else if (command instanceof IProcedure) {
+ // TODO: fill in for "procedure" command support
+ }
+ else if (command instanceof IBatchedUpdates) {
+ // TODO: fill in for "batched updates" command support
+ }
+
+ // Note here that we executed the command, however the results are read by
calling
+ // next() or getUpdateCounts() or getOutputParameterValues() methods.
+ List types = determineOutputTypes(this.command);
+ createDummyRow(types);
+ }
+
+ @Override
+ public List<?> next() throws ConnectorException, DataNotAvailableException {
+ // create and return one row at a time for your
+
+ return row;
+ }
+
+ @Override
+ public int[] getUpdateCounts() throws DataNotAvailableException, ConnectorException
{
+ return new int [] {0};
+ }
+
+ @Override
+ public List<?> getOutputParameterValues() throws ConnectorException {
+ IProcedure proc = (IProcedure)this.command;
+ int count = 0;
+ for (IParameter param : proc.getParameters()) {
+ if (param.getDirection() == Direction.INOUT || param.getDirection() == Direction.OUT
|| param.getDirection() == Direction.RETURN) {
+ count++;
+ }
+ }
+ return Arrays.asList(new Object[count]);
+ }
+
+
+ @Override
+ public void close() throws ConnectorException {
+ // TODO:cleanup your execution based resources here
+ }
+
+ @Override
+ public void cancel() throws ConnectorException {
+ //TODO: initiate the "abort" of execution
+ }
+
+ private List<Class<?>> determineOutputTypes(ICommand command) throws
ConnectorException {
+ // Get select columns and lookup the types in metadata
+ if(command instanceof IQueryCommand) {
+ IQueryCommand query = (IQueryCommand) command;
+ return Arrays.asList(query.getColumnTypes());
+ }
+
+ if (command instanceof IProcedure) {
+ return Arrays.asList(((IProcedure)command).getResultSetColumnTypes());
+ }
+
+ // this is for insert/update/delete calls
+ List<Class<?>> types = new ArrayList<Class<?>>(1);
+ types.add(Integer.class);
+ return types;
+ }
+
+ // TODO: replace this method with your own.
+ private void createDummyRow(List<Class<?>> types) {
+ row = new ArrayList<Object>(types.size());
+
+ for (Class<?> type : types) {
+ row.add(getValue(type) );
+ }
+ }
+
+ // TODO: this method is provided for example purposes only for creating a dummy row.
+ private Object getValue(Class type) {
+ if(type.equals(java.lang.String.class)) {
+ return "some string value";
+ } else if(type.equals(java.lang.Integer.class)) {
+ return new Integer(0);
+ } else if(type.equals(java.lang.Short.class)) {
+ return new Short((short)0);
+ } else if(type.equals(java.lang.Long.class)) {
+ return new Long(0);
+ } else if(type.equals(java.lang.Float.class)) {
+ return new Float(0.0);
+ } else if(type.equals(java.lang.Double.class)) {
+ return new Double(0.0);
+ } else if(type.equals(java.lang.Character.class)) {
+ return new Character('c');
+ } else if(type.equals(java.lang.Byte.class)) {
+ return new Byte((byte)0);
+ } else if(type.equals(java.lang.Boolean.class)) {
+ return Boolean.FALSE;
+ } else if(type.equals(java.math.BigInteger.class)) {
+ return new BigInteger("0");
+ } else if(type.equals(java.math.BigDecimal.class)) {
+ return new BigDecimal("0");
+ } else if(type.equals(java.sql.Date.class)) {
+ return new Date(cal.getTimeInMillis());
+ } else if(type.equals(java.sql.Time.class)) {
+ return new Time(cal.getTimeInMillis());
+ } else if(type.equals(java.sql.Timestamp.class)) {
+ return new Timestamp(cal.getTimeInMillis());
+ } else if(type.equals(TypeFacility.RUNTIME_TYPES.CLOB)) {
+ return this.config.getTypeFacility().convertToRuntimeType("some string
value");
+ } else if(type.equals(TypeFacility.RUNTIME_TYPES.BLOB)) {
+ return this.config.getTypeFacility().convertToRuntimeType("some string
value");
+ } else {
+ return "some string value";
+ }
+ }
+
+}
Property changes on:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java
===================================================================
---
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java 2009-12-15
17:41:34 UTC (rev 1667)
@@ -0,0 +1,12 @@
+/*
+ * ${license}
+ */
+package ${package-name};
+
+import org.teiid.connector.basic.BasicManagedConnectionFactory;
+
+public class ${connector-name}ManagedConnectionFactory extends
BasicManagedConnectionFactory{
+
+ // ra.xml files getters and setters go here.
+
+}
Property changes on:
branches/JCA/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/JCA/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml
===================================================================
--- branches/JCA/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml 2009-12-15
17:41:34 UTC (rev 1667)
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<connector
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+ version="1.5">
+
+ <vendor-name>${vendor-name}</vendor-name>
+ <eis-type>${connector-name}</eis-type>
+ <resourceadapter-version>1.0</resourceadapter-version>
+ <license>
+ <description>
+ ${license}
+ </description>
+ <license-required>true</license-required>
+ </license>
+ <resourceadapter>
+
<resourceadapter-class>org.teiid.connector.basic.BasicResourceAdapter</resourceadapter-class>
+
+ <outbound-resourceadapter>
+ <connection-definition>
+
<managedconnectionfactory-class>${package-name}.${connector-name}ManagedConnectionFactory</managedconnectionfactory-class>
+
+ <!-- Common properties for all connectors -->
+ <config-property>
+ <description>Connector Class</description>
+ <config-property-name>ConnectorClass</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+
<config-property-value>${package-name}.${connector-name}Connector</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Connector Capabilities</description>
+ <description>The class to use to provide the Connector
Capabilities</description>
+
<config-property-name>CapabilitiesClass</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+
<config-property-value>${package-name}.${connector-name}Capabilities</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Is Immutable</description>
+ <description>Is Immutable, True if the source never
changes.</description>
+ <config-property-name>Immutable</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>false</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Is XA Capable</description>
+ <description>True, if this connector supports XA
Transactions</description>
+ <config-property-name>XaCapable</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>false</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Exception on Exceeding Max Rows</description>
+ <description>Indicates if an Exception should be thrown if the
specified value for Maximum Result Rows is exceeded; else no exception and no more than
the maximum will be returned</description>
+
<config-property-name>ExceptionOnMaxRows</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>true</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Maximum Result Rows</description>
+ <description>Maximum Result Rows allowed</description>
+ <config-property-name>MaxResultRows</config-property-name>
+
<config-property-type>java.lang.Integer</config-property-type>
+ <config-property-value>10000</config-property-value>
+ </config-property>
+
+ <!-- ${connector-name} Specific properties START -->
+
+
+ <!-- ${connector-name} Specific properties END -->
+
+
<connectionfactory-interface>org.teiid.connector.api.Connector</connectionfactory-interface>
+
<connectionfactory-impl-class>org.teiid.connector.basic.WrappedConnector</connectionfactory-impl-class>
+
<connection-interface>org.teiid.connector.api.Connection</connection-interface>
+
<connection-impl-class>org.teiid.connector.basic.WrappedConnection</connection-impl-class>
+
+ </connection-definition>
+
+ <transaction-support>NoTransaction</transaction-support>
+
+ <authentication-mechanism>
+
<authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
+
<credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
+ </authentication-mechanism>
+ <reauthentication-support>false</reauthentication-support>
+ </outbound-resourceadapter>
+ </resourceadapter>
+</connector>
Property changes on:
branches/JCA/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain