[teiid-commits] teiid SVN: r3865 - in branches/7.7.x/connectors/sandbox/translator-coherence: src/main/java/org/teiid/translator/coherence and 5 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Feb 10 17:32:36 EST 2012


Author: van.halbert
Date: 2012-02-10 17:32:36 -0500 (Fri, 10 Feb 2012)
New Revision: 3865

Added:
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceUpdateExecution.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/CoherenceVisitor.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/DeleteVisitor.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/META-INF/
Removed:
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceVisitor.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/resources/META-INF/
   branches/7.7.x/connectors/sandbox/translator-coherence/src/test/resources/Trade.vdb
Modified:
   branches/7.7.x/connectors/sandbox/translator-coherence/pom.xml
   branches/7.7.x/connectors/sandbox/translator-coherence/readme.txt
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecution.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecutionFactory.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/SourceCacheAdapter.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/main/resources/org/teiid/translator/coherence/i18n.properties
   branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TestCoherenceTranslator.java
   branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TradesCacheSource.java
   branches/7.7.x/connectors/sandbox/translator-coherence/usage-guidelines.txt
Log:
added insert and delete sql translation

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/pom.xml
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/pom.xml	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/pom.xml	2012-02-10 22:32:36 UTC (rev 3865)
@@ -115,7 +115,6 @@
       		<systemPath>${basedir}/../connector-coherence/lib/coherence.jar</systemPath>
    	    </dependency> 
 		
-   	    
    	 	<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
@@ -142,7 +141,14 @@
                 <artifactId>jboss-vfs</artifactId>
                 <version>2.1.2.GA</version>
                 <scope>provided</scope>
-            </dependency>       							
+            </dependency>  
+            
+ 			<dependency>
+				<groupId>javax.transaction</groupId>
+                <artifactId>jta</artifactId>
+				<version>1.1</version>
+				<scope>provided</scope>
+			</dependency>                  							
     </dependencies>
 
     	<build>

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/readme.txt
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/readme.txt	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/readme.txt	2012-02-10 22:32:36 UTC (rev 3865)
@@ -21,14 +21,13 @@
 
 	1.	see coherence_connector for deployment
 	2.	copy the translator-coherence-<version>.jar to server/<profile>/deploy/teiid/connectors directory
-	2.	copy the implementation of SourceCacheAdapter to the server/<profile>/lib directory
-	3. 	start server
 
 
+
 Exmaple: To use the example vdb (Trade.vdb), do the following (with the server shutdown)
 
-	1.	copy translator-coherence-<version>-tests.jar to the <profile>/lib directory
-	2.	copy the Trade.vdb, located in src/test/resources, to <profile>/deploy directory
+	1.	set above "setup"
+	2.	copy the Trade.vdb, located in src/test/resources/Coherence_Designer_Project, to <profile>/deploy directory
 	3.	in coherence-ds.xml, set the CacheName property to "Trades" and CacheTranslatorClassName property to "org.teiid.translator.coherence.TradesCacheSource"
 		TradeCacheSource will load the cache upon initial use
 	4.  start JBoss server

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecution.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecution.java	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecution.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -15,6 +15,7 @@
 import org.teiid.translator.DataNotAvailableException;
 import org.teiid.translator.ResultSetExecution;
 import org.teiid.translator.TranslatorException;
+import org.teiid.translator.coherence.visitor.CoherenceVisitor;
 
 
 /**
@@ -60,7 +61,7 @@
 				throws TranslatorException {
 
 		try {
-			List objects = this.connection.get(visitor.getFilter());
+			List<Object> objects = this.connection.get(visitor.getFilter());
 					//"Id in (" + parm + ")", this.connection.getCacheName());
 			
 			if (objects == null)

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecutionFactory.java	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceExecutionFactory.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -28,6 +28,7 @@
 import javax.resource.cci.ConnectionFactory;
 
 import org.teiid.core.util.ReflectionHelper;
+import org.teiid.language.Command;
 import org.teiid.language.QueryExpression;
 import org.teiid.language.Select;
 import org.teiid.metadata.MetadataFactory;
@@ -38,62 +39,73 @@
 import org.teiid.translator.ResultSetExecution;
 import org.teiid.translator.Translator;
 import org.teiid.translator.TranslatorException;
+import org.teiid.translator.UpdateExecution;
 
 
 @Translator(name="coherence", description="A Coherence translator")
 public class CoherenceExecutionFactory extends ExecutionFactory<ConnectionFactory, CoherenceConnection> {
 
-
 	public static final int MAX_SET_SIZE = 100;
-	
+	   
+    private static SourceCacheAdapter cacheTranslator =  null;
     
-    private SourceCacheAdapter cacheTranslator =  null;
+    private MetadataFactory metadataFactory = null;
 	
 	
 	public CoherenceExecutionFactory() {
 		super();
-		setMaxInCriteriaSize(MAX_SET_SIZE);
+		this.setMaxInCriteriaSize(MAX_SET_SIZE);
+		this.setMaxDependentInPredicates(1);
+		this.setSourceRequired(false);
+		this.setSupportsOrderBy(false);
+		this.setSupportsSelectDistinct(false);
+		this.setSupportsInnerJoins(false);
+		this.setSupportsFullOuterJoins(false);
+		this.setSupportsOuterJoins(false);
+
 	}
 	
     @Override
     public void start() throws TranslatorException {
-    	super.start();
+    	super.start();    	
     }
 
     @Override
     public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, CoherenceConnection connection)
     		throws TranslatorException {
-    	createCacheTranslator(connection);
+     	createCacheTranslator(connection);
+
     	return new CoherenceExecution((Select)command, metadata, connection, cacheTranslator);
     }    
+    
+	@Override
+	public UpdateExecution createUpdateExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, CoherenceConnection connection) throws TranslatorException {
+		createCacheTranslator(connection);
 
+		return new CoherenceUpdateExecution(command, connection, metadata, executionContext, cacheTranslator);
+	}   
+
     
     public List getSupportedFunctions() {
         return Collections.EMPTY_LIST;
     }
 
-    public boolean supportsCompareCriteriaEquals() {
-        return true;
-    }
-
-    public boolean supportsInCriteria() {
-        return true;
-    }
     
     @Override
-    public boolean isSourceRequired() {
-    	return false;
-    }
-    
-    @Override
     public void getMetadata(MetadataFactory metadataFactory,
     		CoherenceConnection conn) throws TranslatorException {
-    	
-    	cacheTranslator.setMetadataFactory(metadataFactory);
+    	this.metadataFactory = metadataFactory;
     }
     
+    public SourceCacheAdapter getCacheTranslator() {
+    	return this.cacheTranslator;
+    }
     
-	private void createCacheTranslator(CoherenceConnection conn) throws TranslatorException {
+    
+	private synchronized void createCacheTranslator(CoherenceConnection conn) throws TranslatorException {
+		if (cacheTranslator != null) {
+			return;
+		}
 		if (conn.getCacheTranslatorClassName() == null) {
 			throw new TranslatorException(
 					CoherencePlugin.Util
@@ -102,9 +114,12 @@
 
 		try {
 			String classname = conn.getCacheTranslatorClassName();
-			this.cacheTranslator = (SourceCacheAdapter) ReflectionHelper
+			cacheTranslator = (SourceCacheAdapter) ReflectionHelper
 					.create(classname,
 							null, null);
+			
+	    	cacheTranslator.setMetadataFactory(metadataFactory);
+
 		} catch (Exception e1) {
 			throw new TranslatorException(e1);
 		}

Added: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceUpdateExecution.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceUpdateExecution.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceUpdateExecution.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -0,0 +1,432 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.coherence;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.resource.ResourceException;
+
+import org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl;
+import org.teiid.language.ColumnReference;
+import org.teiid.language.Command;
+import org.teiid.language.Comparison;
+import org.teiid.language.Condition;
+import org.teiid.language.Delete;
+import org.teiid.language.Expression;
+import org.teiid.language.ExpressionValueSource;
+import org.teiid.language.Insert;
+import org.teiid.language.Literal;
+import org.teiid.language.NamedTable;
+import org.teiid.language.SetClause;
+import org.teiid.language.Update;
+import org.teiid.language.Comparison.Operator;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.AbstractMetadataRecord;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ForeignKey;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.resource.adapter.coherence.CoherenceConnection;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.DataNotAvailableException;
+import org.teiid.translator.UpdateExecution;
+import org.teiid.translator.coherence.visitor.CoherenceVisitor;
+import org.teiid.translator.coherence.visitor.DeleteVisitor;
+
+import com.tangosol.coherence.component.util.Collections;
+import com.tangosol.coherence.component.util.Iterator;
+
+
+
+/**
+ * Please see the user's guide for a full description of capabilties, etc.
+ * 
+ * Description/Assumptions:
+ * 
+ */
+public class CoherenceUpdateExecution implements UpdateExecution {
+	protected CoherenceConnection connection;
+	protected RuntimeMetadata metadata;
+	protected ExecutionContext context;
+	protected Command command;
+	protected SourceCacheAdapter cacheTranslator;
+	protected CoherenceVisitor visitor = null;
+	protected int result;
+	
+	public CoherenceUpdateExecution(Command command,
+			CoherenceConnection coherenceConnection,
+			RuntimeMetadata metadata, ExecutionContext context, SourceCacheAdapter cacheTranslator) {
+		this.connection = coherenceConnection;
+		this.metadata = metadata;
+		this.context = context;
+		this.command = command;
+		this.cacheTranslator = cacheTranslator;
+		this.visitor = new CoherenceVisitor(metadata);
+	}	
+	
+	/** execute generic update-class (either an update, delete, or insert)
+	 * operation and returns a count of affected rows.  Since underlying
+	 * Coherence operations (and this connector) can modify at most one cache
+	 * object at a time, this will always return 1.  It will never
+	 * actually return 0, because if an operation fails, a
+	 * ConnectorException will be thrown instead.
+	 * here for the sake of efficiency.
+	 */
+	@Override
+	public void execute() throws TranslatorException {
+
+		if (command instanceof Update) {
+			executeUpdate();
+		}
+		else if (command instanceof Delete) {
+			executeDelete();
+		}
+		else if (command instanceof Insert) {
+			executeInsert();
+		}
+//		else {
+//            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.incorrectCommandError"); //$NON-NLS-1$
+//			throw new TranslatorException(msg);
+//		}
+	}
+	
+	@Override
+	public int[] getUpdateCounts() throws DataNotAvailableException,
+			TranslatorException {
+		return new int[] {1};
+	}
+
+	/**
+	 * Private method to perform the inserting of an object into the cache
+	 * @throws TranslatorException
+	 */
+	private void executeInsert()
+			throws TranslatorException {
+
+		Insert icommand = (Insert) command;		
+
+		RuntimeMetadataImpl impl = (RuntimeMetadataImpl) metadata;
+		
+		Table t = metadata.getTable(icommand.getTable().getMetadataObject().getFullName());
+		List<ForeignKey> fks = t.getForeignKeys();
+		
+		String parentToChildMethod = null;
+		String pkColName = null;
+		
+		// if a foreign key exist, then what's being updated is contained in its parent object.
+		// gather all the foreign key related info that will be needed
+		String parentColName = null;
+		Table parentTable = null;
+		// if a foreign key is defined, then this is a child object being processed
+		if (fks.size() > 0) {
+			ForeignKey fk = fks.get(0);
+			parentTable = fk.getParent();
+			// the name of the method to obtain the collection is the nameInSource of the foreginKey
+			parentToChildMethod = fk.getNameInSource();
+			
+			// there must only be 1 column in the primary key
+			parentColName = visitor.getNameFromElement(fk.getPrimaryKey().getColumns().get(0));
+					
+		} else {
+			// process the top level object
+			List<Column> pk = t.getPrimaryKey().getColumns();
+			if (pk == null || pk.isEmpty()) {
+	            final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noPrimaryKeyDefinedOnTable", new Object[] {t.getName()}); //$NON-NLS-1$
+				throw new TranslatorException(msg);		
+			}
+			
+			pkColName = visitor.getNameFromElement(pk.get(0));
+		
+		}
+		
+		
+		List<ColumnReference> insertElementList = icommand.getColumns();
+		List<Expression> insertValueList = ((ExpressionValueSource)icommand.getValueSource()).getValues();
+		if(insertElementList.size() != insertValueList.size()) {
+			throw new TranslatorException("Error:  columns.size and values.size are not the same.");
+		}
+		
+		Object parentObject = null;
+		Object parentContainer = null;
+		ColumnReference insertElement;
+		String[] nameOfElement = new String[insertElementList.size()];
+		
+		int parentValueLoc = -1;
+
+		for (int i=0; i < insertElementList.size(); i++) {
+			insertElement = insertElementList.get(i);
+//			// call utility class to get NameInSource/Name of element
+			nameOfElement[i]= visitor.getNameFromElement(insertElement.getMetadataObject());
+			
+			if (parentColName != null) {
+				if (nameOfElement[i].equalsIgnoreCase(parentColName)) {
+					parentValueLoc = i;					
+				}
+			}
+				
+		}		
+		
+		// this loop will
+		// 	-  get the nameInSource for each column that will be used to set the value
+		//  -  (and primarily), determine the location of the column that corresponds to the foreign key
+		//		the value for the foreign key will be needed to find the parent
+		if (parentColName != null) {
+			if (parentValueLoc == -1) {
+	            final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noColumnMatchedForeignColumn", new Object[] {t.getName(), parentColName}); //$NON-NLS-1$
+				throw new TranslatorException(msg);
+				
+			}
+			Object parentValue = insertValueList.get(parentValueLoc);
+			Object val;
+			if(parentValue instanceof Literal) {
+				Literal literalValue = (Literal)parentValue;
+				val = literalValue.getValue();
+				//.toString();
+			} else {
+				val = parentValue;
+				//.toString();
+			}
+			
+			// get the parent object from the cache
+			try {
+				List<Object> result = this.connection.get(visitor.createFilter(parentColName + " = " + val));
+				if (result == null || result.isEmpty()) {
+		            final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noobjectfound", new Object[] {parentTable.getName(), parentColName, val}); //$NON-NLS-1$
+					throw new TranslatorException(msg);
+				}
+				parentObject = result.get(0);
+			} catch (ResourceException e) {
+				throw new TranslatorException(e);
+			}			
+			
+			List<String> token = new ArrayList<String>(1);
+			token.add(parentToChildMethod);
+			 
+			// call to get the Object on the parent, which will be a container of some sort, for which the new object will be added
+			parentContainer = cacheTranslator.getValue(visitor.getTableName(), token, Collections.class, parentObject, 0);
+
+			
+		} 
+		// create the new object that will either be added as a top level object or added to the parent container
+		String tableName =  this.visitor.getNameFromTable(t);
+		Object newObject = cacheTranslator.createObjectFromMetadata(tableName);		
+
+		Object keyvalue = null;
+		for (int i=0; i < insertElementList.size(); i++) {
+			insertElement = insertElementList.get(i);
+			
+			Object value = insertValueList.get(i);
+			Object val;
+			if(value instanceof Literal) {
+				Literal literalValue = (Literal)value;
+				val = literalValue.getValue();
+				//.toString();
+				if(null != val && val instanceof String) {
+					//!val.isEmpty()) {
+					val = this.stripQutes((String) val);
+				}
+			} else {
+				val = value;
+				//.toString();
+			}
+
+			if (parentColName == null && nameOfElement[i].equalsIgnoreCase(pkColName)) {
+				keyvalue = val;
+			}
+			
+		    this.cacheTranslator.setValue(tableName, nameOfElement[i], newObject, val, insertElement.getType()); 
+		}
+
+		if (parentColName == null) {
+			// add top level object
+			try {
+				this.connection.add(keyvalue, newObject);
+			} catch (ResourceException e) {
+				throw new TranslatorException(e);
+			}			
+		} else {
+			// TODO:  add logic to add Map and Array's
+			((Collection) parentContainer).add(newObject);
+
+		}
+		
+	}
+
+
+	private void executeDelete()
+			throws TranslatorException {
+		
+		DeleteVisitor visitor = new DeleteVisitor(metadata);
+		
+    	visitor.visitNode((Delete) command);
+    	
+        if(visitor.getException() != null) { 
+            throw visitor.getException();
+        }
+
+		
+        for (java.util.Iterator it=visitor.getKeys().iterator(); it.hasNext();) {
+        	Object key = it.next();
+			try {
+				this.connection.remove(key);
+			} catch (ResourceException e) {
+				throw new TranslatorException(e);
+			}	
+        }
+
+	}
+
+	// Private method to actually do an update operation.  Per JNDI doc at
+	// http://java.sun.com/products/jndi/tutorial/ldap/models/operations.html, 
+	// the JNDI method to use to update an entry to LDAP is one of the
+	// DirContext.modifyAttributes() methods that takes ModificationItem[]
+	// as a parameter, so that is what is used here.
+	// Note that this method does not allow for changing of the DN - to
+	// implement that we would need to use Context.rename().  Since right
+	// now we only call modifyAttributes(), and don't check for the DN
+	// in the list of updates, we will attempt to update the DN using
+	// modifyAttributes(), and let the LDAP server fail the request (and
+	// send us the explanation for the failure, which is returned in
+	// a ConnectorException)
+	//
+	// The update criteria must include only an equals comparison
+	// on the "DN" column ("WHERE DN='cn=John Doe,ou=people,dc=company,dc=com'") 
+	private void executeUpdate()
+			throws TranslatorException {
+//
+//		List<SetClause> updateList = ((Update)command).getChanges();
+//		Condition criteria = ((Update)command).getWhere();
+//
+//		// since we have the exact same processing rules for criteria
+//		// for updates and deletes, we use a common private method to do this.
+//		// note that this private method will throw a ConnectorException
+//		// for illegal criteria, which we deliberately don't catch
+//		// so it gets passed on as is.
+//		String distinguishedName = getDNFromCriteria(criteria);
+//		
+//
+//		// this will be the list of modifications to attempt.  Since
+//		// we currently blindly try all the updates the query
+//		// specifies, right now this is the same size as the updateList.
+//		// When we start filtering out DN changes (which would need to
+//		// be performed separately using Context.rename()), we will
+//		// need to account for this in determining this list size. 
+//		ModificationItem[] updateMods = new ModificationItem[updateList.size()];
+//		ColumnReference leftElement;
+//		Expression rightExpr;
+//		String nameLeftElement;
+//		Object valueRightExpr;
+//		// iterate through the supplied list of updates (each of
+//		// which is an ICompareCriteria with an IElement on the left
+//		// side and an IExpression on the right, per the Connector
+//		// API).
+//		for (int i=0; i < updateList.size(); i++) {
+//			SetClause setClause = updateList.get(i);
+//			// trust that connector API is right and left side
+//			// will always be an IElement
+//			leftElement = setClause.getSymbol();
+//			// call utility method to get NameInSource/Name for element
+//			nameLeftElement = getNameFromElement(leftElement);
+//			// get right expression - if it is not a literal we
+//			// can't handle that so throw an exception
+//			rightExpr = setClause.getValue();
+//			if (!(rightExpr instanceof Literal)) { 
+//	            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
+//				throw new TranslatorException(msg);
+//		}
+//			valueRightExpr = ((Literal)rightExpr).getValue();
+//			// add in the modification as a replacement - meaning
+//			// any existing value(s) for this attribute will
+//			// be replaced by the new value.  If the attribute
+//			// didn't exist, it will automatically be created
+//			// TODO - since null is a valid attribute
+//			// value, we don't do any special handling of it right
+//			// now.  But maybe null should mean to delete an
+//			// attribute?
+//		        updateMods[i] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(nameLeftElement, valueRightExpr));
+//		}
+//		// just try to update an LDAP entry using the DN and
+//		// attributes specified in the UPDATE operation.  If it isn't
+//		// legal, we'll get a NamingException back, whose explanation
+//		// we'll return in a ConnectorException
+//		try {
+//			ldapCtx.modifyAttributes(distinguishedName, updateMods);
+//		} catch (NamingException ne) {
+//            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.updateFailed",distinguishedName,ne.getExplanation()); //$NON-NLS-1$
+//			throw new TranslatorException(msg);
+//		// don't remember why I added this generic catch of Exception,
+//		// but it does no harm...
+//		} catch (Exception e) {
+//            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.updateFailedUnexpected",distinguishedName); //$NON-NLS-1$
+//			throw new TranslatorException(e, msg);
+//		}
+	}
+
+	// cancel here by closing the copy of the ldap context (if it was
+	// initialized, which is only true if execute() was previously called)
+	// calling close on already closed context is safe per
+	// javax.naming.Context javadoc so we won't worry about this also
+	// happening in our close method
+	public void cancel() throws TranslatorException {
+		close();
+	}
+
+	// close here by closing the copy of the ldap context (if it was
+	// initialized, which is only true if execute() was previously called)
+	// calling close on already closed context is safe per
+	// javax.naming.Context javadoc so we won't worry about this also
+	// happening in our close method
+	public void close() {
+//		try {
+//			if(ldapCtx != null) {
+//				ldapCtx.close();
+//			}
+//		} catch (NamingException ne) {
+//            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.closeContextError",ne.getExplanation()); //$NON-NLS-1$
+//            LogManager.logWarning(LogConstants.CTX_CONNECTOR,msg);
+//		}
+	}
+	
+	private String stripQutes(String id) {
+		if((id.startsWith("'") && id.endsWith("'"))) {
+			id = id.substring(1,id.length()-1);
+		} else if ((id.startsWith("\"") && id.endsWith("\""))) {
+			id = id.substring(1,id.length()-1);
+		}
+		return id;
+	}
+
+}
+	
+
+
+
+				
+				
+				
+				
+				
+							

Deleted: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceVisitor.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceVisitor.java	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceVisitor.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -1,324 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.translator.coherence;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Comparison;
-import org.teiid.language.Comparison.Operator;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.In;
-import org.teiid.language.Like;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.ScalarSubquery;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.Select;
-import org.teiid.language.TableReference;
-import org.teiid.language.visitor.HierarchyVisitor;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.metadata.Table;
-import org.teiid.resource.adapter.coherence.CoherenceFilterUtil;
-import org.teiid.translator.TranslatorException;
-
-import com.tangosol.util.Filter;
-
-/**
- */
-public class CoherenceVisitor extends HierarchyVisitor {
-
-	private String tableName = null;
-	protected String[] attributeNames = null;
-	protected Class[] attributeTypes = null;
-	private RuntimeMetadata metadata;
-	private Filter filter = null;
-
-    private TranslatorException exception;
-
-    /**
-     * 
-     */
-    public CoherenceVisitor(RuntimeMetadata metadata) {
-        super();        
-        this.metadata = metadata;
-    }
-    
-    public Filter getFilter() {
-		return filter;
-
-    }
- 
-    public String getTableName() {
-    	return tableName;
-    }
-    
-    public String[] getAttributeNames() {
-    	return attributeNames;
-    }
-    
-    public Class[] getAttributeTypes() {
-    	return attributeTypes;
-    }    
-    
-    public TranslatorException getException() {
-        return this.exception;
-    }
-
-    
-	public void visit(Select query) {
-		super.visit(query);
-		
-		Iterator<DerivedColumn> selectSymbolItr = query.getDerivedColumns().iterator();
-		attributeNames = new String[query.getDerivedColumns().size()];
-		attributeTypes = new Class[query.getDerivedColumns().size()];
-		
-		int i=0;
-		while(selectSymbolItr.hasNext()) {
-			Column e = getElementFromSymbol(selectSymbolItr.next());
-			String attributeName = this.getNameFromElement(e);
-			Class attributeClass = e.getJavaType();
-			
-			attributeNames[i] = attributeName;
-			attributeTypes[i] = attributeClass;
-
-			i++;
-		}
-
-		
-		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) {
-		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison criteria."); //$NON-NLS-1$
-		try {
-			Comparison.Operator op = ((Comparison) obj).getOperator();
-	       
-			Expression lhs = ((Comparison) obj).getLeftExpression();
-			Expression rhs = ((Comparison) obj).getRightExpression();
-	
-			String lhsString = getExpressionString(lhs);
-			String rhsString = getExpressionString(rhs);
-			if(lhsString == null || rhsString == null) {
-	            final String msg = CoherencePlugin.Util.getString("CoherenceVisitor.missingComparisonExpression"); //$NON-NLS-1$
-				exception = new TranslatorException(msg); 
-			}
-	
-	        if(rhs instanceof Literal) {
-	            Literal literal = (Literal) rhs;
-	            filter = CoherenceFilterUtil.createCompareFilter(lhsString, literal.getValue(), op, literal.getType() );
-	            
-	        } else {
-	            Literal literal = (Literal) lhs;
-	            filter = CoherenceFilterUtil.createCompareFilter(rhsString, literal.getValue(), op, literal.getType() );
-	        	
-	        }
-		}catch (TranslatorException t) {
-			exception = t;
-		}
-    }
-    
-    public void visit(Like obj) {
-    	
-		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing LIKE criteria."); //$NON-NLS-1$
-//		isNegated = ((Like) criteria).isNegated();
-		// Convert LIKE to Equals, where any "%" symbol is replaced with "*".
-		try {
-			Comparison.Operator op = Operator.EQ;
-			Expression lhs = ((Like) obj).getLeftExpression();
-			Expression rhs = ((Like) obj).getRightExpression();
-		
-			String lhsString = getExpressionString(lhs);
-			String rhsString = getExpressionString(rhs);
-//			rhsString = rhsString.replace("%", "*"); //$NON-NLS-1$ //$NON-NLS-2$
-			filter = CoherenceFilterUtil.createFilter(lhsString + " LIKE \'" + rhsString + "\'");		
-		}catch (TranslatorException t) {
-			exception = t;
-		}
-    }
-
-    
-    public void visit(In obj) {
-		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); //$NON-NLS-1$
-//		isNegated = ((In) criteria).isNegated();
-		try {
-			Expression lhs = ((In)obj).getLeftExpression();
-			String lhsString = getExpressionString(lhs);
-			
-			List<Expression> rhsList = ((In)obj).getRightExpressions();
-	
-			Class type = null;
-			List parms = new ArrayList(rhsList.size());
-	        Iterator iter = rhsList.iterator();
-	        while(iter.hasNext()) {
-	            Expression expr = (Expression) iter.next();
-	            type = addParmFromExpression(expr, parms);
-	            
-	        }
-	        
-	        filter = CoherenceFilterUtil.createInFilter(lhsString, parms, type);
-		}catch (TranslatorException t) {
-			exception = t;
-		}
-	        
-    }
-    
-    private Class addParmFromExpression(Expression expr, List parms ) {
-    	Class type = null;
-        if(expr instanceof Literal) {
-        	Long longparm = null;
-            Literal literal = (Literal) expr;
-            
-            parms.add(literal);
-            
-            type = literal.getType();
-  
-        } else {
-            this.exception = new TranslatorException("CoherenceVisitor.Unsupported_expression" + expr); //$NON-NLS-1$
-        }
-        
-        return type;
-         
-    }
-	/** 
-	 * Method to get name from the supplied Element
-	 * @param e the supplied Element
-	 * @return the name
-	 */
-    // GHH 20080326 - found that code to fall back on Name if NameInSource
-	// was null wasn't working properly, so replaced with tried and true
-	// code from another custom connector.
-	public String getNameFromElement(Column e) {
-		String attributeName = e.getNameInSource();
-		if (attributeName == null || attributeName.equals("")) { //$NON-NLS-1$
-			attributeName = e.getName();
-			// If name in source is not set, then fall back to the column name.
-		}
-		return attributeName;
-	}
-		
-    /**
-     * Helper method for getting runtime {@link org.teiid.connector.metadata.runtime.Element} from a
-     * {@link org.teiid.language.DerivedColumn}.
-     * @param symbol Input ISelectSymbol
-     * @return Element returned metadata runtime Element
-     */
-    private Column getElementFromSymbol(DerivedColumn symbol) {
-        ColumnReference expr = (ColumnReference) symbol.getExpression();
-        return expr.getMetadataObject();
-    }
-	    
-	// GHH 20080326 - found that code to fall back on Name if NameInSource
-	// was null wasn't working properly, so replaced with tried and true
-	// code from another custom connector.
-	private String getExpressionString(Expression e) throws TranslatorException {
-		String expressionName = null;
-		// GHH 20080326 - changed around the IElement handling here
-		// - the rest of this method is unchanged
-		if(e instanceof ColumnReference) {
-			Column mdIDElement = ((ColumnReference)e).getMetadataObject();
-			expressionName = mdIDElement.getNameInSource();
-			if(expressionName == null || expressionName.equals("")) {  //$NON-NLS-1$
-				expressionName = mdIDElement.getName();
-			}
-		} else if(e instanceof Literal) {
-//			try {
-//				if(((Literal)e).getType().equals(Class.forName(Timestamp.class.getName()))) {
-//					LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Found an expression that uses timestamp; converting to LDAP string format."); //$NON-NLS-1$
-//					Timestamp ts = (Timestamp)((Literal)e).getValue();
-//					Date dt = new Date(ts.getTime());
-//					//TODO: Fetch format if provided.
-//					SimpleDateFormat sdf = new SimpleDateFormat(LDAPConnectorConstants.ldapTimestampFormat);
-//					expressionName = sdf.format(dt);
-//					LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Timestamp to stsring is: " + expressionName); //$NON-NLS-1$
-//				}
-//				else {
-//					expressionName = ((Literal)e).getValue().toString();
-//				}
-				
-				expressionName = ((Literal)e).getValue().toString();
-//			} catch (ClassNotFoundException cce) {
-//	            final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.timestampClassNotFoundError"); //$NON-NLS-1$
-//				throw new TranslatorException(cce, msg); 
-//			}
-//				
-		} else {
-			if(e instanceof AggregateFunction) {
-				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IAggregate, but it is not supported. Check capabilities."); //$NON-NLS-1$
-			} else if(e instanceof Function) {
-				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IFunction, but it is not supported. Check capabilties."); //$NON-NLS-1$
-			} else if(e instanceof ScalarSubquery) {
-				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IScalarSubquery, but it is not supported. Check capabilties."); //$NON-NLS-1$
-			} else if (e instanceof SearchedCase) {
-				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received ISearchedCaseExpression, but it is not supported. Check capabilties."); //$NON-NLS-1$
-			}
-            final String msg = CoherencePlugin.Util.getString("CoherenceVisitory.unsupportedElementError" , e.toString()); //$NON-NLS-1$
-			throw new TranslatorException(msg); 
-		}
-		expressionName = escapeReservedChars(expressionName);
-		return expressionName;
-	}
-	
-	private String escapeReservedChars(String expr) {
-		StringBuffer sb = new StringBuffer();
-        for (int i = 0; i < expr.length(); i++) {
-            char curChar = expr.charAt(i);
-            switch (curChar) {
-                case '\\':
-                    sb.append("\\5c"); //$NON-NLS-1$
-                    break;
-                case '*':
-                    sb.append("\\2a"); //$NON-NLS-1$
-                    break;
-                case '(':
-                    sb.append("\\28"); //$NON-NLS-1$
-                    break;
-                case ')':
-                    sb.append("\\29"); //$NON-NLS-1$
-                    break;
-                case '\u0000': 
-                    sb.append("\\00"); //$NON-NLS-1$
-                    break;
-                default:
-                    sb.append(curChar);
-            }
-        }
-        return sb.toString();
-	}	
-	
-}

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/SourceCacheAdapter.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/SourceCacheAdapter.java	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/SourceCacheAdapter.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -35,27 +35,74 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.core.util.ReflectionHelper;
 import org.teiid.core.util.StringUtil;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.metadata.Column;
+import org.teiid.metadata.KeyRecord;
 import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.Schema;
 import org.teiid.metadata.Table;
 import org.teiid.translator.TranslatorException;
+import org.teiid.translator.coherence.visitor.CoherenceVisitor;
 
 
 public abstract class SourceCacheAdapter {
-    
-    protected MetadataFactory metadataFactory = null;
+  
+  protected MetadataFactory metadataFactory = null;
+
+	/*****************
+	 * Methods for Adding the source metadata
+	 *****************/
+	
+      protected Schema addSchema(String s) throws TranslatorException {
+    	  Schema sc = new Schema();
+    	  sc.setName(s);
+    	  sc.setPhysical(true);
+    	  metadataFactory.getMetadataStore().addSchema(sc);
+    	  return sc;
+    	  
+      }
+	  protected Table addTable(String t) throws TranslatorException {
+		  return metadataFactory.addTable(t); //$NON-NLS-1$
+	  }
+
+	  protected KeyRecord addPrimaryKey(String name, List<String> columnNames, Table table) throws TranslatorException {
+		  return metadataFactory.addPrimaryKey(name, columnNames, table); //$NON-NLS-1$
+	  }
+
+	  protected KeyRecord addForeignKey(String name, List<String> columnNames, Table pktable, Table table) throws TranslatorException {
+		  return metadataFactory.addForiegnKey(name, columnNames, pktable, table);
+	  }
+	  
+	  protected void addColumn(String columnName, String nameInSource, String dataType, Table t) throws TranslatorException {
+		  Column c = metadataFactory.addColumn(columnName, dataType, t); //$NON-NLS-1$
+		  c.setNameInSource(nameInSource);	  
+	  }
+	 
+	  /**
+	   * END of Methods for Adding source metadata
+	   */
  
     /**
      * Called so the implementor can defined its table/column metadata
      * Use the methods @see #addTable and @see #addColumn.
      */
-  abstract void addMetadata() throws TranslatorException;
+  public void addMetadata() throws TranslatorException {
+	  
+  }
   
   /**
+   * Called to request the class name for the specified <code>objectName</code>
+   * @param objectName is the name of the object for which the class name is being requested
+   * @return String class name for the specified objectName
+   * @throws TranslatorException
+   */
+//  public abstract String getMappedClass(String objectName) throws TranslatorException;
+  
+  /**
    * Called to translate the list of <code>objects</code> returned from the Coherence cache.
    * The implementor will use the <code>visitor</code> to obtain sql parsed information 
    * needed to understand the columns requested.  Then use the @see #retrieveValue method
@@ -168,8 +215,7 @@
 								// when a collection is found, need to find the value for the row
 								// in order to do that, need to pick where retrieve process left off
 								List<String> tokens = StringUtil.getTokens(n, ".");
-								final ParmHolder holder = ParmHolder.createParmHolder(visitor.getTableName(), tokens, attributeTypes[i]);
-								Object colvalue =  retrieveValue(holder, colt, collectionNodeDepth + 1);
+								Object colvalue = getValue(visitor.getTableName(), tokens, attributeTypes[i], colt, collectionNodeDepth + 1);
 								row.add(colvalue);
 								
 							} else {
@@ -214,15 +260,12 @@
     	addMetadata();
     }
 
-  protected Table addTable(String t) throws TranslatorException {
-	  return metadataFactory.addTable(t); //$NON-NLS-1$
+  public Object getValue(String tableName, List<String> nameTokens, Class type, Object cachedObject, int level ) throws TranslatorException {
+		final ParmHolder holder = ParmHolder.createParmHolder(tableName, nameTokens, type);
+		Object value =  retrieveValue(holder, cachedObject, level);
+		return value;
+
   }
-  
-  protected void addColumn(String columnName, String nameInSource, String dataType, Table t) throws TranslatorException {
-	  Column c = metadataFactory.addColumn(columnName, dataType, t); //$NON-NLS-1$
-	  c.setNameInSource(nameInSource);	  
-  }
- 
 
 		
 private Object retrieveValue(ParmHolder holder, Object cachedObject, int level) throws TranslatorException {
@@ -254,17 +297,20 @@
 		 
 		 final Object value = m.invoke(cachedObject, null);
 		 
-		 if (atTheBottom) {
-			 return value;
-		 }
-		 
 		 // if an array or collection, return, this will be processed after all objects are obtained
 		 // in order the number of rows can be created
+		 if (value == null) {
+			 return null;
+		 }
 		  if (value.getClass().isArray() || value instanceof Collection || value instanceof Map) {
 			  holder.setCollection(level);  
 //			  System.out.println("Found Collection: " + methodName);
 			  return value;
 		  }
+			 
+			 if (atTheBottom) {
+				 return value;
+			 }
 
 		  return retrieveValue(holder, value, ++level);
 
@@ -284,63 +330,85 @@
 	 }
   }
 
+  public Object createObjectFromMetadata(String metadataName) throws TranslatorException {
+//	  String mappedClass = getMappedClass(metadataName);
+	  return createObject(metadataName);
+	  
+  }
 
-  public static Object createObject(String objectClassName) throws TranslatorException {
+  private Object createObject(String objectClassName) throws TranslatorException {
 		try {
 			
-			Object classObj =  ReflectionHelper
+			return  ReflectionHelper
 					.create(objectClassName,
 							null, null);
-			return classObj;
 		} catch (Exception e1) {
 			throw new TranslatorException(e1);
 		}
 	  
   }
   
-  public static Object setValue(String tableName, String columnName, Object cachedObject, Object value, Class classtype) throws TranslatorException {
+  public Object setValue(String tableName, String columnName, Object cachedObject, Object value, Class classtype) throws TranslatorException {
 		LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Adding value to attribute: " + columnName); //$NON-NLS-1$
+		
 	 try {
 		 ArrayList argTypes = new ArrayList(1);
 		 argTypes.add(classtype);
 		 Method m = findBestMethod(cachedObject.getClass(), "set" + columnName, argTypes);
-		 Object newValue = getArg(m, value);
+		 
+		 Class[] setTypes = m.getParameterTypes();
+		 
+		 
+		 Object newValue = null;
+		 if (value instanceof Collection || value instanceof Map || value.getClass().isArray() ) {
+			 newValue = value;
+		 } else {
+			 newValue = DataTypeManager.transformValue(value, setTypes[0]);
+		 }
+	//	 Object newValue = getArg(m, value);
 			 m.invoke(cachedObject, new Object[] {newValue});
 		 	
 		 	LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Set value " + value); //$NON-NLS-1$
-		 return value;
+		 return newValue;
 	 } catch (InvocationTargetException x) {
+		 x.printStackTrace();
 		 Throwable cause = x.getCause();
 		 System.err.format("invocation of %s failed: %s%n",
 				 "set" + columnName, cause.getMessage());
 		 LogManager.logError(LogConstants.CTX_CONNECTOR, "Error calling set" + columnName + ":" + cause.getMessage());
 		 return null;
 	 } catch (Exception e) {
+		 e.printStackTrace();
 		 throw new TranslatorException(e.getMessage());
 	 }
 
 }  
   
-  private static Object getArg(Method m, int value) {
+
+  private  Object getArg(Method m, int value) {
 	  return Integer.valueOf(value);
   }
-  private static Object getArg(Method m, double value) {
+  private  Object getArg(Method m, double value) {
 	  return Double.valueOf(value);
   }
-  private static Object getArg(Method m, long value) {
+  private  Object getArg(Method m, long value) {
 	  return Long.valueOf(value);
   }
-  private static Object getArg(Method m, float value) {
+  private  Object getArg(Method m, float value) {
 	  return Float.valueOf(value);
   }
-  private static Object getArg(Method m, short value) {
+  private  Object getArg(Method m, short value) {
 	  return Short.valueOf(value);
   }
-  private static Object getArg(Method m, boolean value) {
+  private  Object getArg(Method m, boolean value) {
 	  return Boolean.valueOf(value);
   }
+  
+  private  Object getArg(Method m, Long value) {
+	  return value.longValue();
+  }
 
-  private static Object getArg(Method m, Object value) throws Exception {
+  private  Object getArg(Method m, Object value) throws Exception {
 	  return value;
   }
 
@@ -397,7 +465,7 @@
 //  }
   
   
-  private static Method findBestMethod(Class objectClass, String methodName, List argumentsClasses) throws SecurityException, NoSuchMethodException {
+  private  Method findBestMethod(Class objectClass, String methodName, List argumentsClasses) throws SecurityException, NoSuchMethodException {
       ReflectionHelper rh = new ReflectionHelper(objectClass);
       
       if (argumentsClasses == null) {
@@ -430,7 +498,7 @@
 		
 	}
 	
-	static ParmHolder createParmHolder(String tablename, List<String> parsedAttributeName,  Class type) {
+	static ParmHolder createParmHolder(String tablename, List<String> parsedAttributeName,  Class<?> type) {
 			
 		holder.tableName = tablename;
 		holder.nameNodes = parsedAttributeName;

Copied: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/CoherenceVisitor.java (from rev 3846, branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/CoherenceVisitor.java)
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/CoherenceVisitor.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/CoherenceVisitor.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -0,0 +1,353 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.translator.coherence.visitor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.teiid.language.AggregateFunction;
+import org.teiid.language.ColumnReference;
+import org.teiid.language.Comparison;
+import org.teiid.language.Comparison.Operator;
+import org.teiid.language.DerivedColumn;
+import org.teiid.language.Expression;
+import org.teiid.language.Function;
+import org.teiid.language.In;
+import org.teiid.language.Like;
+import org.teiid.language.Literal;
+import org.teiid.language.NamedTable;
+import org.teiid.language.ScalarSubquery;
+import org.teiid.language.SearchedCase;
+import org.teiid.language.Select;
+import org.teiid.language.TableReference;
+import org.teiid.language.visitor.HierarchyVisitor;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.resource.adapter.coherence.CoherenceFilterUtil;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.coherence.CoherencePlugin;
+
+import com.tangosol.util.Filter;
+
+/**
+ */
+public class CoherenceVisitor extends HierarchyVisitor {
+
+	private String tableName = null;
+	protected String[] attributeNames = null;
+	protected Class[] attributeTypes = null;
+	private RuntimeMetadata metadata;
+	private Filter filter = null;
+
+    private TranslatorException exception;
+
+    /**
+     * 
+     */
+    public CoherenceVisitor(RuntimeMetadata metadata) {
+        super();        
+        this.metadata = metadata;
+    }
+    
+    public Filter getFilter() {
+		return filter;
+
+    }
+ 
+    public String getTableName() {
+    	return tableName;
+    }
+    
+    public String[] getAttributeNames() {
+    	return attributeNames;
+    }
+    
+    public Class[] getAttributeTypes() {
+    	return attributeTypes;
+    }    
+    
+    public TranslatorException getException() {
+        return this.exception;
+    }
+    
+    public Filter createFilter(String criteria)  throws TranslatorException {
+        return CoherenceFilterUtil.createFilter(criteria);
+        
+    }
+
+    
+	public void visit(Select query) {
+		super.visit(query);
+		
+		Iterator<DerivedColumn> selectSymbolItr = query.getDerivedColumns().iterator();
+		attributeNames = new String[query.getDerivedColumns().size()];
+		attributeTypes = new Class[query.getDerivedColumns().size()];
+		
+		int i=0;
+		while(selectSymbolItr.hasNext()) {
+			Column e = getElementFromSymbol(selectSymbolItr.next());
+			String attributeName = this.getNameFromElement(e);
+			Class attributeClass = e.getJavaType();
+			
+			attributeNames[i] = attributeName;
+			attributeTypes[i] = attributeClass;
+
+			i++;
+		}
+
+		
+		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) {
+		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison criteria."); //$NON-NLS-1$
+		try {
+			Comparison.Operator op = ((Comparison) obj).getOperator();
+	       
+			Expression lhs = ((Comparison) obj).getLeftExpression();
+			Expression rhs = ((Comparison) obj).getRightExpression();
+	
+			String lhsString = getExpressionString(lhs);
+			String rhsString = getExpressionString(rhs);
+			if(lhsString == null || rhsString == null) {
+	            final String msg = CoherencePlugin.Util.getString("CoherenceVisitor.missingComparisonExpression"); //$NON-NLS-1$
+				exception = new TranslatorException(msg); 
+			}
+
+			if (rhs instanceof Literal || lhs instanceof Literal) {
+		        if(rhs instanceof Literal) {
+		            Literal literal = (Literal) rhs;
+		            addCompareCriteria(lhsString, literal.getValue(), op, literal.getType() );
+		            
+//		            filter = CoherenceFilterUtil.createCompareFilter(lhsString, literal.getValue(), op, literal.getType() );
+		            
+		        } else {
+		            Literal literal = (Literal) lhs;
+		            addCompareCriteria(rhsString, literal.getValue(), op, literal.getType() );
+//		            filter = CoherenceFilterUtil.createCompareFilter(rhsString, literal.getValue(), op, literal.getType() );
+		        	
+		        }
+			}
+		}catch (TranslatorException t) {
+			exception = t;
+		}
+    }
+    
+    public void addCompareCriteria(String columnname, Object value, Operator op, Class<?> type ) throws TranslatorException {
+        filter = CoherenceFilterUtil.createCompareFilter(columnname, value, op, type);
+    }
+    
+    public void visit(Like obj) {
+    	
+		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing LIKE criteria."); //$NON-NLS-1$
+//		isNegated = ((Like) criteria).isNegated();
+		// Convert LIKE to Equals, where any "%" symbol is replaced with "*".
+		try {
+			Comparison.Operator op = Operator.EQ;
+			Expression lhs = ((Like) obj).getLeftExpression();
+			Expression rhs = ((Like) obj).getRightExpression();
+		
+			String lhsString = getExpressionString(lhs);
+			String rhsString = getExpressionString(rhs);
+//			rhsString = rhsString.replace("%", "*"); //$NON-NLS-1$ //$NON-NLS-2$
+			filter = CoherenceFilterUtil.createFilter(lhsString + " LIKE \'" + rhsString + "\'");		
+		}catch (TranslatorException t) {
+			exception = t;
+		}
+    }
+
+    
+    public void visit(In obj) {
+		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); //$NON-NLS-1$
+//		isNegated = ((In) criteria).isNegated();
+		try {
+			Expression lhs = ((In)obj).getLeftExpression();
+			String lhsString = getExpressionString(lhs);
+			
+			List<Expression> rhsList = ((In)obj).getRightExpressions();
+	
+			Class type = null;
+			List parms = new ArrayList(rhsList.size());
+	        Iterator iter = rhsList.iterator();
+	        while(iter.hasNext()) {
+	            Expression expr = (Expression) iter.next();
+	            type = addParmFromExpression(expr, parms);
+	            
+	        }
+	        
+	        addInCriteria(lhsString, parms, type);
+//	        filter = CoherenceFilterUtil.createInFilter(lhsString, parms, type);
+		}catch (TranslatorException t) {
+			exception = t;
+		}
+	        
+    }
+    
+    public void addInCriteria(String columnname, List<Object> parms, Class<?> type ) throws TranslatorException {
+        filter = CoherenceFilterUtil.createInFilter(columnname, parms, type);
+    }
+    
+    private Class addParmFromExpression(Expression expr, List parms ) {
+    	Class type = null;
+        if(expr instanceof Literal) {
+        	Long longparm = null;
+            Literal literal = (Literal) expr;
+            
+            parms.add(literal);
+            
+            type = literal.getType();
+  
+        } else {
+            this.exception = new TranslatorException("CoherenceVisitor.Unsupported_expression" + expr); //$NON-NLS-1$
+        }
+        
+        return type;
+         
+    }
+	/** 
+	 * Method to get name from the supplied Element
+	 * @param e the supplied Element
+	 * @return the name
+	 */
+    // GHH 20080326 - found that code to fall back on Name if NameInSource
+	// was null wasn't working properly, so replaced with tried and true
+	// code from another custom connector.
+	public String getNameFromElement(Column e) {
+		String attributeName = e.getNameInSource();
+		if (attributeName == null || attributeName.equals("")) { //$NON-NLS-1$
+			attributeName = e.getName();
+			// If name in source is not set, then fall back to the column name.
+		}
+		return attributeName;
+	}
+
+	public String getNameFromTable(Table e) {
+		String tableName = e.getNameInSource();
+		if (tableName == null || tableName.equals("")) { //$NON-NLS-1$
+			tableName = e.getName();
+			// If name in source is not set, then fall back to the column name.
+		}
+		return tableName;
+	}
+
+    /**
+     * Helper method for getting runtime {@link org.teiid.connector.metadata.runtime.Element} from a
+     * {@link org.teiid.language.DerivedColumn}.
+     * @param symbol Input ISelectSymbol
+     * @return Element returned metadata runtime Element
+     */
+    private Column getElementFromSymbol(DerivedColumn symbol) {
+        ColumnReference expr = (ColumnReference) symbol.getExpression();
+        return expr.getMetadataObject();
+    }
+	    
+	// GHH 20080326 - found that code to fall back on Name if NameInSource
+	// was null wasn't working properly, so replaced with tried and true
+	// code from another custom connector.
+	private String getExpressionString(Expression e) throws TranslatorException {
+		String expressionName = null;
+		// GHH 20080326 - changed around the IElement handling here
+		// - the rest of this method is unchanged
+		if(e instanceof ColumnReference) {
+			Column mdIDElement = ((ColumnReference)e).getMetadataObject();
+			expressionName = mdIDElement.getNameInSource();
+			if(expressionName == null || expressionName.equals("")) {  //$NON-NLS-1$
+				expressionName = mdIDElement.getName();
+			}
+		} else if(e instanceof Literal) {
+//			try {
+//				if(((Literal)e).getType().equals(Class.forName(Timestamp.class.getName()))) {
+//					LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Found an expression that uses timestamp; converting to LDAP string format."); //$NON-NLS-1$
+//					Timestamp ts = (Timestamp)((Literal)e).getValue();
+//					Date dt = new Date(ts.getTime());
+//					//TODO: Fetch format if provided.
+//					SimpleDateFormat sdf = new SimpleDateFormat(LDAPConnectorConstants.ldapTimestampFormat);
+//					expressionName = sdf.format(dt);
+//					LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Timestamp to stsring is: " + expressionName); //$NON-NLS-1$
+//				}
+//				else {
+//					expressionName = ((Literal)e).getValue().toString();
+//				}
+				
+				expressionName = ((Literal)e).getValue().toString();
+//			} catch (ClassNotFoundException cce) {
+//	            final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.timestampClassNotFoundError"); //$NON-NLS-1$
+//				throw new TranslatorException(cce, msg); 
+//			}
+//				
+		} else {
+			if(e instanceof AggregateFunction) {
+				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IAggregate, but it is not supported. Check capabilities."); //$NON-NLS-1$
+			} else if(e instanceof Function) {
+				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IFunction, but it is not supported. Check capabilties."); //$NON-NLS-1$
+			} else if(e instanceof ScalarSubquery) {
+				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IScalarSubquery, but it is not supported. Check capabilties."); //$NON-NLS-1$
+			} else if (e instanceof SearchedCase) {
+				LogManager.logError(LogConstants.CTX_CONNECTOR, "Received ISearchedCaseExpression, but it is not supported. Check capabilties."); //$NON-NLS-1$
+			}
+            final String msg = CoherencePlugin.Util.getString("CoherenceVisitory.unsupportedElementError" , e.toString()); //$NON-NLS-1$
+			throw new TranslatorException(msg); 
+		}
+		expressionName = escapeReservedChars(expressionName);
+		return expressionName;
+	}
+	
+	private String escapeReservedChars(String expr) {
+		StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < expr.length(); i++) {
+            char curChar = expr.charAt(i);
+            switch (curChar) {
+                case '\\':
+                    sb.append("\\5c"); //$NON-NLS-1$
+                    break;
+                case '*':
+                    sb.append("\\2a"); //$NON-NLS-1$
+                    break;
+                case '(':
+                    sb.append("\\28"); //$NON-NLS-1$
+                    break;
+                case ')':
+                    sb.append("\\29"); //$NON-NLS-1$
+                    break;
+                case '\u0000': 
+                    sb.append("\\00"); //$NON-NLS-1$
+                    break;
+                default:
+                    sb.append(curChar);
+            }
+        }
+        return sb.toString();
+	}	
+	
+}

Added: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/DeleteVisitor.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/DeleteVisitor.java	                        (rev 0)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/java/org/teiid/translator/coherence/visitor/DeleteVisitor.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.coherence.visitor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.teiid.language.Comparison.Operator;
+import org.teiid.language.Delete;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.TranslatorException;
+
+
+public class DeleteVisitor extends CoherenceVisitor  {
+	private Collection deleteKeys = new ArrayList();
+	
+	public DeleteVisitor(RuntimeMetadata metadata) {
+		super(metadata);
+	}
+
+	@Override
+	public void visit(Delete delete) {
+		super.visit(delete);
+	}
+	
+	public Collection getKeys() {
+		return this.deleteKeys;
+	}
+	
+    public void addCompareCriteria(String columnname, Object value, Operator op, Class<?> type ) throws TranslatorException {
+    	deleteKeys.add(value);
+    }
+
+    public void addInCriteria(String columnname, List<Object> parms, Class<?> type ) throws TranslatorException {
+    	deleteKeys.addAll(parms);
+    }
+
+}

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/src/main/resources/org/teiid/translator/coherence/i18n.properties
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/main/resources/org/teiid/translator/coherence/i18n.properties	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/main/resources/org/teiid/translator/coherence/i18n.properties	2012-02-10 22:32:36 UTC (rev 3865)
@@ -22,4 +22,8 @@
 
 CoherenceVisitor.missingComparisonExpression=Missing either left or right expression in comparison
 
-CoherenceVisitory.unsupportedElementError=Unsupported element {0}
\ No newline at end of file
+CoherenceVisitory.unsupportedElementError=Unsupported element {0}
+
+CoherenceUpdateExecution.noobjectfound=No object found in cache for table {0}, column {1} and value {2}
+CoherenceUpdateExecution.noColumnMatchedForeignColumn=No column in the Insert statement matched the foreign key column {1} on table {0}
+CoherenceUpdateExecution.noPrimaryKeyDefinedOnTable=A primary key must be defined on table {0} in order to add to the cache
\ No newline at end of file

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TestCoherenceTranslator.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TestCoherenceTranslator.java	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TestCoherenceTranslator.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -22,54 +22,138 @@
 
 package org.teiid.translator.coherence;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.junit.Test;
 import org.teiid.cdk.api.ConnectorHost;
 import org.teiid.cdk.api.TranslationUtility;
 import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.util.UnitTestUtil;
 import org.teiid.metadata.Column;
+import org.teiid.metadata.ForeignKey;
+import org.teiid.metadata.KeyRecord;
+import org.teiid.metadata.KeyRecord.Type;
 import org.teiid.metadata.MetadataStore;
 import org.teiid.metadata.Schema;
 import org.teiid.metadata.Table;
+import org.teiid.query.mapping.relational.QueryNode;
 import org.teiid.query.metadata.QueryMetadataInterface;
 import org.teiid.query.unittest.RealMetadataFactory;
+import org.teiid.resource.adapter.coherence.CoherenceConnection;
 import org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory;
 
 
 public class TestCoherenceTranslator extends TestCase  {
 	
-	public static final String CACHE_NAME = "Trades";
 	public static final String OBJECT_TRANSLATOR = "org.teiid.translator.coherence.TradesCacheSource";
-
 	
 	public static QueryMetadataInterface metadata = null;
+
+	protected ConnectorHost host = null;
 	
-	public static ConnectorHost host = null;
-	
-	public static final int NUMLEGS = 10;
-	public static final int NUMTRADES = 3;
-
-	static {
-		new TradesCacheSource();		
+	@Override
+	protected void setUp() throws Exception {
+		// TODO Auto-generated method stub
+		super.setUp();
 		
-	}
-
-	private ConnectorHost setup() throws Exception {
+		new TradesCacheSource().addMetadata();
+		
 		CoherenceManagedConnectionFactory connFactory = new CoherenceManagedConnectionFactory();
-		connFactory.setCacheName(CACHE_NAME);
+		connFactory.setCacheName(TradesCacheSource.CACHE_NAME);
 		connFactory.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
-		
+		CoherenceConnection conn = (CoherenceConnection) connFactory.createConnectionFactory().getConnection();
+			
 		CoherenceExecutionFactory execFactory = new CoherenceExecutionFactory();
 			
-		ConnectorHost host = new ConnectorHost(execFactory, connFactory.createConnectionFactory().getConnection(), UnitTestUtil.getTestDataPath() + "/Trade.vdb");
-		return host;
+		host = new ConnectorHost(execFactory, conn, getTradeTranslationUtility());
+				///UnitTestUtil.getTestDataPath() + "/Coherence_Designer_Project/Trade.vdb");
 	}
+	
+	@Override
+	protected void tearDown() throws Exception {
+		// TODO Auto-generated method stub
+		super.tearDown();
+		
+		
+		host = null;
+	}
 
+	public void testInsertAndDelete() throws Exception {
+		StringBuilder tradeSQL = new StringBuilder();
+		
+					tradeSQL.append("INSERT INTO Trade_Update.Trade (tradeid, name) VALUES (");
+					tradeSQL.append(99);
+					tradeSQL.append(",");
+					tradeSQL.append(" 'TradeName ");
+					tradeSQL.append(99);
+					tradeSQL.append("')");
+												
+		host.executeCommand(tradeSQL.toString());
+		
+		List actualResults = host.executeCommand("select * From Trade_Update.Trade where Trade_Update.Trade.TradeID = 99");
+		//tradeid, name
+        // Compare actual and expected results
+		// should get back the 10 legs for each trade (3) totaling 30
+        assertEquals("Did not get expected number of rows", 1, actualResults.size()); //$NON-NLS-1$
+        
+        
+//		tradeSQL = new StringBuilder();
+//		
+//		tradeSQL.append("INSERT INTO Trade_Update.Leg (tradeid, LegID, name, Notational) VALUES (");
+//		tradeSQL.append(99);
+//		tradeSQL.append(",");
+//		tradeSQL.append(1);
+//		tradeSQL.append(",");		
+//		tradeSQL.append(" 'Leg ");
+//		tradeSQL.append(1);
+//		tradeSQL.append("',");		
+//		tradeSQL.append(1.24);
+//		tradeSQL.append(")");
+//									
+//		System.out.println(tradeSQL.toString());
+//		host.executeCommand(tradeSQL.toString());
+//
+//		tradeSQL = new StringBuilder();
+//		
+//		tradeSQL.append("INSERT INTO Trade_Update.Leg (tradeid, LegID, name, Notational) VALUES (");
+//		tradeSQL.append(99);
+//		tradeSQL.append(",");
+//		tradeSQL.append(2);
+//		tradeSQL.append(",");		
+//		tradeSQL.append(" 'Leg ");
+//		tradeSQL.append(2);
+//		tradeSQL.append("',");		
+//		tradeSQL.append(2.48);		
+//		tradeSQL.append(")");
+//									
+//		System.out.println(tradeSQL.toString());
+//		host.executeCommand(tradeSQL.toString());
+		
+		
+		
+//		actualResults = host.executeCommand(
+//	      		"SELECT Trade_Update.Trade.TradeID, Trade_Update.Trade.Name, Trade_Update.Leg.LegID, Trade_Update.Leg.Notational, Trade_Update.Leg.Name AS LegName " +
+//	        	" FROM Trade_Update.Trade, Trade_Update.Leg " +
+//	        	 "WHERE	Trade_Update.Trade.TradeID = Trade_Update.Leg.TradeID and Trade_Update.Trade.TradeID = 99");
+//
+//	     assertEquals("Did not get expected number of rows", 2, actualResults.size()); //$NON-NLS-1$
+        
+ 
+		actualResults = host.executeCommand("DELETE FROM Trade_Update.Trade Where Trade_Update.Trade.TradeID = 99");
+		
+		actualResults = host.executeCommand("select * From Trade_Update.Trade where Trade_Update.Trade.TradeID = 99");
+		//tradeid, name
+        // Compare actual and expected results
+		// should get back the 10 legs for each trade (3) totaling 30
+        assertEquals("Did not get expected number of rows", 0, actualResults.size()); //$NON-NLS-1$
+		
+     
+        
+             
+	}	
+
 	/**
 	 * This will instantiate the {@link CoherenceManagedConnectionFactory} and
 	 * obtain a connection to
@@ -78,9 +162,16 @@
 	 */
 	public void testGet1TradeWith10Legs() throws Exception {
 			
-		ConnectorHost host = setup();
+		List<List> actualResults = host.executeCommand(
+	      		"SELECT Trade_Update.Trade.TradeID, Trade_Update.Trade.Name, Trade_Update.Leg.LegID, Trade_Update.Leg.Notational, Trade_Update.Leg.Name AS LegName " +
+	        	" FROM Trade_Update.Trade, Trade_Update.Leg " +
+	        	 "WHERE	Trade_Update.Trade.TradeID = Trade_Update.Leg.TradeID ");
 		
-		List<List> actualResults = host.executeCommand("select tradeid, name, LegId, notational From Trade where tradeid = 1");
+	    //    		"SELECT * FROM Trade.Trad " +
+	      //  			" WHERE Trade.Trade.TradeID = Trade.Trade.TradeID");
+	  
+				
+		//"select tradeid, name, LegId, notational From Trade_View.Trades where tradeid = 1");
 		
 		for (Iterator it=actualResults.iterator(); it.hasNext();) {
 			List row = (List) it.next();
@@ -94,16 +185,14 @@
 		
         // Compare actual and expected results
 		// should get back the 10 legs associated with the trade
-        assertEquals("Did not get expected number of rows", 10, actualResults.size()); //$NON-NLS-1$
+        assertEquals("Did not get expected number of rows", 30, actualResults.size()); //$NON-NLS-1$
              
 	}
 
 	public void testGetAllTrades() throws Exception {
 		
-		ConnectorHost host = setup();
-		
-		List actualResults = host.executeCommand("select tradeid, name From Trade");
-		
+		List actualResults = host.executeCommand("select * From Trade_Update.Trade");
+		//tradeid, name
         // Compare actual and expected results
 		// should get back the 10 legs for each trade (3) totaling 30
         assertEquals("Did not get expected number of rows", 3, actualResults.size()); //$NON-NLS-1$
@@ -111,88 +200,50 @@
 	}	
 	
 	public void testTradesAndLegsWhereTradeLessThanGreatThan() throws Exception {
+		
+		String prefix = "SELECT Trade_Update.Trade.TradeID, Trade_Update.Trade.Name, Trade_Update.Leg.LegID, Trade_Update.Leg.Notational, Trade_Update.Leg.Name AS LegName " +
+    	" FROM Trade_Update.Trade, Trade_Update.Leg " +
+   	 "WHERE	Trade_Update.Trade.TradeID = Trade_Update.Leg.TradeID and ";
 
+		List actualResults = host.executeCommand(prefix + "Trade_Update.Trade.TradeID > 2");
 		
-		ConnectorHost host = setup();
-		
-		List actualResults = host.executeCommand("select tradeid, legid, notational From Trade where tradeid > 2");
-		
         assertEquals("Did not get expected number of rows", 10, actualResults.size()); //$NON-NLS-1$
         
-		actualResults = host.executeCommand("select tradeid, legid, notational From Trade where tradeid < 3");
+		actualResults = host.executeCommand(prefix + "Trade_Update.Trade.TradeID < 3");
 		
         assertEquals("Did not get expected number of rows", 20, actualResults.size()); //$NON-NLS-1$
 
-		actualResults = host.executeCommand("select tradeid, legid, notational From Trade where tradeid <= 3");
+		actualResults = host.executeCommand(prefix + "Trade_Update.Trade.TradeID <= 3");
 		
         assertEquals("Did not get expected number of rows", 30, actualResults.size()); //$NON-NLS-1$
         
-        actualResults = host.executeCommand("select tradeid, legid, notational From Trade where tradeid >= 1");
+        actualResults = host.executeCommand(prefix + "Trade_Update.Trade.TradeID >= 1");
 		
         assertEquals("Did not get expected number of rows", 30, actualResults.size()); //$NON-NLS-1$
         
-		actualResults = host.executeCommand("select tradeid, legid, notational From Trade where tradeid < 1");
+		actualResults = host.executeCommand(prefix + "Trade_Update.Trade.TradeID < 1");
 		
         assertEquals("Did not get expected number of rows", 0, actualResults.size()); //$NON-NLS-1$
               
            
 	}	
 	
-	/**
-	 * This is not supported out-of-the-box in Coherence, but can be developed
-	 * @throws Exception
-	 */
-//	public void testTradesAndLegsWhereLegLessThanGreatThan() throws Exception {
-//
-//		CoherenceManagedConnectionFactory connFactory = new CoherenceManagedConnectionFactory();
-//		connFactory.setCacheName(CACHE_NAME);
-//		connFactory.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
-//
-//		CoherenceExecutionFactory execFactory = new CoherenceExecutionFactory();
-//			
-//		ConnectorHost host = new ConnectorHost(execFactory, connFactory.createConnectionFactory().getConnection(), getTradeTranslationUtility());
-//		
-//		List actualResults = host.executeCommand("select tradeid, legid, notational From Trade where legid > 2");
-//		
-//        assertEquals("Did not get expected number of rows", 10, actualResults.size()); //$NON-NLS-1$
-//        
-//		actualResults = host.executeCommand("select tradeid, legid, notational From Trade where legid < 3");
-//		
-//        assertEquals("Did not get expected number of rows", 20, actualResults.size()); //$NON-NLS-1$
-//
-//		actualResults = host.executeCommand("select tradeid, legid, notational From Trade where legid <= 3");
-//		
-//        assertEquals("Did not get expected number of rows", 30, actualResults.size()); //$NON-NLS-1$
-//        
-//        actualResults = host.executeCommand("select tradeid, legid, notational From Trade where legid >= 1");
-//		
-//        assertEquals("Did not get expected number of rows", 30, actualResults.size()); //$NON-NLS-1$
-//        
-//		actualResults = host.executeCommand("select tradeid, legid, notational From Trade where legid < 1");
-//		
-//        assertEquals("Did not get expected number of rows", 0, actualResults.size()); //$NON-NLS-1$
-//              
-//           
-//	}	
 	
 
 	public void testLikeTradesWithLegs() throws Exception {
 
-		CoherenceManagedConnectionFactory connFactory = new CoherenceManagedConnectionFactory();
-		connFactory.setCacheName(CACHE_NAME);
-		connFactory.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
+		String prefix = "SELECT Trade_Update.Trade.TradeID, Trade_Update.Trade.Name, Trade_Update.Leg.LegID, Trade_Update.Leg.Notational, Trade_Update.Leg.Name AS LegName " +
+    	" FROM Trade_Update.Trade, Trade_Update.Leg " +
+   	 "WHERE	Trade_Update.Trade.TradeID = Trade_Update.Leg.TradeID and ";
 
-		CoherenceExecutionFactory execFactory = new CoherenceExecutionFactory();
-			
-		ConnectorHost host = new ConnectorHost(execFactory, connFactory.createConnectionFactory().getConnection(),getTradeTranslationUtility());
+	
+		List actualResults = host.executeCommand(prefix + " Trade_Update.Trade.Name like 'Trade%' ");
 		
-		List actualResults = host.executeCommand("select tradeid, name, legid, notational From Trade where Name like 'Trade%' ");
-		
         // Compare actual and expected results
 		// should get back the 10 legs for each trade (3) totaling 30
         assertEquals("Did not get expected number of rows", 30, actualResults.size()); //$NON-NLS-1$
         
-        actualResults = host.executeCommand("select tradeid, legid, notational From Trade where Name like '%2%' ");
+        actualResults = host.executeCommand(prefix + " Trade_Update.Trade.Name like '%2%' ");
 		
         // Compare actual and expected results
 		// should get back the 10 legs for each trade (3) totaling 30
@@ -205,43 +256,94 @@
     
 	public TranslationUtility getTradeTranslationUtility() {
 		MetadataStore metadataStore = new MetadataStore();
-        // Create models
-        Schema trading = RealMetadataFactory.createPhysicalModel("CoherenceModel", metadataStore); //$NON-NLS-1$
+        // Create TRADE
+        Schema trading = RealMetadataFactory.createPhysicalModel("Trade_Update", metadataStore); //$NON-NLS-1$
         
         // Create physical groups
-        Table quotes = RealMetadataFactory.createPhysicalGroup("TRADE", trading); //$NON-NLS-1$
+        Table trade = RealMetadataFactory.createPhysicalGroup("TRADE", trading); //$NON-NLS-1$
+        trade.setNameInSource("org.teiid.translator.coherence.Trade");
                 
         // Create physical elements
         String[] elemNames = new String[] {
-                "NAME", "TRADEID", "LEGID", "NOTATIONAL", "LEGNAME"  //$NON-NLS-1$ //$NON-NLS-2$
+                "NAME", "TRADEID"  //$NON-NLS-1$ //$NON-NLS-2$
         };
         String[] elemTypes = new String[] {  
         		DataTypeManager.DefaultDataTypes.STRING,
-                DataTypeManager.DefaultDataTypes.LONG, 
-                DataTypeManager.DefaultDataTypes.LONG,
-                DataTypeManager.DefaultDataTypes.DOUBLE,
-        		DataTypeManager.DefaultDataTypes.STRING
+                DataTypeManager.DefaultDataTypes.LONG
         };
         
-        List<Column> cols = RealMetadataFactory.createElements(quotes, elemNames, elemTypes);
+        List<Column> cols = RealMetadataFactory.createElements(trade, elemNames, elemTypes);
         
         // Set name in source on each column
         String[] nameInSource = new String[] {
         		"Name",
-            	"TradeId", 
-                "Legs.LegId",           
-                "Legs.Notational",
-                "Legs.Name"
+            	"TradeId"
         };
         for(int i=0; i<nameInSource.length; i++) {
             cols.get(i).setNameInSource(nameInSource[i]);
         }
+        List<Column> keys = new ArrayList(1);
+        keys.add(cols.get(1));
         
+        KeyRecord trade_pk = RealMetadataFactory.createKey(Type.Primary, "TradeID_PK", trade, keys);
+        
+        // LEG
+        Table leg = RealMetadataFactory.createPhysicalGroup("LEG", trading); //$NON-NLS-1$
+        leg.setNameInSource("org.teiid.translator.coherence.Leg");
+        
+        // Create physical elements
+        String[] legNames = new String[] {
+                "LEGID", "NOTATIONAL", "NAME", "TRADEID"  //$NON-NLS-1$ //$NON-NLS-2$
+        };
+        String[] legTypes = new String[] {  
+                DataTypeManager.DefaultDataTypes.LONG,
+                DataTypeManager.DefaultDataTypes.DOUBLE,
+        		DataTypeManager.DefaultDataTypes.STRING,
+                DataTypeManager.DefaultDataTypes.LONG
+                       };
+        
+        List<Column> legcols = RealMetadataFactory.createElements(leg, legNames, legTypes);
+        
+        // Set name in source on each column
+        String[] legnameInSource = new String[] {
+                "Legs.LegId",           
+                "Legs.Notational",
+                "Legs.Name",
+                "TradeID"
+        };
+        for(int i=0; i<legnameInSource.length; i++) {
+            legcols.get(i).setNameInSource(legnameInSource[i]);
+        }
+        
+        List<Column> legkeys = new ArrayList(1);
+        keys.add(legcols.get(0));
+        
+        RealMetadataFactory.createKey(Type.Primary, "Leg_ID_PK", leg, legkeys);
+        
+        List<Column> foreignkey = new ArrayList(1);
+        foreignkey.add(legcols.get(3));
+        
+        ForeignKey fk = RealMetadataFactory.createForeignKey("TRADE_FK", leg, foreignkey, trade_pk);
+        fk.setNameInSource("Legs");
+        fk.setParent(trade);
+ 
+       
         // Set column-specific properties
  //       cols.get(0).setSelectable(false);
  //       cols.get(0).setSearchType(SearchType.Unsearchable);
         
-		return new TranslationUtility(RealMetadataFactory.createTransformationMetadata(metadataStore, "trading"));
+        Schema tradeview = RealMetadataFactory.createVirtualModel("Trade_View", metadataStore);
+        
+        QueryNode qn = new QueryNode(
+        		"SELECT Trade_Update.Trade.TradeID, Trade_Update.Trade.Name, Trade_Update.Leg.LegID, Trade_Update.Leg.Notational, Trade_Update.Leg.Name AS LegName " +
+        	" FROM Trade_Update.Trade, Trade_Update.Leg " +
+        	 "WHERE	Trade_Update.Trade.TradeID = Trade_Update.Leg.TradeID " +    		
+        		"SELECT * FROM Trade.Trad " +
+        			" WHERE Trade.Trade.TradeID = Trade.Trade.TradeID");
+        
+        Table trades = RealMetadataFactory.createVirtualGroup("Trades", tradeview, qn);
+        
+  		return new TranslationUtility(RealMetadataFactory.createTransformationMetadata(metadataStore, "Trade"));
 	}
     
 }

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TradesCacheSource.java
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TradesCacheSource.java	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/src/test/java/org/teiid/translator/coherence/TradesCacheSource.java	2012-02-10 22:32:36 UTC (rev 3865)
@@ -4,13 +4,12 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.teiid.core.types.DataTypeManager;
-import org.teiid.metadata.Table;
 import org.teiid.translator.TranslatorException;
 
 import com.tangosol.net.CacheFactory;
 import com.tangosol.net.NamedCache;
 
+
 /**
  * Sample implementation of the SouceCacheAdapter that will
  * translate the Trade related objects to the row/columns that
@@ -21,66 +20,65 @@
  */
 public class TradesCacheSource extends SourceCacheAdapter {
 	public static final String CACHE_NAME = "Trades";
+
+	
 	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
 	 */
-	public static void loadCoherence() throws Exception {
+	private static void loadCoherence() throws Exception {
 		NamedCache tradesCache = CacheFactory.getCache(CACHE_NAME);
-
-		// populate the cache
-		Map legsMap = new HashMap();
+		TradesCacheSource translator = new TradesCacheSource();
 		
-		Object trade = createObject("org.teiid.translator.coherence.Trade");
 		for (int i = 1; i <= NUMTRADES; i++) {
 
+			Trade trade = (Trade) translator.createObjectFromMetadata("org.teiid.translator.coherence.Trade");
+//			execFactory.getCacheTranslator().createObject("org.teiid.translator.coherence.Trade");
+			
+			Map legsMap = new HashMap();
 			for (int j = 1; j <= NUMLEGS; j++) {
-				Object leg = createObject("org.teiid.translator.coherence.Leg");
+	
+				Object leg = translator.createObjectFromMetadata("org.teiid.translator.coherence.Leg");
+					//createObject("org.teiid.translator.coherence.Leg");
 					//new Leg();
 				if (leg == null) {
 					throw new Exception("Unable to create leg");
 				}
-				setValue("Trade", "LegId", leg, j, long.class);
-				setValue("Trade", "Notational", leg, j, double.class);
-				setValue("Trade", "Name", leg, "LegName " + j, String.class);
+				translator.setValue("Trade", "LegId", leg, j, long.class);
+				translator.setValue("Trade", "Notational", leg, j, double.class);
+				translator.setValue("Trade", "Name", leg, "LegName " + j, String.class);
 				
 				legsMap.put(j, leg);
 			}
 			
-			setValue("Trade", "TradeId", trade, i, long.class);
-			setValue("Trade", "Name", trade, "TradeName " + i, String.class);
-			setValue("Trade", "Legs", trade, legsMap, Map.class);
+			translator.setValue("Trade", "TradeId", trade, i, long.class);
+			translator.setValue("Trade", "Name", trade, "TradeName " + i, String.class);
+			translator.setValue("Trade", "Legs", trade, legsMap, Map.class);
 			
 			tradesCache.put(i, trade);
 		}
 
-		System.out.println("Loaded Coherence");
 
-	}	
-	
+	}
+
+	@Override
 	public void addMetadata() throws TranslatorException {
+		// TODO Auto-generated method stub
+		try {
+			System.out.println("Loading Coherence");
+			loadCoherence();
+			System.out.println("Loaded Coherence");
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 		
-		Table t = addTable("Trade");
-		addColumn("Name", "Name", DataTypeManager.DefaultDataTypes.STRING, t); //$NON-NLS-1$
-		addColumn("TradeId", "TradeId", DataTypeManager.DefaultDataTypes.LONG, t); //$NON-NLS-1$
-		addColumn("LegId", "Legs.LegId", DataTypeManager.DefaultDataTypes.LONG, t); //$NON-NLS-1$
-		addColumn("Notational", "Legs.Notational", DataTypeManager.DefaultDataTypes.DOUBLE, t); //$NON-NLS-1$
-		addColumn("LegName", "Legs.Name", DataTypeManager.DefaultDataTypes.STRING, t); //$NON-NLS-1$
-						
 	}
-	
+
 }

Deleted: branches/7.7.x/connectors/sandbox/translator-coherence/src/test/resources/Trade.vdb
===================================================================
(Binary files differ)

Modified: branches/7.7.x/connectors/sandbox/translator-coherence/usage-guidelines.txt
===================================================================
--- branches/7.7.x/connectors/sandbox/translator-coherence/usage-guidelines.txt	2012-02-10 22:28:36 UTC (rev 3864)
+++ branches/7.7.x/connectors/sandbox/translator-coherence/usage-guidelines.txt	2012-02-10 22:32:36 UTC (rev 3865)
@@ -27,8 +27,14 @@
 	
 2.	The Coherence Cache Name will be set on the Coherence Connector, see it for configuration.
 
+-	Top level object must have a primary key defined for the attribute that's the key to finding the object in the cache
 
-
+3.  Model a container object (collection, array, map) as another table.
+	-   on the child table, add the primary key column on the parent table to the child table (column must not be updatable)
+	-	a foreign key must be defined, using the primary key on parent and the parent column added to the child (in above step),
+		the nameInSource for the foreign key is the name of the method (excluding get/set prefix)
+	
+	
 ------------
 Limitations
 ------------



More information about the teiid-commits mailing list