Author: vhalbert(a)redhat.com
Date: 2011-05-18 16:11:01 -0400 (Wed, 18 May 2011)
New Revision: 3180
Added:
trunk/connectors/sandbox/coherence_connector/
trunk/connectors/sandbox/coherence_connector/lib/
trunk/connectors/sandbox/coherence_connector/pom.xml
trunk/connectors/sandbox/coherence_connector/readme.txt
trunk/connectors/sandbox/coherence_connector/src/
trunk/connectors/sandbox/coherence_connector/src/main/
trunk/connectors/sandbox/coherence_connector/src/main/java/
trunk/connectors/sandbox/coherence_connector/src/main/java/org/
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnection.java
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnectionImpl.java
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceManagedConnectionFactory.java
trunk/connectors/sandbox/coherence_translator/
trunk/connectors/sandbox/coherence_translator/pom.xml
trunk/connectors/sandbox/coherence_translator/readme.txt
trunk/connectors/sandbox/coherence_translator/src/
trunk/connectors/sandbox/coherence_translator/src/main/
trunk/connectors/sandbox/coherence_translator/src/main/java/
trunk/connectors/sandbox/coherence_translator/src/main/java/org/
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/BaseID.java
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecution.java
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecutionFactory.java
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceVisitor.java
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Leg.java
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Trade.java
Log:
TEIID-1594 adding to the sandbox an example of accessing a Coherence cache
Added: trunk/connectors/sandbox/coherence_connector/pom.xml
===================================================================
--- trunk/connectors/sandbox/coherence_connector/pom.xml (rev 0)
+++ trunk/connectors/sandbox/coherence_connector/pom.xml 2011-05-18 20:11:01 UTC (rev
3180)
@@ -0,0 +1,75 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>coherence_connector</artifactId>
+ <groupId>org.teiid.coherence.connector</groupId>
+ <name>Coherence Connector</name>
+ <version>0.1</version>
+ <packaging>rar</packaging>
+ <description>This connector reads data from Coherence.</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-api</artifactId>
+ <scope>provided</scope>
+ <version>7.1.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <scope>provided</scope>
+ <version>7.1.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <scope>provided</scope>
+ <version>1.5</version>
+ </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>
Property changes on: trunk/connectors/sandbox/coherence_connector/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added: trunk/connectors/sandbox/coherence_connector/readme.txt
===================================================================
--- trunk/connectors/sandbox/coherence_connector/readme.txt (rev
0)
+++ trunk/connectors/sandbox/coherence_connector/readme.txt 2011-05-18 20:11:01 UTC (rev
3180)
@@ -0,0 +1,27 @@
+connector readme
+
+The coherence_connector is an example of how an Oracle Coherence cache can be exposed for
access by the coherence_translator.
+
+Setup:
+
+- add the coherence.jar to the coherence_connector/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/coherence_connector-0.1.rar to server/<profile>/deploy/teiid
directory
+- copy src/main/resources/coherence-ds.xml to server/<profile>/deploy directory
+- copy the coherence.jar to the <profile>/lib directory
+
+- see the coherence_translator for deployment
Property changes on: trunk/connectors/sandbox/coherence_connector/readme.txt
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnection.java
===================================================================
---
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnection.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnection.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,13 @@
+package org.teiid.coherence.connector;
+
+import java.util.List;
+
+import javax.resource.ResourceException;
+
+
+public interface CoherenceConnection {
+
+ public List<Object> get(String criteria) throws ResourceException;
+
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnection.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnectionImpl.java
===================================================================
---
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnectionImpl.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnectionImpl.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,188 @@
+/*
+ * 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.coherence.connector;
+
+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.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;
+import com.tangosol.util.QueryHelper;
+
+/**
+ * Represents a connection to a Coherence data source.
+ */
+public class CoherenceConnectionImpl extends BasicConnection implements
CoherenceConnection {
+
+ private NamedCache tradesCache = null;
+
+
+ public CoherenceConnectionImpl(CoherenceManagedConnectionFactory config) throws
ResourceException {
+
+ tradesCache = CacheFactory.getCache(config.getCacheName());
+
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Coherence Connection has been
newly created."); //$NON-NLS-1$
+ }
+
+ /**
+ * Close the connection, if a connection requires closing.
+ * (non-Javadoc)
+ */
+ @Override
+ public void close() {
+// LogManager.logDetail(LogConstants.CTX_CONNECTOR,"Coherence Connector has been
closed."); //$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."); //$NON-NLS-1$
+ return true;
+ }
+
+// original example getting the legs in a trade
+// public List<Leg> getLegs(List<Long> legIds) throws ResourceException {
+//
+// NamedCache tradesCache = CacheFactory.getCache("Trades");
+// Map legsMap = new HashMap();
+//
+// Leg leg = new Leg();
+// Set legsSet;
+// Map.Entry legsEntry;
+//
+// List<Leg> legs = new ArrayList<Leg>();
+//
+// Trade trade = null;
+// for (int i=1; i<=3; i++){
+// trade = (Trade)tradesCache.get(i);
+// legsMap = trade.getLegs();
+// legsSet = legsMap.entrySet();
+// Iterator k = legsSet.iterator();
+// while(k.hasNext()){
+// legsEntry = (Map.Entry)k.next();
+// leg = (Leg)legsEntry.getValue();
+// if (matchId(leg, legIds)) {
+//
+// System.out.print("Leg Id: " + leg.getId() + " , notional
value: " + leg.getNotional() + "\n");
+// legs.add(leg);
+// }
+// }
+// }
+//
+// return legs;
+// }
+
+// private boolean matchId(BaseID baseID, List<Long> ids) {
+// Iterator<Long> it = ids.iterator();
+// while (it.hasNext()) {
+// Long id = it.next();
+// if (id.longValue() == baseID.getId()) return true;
+// }
+// return false;
+// }
+
+
+ // original example passing in ids to find
+// public List<Object> getTrades(List<Long> ids) throws ResourceException {
+//
+// List<Object> trades = new ArrayList();
+//
+// if (ids == null || ids.isEmpty()) {
+// trades.addAll(tradesCache.values());
+//
+// } else {
+//
+// String parm = null;
+// for (Iterator<Long> it = ids.iterator(); it.hasNext();) {
+// Long t = it.next();
+// if (parm != null) {
+// parm += ",";
+// }
+// parm = String.valueOf(t);
+//
+// }
+//
+// // filter wouldn't work until the long "L" indicater was added to
+// // the parm
+// // the examples showed using a float 7.0f
+// Filter filter = QueryHelper.createFilter("Id = " + parm + "l");
+//
+// Set mapResult = (Set) tradesCache.entrySet(filter);
+//
+// for (Iterator it = mapResult.iterator(); it.hasNext();) {
+// Map.Entry o = (Map.Entry) it.next();
+// trades.add(o.getValue());
+// }
+//
+// }
+//
+// return trades;
+//
+// }
+
+ public List<Object> get(String criteria) throws ResourceException {
+ List<Object> objects = null;
+ if (criteria == null || criteria.trim().length() == 0) {
+ objects = new ArrayList(tradesCache.size());
+ objects.addAll(tradesCache.values());
+ return objects;
+
+ }
+
+ objects = new ArrayList();
+ Filter filter = QueryHelper.createFilter(criteria);
+
+ Set<ConverterCollections.ConverterEntrySet> mapResult =
(Set<ConverterCollections.ConverterEntrySet>) tradesCache
+ .entrySet(filter);
+
+ for (Iterator it = mapResult.iterator(); it.hasNext();) {
+ Map.Entry o = (Map.Entry) it.next();
+ objects.add(o.getValue());
+ }
+ return objects;
+
+ }
+
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceConnectionImpl.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceManagedConnectionFactory.java
===================================================================
---
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceManagedConnectionFactory.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceManagedConnectionFactory.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,56 @@
+/*
+ * 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.coherence.connector;
+
+import javax.resource.ResourceException;
+
+import org.teiid.resource.spi.BasicConnectionFactory;
+import org.teiid.resource.spi.BasicManagedConnectionFactory;
+
+public class CoherenceManagedConnectionFactory extends BasicManagedConnectionFactory {
+
+ private static final long serialVersionUID = -1832915223199053471L;
+
+ private String cacheName = "Trades";
+
+ @Override
+ public BasicConnectionFactory createConnectionFactory() throws ResourceException {
+ return new BasicConnectionFactory() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public CoherenceConnectionImpl getConnection() throws ResourceException {
+ return new CoherenceConnectionImpl(CoherenceManagedConnectionFactory.this);
+ }
+ };
+ }
+
+ public String getCacheName() {
+ return cacheName;
+ }
+
+ public void setCacheName(String cachename) {
+ this.cacheName = cachename;
+ }
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_connector/src/main/java/org/teiid/coherence/connector/CoherenceManagedConnectionFactory.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added: trunk/connectors/sandbox/coherence_translator/pom.xml
===================================================================
--- trunk/connectors/sandbox/coherence_translator/pom.xml (rev 0)
+++ trunk/connectors/sandbox/coherence_translator/pom.xml 2011-05-18 20:11:01 UTC (rev
3180)
@@ -0,0 +1,56 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>coherence_translator</artifactId>
+ <groupId>org.teiid.coherence.translator</groupId>
+ <name>Coherence Translator</name>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+ <description>This is the tranlator for a Coherence
connector</description>
+
+ <dependencies>
+
+ <dependency>
+ <artifactId>coherence_connector</artifactId>
+ <groupId>org.teiid.coherence.connector</groupId>
+ <scope>compile</scope>
+ <classifier>lib</classifier>
+ <version>0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-api</artifactId>
+ <scope>provided</scope>
+ <version>7.1.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <scope>provided</scope>
+ <version>7.1.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <scope>provided</scope>
+ <version>1.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>coherence</groupId>
+ <artifactId>coherence</artifactId>
+ <version>3.6.1</version>
+ <scope>system</scope>
+
<systemPath>${basedir}/../coherence_connector/lib/coherence.jar</systemPath>
+ </dependency>
+
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Property changes on: trunk/connectors/sandbox/coherence_translator/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added: trunk/connectors/sandbox/coherence_translator/readme.txt
===================================================================
--- trunk/connectors/sandbox/coherence_translator/readme.txt (rev
0)
+++ trunk/connectors/sandbox/coherence_translator/readme.txt 2011-05-18 20:11:01 UTC (rev
3180)
@@ -0,0 +1,43 @@
+{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
+{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
+{\colortbl;\red255\green255\blue255;}
+\margl1440\margr1440\vieww15400\viewh13820\viewkind0
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
+
+\f0\fs24 \cf0 translator readme\
+\
+The coherence_translator is very simple implementation of mapping a Coherence cache to
relational sql request. This translator requires the deployment of the
coherence_connector.\
+\
+This translator is coded to expect Trades and Legs to be in the cache. It was not
generically implemented to handle any type of objects loaded into the cache. Feel free
to rework it to make it better.\
+\
+\
+There is an example model (Coherence.xmi) and vdb (Coherence.vdb) that are located in the
src/test/resources directory. These can be used as a example for modeling Coherence as a
source.\
+\
+\
+BUILD:\
+---------\
+run mvn clean install\
+\
+\
+\
+DEPLOYMENT\
+--------------------\
+\
+setup \
+\
+ 1. see coherence_connector for deployment\
+ 2. deploy the Coherence.vdb from src/test/resources to the <profile>/deploy/
directory\
+ 3. copy the coherence_translator-0.1.jar to server/<profile>/deploy/teiid
directory\
+ 4. restart server\
+\
+ NOTE: to preload a coherence cache with test data, build the coherence_translotr
project, the junit tests will load the cache.\
+\
+ 5. use the teiid simpleclient example to run the following:\
+\
+ ./run.sh localhost 31000 Coherence "select * from trade"\
+\
+\
+Other notes:\
+- the coherence translator has the translator name of "coherence", which must
match the translator defined in the vdb that's mapped to the Coherence source.\
+\
+}
\ No newline at end of file
Property changes on: trunk/connectors/sandbox/coherence_translator/readme.txt
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/BaseID.java
===================================================================
---
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/BaseID.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/BaseID.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,27 @@
+package org.teiid.coherence.translator;
+
+
+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;
+ }
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/BaseID.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecution.java
===================================================================
---
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecution.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecution.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,153 @@
+/*
+ * ${license}
+ */
+package org.teiid.coherence.translator;
+
+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.coherence.connector.CoherenceConnection;
+import org.teiid.language.Select;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.DataNotAvailableException;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.TranslatorException;
+
+
+
+/**
+ * Execution of a command. This may be select, update or procedure command.
+ */
+public class CoherenceExecution implements ResultSetExecution {
+
+ // Connector resources
+ private CoherenceExecutionFactory config;
+ private RuntimeMetadata metadata;
+ private Select query;
+ private List results;
+ private CoherenceConnection connection;
+
+ private Iterator resultsIt = null;
+
+ private List<Object> row;
+
+ public CoherenceExecution(Select query, RuntimeMetadata metadata, CoherenceConnection
connection) {
+ this.metadata = metadata;
+ this.query = query;
+ this.connection = connection;
+ }
+
+ @Override
+ public void execute() throws TranslatorException {
+ // Log our command
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Coherence executing
command: " + query); //$NON-NLS-1$
+
+ // Build url
+ Map<String, List<Long>> targetArguments = translateQuery(query);
+
+ // Execute url to get results
+ this.results = executeQuery(targetArguments);
+ this.resultsIt = this.results.iterator();
+ }
+
+ private Map<String, List<Long>> translateQuery(Select query) throws
TranslatorException {
+
+ CoherenceVisitor visitor = new CoherenceVisitor(metadata);
+ visitor.visitNode(query);
+
+ if(visitor.getException() != null) {
+ throw visitor.getException();
+ }
+ return visitor.getCriteria();
+
+ }
+
+ protected List executeQuery(Map<String, List<Long>> arguments)
+ throws TranslatorException {
+ List rows = new ArrayList();
+
+ String tablename = (String) arguments.keySet().iterator().next();
+ List<Long> args = arguments.get(tablename);
+
+ try {
+ String parm = null;
+ for (Iterator<Long> it = args.iterator(); it.hasNext();) {
+ Long t = it.next();
+ if (parm != null) {
+ parm += ",";
+ }
+ parm = String.valueOf(t + "l");
+
+ }
+
+ List<Object> trades = this.connection.get("Id in (" + parm +
")");
+ if (trades == null)
+ return rows;
+
+ List<Object> row = new ArrayList<Object>(trades.size());
+
+ for (Iterator<Object> it = trades.iterator(); it.hasNext();) {
+ Trade t = (Trade) it.next();
+
+ Map legsMap = t.getLegs();
+
+ Set legsSet = legsMap.entrySet();
+ Iterator k = legsSet.iterator();
+ while (k.hasNext()) {
+ Map.Entry legsEntry = (Map.Entry) k.next();
+ Leg leg = (Leg) legsEntry.getValue();
+
+ row = new ArrayList<Object>(3);
+
+ // the types loaded here must match @link{CoherenceExecutionFactory#getMetadata)
+ row.add(new Long(t.getId()));
+ row.add(new Long(leg.getId()));
+ row.add(new Double(leg.getNotional()));
+
+ rows.add(row);
+
+ }
+ }
+
+ return rows;
+
+ } catch (ResourceException re) {
+ re.printStackTrace();
+ }
+
+ return rows;
+ }
+
+
+
+
+ @Override
+ public List<?> next() throws TranslatorException, DataNotAvailableException {
+ // create and return one row at a time for your resultset.
+ if (resultsIt.hasNext()) {
+ return (List) resultsIt.next();
+ }
+
+ return null;
+ }
+
+
+ @Override
+ public void close() {
+ // TODO:cleanup your execution based resources here
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+ //TODO: initiate the "abort" of execution
+ }
+
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecution.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecutionFactory.java
===================================================================
---
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecutionFactory.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecutionFactory.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,93 @@
+/*
+ * 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.coherence.translator;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.resource.cci.ConnectionFactory;
+
+
+import org.teiid.coherence.connector.CoherenceConnection;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.language.QueryExpression;
+import org.teiid.language.Select;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+
+
+@Translator(name="coherence", description="A translator for testing
Coherence")
+public class CoherenceExecutionFactory extends ExecutionFactory<ConnectionFactory,
CoherenceConnection> {
+
+
+ public static final int MAX_SET_SIZE = 100;
+
+ @Override
+ public void start() throws TranslatorException {
+ }
+
+ @Override
+ public ResultSetExecution createResultSetExecution(QueryExpression command,
ExecutionContext executionContext, RuntimeMetadata metadata, CoherenceConnection
connection)
+ throws TranslatorException {
+ return new CoherenceExecution((Select)command, metadata, connection);
+ }
+
+ public List getSupportedFunctions() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public boolean supportsCompareCriteriaEquals() {
+ return true;
+ }
+
+ public boolean supportsInCriteria() {
+ return true;
+ }
+
+ public int getMaxInCriteriaSize() {
+ return MAX_SET_SIZE;
+ }
+
+ @Override
+ public boolean isSourceRequired() {
+ return false;
+ }
+
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory,
+ CoherenceConnection conn) throws TranslatorException {
+ Table t = metadataFactory.addTable("Trade"); //$NON-NLS-1$
+ metadataFactory.addColumn("tradeid", DataTypeManager.DefaultDataTypes.LONG,
t); //$NON-NLS-1$
+ metadataFactory.addColumn("legid", DataTypeManager.DefaultDataTypes.LONG, t);
//$NON-NLS-1$
+ metadataFactory.addColumn("notational",
DataTypeManager.DefaultDataTypes.DOUBLE, t); //$NON-NLS-1$
+ }
+
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceExecutionFactory.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceVisitor.java
===================================================================
---
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceVisitor.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceVisitor.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,121 @@
+/*
+ * 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.coherence.translator;
+
+import java.util.*;
+
+import org.teiid.language.*;
+import org.teiid.language.visitor.HierarchyVisitor;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.translator.TranslatorException;
+
+
+
+/**
+ */
+public class CoherenceVisitor extends HierarchyVisitor {
+
+ private String tableName = null;
+ private List<Long> ids = new ArrayList<Long>();
+ private RuntimeMetadata metadata;
+
+ private TranslatorException exception;
+
+ /**
+ *
+ */
+ public CoherenceVisitor(RuntimeMetadata metadata) {
+ super();
+ this.metadata = metadata;
+ }
+
+
+ public Map<String, List<Long>> getCriteria() {
+
+ Map<String, List<Long>> criteria = new HashMap<String,
List<Long>>();
+ criteria.put(tableName, ids);
+
+ return criteria;
+ }
+
+ public TranslatorException getException() {
+ return this.exception;
+ }
+
+
+ public void visit(Select query) {
+ super.visit(query);
+ List<TableReference> tables = query.getFrom();
+ TableReference t = tables.get(0);
+ if(t instanceof NamedTable) {
+ Table group = ((NamedTable)t).getMetadataObject();
+ tableName = group.getName();
+ }
+
+ }
+
+
+ public void visit(Comparison obj) {
+ Expression expr = obj.getRightExpression();
+ addIdFromExpression(expr);
+ }
+
+ public void visit(In obj) {
+ List exprs = obj.getRightExpressions();
+ Iterator iter = exprs.iterator();
+ while(iter.hasNext()) {
+ Expression expr = (Expression) iter.next();
+ addIdFromExpression(expr);
+
+ }
+ }
+
+ private void addIdFromExpression(Expression expr) {
+ if(expr instanceof Literal) {
+ Long longparm = null;
+ Literal literal = (Literal) expr;
+ if(literal.getType() == String.class) {
+ String parm = (String) literal.getValue();
+
+ longparm = new Long(parm);
+
+ } else if (literal.getType() == Long.class) {
+ Object obj = literal.getValue();
+
+ longparm = ((Long)obj);
+
+
+ } else {
+ this.exception = new
TranslatorException("CoherenceVisitor.Unexpected_type",
literal.getType().getName()); //$NON-NLS-1$
+ }
+
+ ids.add(longparm);
+
+ } else {
+ this.exception = new
TranslatorException("TickerCollectorVisitor.Unexpected_expression" + expr);
//$NON-NLS-1$
+ }
+
+ }
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/CoherenceVisitor.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Leg.java
===================================================================
---
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Leg.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Leg.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,28 @@
+package org.teiid.coherence.translator;
+
+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;
+ }
+}
Property changes on:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Leg.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Added:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Trade.java
===================================================================
---
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Trade.java
(rev 0)
+++
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Trade.java 2011-05-18
20:11:01 UTC (rev 3180)
@@ -0,0 +1,33 @@
+package org.teiid.coherence.translator;
+
+import java.io.Serializable;
+
+import java.util.Map;
+
+
+
+public class Trade extends BaseID implements Serializable {
+
+ private static final long serialVersionUID = 8611785625511714561L;
+
+private Map legs;
+
+ public Trade() {
+ super();
+ }
+
+ public Trade(long tradeId, Map legs) {
+ super(tradeId);
+ this.legs = legs;
+ }
+
+
+ public void setLegs(Map legs) {
+ this.legs = legs;
+ }
+
+ public Map getLegs() {
+ return legs;
+ }
+
+}
Property changes on:
trunk/connectors/sandbox/coherence_translator/src/main/java/org/teiid/coherence/translator/Trade.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF