[jboss-svn-commits] JBL Code SVN: r29435 - in labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src: main/java/uk/ac/ncl/sdia/a8905943/entitymanager and 7 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 22 13:10:37 EDT 2009


Author: whitingjr
Date: 2009-09-22 13:10:36 -0400 (Tue, 22 Sep 2009)
New Revision: 29435

Added:
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/Action.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/AddAction.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/RemoveAction.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/ReplaceAction.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/NoOpFilter.java
Modified:
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/aspects/STMWriteAspect.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/AbstractFieldParameter.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/RepeatableReadIsolationImpl.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/FieldWriteParameter.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/IdentityFieldWriteParameter.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/xpath/extension/NotInExtensionFunction.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/TestUnitModelReplicatedMemory.java
Log:
Added refactoring of update mechanism.

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/aspects/STMWriteAspect.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/aspects/STMWriteAspect.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/aspects/STMWriteAspect.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -12,6 +12,7 @@
 import uk.ac.ncl.sdia.a8905943.stm.STM;
 import uk.ac.ncl.sdia.a8905943.stm.annotation.InjectedSTM;
 import uk.ac.ncl.sdia.a8905943.stm.field.FieldWriteParameter;
+import uk.ac.ncl.sdia.a8905943.stm.field.ReplaceAction;
 
 public class STMWriteAspect extends AbstractSTMAspect
 {
@@ -36,9 +37,7 @@
       {
          logger.debug("stm field has an object and calling method on stm");
          logger.trace("number of arguments ["+invocation.getArguments().length+"]");
-         FieldWriteParameter write = new FieldWriteParameter(getHandle(invocation, "set"), invocation.getArguments()[0]);
-//         write.setHandle(getHandle(invocation, "set"));
-//         write.setNewObject(invocation.getArguments()[0]); // this ain't pretty;
+         FieldWriteParameter write = new FieldWriteParameter(getHandle(invocation, "set"), invocation.getArguments()[0], null);
          returnValue = this.stm.write(  write );
       }
       else

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -11,16 +11,21 @@
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
+import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import javax.persistence.spi.PersistenceUnitTransactionType;
 
+import org.apache.commons.jxpath.ClassFunctions;
 import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.jboss.resource.adapter.jdbc.WrappedConnection;
 
@@ -30,8 +35,13 @@
 import uk.ac.ncl.sdia.a8905943.handle.exception.FieldNotFoundException;
 import uk.ac.ncl.sdia.a8905943.persistence.jdbc.STMConnection;
 import uk.ac.ncl.sdia.a8905943.stm.activation.STMDisabled;
+import uk.ac.ncl.sdia.a8905943.stm.field.AddAction;
 import uk.ac.ncl.sdia.a8905943.stm.field.IdentityFieldWriteParameter;
+import uk.ac.ncl.sdia.a8905943.stm.field.RemoveAction;
 import uk.ac.ncl.sdia.a8905943.stm.query.STMQueryImpl;
+import uk.ac.ncl.sdia.a8905943.stm.query.filter.Filter;
+import uk.ac.ncl.sdia.a8905943.stm.query.filter.NoOpFilter;
+import uk.ac.ncl.sdia.a8905943.stm.query.xpath.extension.NotInExtensionFunction;
 
 
 final class STMEntityManagerImpl implements EntityManager
@@ -189,6 +199,22 @@
       }
       return returnValue;
    }
+   private Query createQuery( String qlString, Filter filter)
+      throws IllegalArgumentException
+   {
+      detectectClosedConnection();
+      Query returnValue = null;
+      if (null != qlString && null != filter)
+      {
+         returnValue = new STMQueryImpl(this.xpathContext, qlString, filter);
+      }
+      else
+      {
+         throw new IllegalArgumentException(
+               "The query string or filter provided is null.");
+      }
+      return returnValue;
+   }
 
    @SuppressWarnings("unchecked")
    @Override
@@ -199,6 +225,7 @@
     * The entity class is annotated with the STMEntity annotation.
     * This method does not hit the STM system and only uses reflection to create
     * an instance of the entity.
+    * Returns the entity or null if not found.
     */
    @STMDisabled
    public <T> T find(Class<T> entityClass, Object primaryKey)
@@ -210,24 +237,27 @@
          logger.debug("STMEntityManagerImpl.find called.");
       }
 
-      detectectClosedConnection();
-
       FieldUtils fieldUtils = new FieldUtils();
       try
       {
          Field idField = fieldUtils.findIdField(entityClass);
          StringBuffer queryStatement = new StringBuffer();
-
+         /* Use custom function to filter the returned entities. The function is 
+          * used here because the EntityManager is manually building the query
+          * expression. */
          queryStatement.append("model/").append(entityClass.getName()).append(
                "[").append(idField.getName());
-         queryStatement.append("=$identityValue]");
-         Query query = this.createQuery(queryStatement.toString());
+         queryStatement.append("=$identityValue and stmf:notin(").append(idField.getName()).append(")]");
+         this.xpathContext.setFunctions(new ClassFunctions(NotInExtensionFunction.class, "stmf"));
+         Query query = this.createQuery(queryStatement.toString(), new NoOpFilter());
          query.setParameter("identityValue", primaryKey);
+         query.setParameter("exclusionList", getSTMConnection().getSTM().getDeletedEntities(entityClass));
          if (logger.isTraceEnabled())
          {
             logger.trace("Executing query [" + queryStatement.toString()
                   + "] with primary key value [" + primaryKey + "].");
          }
+         detectectClosedConnection();
          returnValue = (T) query.getSingleResult();
       }
       catch (FieldNotFoundException fnfe)
@@ -235,7 +265,16 @@
          logger.error("Identity field not found when finding entity.", fnfe);
          throw new IllegalArgumentException(fnfe.getMessage());
       }
-
+      catch (NoResultException nre)
+      {// catch this exception and return null as expeced by the interface spec
+         logger.warn("The entity with id["+primaryKey+"] was not found", nre);
+      }
+      finally
+      {// undeclare the variable set to avoid affecting other queries
+         this.xpathContext.getVariables().undeclareVariable("exclusionList");
+         this.xpathContext.getVariables().undeclareVariable("identityValue");
+      }
+      detectectClosedConnection();
       return returnValue;
    }
 
@@ -334,6 +373,48 @@
          {
             throw new EntityExistsException("Attempt to persist an entity which already exists in the system with unique identity.");
          }
+         else
+         {
+            boolean alreadyDeleted = false;
+            List<String> ids = Arrays.asList( StringUtils.split(getSTMConnection().getSTM().getDeletedEntities(entity.getClass()), ","));
+            // detect if this entity has been removed within the same transaction, it will be stored in the deleted history
+            for (String entityId : ids)
+            {
+               if (StringUtils.equals(entityId , id.toString()))
+               {
+                  alreadyDeleted = true;
+                  break;
+               }
+            }
+            if (alreadyDeleted)
+            {// reinstate the entity back into the system
+               for (Method method :  fieldUtils.retrieveTransactionalSetterMethods(entity.getClass()))
+               {
+                  //TODO:jrw consider what to do here, depends on remove functionality. Are fields left hanging around and cleaned up when the transaction commits ? 
+                  /*try
+                  {
+                     method.invoke(entity, nullref);
+                  }
+                  catch (InvocationTargetException ite)
+                  {
+                     logger.error("Error occurred when invoking each write method on entity.", ite);
+                     throw new RuntimeException("Problem occurred invoking method to remove it's contents. Potential cleanup operation required.");
+                  }
+                  catch (IllegalAccessException iae)
+                  {
+                     logger.error("Error occurred when invoking each write method on entity.", iae);
+                     throw new RuntimeException("Problem occured accessing method to remove the field from field store. Potential cleanup operation required.");
+                  }*/
+                  long fieldStoreHandle = new HandleUtils().getHandle(entity.getClass(), id, identityField.getName());
+                  IdentityFieldWriteParameter write = new IdentityFieldWriteParameter(fieldStoreHandle, id, id, entity.getClass(), new AddAction());
+                  this.getSTMConnection().getSTM().write(write);
+               }
+            }
+            else
+            {// add a new entity
+               
+            }
+         }
          // TODO: jrw, think about what has been already persisted considering an entity is directly "wired" into the persistence system.
       }
       catch (FieldNotFoundException fnfe)
@@ -354,10 +435,10 @@
    public void remove(Object entity)
    {
       detectectClosedConnection();
-      //TODO: jrw: complete method, find all the setter methods of this entity. loop through and set each to null. Do not notify the model store leave this till committment.
       /* Nullify all the entity fields. identity is excluded */
       Object nullref =null;
       FieldUtils fieldUtils = new FieldUtils();
+      /*
       for (Method method :  fieldUtils.retrieveTransactionalSetterMethods(entity.getClass()))
       {
          try
@@ -375,13 +456,14 @@
             throw new RuntimeException("Problem occured accessing method to remove the field from field store. Potential cleanup operation required.");
          }
       }
+      */
       try
-      {/* Now nullify the identity field */
+      {// Now nullify the identity field 
          Field identityField = fieldUtils.findIdField(entity.getClass());
          Long identity = fieldUtils.getValue(identityField, entity);
          long fieldStoreHandle = new HandleUtils().getHandle(entity.getClass(), identity, identityField.getName());
          
-         IdentityFieldWriteParameter write = new IdentityFieldWriteParameter(fieldStoreHandle, nullref, identity, entity.getClass());
+         IdentityFieldWriteParameter write = new IdentityFieldWriteParameter(fieldStoreHandle, nullref, identity, entity.getClass(), new RemoveAction());
          this.getSTMConnection().getSTM().write(write);
       }
       catch (FieldNotFoundException fnfe)

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/AbstractFieldParameter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/AbstractFieldParameter.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/AbstractFieldParameter.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -82,4 +82,7 @@
    {
       this.isTransactional = isTransactional;
    }
+   public void processIdentityField()
+   {// no operation
+   }
 }
\ No newline at end of file

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/RepeatableReadIsolationImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/RepeatableReadIsolationImpl.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/isolation/RepeatableReadIsolationImpl.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -5,9 +5,11 @@
 
 import org.apache.log4j.Logger;
 
+import uk.ac.ncl.sdia.a8905943.stm.field.AddAction;
 import uk.ac.ncl.sdia.a8905943.stm.field.FieldReadParameter;
 import uk.ac.ncl.sdia.a8905943.stm.field.FieldWriteParameter;
 import uk.ac.ncl.sdia.a8905943.stm.field.IdentityFieldWriteParameter;
+import uk.ac.ncl.sdia.a8905943.stm.field.ReplaceAction;
 import uk.ac.ncl.sdia.a8905943.stm.object.TransactedObjectReference;
 
 /**
@@ -73,7 +75,20 @@
    {
       Boolean returnValue = null;
       TransactedObjectReference fieldReference = null;
-      if (fieldWrite.getWrites().containsKey(fieldWrite.getHandle()))
+      if (null == fieldWrite.getAction())
+      {// the annotation could not determine if data existed already
+         if (fieldWrite.getWrites().containsKey(fieldWrite.getHandle()))
+         {
+            fieldWrite.setAction(new ReplaceAction());
+         }
+         else
+         {
+            fieldWrite.setAction(new AddAction());
+         }
+      }
+      fieldWrite.getAction().execute(fieldWrite);
+      
+      /*if (fieldWrite.getWrites().containsKey(fieldWrite.getHandle()))
       {// this field has been written before, overwrite it
          fieldReference = fieldWrite.getWrites().get(fieldWrite.getHandle());
          fieldReference.setValue(fieldWrite.getNewObject());
@@ -83,21 +98,30 @@
          fieldReference = new TransactedObjectReference(fieldWrite.getHandle(), fieldWrite.getNewObject(), fieldWrite.getVersion());
          fieldWrite.getWrites().put(fieldWrite.getHandle(), fieldReference);
       }
-      if (null == fieldWrite.getNewObject() && fieldWrite.isIdentityField())
-      {// this is an entity being removed from the persistency system
-         IdentityFieldWriteParameter identityWrite = (IdentityFieldWriteParameter)fieldWrite;
-         Set<Long> removedEntityIdentities = null;
-         if (fieldWrite.getWrittenIdentityFields().containsKey(fieldWrite.getClass().getName()))
-         {// previous removal
-            removedEntityIdentities = fieldWrite.getWrittenIdentityFields().get(fieldWrite.getClass().getName());
+      */
+      
+      if ( fieldWrite.isIdentityField())
+      {
+         if (null == fieldWrite.getNewObject() )
+         {// this is an entity being removed from the persistency system
+            IdentityFieldWriteParameter identityWrite = (IdentityFieldWriteParameter)fieldWrite;
+            Set<Long> removedEntityIdentities = null;
+            if (fieldWrite.getWrittenIdentityFields().containsKey(fieldWrite.getClass().getName()))
+            {// previous removal
+               removedEntityIdentities = fieldWrite.getWrittenIdentityFields().get(fieldWrite.getClass().getName());
+            }
+            else
+            {// first removal for entity type
+               removedEntityIdentities = new HashSet<Long>();
+               removedEntityIdentities.add(fieldWrite.getIdentity() );
+               fieldWrite.getWrittenIdentityFields().put(identityWrite.getType().getName(), removedEntityIdentities);
+            }
+            removedEntityIdentities.add(fieldWrite.getIdentity());
          }
          else
-         {// first removal for entity type
-            removedEntityIdentities = new HashSet<Long>();
-            removedEntityIdentities.add(fieldWrite.getIdentity() );
-            fieldWrite.getWrittenIdentityFields().put(identityWrite.getType().getName(), removedEntityIdentities);
+         {// this represents an entity being added to the persistent store
+            
          }
-         removedEntityIdentities.add(fieldWrite.getIdentity());
       }
       
       returnValue = Boolean.TRUE;

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -9,22 +9,22 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.log4j.Logger;
 
 import uk.ac.ncl.sdia.a8905943.factory.TransactionFactory;
 import uk.ac.ncl.sdia.a8905943.impl.STMTransactionImpl;
 import uk.ac.ncl.sdia.a8905943.isolation.factory.IsolationFactory;
-import uk.ac.ncl.sdia.a8905943.persistence.jdbc.STMConnection;
 import uk.ac.ncl.sdia.a8905943.stm.exception.IsolationLevelNotConfiguredException;
 import uk.ac.ncl.sdia.a8905943.stm.field.FieldReadParameter;
 import uk.ac.ncl.sdia.a8905943.stm.field.FieldWriteParameter;
 import uk.ac.ncl.sdia.a8905943.stm.model.LoadEntityParameter;
 import uk.ac.ncl.sdia.a8905943.stm.object.TransactedObjectReference;
+import uk.ac.ncl.sdia.a8905943.stm.query.filter.DeletedEntityFilter;
+import uk.ac.ncl.sdia.a8905943.stm.query.filter.Filter;
 import uk.ac.ncl.sdia.a8905943.stm.transaction.PrepareParameter;
 import uk.ac.ncl.sdia.a8905943.stm.transaction.STMTransaction;
 import uk.ac.ncl.sdia.a8905943.stm.transaction.TransactionManager;
-import uk.ac.ncl.sdia.a8905943.stm.query.filter.DeletedEntityFilter;
-import uk.ac.ncl.sdia.a8905943.stm.query.filter.Filter;
 
 /**
  * This object is a proxy to the transactional memory system. It provides a
@@ -272,4 +272,33 @@
       }
       return returnValue;
    }
+   /**
+    * This method returns a comma separated list of deleted entities during this transaction for 
+    * the given type.
+    * 
+    * @return
+    */
+   public String getDeletedEntities(Class entityClass)
+   {
+      String returnValue = StringUtils.EMPTY;
+      if (null != entityClass)
+      {
+         STMTransaction transaction = TransactionFactory.getFactory().getCurrentTransaction(false);
+         for (String key: transaction.getDeletedEntities().keySet())
+         {
+            if (StringUtils.equals(entityClass.getName(), key))
+            {// found the entity collection of deleted entities
+               if (transaction.getDeletedEntities().get(key).isEmpty())
+               {// use a unique identity never used in the system, needed to avoid a query expression compilation problem
+                  returnValue = NumberUtils.LONG_ZERO.toString();
+               }
+               else
+               {
+                  returnValue = StringUtils.join(transaction.getDeletedEntities().get(key), ",");
+               }
+            }
+         }
+      }
+      return returnValue.toString();
+   }
 }

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/Action.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/Action.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/Action.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -0,0 +1,28 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package uk.ac.ncl.sdia.a8905943.stm.field;
+
+public interface Action
+{
+   public void execute(FieldWriteParameter parameter);
+}

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/AddAction.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/AddAction.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/AddAction.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -0,0 +1,38 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package uk.ac.ncl.sdia.a8905943.stm.field;
+
+import uk.ac.ncl.sdia.a8905943.stm.object.TransactedObjectReference;
+
+public class AddAction implements Action
+{
+
+   @Override
+   public void execute(FieldWriteParameter parameter)
+   {
+      TransactedObjectReference fieldReference = new TransactedObjectReference(parameter.getHandle(), parameter.getNewObject(), parameter.getVersion());
+      parameter.getWrites().put(parameter.getHandle(), fieldReference);
+
+   }
+
+}

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/FieldWriteParameter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/FieldWriteParameter.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/FieldWriteParameter.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -17,7 +17,18 @@
 {
    private Object newObject;
    private Map<String, Set<Long>> writtenIdentityFields = new HashMap<String, Set<Long>>();
+   private Action action;
 
+   public void setAction(Action action)
+   {
+      this.action = action;
+   }
+
+   public Action getAction()
+   {
+      return action;
+   }
+
    public Map<String, Set<Long>> getWrittenIdentityFields()
    {
       return writtenIdentityFields;
@@ -37,10 +48,11 @@
    {
       this.newObject = newObject;
    }
-   public FieldWriteParameter(long handle, Object newObject)
+   public FieldWriteParameter(long handle, Object newObject, Action fieldAction)
    {
       this.handle = handle;
       this.newObject = newObject;
+      this.action = fieldAction;
    }
    @Override
    public boolean isIdentityField()

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/IdentityFieldWriteParameter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/IdentityFieldWriteParameter.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/IdentityFieldWriteParameter.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -34,9 +34,9 @@
    }
 
    public IdentityFieldWriteParameter(long handle, Object newObject,
-         Long identity, Class type)
+         Long identity, Class type, Action fieldAction)
    {
-      super(handle, newObject);
+      super(handle, newObject, fieldAction);
       setIdentity(identity);
       setType(type);
    }
@@ -51,4 +51,9 @@
       this.type = type;
    }
 
+   @Override
+   public void processIdentityField()
+   {// custom processing for 
+      
+   }
 }

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/RemoveAction.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/RemoveAction.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/RemoveAction.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -0,0 +1,57 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package uk.ac.ncl.sdia.a8905943.stm.field;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import uk.ac.ncl.sdia.a8905943.stm.object.TransactedObjectReference;
+
+public class RemoveAction implements Action
+{
+
+   @Override
+   public void execute(FieldWriteParameter parameter)
+   {
+      TransactedObjectReference fieldReference =  parameter.getWrites().get(parameter.getHandle());
+      fieldReference.setValue(parameter.getNewObject());
+      //TODO: change the collection of deleted entity ids
+      if (parameter.isIdentityField())
+      {
+         IdentityFieldWriteParameter identityWrite = (IdentityFieldWriteParameter)parameter;
+         Set<Long> removedEntityIdentities = null;
+         if (parameter.getWrittenIdentityFields().containsKey(parameter.getClass().getName()))
+         {// previous removal
+            removedEntityIdentities = parameter.getWrittenIdentityFields().get(parameter.getClass().getName());
+         }
+         else
+         {// first removal for entity type
+            removedEntityIdentities = new HashSet<Long>(); 
+            removedEntityIdentities.add(parameter.getIdentity() );
+            parameter.getWrittenIdentityFields().put(identityWrite.getType().getName(), removedEntityIdentities);
+         }
+         removedEntityIdentities.add(parameter.getIdentity());
+      }
+   }
+
+}

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/ReplaceAction.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/ReplaceAction.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/field/ReplaceAction.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -0,0 +1,37 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package uk.ac.ncl.sdia.a8905943.stm.field;
+
+import uk.ac.ncl.sdia.a8905943.stm.object.TransactedObjectReference;
+
+public class ReplaceAction implements Action
+{
+
+   @Override
+   public void execute(FieldWriteParameter parameter)
+   {
+      TransactedObjectReference fieldReference =  parameter.getWrites().get(parameter.getHandle());
+      fieldReference.setValue(parameter.getNewObject());
+   }
+
+}

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/NoOpFilter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/NoOpFilter.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/NoOpFilter.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -0,0 +1,36 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package uk.ac.ncl.sdia.a8905943.stm.query.filter;
+
+import java.util.Collection;
+
+public class NoOpFilter implements Filter
+{
+
+   @Override
+   public void filter(Collection collection)
+   {
+      //no operation
+   }
+
+}

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/xpath/extension/NotInExtensionFunction.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/xpath/extension/NotInExtensionFunction.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/xpath/extension/NotInExtensionFunction.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -33,19 +33,18 @@
 {
    private static final Logger logger = Logger.getLogger(NotInExtensionFunction.class);
    /**
-    * This method provides the sql like two expression functions NOT, IN (...).
-    * Use this function to exclude values. 
+    * This method provides the sql like two expression functions NOT IN (...).
+    * Use this function to exclude values. [notin($exclusionList)]
     * 
+    * 
     * @param expressionContext
     * @return
     */
-   public static boolean notIn(ExpressionContext expressionContext, String value)
+   public static boolean notin(ExpressionContext expressionContext, String value)
    {
       boolean returnValue = true;
       
       logger.info("VAlue of exclusion variable is ["+expressionContext.getJXPathContext().getVariables().getVariable("exclusionList")+"]");
-      //Object excludedVariable = expressionContext.getJXPathContext().getVariables().getVariable("exclusionList");
-      //List excludedList = (List)excludedVariable;
       List<String> exclusionList =  Arrays.asList( StringUtils.split((String)expressionContext.getJXPathContext().getVariables().getVariable("exclusionList"), ","));
       for (String excludedValue : exclusionList)
       {

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -174,6 +174,52 @@
       Assert.assertNotNull(resultSet);
       Assert.assertEquals(1, resultSet.size());
 	}
+	
+	@Test
+	public void testCheckFindingDeletedEntityNoResult()
+	{
+	   Map<String, List<Object>> modelStore = this.stm.getModel();
+      Long carId = new Long(1);
+      LeccyCar car = new LeccyCar(carId);
+      List<Object> carList = new ArrayList<Object>();
+      carList.add(car);
+      carList.add(new LeccyCar(new Long(2)));
+      String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
+      Assert.assertEquals(carFQCN, car.getClass().getName());
+      modelStore.put(car.getClass().getName(), carList);
+      
+      Assert.assertNotNull(this.entityManager);
+      LeccyCar foundEntity = this.entityManager.find(LeccyCar.class, carId);
+      Assert.assertNotNull(foundEntity);
+      Assert.assertNotNull(foundEntity.getId());
+      Assert.assertEquals(foundEntity.getId(), carId  );
+      this.entityManager.remove(foundEntity);
+      LeccyCar secondAttemptAfterRemoval = this.entityManager.find(LeccyCar.class, carId);
+      Assert.assertNull(secondAttemptAfterRemoval);
+	}
+	@Test
+   public void testCheckFindingDeletedAfterAdding()
+   {
+      Map<String, List<Object>> modelStore = this.stm.getModel();
+      Long carId = new Long(1);
+      LeccyCar car = new LeccyCar(carId);
+      List<Object> carList = new ArrayList<Object>();
+      carList.add(car);
+      carList.add(new LeccyCar(new Long(2)));
+      String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
+      Assert.assertEquals(carFQCN, car.getClass().getName());
+      modelStore.put(car.getClass().getName(), carList);
+      
+      Assert.assertNotNull(this.entityManager);
+      LeccyCar foundEntity = this.entityManager.find(LeccyCar.class, carId);
+      Assert.assertNotNull(foundEntity);
+      Assert.assertNotNull(foundEntity.getId());
+      Assert.assertEquals(foundEntity.getId(), carId  );
+      this.entityManager.remove(foundEntity);
+      LeccyCar secondAttemptAfterRemoval = this.entityManager.find(LeccyCar.class, carId);
+      Assert.assertNull(secondAttemptAfterRemoval);
+      
+   }
 
 	@Override
 	public void setUp() {

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/TestUnitModelReplicatedMemory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/TestUnitModelReplicatedMemory.java	2009-09-22 15:13:03 UTC (rev 29434)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/TestUnitModelReplicatedMemory.java	2009-09-22 17:10:36 UTC (rev 29435)
@@ -107,7 +107,7 @@
       JXPathContext context = JXPathContext.newContext(this.stm);
       context.setFunctions(new ClassFunctions(NotInExtensionFunction.class, "query-func"));
       context.getVariables().declareVariable("exclusionList", "MG,Ford");
-      Iterator<Car> carIterator = context.iterate("model/uk.ac.ncl.sdia.a8905943.model.Car[query-func:notIn(make)]");
+      Iterator<Car> carIterator = context.iterate("model/uk.ac.ncl.sdia.a8905943.model.Car[query-func:notin(make)]");
       Assert.assertNotNull(carIterator);
       List<Car> carList = IteratorUtils.toList(carIterator);
       Assert.assertNotNull(carList);



More information about the jboss-svn-commits mailing list