[teiid-commits] teiid SVN: r2833 - in trunk/connectors/sandbox/connector-template/src/main: rar/META-INF and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Jan 11 17:54:45 EST 2011


Author: rareddy
Date: 2011-01-11 17:54:45 -0500 (Tue, 11 Jan 2011)
New Revision: 2833

Added:
   trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ConnectionImpl.java
Removed:
   trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java
   trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java
   trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java
   trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java
Modified:
   trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java
   trunk/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml
Log:
misc: connector template for auto generation of the files

Deleted: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java	2011-01-11 21:28:40 UTC (rev 2832)
+++ trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Capabilities.java	2011-01-11 22:54:45 UTC (rev 2833)
@@ -1,21 +0,0 @@
-/*
- * ${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.
-}

Deleted: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java	2011-01-11 21:28:40 UTC (rev 2832)
+++ trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java	2011-01-11 22:54:45 UTC (rev 2833)
@@ -1,33 +0,0 @@
-/*
- * ${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() {
-    	
-    }
-}

Copied: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ConnectionImpl.java (from rev 2819, trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connection.java)
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ConnectionImpl.java	                        (rev 0)
+++ trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ConnectionImpl.java	2011-01-11 22:54:45 UTC (rev 2833)
@@ -0,0 +1,30 @@
+/*
+ * ${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. You must define ${connector-name}Connection interface, that 
+ * extends the "javax.resource.cci.Connection"
+ */
+public class ${connector-name}ConnectionImpl extends BasicConnection implements ${connector-name}Connection {
+
+    private ${connector-name}ManagedConnectionFactory config;
+
+    public ${connector-name}ConnectionImpl(${connector-name}ManagedConnectionFactory env) {
+        this.config = env;
+        // todo: connect to your source here
+    }
+    
+    @Override
+    public void close() {
+    	
+    }
+}


Property changes on: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ConnectionImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java	2011-01-11 21:28:40 UTC (rev 2832)
+++ trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Connector.java	2011-01-11 22:54:45 UTC (rev 2833)
@@ -1,38 +0,0 @@
-/*
- * ${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;
-    }
-}

Deleted: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java	2011-01-11 21:28:40 UTC (rev 2832)
+++ trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}Execution.java	2011-01-11 22:54:45 UTC (rev 2833)
@@ -1,190 +0,0 @@
-/*
- * ${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 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;
-
-
-/**
- * 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 resultset.
-        
-        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 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) {
-    	Calendar cal = Calendar.getInstance();
-    	cal.clear();
-    	cal.set(1969, 11, 31, 18, 0, 0);
-    	
-        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";
-        }
-    }    
-
-}

Modified: trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java	2011-01-11 21:28:40 UTC (rev 2832)
+++ trunk/connectors/sandbox/connector-template/src/main/java/${package-name}/${connector-name}ManagedConnectionFactory.java	2011-01-11 22:54:45 UTC (rev 2833)
@@ -5,8 +5,18 @@
 
 import org.teiid.connector.basic.BasicManagedConnectionFactory;
 
-public class ${connector-name}ManagedConnectionFactory extends BasicManagedConnectionFactory{
+public class ${connector-name}ManagedConnectionFactory extends BasicManagedConnectionFactory {
 	
+	@Override
+	public BasicConnectionFactory createConnectionFactory() throws ResourceException {
+		return new BasicConnectionFactory() {
+			@Override
+			public BasicConnection getConnection() throws ResourceException {
+				return new ${connector-name}ConnectionImpl(this);
+			}
+		};
+	}	
+	
 	// ra.xml files getters and setters go here.
 
 }

Modified: trunk/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml
===================================================================
--- trunk/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml	2011-01-11 21:28:40 UTC (rev 2832)
+++ trunk/connectors/sandbox/connector-template/src/main/rar/META-INF/ra.xml	2011-01-11 22:54:45 UTC (rev 2833)
@@ -16,7 +16,7 @@
       <license-required>true</license-required>
    </license>
    <resourceadapter>
-      <resourceadapter-class>org.teiid.connector.basic.BasicResourceAdapter</resourceadapter-class>
+      <resourceadapter-class>org.teiid.resource.spi.BasicResourceAdapter</resourceadapter-class>
 
       <outbound-resourceadapter>
          <connection-definition>
@@ -24,57 +24,21 @@
 
             <!-- Common properties for all connectors -->
             <config-property>
-               <description>{$display:"Connector Class",$advanced:"true"}</description>
-               <config-property-name>ConnectorClass</config-property-name>
+               <description>{$display:"sample",$required:"true"}</description>
+               <config-property-name>SampleProperty</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-value>sample-value</config-property-value>
             </config-property>
 
-            <config-property>
-               <description>{$display:"Connector Capabilities",$description:"The class to use to provide the Connector Capabilities",$advanced:"true"}</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>{$display:"Is Immutable",$description:"Is Immutable, True if the source never changes.",$advanced:"true"}</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>{$display:"Is XA Capable",$description:"True, if this connector supports XA Transactions",$advanced:"true"}</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>{$display:"Exception on Exceeding Max Rows",$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",$advanced:"true"}</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>{$display:"Maximum Result Rows",$description:"Maximum Result Rows allowed",$advanced:"true"}</description>
-               <config-property-name>MaxResultRows</config-property-name>
-               <config-property-type>java.lang.Integer</config-property-type>
-               <config-property-value>-1</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>
+            <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
+            <connectionfactory-impl-class>org.teiid.resource.spi.WrappedConnectionFactory</connectionfactory-impl-class>
+            <connection-interface>javax.resource.cci.Connection</connection-interface>
+            <connection-impl-class>org.teiid.resource.spi.WrappedConnection</connection-impl-class>
 
          </connection-definition>
          



More information about the teiid-commits mailing list