[teiid-commits] teiid SVN: r3847 - in branches/7.7.x/connectors/sandbox: connector-coherence and 22 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Feb 6 00:44:37 EST 2012


Author: van.halbert
Date: 2012-02-06 00:44:36 -0500 (Mon, 06 Feb 2012)
New Revision: 3847

Added:
   branches/7.7.x/connectors/sandbox/connector-coherence/
   branches/7.7.x/connectors/sandbox/connector-coherence/lib/
   branches/7.7.x/connectors/sandbox/connector-coherence/pom.xml
   branches/7.7.x/connectors/sandbox/connector-coherence/readme.txt
   branches/7.7.x/connectors/sandbox/connector-coherence/src/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnection.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnectionImpl.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceFilterUtil.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceManagedConnectionFactory.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/rar/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/rar/META-INF/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/rar/META-INF/ra.xml
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/resource/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/resource/adapter/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/resource/adapter/i18n.properties
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/BaseID.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Leg.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestCoherenceConnection.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestObjectTranslator.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Trade.java
   branches/7.7.x/connectors/sandbox/connector-coherence/src/test/resources/
Log:
new version of coherence connector and renamed to match other projects

Added: branches/7.7.x/connectors/sandbox/connector-coherence/pom.xml
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/pom.xml	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/pom.xml	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,81 @@
+<?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>sandbox</artifactId>
+        <groupId>org.jboss.teiid.connectors</groupId>
+        <version>7.7.0.CR1</version>
+    </parent-->
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>connector-coherence</artifactId>
+    <groupId>org.jboss.teiid.connectors.sandbox</groupId>
+    <name>Coherence Connector</name>
+    <version>7.7.0.CR1</version>
+    <packaging>rar</packaging>
+    <description>This connector reads data from a Coherence cache</description>
+    <dependencies>
+        <dependency>
+            <groupId>org.jboss.teiid</groupId>
+            <artifactId>teiid-api</artifactId>
+            <version>7.7.0.CR1</version>
+             <scope>provided</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.jboss.teiid</groupId>
+            <artifactId>teiid-common-core</artifactId>  
+            <version>7.7.0.CR1</version>
+             <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.resource</groupId>
+            <artifactId>connector-api</artifactId>
+             <version>1.5</version>
+              <scope>provided</scope>
+        </dependency>
+        
+    	<dependency>
+	      	<groupId>coherence</groupId>
+    	  	<artifactId>coherence</artifactId>
+    	  	<version>3.6.1</version>
+     	 	<scope>system</scope>
+      		<systemPath>${basedir}/lib/coherence.jar</systemPath>
+   	    </dependency>  
+   	    
+   	    
+   	 	<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>		
+			<version>4.4</version>
+			<scope>test</scope>
+		</dependency>           
+        
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+            		<groupId>org.apache.maven.plugins</groupId>
+					<artifactId>maven-jar-plugin</artifactId>
+					<version>2.2</version>
+                 <executions>
+                    <execution>
+                        <id>build_jar</id>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>deploy_jar</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                        <configuration>
+                            <classifier>lib</classifier>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: branches/7.7.x/connectors/sandbox/connector-coherence/readme.txt
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/readme.txt	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/readme.txt	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,41 @@
+connector readme
+
+The coherence_connector is an example of how an Oracle Coherence cache can be exposed for access by the translator-coherence. 
+
+Design Note:
+- 	The cacheName is defined in the coherence-ds.xml.   This ties the cache to the physical model.  If a different cache is needed,
+ 	then a new/different coherence-ds.xml will need to be deployed.  And that will also require a new physical model to be created that
+ 	is assigned to this new datasource in the vdb.
+ 	
+ 	Why?  Coherence, at the time of writing this, doesn't support doing joins across caches.  However, Teiid can enable this by this design.
+ 	
+-   The CacheTranslatorClassName is defined in the coherence-ds.xml.   This is an implementation that extends org.teiid.translator.coherence.SourceCacheAdapter,
+	which is located in the tranlator-coherence project.  The parameter setting has been set in the coherence-ds.xml so that it can be changed without
+	having to update the vdb in designer and redeploy the vdb.	
+
+-------------------------
+To compile and run tests:
+-------------------------
+
+-	add the coherence.jar to the connector_coherence/lib directory
+
+Coherence can be downloaded from:   http://www.oracle.com/technetwork/middleware/coherence/downloads/index.html
+
+Build:
+
+run mvn clean install
+
+
+-------------------------
+Deployment:
+-------------------------
+
+deploy the following files to the jboss as server
+
+-  copy target/connector-coherence-<version>.rar  to  server/<profile>/deploy/teiid directory
+-  copy src/main/resources/coherence-ds.xml to  server/<profile>/deploy  directory
+	a. Set the CacheName in the coherence-ds.xml
+	b. Set the CacheTranslatorClassName in the coherence-ds.xml
+-  copy the coherence.jar to the <profile>/lib directory
+
+-  see the translator_coherence to deploy the translator deployment

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnection.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnection.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnection.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,54 @@
+/*
+ * 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.resource.adapter.coherence;
+
+import java.util.List;
+
+import com.tangosol.util.Filter;
+
+import javax.resource.ResourceException;
+
+/**
+ * CoherenceConnection interface used by the Coherence Translator to obtain cached objects.
+ * @author vhalbert
+ *
+ * TODO:  Add the ability to add/update objects in the cache
+ */
+
+public interface CoherenceConnection {
+	
+		
+	/**
+	 * Returns the objects from the Coherence Cache based on the <code>criteria</code> filter sepcified.
+	 * @param criteria
+	 * @return List of objects found in the cache.
+	 * @throws ResourceException
+	 */
+	public List<Object> get(Filter criteria) throws ResourceException;
+	
+	/**
+	 * Returns the name of the cache translator class name to use.
+	 * @return String name of the cache translator class
+	 */
+	public String getCacheTranslatorClassName();
+	
+}

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnectionImpl.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnectionImpl.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceConnectionImpl.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,130 @@
+/*
+ * 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.resource.adapter.coherence;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+
+import org.teiid.core.BundleUtil;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.resource.spi.BasicConnection;
+
+import com.tangosol.net.CacheFactory;
+import com.tangosol.net.NamedCache;
+import com.tangosol.util.ConverterCollections;
+import com.tangosol.util.Filter;
+
+/** 
+ * Represents an implementation for the connection to a Coherence data source. 
+ */
+public class CoherenceConnectionImpl extends BasicConnection implements CoherenceConnection { 
+	
+	public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CoherenceConnection.class);
+
+	private NamedCache sourceCache  = null;
+	private String translatorName = null;
+	private String cacheName = null;
+	
+	
+	public CoherenceConnectionImpl(CoherenceManagedConnectionFactory config) throws ResourceException {
+		
+		sourceCache = getCache(config.getCacheName());
+		translatorName = config.getCacheTranslatorClassName();
+		LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Coherence Connection has been newly created"); //$NON-NLS-1$
+	}
+	
+	public String getCacheTranslatorClassName() {
+		return  this.translatorName;
+		
+	}
+
+	
+	/** 
+	 * Close the connection, if a connection requires closing.
+	 * (non-Javadoc)
+	 */
+	@Override
+    public void close() {
+		CacheFactory.releaseCache( sourceCache);
+		sourceCache = null;
+
+		LogManager.logDetail(LogConstants.CTX_CONNECTOR,"Coherence NamedCache " + cacheName + " has been released."); //$NON-NLS-1$
+	}
+
+	/** 
+	 * Currently, this method always returns alive. We assume the connection is alive,
+	 * and rely on proper timeout values to automatically clean up connections before
+	 * any server-side timeout occurs. Rather than incur overhead by rebinding,
+	 * we'll assume the connection is always alive, and throw an error when it is actually used,
+	 * if the connection fails. This may be a more efficient way of handling failed connections,
+	 * with the one tradeoff that stale connections will not be detected until execution time. In
+	 * practice, there is no benefit to detecting stale connections before execution time.
+	 * 
+	 * One possible extension is to implement a UnsolicitedNotificationListener.
+	 * (non-Javadoc)
+	 */
+	public boolean isAlive() {
+		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Coherence Connection is alive for namedCache " + cacheName); //$NON-NLS-1$
+		return true;
+	}
+	
+	public List<Object> get(Filter criteria) throws ResourceException {
+//		System.out.println("CoherenceConnection cacheName: " +  cacheName + " filter: " + (criteria != null ? criteria.toString() : "NULL" ));
+		List<Object> objects = new ArrayList<Object>();
+		
+		Set<ConverterCollections.ConverterEntrySet> mapResult = (Set<ConverterCollections.ConverterEntrySet>) sourceCache
+		.entrySet(criteria);
+		
+
+		for (Iterator it = mapResult.iterator(); it.hasNext();) {
+			Map.Entry o = (Map.Entry) it.next();
+			objects.add(o.getValue());
+//			System.out.println("CoherenceConnection: loaded result " + o.getValue().toString() );
+
+		}
+		
+//		System.out.println("CoherenceConnection: loaded " + objects.size() + " results ");
+
+		return objects;
+
+	}
+	
+	private NamedCache getCache(String name) {
+		this.cacheName = name;
+		
+		sourceCache = CacheFactory.getCache(name);
+		
+		LogManager.logDetail(LogConstants.CTX_CONNECTOR,"Coherence NamedCache " + cacheName + " has been obtained."); //$NON-NLS-1$
+
+		return sourceCache;
+		
+	}
+
+
+}

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceFilterUtil.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceFilterUtil.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceFilterUtil.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,92 @@
+package org.teiid.resource.adapter.coherence;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.teiid.core.BundleUtil;
+import org.teiid.language.Comparison;
+import org.teiid.translator.TranslatorException;
+
+import com.tangosol.util.Filter;
+import com.tangosol.util.QueryHelper;
+
+/**
+ * 
+ * @author vhalbert
+ *
+ *	TODO:  add the LimitFilter
+ */
+
+public class CoherenceFilterUtil {
+	public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CoherenceFilterUtil.class);
+
+    
+    public static Filter createFilter(String filterString) throws TranslatorException {
+		return QueryHelper.createFilter(filterString); 	
+    }  
+    
+    public static Filter createInFilter(String colName, List<Object> parms, Class<?> type) throws TranslatorException {
+		String parm = null;
+		for (Iterator<Object> it = parms.iterator(); it.hasNext();) {
+			Object t = it.next();
+			if (parm != null) {
+				parm += ",";
+			}
+            if(type == String.class) {
+            	parm = (String) t;        
+            } else if (type == Long.class) {
+                parm = String.valueOf(t + "l");
+               
+            } else {
+            	parm = t.toString();
+            }
+
+		}
+    
+		String filterString = colName + " in (" + parm + ")";
+		return QueryHelper.createFilter(filterString);
+  	
+    }
+    
+    public static Filter createCompareFilter(String colName, Object parm, Comparison.Operator op, Class<?> type) throws TranslatorException {
+    	String parmValue = null;
+        if(type == String.class) {
+        	parmValue = (String) parm;        
+        } else if (type == Long.class) {
+        	parmValue = String.valueOf(parm + "l");
+           
+        } else {
+        	parmValue = parm.toString();
+        }
+        
+        String opString = " = ";
+        
+		switch(op) {
+	    case NE:
+		case EQ:
+			break;
+		case GT:
+			opString = " > ";
+			break;
+		case GE:
+			opString = " >= "; 
+			break;
+		case LT:
+			opString = " < ";
+			break;
+		case LE:
+			opString = " <= "; 
+			break;
+		default:
+            final String msg = UTIL.getString("CoherenceVisitor.criteriaNotSupportedError"); 
+			throw new TranslatorException(msg); 
+			
+		}
+        
+		String filterString = colName + opString + parmValue ;
+		return QueryHelper.createFilter(filterString);
+  	
+    }  
+  
+
+}

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceManagedConnectionFactory.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceManagedConnectionFactory.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/main/java/org/teiid/resource/adapter/coherence/CoherenceManagedConnectionFactory.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,78 @@
+/*
+ * 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.resource.adapter.coherence;
+
+import javax.resource.ResourceException;
+
+import org.teiid.core.BundleUtil;
+import org.teiid.resource.spi.BasicConnectionFactory;
+import org.teiid.resource.spi.BasicManagedConnectionFactory;
+
+public class CoherenceManagedConnectionFactory extends BasicManagedConnectionFactory {
+	
+	private static final long serialVersionUID = -1832915223199053471L;
+	public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CoherenceManagedConnectionFactory.class);
+
+	private String cacheName;
+	private String cacheTranslatorClassName = null;
+
+	
+	
+	@Override
+	public BasicConnectionFactory createConnectionFactory() throws ResourceException {
+		if (cacheName == null) {
+			throw new ResourceException(UTIL.getString("CoherenceManagedConnectionFactory.cachename_not_set")); //$NON-NLS-1$
+		}
+		
+		if (cacheTranslatorClassName == null) {
+			throw new ResourceException(UTIL.getString("CoherenceVisitor.cacheTranslatorClassName_not_set")); //$NON-NLS-1$
+		}	
+		
+		return new BasicConnectionFactory() {
+
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			public CoherenceConnectionImpl getConnection() throws ResourceException {
+				return new CoherenceConnectionImpl(CoherenceManagedConnectionFactory.this);
+			}
+		};
+	}	
+	
+	public String getCacheName() {
+		return this.cacheName;
+	}
+	
+	public void setCacheName(String cacheName) {
+		this.cacheName = cacheName;
+	}
+	
+    
+	public String getCacheTranslatorClassName() {
+		return cacheTranslatorClassName;
+	}
+	
+	public void setCacheTranslatorClassName(String className) {
+		this.cacheTranslatorClassName = className;
+	}
+	
+}

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/main/rar/META-INF/ra.xml
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/main/rar/META-INF/ra.xml	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/main/rar/META-INF/ra.xml	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<connector version="1.5">
+
+   <vendor-name>Red Hat Middleware LLC</vendor-name>
+   <eis-type>Teiid Coherence Connector</eis-type>
+   <resourceadapter-version>1.0</resourceadapter-version>
+   <license>
+      <description>
+ JBoss, Home of Professional Open Source.
+ Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ as indicated by the @author tags. See the copyright.txt file in the
+ distribution for a full listing of individual contributors.
+
+ This 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 software 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 software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+      </description>
+      <license-required>true</license-required>
+   </license>
+   <resourceadapter>
+      <resourceadapter-class>org.teiid.resource.spi.BasicResourceAdapter</resourceadapter-class>
+
+      <outbound-resourceadapter>
+         <connection-definition>
+            <managedconnectionfactory-class>org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory</managedconnectionfactory-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>
+            
+            <config-property>
+               <description>{$display:"Coherence Cache Name",$description:"Name of the Coherence Cache",$required:"true"}</description>
+               <config-property-name>CacheName</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+            </config-property>  
+            <config-property>
+               <description>{$display:"Coherence Object Translator Class Name",$description:"Name of the class to translate objects in Coherence Cache",$required:"true"}</description>
+               <config-property-name>CacheTranslatorClassName</config-property-name>
+               <config-property-type>java.lang.String</config-property-type>
+               <config-property-value>org.teiid.translator.coherence.SourceCacheAdapter</config-property-value>
+            </config-property>           
+
+         </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>

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/resource/adapter/i18n.properties
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/resource/adapter/i18n.properties	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/main/resources/org/teiid/resource/adapter/i18n.properties	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+
+CoherenceManagedConnectionFactory.cachename_not_set=Coherence cache name not set in the datasource -ds.xml file
+CoherenceVisitor.cacheTranslatorClassName_not_set=CacheTranslatorClassName not set.  This class will perform the object translation.
+
+

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/BaseID.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/BaseID.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/BaseID.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,27 @@
+package org.teiid.resource.adapter.coherence;
+
+
+import java.io.Serializable;
+
+public abstract class BaseID implements Serializable {
+
+ private long id;
+
+   public BaseID() {
+       super();
+   }
+
+   public BaseID(long id) {
+       super();
+       this.id = id;
+   }
+
+   public void setId(long id) {
+       this.id = id;
+   }
+
+   public long getId() {
+       return id;
+   }
+
+}

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Leg.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Leg.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Leg.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,28 @@
+package org.teiid.resource.adapter.coherence;
+
+import java.io.Serializable;
+
+
+public class Leg extends BaseID implements Serializable {
+
+	private static final long serialVersionUID = 7683272638393477962L;
+	
+private double notional;
+
+   public Leg() {
+       super();
+   }
+
+   public Leg(long legId, double notional) {
+       super(legId);
+       this.notional = notional;
+   }
+
+   public void setNotional(double notional) {
+       this.notional = notional;
+   }
+
+   public double getNotional() {
+       return notional;
+   }
+}

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestCoherenceConnection.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestCoherenceConnection.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestCoherenceConnection.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,232 @@
+/*
+ * 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.resource.adapter.coherence;
+        
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+import org.teiid.language.Comparison;
+import org.teiid.resource.adapter.coherence.CoherenceConnection;
+import org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory;
+
+import com.tangosol.net.CacheFactory;
+import com.tangosol.net.NamedCache;
+import com.tangosol.util.Filter;
+import junit.framework.TestCase;
+
+public class TestCoherenceConnection extends TestCase  {
+	
+	public static final String CACHE_NAME = "Trades";
+	
+	public static final String OBJECT_TRANSLATOR = "org.teiid.resource.adapter.coherence.TestObjectTranslator";
+	
+	public static final int NUMLEGS = 10;
+	public static final int NUMTRADES = 3;
+
+	static {
+		try {
+			loadCoherence();
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * Load the cache with 3 trades and 10 legs for each trade.
+	 * 
+	 * @throws Exception
+	 */
+	private static void loadCoherence() throws Exception {
+		NamedCache tradesCache = CacheFactory.getCache(CACHE_NAME);
+
+		// populate the cache
+		Map legsMap = new HashMap();
+		Trade trade = new Trade();
+
+		for (int i = 1; i <= NUMTRADES; i++) {
+
+			for (int j = 1; j <= NUMLEGS; j++) {
+				Leg leg = new Leg();
+				leg.setId(j);
+				leg.setNotional(i + j);
+				legsMap.put(j, leg);
+			}
+			trade.setId(i);
+			trade.setName("NameIs " + i);
+			trade.setLegs(legsMap);
+			tradesCache.put(i, trade);
+		}
+
+		System.out.println("Loaded Coherence");
+
+	}
+
+	/**
+	 * This will instantiate the {@link CoherenceManagedConnectionFactory} and
+	 * obtain a connection to
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testGet1Trade() throws Exception {
+
+		CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
+		f.setCacheName(CACHE_NAME);
+		f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+		CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
+
+		List<Object> ids = new ArrayList<Object>();
+		ids.add(new Long(1));
+		
+		Filter criteria = CoherenceFilterUtil.createInFilter("id", ids, Long.class);
+
+		List<?> trades = conn.get(criteria);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", 1, trades.size());
+
+		// grab the first trade to confirm trade 1 was found in the cache.
+		Trade t = (Trade) trades.get(0);
+		Map legs = t.getLegs();
+		assertEquals("Did not get expected number of legs", NUMLEGS, legs.size());
+
+	}
+
+	@Test
+	public void testGetAllTrades() throws Exception {
+
+		CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
+		f.setCacheName(CACHE_NAME);
+		f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+
+		CoherenceConnection conn = (CoherenceConnection) f
+				.createConnectionFactory().getConnection();
+
+		List<Object> trades = conn.get(null);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", NUMTRADES, trades.size());
+
+
+		Trade t = (Trade) trades.get(0);
+		Map legs = t.getLegs();
+		assertEquals("Did not get expected number of legs", NUMLEGS, legs.size());
+
+	}
+	
+	@Test
+	public void testLike() throws Exception {
+
+		CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
+		f.setCacheName(CACHE_NAME);
+		f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+
+		CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
+		
+		Filter criteria = CoherenceFilterUtil.createFilter("Name like 'Name%'");
+
+		List<?> trades = conn.get(criteria);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", 3, trades.size());
+
+
+	}
+	
+	@Test
+	public void testIn() throws Exception {
+
+		CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
+		f.setCacheName(CACHE_NAME);
+		f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+
+		CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
+		
+		// NOTE:  Coherence, because the datatype of ID is long, wants the "l" appended to the value
+		Filter criteria = CoherenceFilterUtil.createFilter("Id In (1l)");
+
+		List<?> trades = conn.get(criteria);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", 1, trades.size());
+
+
+	}	
+	
+	
+	@Test
+	public void testEqualOnTrade() throws Exception {
+
+		CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
+		f.setCacheName(CACHE_NAME);
+		f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+
+		CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
+		
+		// NOTE:  Coherence, because the datatype of ID is long, wants the "l" appended to the value
+		Filter criteria = CoherenceFilterUtil.createFilter("Id = 1l");
+
+		List<?> trades = conn.get(criteria);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", 1, trades.size());
+				
+		long l = 1;
+		criteria = CoherenceFilterUtil.createCompareFilter("Id",  l, Comparison.Operator.EQ, Long.class);
+
+		trades = conn.get(criteria);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", 1, trades.size());
+
+
+
+	}	
+	
+	/**
+	 * this test will not work out-of-the-box.  Coherence, from what I've found, doen'st support this, but can be developed.
+	 * @throws Exception
+	 */
+	@Test
+	public void xtestEqualOnContainerObject() throws Exception {
+
+		CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
+		f.setCacheName(CACHE_NAME);
+		f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+
+		CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
+		long l = 1;
+		// NOTE:  Coherence, because the datatype of ID is long, wants the "l" appended to the value
+//		Filter criteria = CoherenceFilterUtil.createFilter("Id = 1l");
+		Filter criteria = CoherenceFilterUtil.createCompareFilter("getLegs.getLegId",  l, Comparison.Operator.EQ, Long.class);
+
+
+		List<?> trades = conn.get(criteria);
+		assertNotNull(trades);
+		assertEquals("Did not get expected number of trades", 1, trades.size());
+
+
+	}	
+}
+
+

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestObjectTranslator.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestObjectTranslator.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/TestObjectTranslator.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,5 @@
+package org.teiid.resource.adapter.coherence;
+
+public class TestObjectTranslator {
+
+}
\ No newline at end of file

Added: branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Trade.java
===================================================================
--- branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Trade.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/connector-coherence/src/test/java/org/teiid/resource/adapter/coherence/Trade.java	2012-02-06 05:44:36 UTC (rev 3847)
@@ -0,0 +1,49 @@
+package org.teiid.resource.adapter.coherence;
+
+import java.io.Serializable;
+
+import java.util.Map;
+
+
+
+public class Trade extends BaseID implements Serializable {
+
+	private static final long serialVersionUID = 8611785625511714561L;
+	
+private Map legs;
+private String name;
+
+   public Trade() {
+       super();
+   }
+
+   public Trade(long tradeId, Map legs) {
+       super(tradeId);
+       this.legs = legs;
+   }
+   
+   public void setName(String name) {
+	   this.name = name;
+   }
+   
+   public String getName() {
+	   return this.name;
+   }
+
+
+   public void setLegs(Map legs) {
+       this.legs = legs;
+   }
+
+   public Map getLegs() {
+       return legs;
+   }
+   
+   public String toString() {
+	   
+	   StringBuffer sb = new StringBuffer("Trade:");
+	   sb.append(" id " + getId());
+	   return sb.toString();
+   }
+   
+}



More information about the teiid-commits mailing list