You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ad...@apache.org on 2006/02/28 17:35:26 UTC

svn commit: r381694 [18/38] - in /incubator/ode/scratch: bpe/ ode/ ode/bpelTests/ ode/bpelTests/probeService/ ode/bpelTests/test1/ ode/bpelTests/test10/ ode/bpelTests/test12/ ode/bpelTests/test13/ ode/bpelTests/test14/ ode/bpelTests/test15/ ode/bpelTes...

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/ObjectCache.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/ObjectCache.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/ObjectCache.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/ObjectCache.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.context.ejb;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ode.uo.util.ApplicationLocalStore;
+
+/**
+ * This class implements  a cache used by the CMP
+ * blob bean for storing deserialized objects.  The
+ * caching is necessary for performance reasons.
+ * 
+ * The cache prunes itself once a configurable
+ * maximum size is reached.  The pruning algorithm
+ * random selects cache elements for deletion.
+ */
+public class ObjectCache
+{ 
+    private final static String MAP_KEY = "OBJECT_CACHE_MAP_KEY";
+
+    // Leave the last two digits for an incremental count.
+    private static long updateCountBase = 
+        (((long)(Math.random()*100000)) + 
+                System.currentTimeMillis())*1000;
+    
+    //TODO - 
+    //Use an application-local property to 
+    //determine the cache size
+    //rather than a system-wide property.
+    private static long maxCacheSize = 
+        Long.parseLong(System.getProperty(
+            "org.apache.ode.context.ejb.ObjectCache.maxCacheSize", 
+              "1000" ));
+    
+    private Map cacheMap;
+        
+    public ObjectCache()
+    {
+        cacheMap = lookupMap();
+    }
+    
+    /**
+     * Get a cached object based on id.  Returns null
+     * if the cache does not contain the object.
+     * @param id
+     * @return
+     */
+    public Object get( String id )
+    {
+        Object retVal = getMap().get(id);
+        return retVal;
+    }
+    
+    /**
+     * Remove the object with the specified id from
+     * the cache if present.
+     * @param id
+     */
+    public void remove( String id )
+    {
+        getMap().remove( id );
+    }
+    
+    /**
+     * Add the specified object to the cache and
+     * index it by the specified id.
+     * @param id
+     * @param object
+     */
+    public void put( String id, 
+            Object object )
+    {
+        
+        getMap().put(id, object );
+        shrinkCache();
+    }
+    
+    /**
+     * Shrink the cache if the current cache size
+     * is less than the configured maximum.
+     * 
+     */
+    private void shrinkCache()
+    {
+        Map map = getMap();
+//        long size = map.size();
+
+        if ( map.size() > maxCacheSize )
+        {
+            Object[] keyArray = 
+                map.keySet().toArray();
+            map.keySet().toArray();
+            
+            int randomindex = 
+                (int)( Math.round(Math.floor(Math.random()*keyArray.length)) );
+            String key = (String)(keyArray[randomindex]);
+            remove(key);
+        }
+    }
+    
+    /**
+     * Return an update count which has been modified
+     * to include a cache-specific prefix.  The prefix is
+     * useful because in a cluster it prevents a bad cache entry from
+     * being incorrectly re-used if a transaction is rolledback
+     * on one node1 in the cluster but completed successfully on node2
+     * in the cluster.  If it were not for the prefix, node1 would
+     * re-use the cached object from the rolledback transaction
+     * because the updatecount would match the updatecount from the
+     * completed transaction on node2.
+     * 
+     * @param updateCount
+     * @return
+     */
+    public static long GetUpdateCount( long updateCount )
+    {
+        return updateCountBase + (updateCount & 511);
+    }
+    
+    /**
+     * Get the map which holds the cache.
+     * 
+     * @return
+     */
+    private Map getMap()
+    {
+        Map returnValue;
+        if (cacheMap == null)
+        {
+            returnValue = lookupMap();
+            if (returnValue == null)
+            {
+                returnValue = CreateMap();
+            }
+            cacheMap = returnValue;
+
+        } else
+        {
+            returnValue = cacheMap;
+        }
+        //debug(returnValue);
+        return returnValue;
+    }
+    
+    /**
+     * See if the map which holds the object cache is already
+     * in component local storage.  If it is return it, 
+     * otherwise return null.
+     * @return
+     */
+    private static Map lookupMap()
+    {
+        Map returnValue = 
+            ( Map )ApplicationLocalStore.get( MAP_KEY );
+        //debug(returnValue);
+        return returnValue;
+    }
+    
+//    private static void debug(Map map)
+//    {
+//        if ( map != null )
+//        {
+//        String debugMessage = 
+//            "Map hashcode = " + map.hashCode() + ", " +
+//            "map size = " + map.size();   
+//        debug(debugMessage);
+//        }
+//    }
+    
+//    private static void debug( String message )
+//    {
+//        if ( message != null )
+//        {
+//        String debug = "ObjectCacheDebug: " + message;
+//        System.out.println(debug);
+//        }
+//    }
+    
+    /**
+     * Create the map which holds the object cache and
+     * insert it into component local storgage.
+     * @return
+     */
+    private synchronized static Map CreateMap()
+    {
+        Map returnValue = lookupMap();
+        if ( returnValue == null)
+        {
+            returnValue =  
+                Collections.synchronizedMap(new HashMap());
+            ApplicationLocalStore.set(MAP_KEY, returnValue);
+            //debug( "Created new context local storage map." );
+        }
+        return returnValue;
+        
+    }
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/AssortedContextOperationsBase.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/AssortedContextOperationsBase.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/AssortedContextOperationsBase.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/AssortedContextOperationsBase.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.IContextService;
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.IPart;
+import org.apache.ode.interaction.IInteraction;
+
+public abstract class AssortedContextOperationsBase extends TimedTest
+{
+	
+	
+	protected abstract IContextService createContextService() throws Exception;
+	protected abstract IInteraction createInteractionObject() throws Exception;
+
+	
+	private IInteraction getInteraction1() throws Exception
+	{
+		if ( m_interaction1 == null )
+		{
+			m_interaction1 = createInteractionObject();
+		}
+		return m_interaction1;
+	}
+	
+	private IInteraction getInteraction2() throws Exception
+	{
+		if ( m_interaction2 == null )
+		{
+			m_interaction2 = createInteractionObject();
+		}
+		return m_interaction2;
+	}
+
+	protected void runIteration() throws Exception
+	{
+		
+
+		IInteraction interaction1 = getInteraction1();
+		IInteraction interaction2 = getInteraction2();
+
+		IContextService contextService = createContextService();
+
+		IHandle handle1 = contextService.createObjectHandle(interaction1);
+
+		IContainer root = contextService.getRoot();
+
+		String processInstance1UUID = "PerformanceTestBP";
+		IContainer processContext1 = root.createContainer(processInstance1UUID);
+
+		IContainer pc1C1 = processContext1.createContainer("C0");
+		IPart pc1C1P1 = pc1C1.createPart("P1");
+		pc1C1P1.setObject(handle1);
+		IPart pc1C1P2 = pc1C1.createPart("P2");
+		pc1C1P2.setObject(interaction1);
+
+
+		IContainer pc1C2 = processContext1.createContainer("C1");
+		IPart pc1C2P1 = pc1C2.createPart("P1");
+		pc1C2P1.setObject(handle1);
+		IPart pc1C2P2 = pc1C2.createPart("P2");
+		pc1C2P2.setObject(interaction2);
+
+
+	}
+	
+	private IInteraction m_interaction1 = null;
+	private IInteraction m_interaction2 = null;
+
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithContainer.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithContainer.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithContainer.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithContainer.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.IContextService;
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.IPart;
+import org.apache.ode.context.base.ContextServiceFactory;
+import org.apache.ode.context.base.ContextTypeEnum;
+import org.apache.ode.context.base.IDataObject;
+import org.apache.ode.context.ejb.EJBDataObjectFactory;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+public class CallSetObjectWithContainer extends TimedTest
+{
+	public CallSetObjectWithContainer() throws Exception
+	{
+	}
+
+	protected void runIteration() throws Exception
+	{
+		m_userTransaction.begin();
+		m_dataObject.setObject(m_container);
+		m_userTransaction.commit();
+	}
+
+	public void init(UUIDService us) throws Exception
+	{
+		m_userTransaction.begin();
+		m_factory = new EJBDataObjectFactory();
+
+		String message1 = "aMessage1";
+		String message2 = "Test Message2";
+
+		BPEProperties props = new BPEProperties();
+
+		IContextService csP =
+			ContextServiceFactory.createContextService(
+				props,
+				us,
+				ContextTypeEnum.PERSISTENT);
+
+		IHandle handle1 = csP.createObjectHandle(message1);
+
+		IContainer root = csP.getRoot();
+
+		String processInstance1UUID = "aaa";
+		IContainer processContext1 = root.createContainer(processInstance1UUID);
+		String processInstance2UUID = "bbb";
+		IContainer processContext2 = root.createContainer(processInstance2UUID);
+
+		IContainer pc1C1 = processContext1.createContainer("myNewMessage1");
+		IPart pc1C1P1 = pc1C1.createPart("param1");
+		pc1C1P1.setObject(handle1);
+		IPart pc1C1P2 = pc1C1.createPart("param2");
+		pc1C1P2.setObject(message2);
+
+
+		IContainer pc1C2 = processContext1.createContainer("myNewMessage2");
+		IPart pc1C2P1 = pc1C2.createPart("param1");
+		pc1C2P1.setObject(handle1);
+		IPart pc1C2P2 = pc1C2.createPart("param2");
+		pc1C2P2.setObject(message2);
+
+
+		m_container = processContext2;
+		m_dataObject = m_factory.create(m_container);
+		m_userTransaction.commit();
+	}
+
+	private EJBDataObjectFactory m_factory = new EJBDataObjectFactory();
+	private IContainer m_container = null;
+	private IDataObject m_dataObject;
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithString.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithString.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithString.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CallSetObjectWithString.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+//import org.apache.ode.context.IContainer;
+import org.apache.ode.context.base.IDataObject;
+import org.apache.ode.context.ejb.EJBDataObjectFactory;
+
+public class CallSetObjectWithString extends TimedTest
+{
+
+	protected void runIteration() throws Exception
+	{	
+		m_userTransaction.begin();
+		m_dataObject.setObject(m_string);
+		m_userTransaction.commit();
+	}
+
+	public void init() throws Exception
+	{
+		m_userTransaction.begin();
+		m_factory = new EJBDataObjectFactory();
+		m_dataObject = m_factory.create(m_string);
+		m_userTransaction.commit();
+	}
+
+	private EJBDataObjectFactory m_factory = new EJBDataObjectFactory();
+//	private IContainer m_container = null;
+	private IDataObject m_dataObject;
+	private String m_string = "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
+	
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateNewDataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateNewDataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateNewDataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateNewDataObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import org.apache.ode.context.ejb.EJBDataObjectFactory;
+
+public class CreateNewDataObject extends TimedTest
+{
+	
+	protected void runIteration() throws Exception
+	{
+		m_userTransaction.begin();
+		m_factory.create( "testMessage" );	
+		m_userTransaction.commit();	
+	}
+	
+	private EJBDataObjectFactory m_factory = new EJBDataObjectFactory();
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateUUID.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateUUID.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateUUID.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/CreateUUID.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import javax.naming.InitialContext;
+import javax.resource.cci.ConnectionFactory;
+
+import org.apache.ode.uuid.connector.IUUIDConnection;
+
+public class CreateUUID extends TimedTest
+{
+
+	public CreateUUID()
+	{
+		setName("CreateUUID"); 
+	}
+
+	protected void runIteration() throws Exception
+	{
+
+		if (connection == null)
+		{
+			InitialContext ctx = new InitialContext();
+			connection =
+				(IUUIDConnection) ((ConnectionFactory) ctx
+					.lookup("java:comp/env/theUUIDService"))
+					.getConnection();
+		}
+		connection.getUUID();
+	}
+
+	private IUUIDConnection connection = null;
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EmptyTransaction.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EmptyTransaction.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EmptyTransaction.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EmptyTransaction.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+
+public class EmptyTransaction extends TimedTest
+{
+	public EmptyTransaction()
+	{
+		setName( "EmptyTransaction" );
+	}
+	
+
+	protected void runIteration() throws Exception
+	{
+		m_userTransaction.begin();
+		m_userTransaction.commit();
+	}
+
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EntityBeanHomeLookup.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EntityBeanHomeLookup.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EntityBeanHomeLookup.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/EntityBeanHomeLookup.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+//import javax.ejb.EJBLocalHome;
+import javax.naming.InitialContext;
+
+public class EntityBeanHomeLookup extends TimedTest
+{
+	public EntityBeanHomeLookup()
+	{
+		setName("EntityBeanHomeLookup");
+	}
+
+	protected void runIteration() throws Exception
+	{
+
+		InitialContext ctx = new InitialContext();
+
+		ctx.lookup("java:comp/env/theCMPObjectBean");
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/FindAndNotThere.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/FindAndNotThere.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/FindAndNotThere.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/FindAndNotThere.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import org.apache.ode.context.ejb.EJBDataObjectFactory;
+
+public class FindAndNotThere extends TimedTest
+{
+
+		protected void runIteration() throws Exception
+	{
+
+		m_factory.find( "This key better not be there." );	
+	
+	}
+	
+	private EJBDataObjectFactory m_factory = new EJBDataObjectFactory();
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/JDBCConnectionLookup.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/JDBCConnectionLookup.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/JDBCConnectionLookup.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/JDBCConnectionLookup.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import javax.naming.InitialContext;
+
+public class JDBCConnectionLookup extends TimedTest
+{
+	public JDBCConnectionLookup()
+	{
+		setName( "JDBCConnectionLookup()" );
+	}
+	
+	protected void runIteration() throws Exception
+	{
+			InitialContext ictx = new InitialContext();
+			ictx.lookup("java:comp/env/jdbc/theDB");
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/MutexBeanHomeLookup.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/MutexBeanHomeLookup.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/MutexBeanHomeLookup.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/MutexBeanHomeLookup.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import javax.naming.InitialContext;
+
+public class MutexBeanHomeLookup extends TimedTest
+{
+	
+	public MutexBeanHomeLookup()
+	{
+		setName( "MutexBeanHomeLookup" );
+	}
+
+	protected void runIteration() throws Exception
+	{
+		InitialContext init = new InitialContext();
+
+		init.lookup("java:comp/theMutex");
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/TimedTest.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/TimedTest.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/TimedTest.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/TimedTest.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import java.io.PrintStream;
+
+import javax.transaction.UserTransaction;
+
+public abstract class TimedTest
+{
+	TimedTest()
+	{
+	}
+	
+	public void init() throws Exception
+	{
+	}
+	
+	TimedTest(String iName, long iIterations)
+	{
+		m_name = iName;
+		m_iterations = iIterations;
+		m_currentIteration = 0;
+	}
+	
+	public void setIterations( long iIterations )
+	{
+		m_iterations = iIterations;
+	}
+	
+	public void setTransaction( UserTransaction iUserTransaction )
+	{
+		m_userTransaction = iUserTransaction;
+	}
+	
+	public void setName( String iName )
+	{
+		m_name = iName;
+	}
+
+	public void printResults(PrintStream oStream)
+	{
+		m_ps = oStream;
+		println("****************************" + m_name + " run complete.");
+		println("Iterations = " + m_iterations);
+		println("Total time in milliseconds  = " + m_totalTimeMillis);
+		println("Total time in seconds = " + m_totalTimeSeconds);
+		println("Iterations/second = " + m_iterationsPerSecond);
+		if (m_exceptionOccurred)
+		{
+			println(
+				"An exception occured during iteration:"
+					+ m_currentIteration
+					+ ":"
+					+ m_exception.toString());
+			m_exception.printStackTrace(m_ps);
+		
+
+		}
+	}
+
+	protected void println(String iValue)
+	{
+		m_ps.println( iValue);
+	}
+
+	public void run() throws Exception
+	{
+		m_exceptionOccurred = false;
+		m_startTime = System.currentTimeMillis();
+		try
+		{
+			for (m_currentIteration = 1;
+				m_currentIteration <= m_iterations;
+				m_currentIteration++)
+			{
+				runIteration();
+			}
+		}
+		catch (Exception e)
+		{
+			m_exceptionOccurred = true;
+			m_exception = e;
+			throw e;
+		}
+		m_endTime = System.currentTimeMillis();
+		m_totalTimeMillis = m_endTime - m_startTime;
+		m_totalTimeSeconds = (double) (m_totalTimeMillis) / (double) (1000);
+		m_iterationsPerSecond =
+			(double) (m_iterations) / (double) (m_totalTimeSeconds);
+
+	}
+
+	protected abstract void runIteration() throws Exception;
+
+	private String m_name = "noName";
+	private long m_iterations = 0;
+	private long m_currentIteration = 0;
+	private long m_startTime = 0;
+	private long m_endTime = 0;
+	private long m_totalTimeMillis;
+	private double m_totalTimeSeconds;
+	private double m_iterationsPerSecond;
+	private boolean m_exceptionOccurred = false;
+	private Exception m_exception;
+	private PrintStream m_ps = null;
+	protected UserTransaction m_userTransaction = null;
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/UUIDConnectionLookup.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/UUIDConnectionLookup.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/UUIDConnectionLookup.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/test/performance/UUIDConnectionLookup.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.ejb.test.performance;
+
+import javax.naming.InitialContext;
+import javax.resource.cci.ConnectionFactory;
+
+//import org.apache.ode.uuid.connector.IUUIDConnection;
+
+public class UUIDConnectionLookup extends TimedTest
+{
+
+	public UUIDConnectionLookup()
+	{
+		setName("UUIDConnectionLookup");
+	}
+	protected void runIteration() throws Exception
+	{
+		InitialContext ctx = new InitialContext();
+		((ConnectionFactory) ctx
+				.lookup("java:comp/env/theUUIDService"))
+				.getConnection();
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContainer.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContainer.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContainer.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContainer.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.nonpersistent;
+
+import java.util.Collection;
+//import java.util.logging.Logger;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.INode;
+import org.apache.ode.context.IPart;
+import org.apache.ode.context.base.ContextServiceException;
+
+
+/**
+ * An in memory/transient implementation of IContainer
+ *
+ * 
+* @author lorenz/waterman
+ */
+public class TransientContainer extends TransientNode implements IContainer
+{
+	static final long serialVersionUID = -348357367551530988L;
+	
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(TransientContainer.class.getName());
+
+	public TransientContainer(String iName ) throws ContextServiceException
+	{
+		super();
+		setName( iName );
+	}
+
+	public TransientContainer(String name, TransientContainer parent) throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType( CONTAINER );
+	}
+
+	protected TransientContainer() throws ContextServiceException
+	{
+		super();
+		setNodeType( CONTAINER );
+	}
+	
+	// Implement the IContainer facade.  Polymorphic enhancements must be made in the
+	// internal* methods, not the IContainer interface methods.
+	
+	public IContainer createContainer( String iContainerLocator ) throws ContextServiceException
+	{
+		return internalCreateContainer( iContainerLocator );
+	}
+	
+	public IPart createPart( String iPartLocator ) throws ContextServiceException
+	{
+		return internalCreatePart( iPartLocator );
+	}
+
+	public INode findChild( String iChildLocator ) throws ContextServiceException 
+	{
+		return internalFindChild( iChildLocator );
+	}
+
+	public void removeChild( String iChildLocator ) throws ContextServiceException
+	{
+		internalRemoveChild( iChildLocator );
+	}
+
+	public void moveNode( INode iSourceNode, String iTargetName ) throws ContextServiceException
+	{
+		internalMoveNode( iSourceNode, iTargetName );
+	}
+
+	public void copyNode( INode iSourceNode, String iTargetName ) throws ContextServiceException
+	{
+		internalCopyNode( iSourceNode, iTargetName );
+	}
+	
+	public Collection getChildren() throws ContextServiceException
+	{
+		return internalGetChildren();
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContextService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContextService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContextService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientContextService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.nonpersistent;
+
+//import java.util.logging.Logger;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.base.ContextService;
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+/**
+ *
+ * An in memory/transient implementation of a context service.
+ * 
+ * @author lorenz/waterman
+ */
+public class TransientContextService extends ContextService
+{
+
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(TransientContainer.class.getName());
+
+	private TransientContainer m_root = null;
+
+	/**
+	 * @see org.apache.ode.context.IContextService#createObjectHandle(java.lang.Object)
+	 */
+	public IHandle createObjectHandle(Object iObject)
+		throws ContextServiceException
+	{
+		return new TransientDataObject(iObject);
+	}
+
+
+
+	/**
+	 * @see org.apache.ode.context.IContextService#getRoot()
+	 */
+	public IContainer getRoot() throws ContextServiceException
+	{
+		if (m_root == null)
+		{
+			m_root = new TransientContainer("TROOT");
+		}
+		return m_root;
+	}
+
+	/**
+	 * @see org.apache.ode.context.IContextService#init(org.apache.ode.util.BPEProperties)
+	 */
+	public void init(BPEProperties props, UUIDService us)
+	{
+		// no op
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.nonpersistent;
+
+import org.apache.ode.context.base.DataObject;
+
+public class TransientDataObject extends DataObject
+{
+    static final long serialVersionUID = -1602208787747724165L;
+    
+	private Object m_internalObject = null;
+	private int m_referenceCount = 0;
+
+	public TransientDataObject(Object iInternalObject)
+		
+	{
+		setObject(iInternalObject);
+	}
+
+	public void setObject(Object obj)
+	{
+		m_internalObject = obj;
+	}
+
+	public Object getObjectForRead()
+	{
+		return m_internalObject;
+	}
+	
+	public Object getObjectForReadWrite()
+	{
+		return m_internalObject;
+	}
+	
+	public Object getObjectForReadWriteWithLock()
+	{
+		// The transient data object does not implement
+		// write locks, so we don't do anything special here.
+		return m_internalObject;
+	}
+		
+	public void decrementRefCount()
+	{
+		m_referenceCount--;
+	}
+	
+	public void incrementRefCount()
+	{
+		m_referenceCount++;
+	}	
+	
+	public long getRefCount()
+	{
+		return m_referenceCount;
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObjectFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObjectFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientDataObjectFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.nonpersistent;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.IDataObject;
+import org.apache.ode.context.base.IDataObjectFactory;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+public class TransientDataObjectFactory implements IDataObjectFactory
+{
+	public void init( BPEProperties iProperties, UUIDService us ) throws ContextServiceException
+	{
+	}
+	
+	public IDataObject find(String iLocator ) throws ContextServiceException
+	{
+		return null;
+	}
+	
+	public IDataObject create(String iLocator, Object iData) throws ContextServiceException
+	{
+
+		return null;
+	}
+	
+	public IDataObject create(Object iData) throws ContextServiceException
+	{
+		return new TransientDataObject( iData );
+	}
+	
+	public void remove( String iLocator ) throws ContextServiceException
+	{
+		
+	}
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientNode.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientNode.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientNode.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientNode.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.nonpersistent;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.DataObject;
+import org.apache.ode.context.base.SuperNode;
+
+/**
+ *
+ * An in memory/transient implementation of INode
+ * 
+ * @author lorenz/waterman
+ */
+public class TransientNode extends SuperNode
+{
+	static final long serialVersionUID = -6819433817373607390L;
+
+	
+	TransientNode()
+	{
+		super();
+	}
+
+	TransientNode(String name, TransientContainer parent)
+		throws ContextServiceException
+	{
+		super(name, parent);
+	}
+
+	protected DataObject createHandle(Object iDataObject)
+	{
+		return new TransientDataObject(iDataObject);
+	}
+
+	protected SuperNode createContainerImpl() throws ContextServiceException
+	{
+		return new TransientContainer();
+	}
+
+	protected SuperNode createPartImpl() throws ContextServiceException
+	{
+		return new TransientPart();
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientPart.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientPart.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientPart.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/nonpersistent/TransientPart.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+/*
+ * Created on Apr 16, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.apache.ode.context.nonpersistent;
+
+//import java.util.logging.Logger;
+
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.IPart;
+import org.apache.ode.context.base.ContextServiceException;
+
+/**
+ * @author waterman
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TransientPart extends TransientNode implements IPart
+{
+
+	static final long serialVersionUID = 6671980478917076399L;
+	
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(TransientPart.class.getName());
+
+	TransientPart(String name, TransientContainer parent)
+		throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType(PART);
+	}
+
+	TransientPart() throws ContextServiceException
+	{
+		super();
+		setNodeType(PART);
+	}
+
+	// Implement IPart Facade. Any polymorphic enhancement
+	// to the base object should be done via the internal* 
+	// methods, not the facade methods.
+
+	public void setObject(Object iObject)
+		throws ContextServiceException
+	{
+		internalSetObject(iObject);
+	}
+
+	public void setObjectHandle(IHandle iObjectHandle) throws ContextServiceException
+	{
+		setReadOnly(true);
+		internalSetObject(iObjectHandle);
+	}
+	
+	public Object getObjectClone() throws ContextServiceException
+	{
+		return internalGetObjectClone();
+	}
+
+	public Object getObjectForRead() throws ContextServiceException
+	{
+		return internalGetObjectForRead();
+	}
+
+	public Object getObjectForReadWrite() throws ContextServiceException
+	{
+		return internalGetObjectForReadWrite();
+	}
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContainer.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContainer.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContainer.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContainer.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+/*
+ * Created on Apr 18, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.apache.ode.context.persistent;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Iterator;
+//import java.util.logging.Logger;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.INode;
+import org.apache.ode.context.IPart;
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.SuperNode;
+import org.apache.ode.context.ejb.BPE_ObjectLocal;
+
+/**
+ * An EJB implemenation of IContainer
+ * 
+ * @author waterman
+ */
+public class PersistentContainer
+	extends PersistentNode
+	implements IContainer, Serializable
+{
+
+	/**
+	 * @param name
+	 * @param parent
+	 */
+	public PersistentContainer(String name, PersistentContainer parent)
+		throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType(CONTAINER);
+	}
+
+	/**
+	 * @param name
+	 * @param parent
+	 */
+	public PersistentContainer(
+		String name,
+		PersistentContainer parent,
+		BPE_ObjectLocal local)
+		throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType(CONTAINER);
+	}
+
+	protected PersistentContainer() throws ContextServiceException
+	{
+		super();
+		setNodeType(CONTAINER);
+	}
+
+	// Implement the IContainer facade.  Polymorphic enhancements must be made in the
+	// internal* methods, not the IContainer interface methods.
+
+	public IContainer createContainer(String iContainerLocator)
+		throws ContextServiceException
+	{
+		IContainer newContainer = internalCreateContainer(iContainerLocator);
+		setDirty(this);
+		return newContainer;
+	}
+
+	public IPart createPart(String iPartLocator) throws ContextServiceException
+	{
+		IPart newPart = internalCreatePart(iPartLocator);
+		setDirty(this);
+		return newPart;
+	}
+
+	public INode findChild(String iChildLocator) throws ContextServiceException
+	{
+		return internalFindChild(iChildLocator);
+	}
+
+	public void removeChild(String iChildLocator)
+		throws ContextServiceException
+	{
+		internalRemoveChild(iChildLocator);
+		setDirty(this);
+	}
+
+	public void moveNode(INode iSourceNode, String iTargetName)
+		throws ContextServiceException
+	{
+		setDirty((SuperNode) iSourceNode);
+		internalMoveNode(iSourceNode, iTargetName);
+		setDirty(this);
+	}
+
+	public void copyNode(INode iSourceNode, String iTargetName)
+		throws ContextServiceException
+	{
+		internalCopyNode(iSourceNode, iTargetName);
+		setDirty(this);
+	}
+
+	public Collection getChildren() throws ContextServiceException
+	{
+		return internalGetChildren();
+	}
+
+	private void writeObject(ObjectOutputStream s) throws IOException
+	{
+		//s.defaultWriteObject();
+		writeNodeElements(s);
+
+		Collection children = null;
+		try
+		{
+			children = this.getInternalChildCollectionForSerialization();
+		}
+		catch (Exception e)
+		{
+			throw new IOException("Failed to get children.");
+		}
+		if (children != null)
+		{
+
+			s.writeInt(children.size());
+			Iterator iter = children.iterator();
+			while (iter.hasNext())
+			{
+				PersistentNode node = (PersistentNode) (iter.next());
+				s.writeObject(node);
+			}
+		}
+		else
+		{
+			s.writeInt(0);
+		}
+	}
+
+	private void readObject(ObjectInputStream s)
+		throws IOException, ClassNotFoundException
+	{
+
+		//s.defaultReadObject();
+		readNodeElements(s);
+		int childCount = s.readInt();
+		int i = 0;
+		while (i < childCount)
+		{
+			SuperNode node = (SuperNode) s.readObject();
+			try
+			{
+				this.addChild(node);
+			}
+			catch (Exception e)
+			{
+				throw new IOException(e.toString());
+			}
+			i++;
+		}
+
+	}
+
+	// Do not change this value unless you want to enforce
+	// incompatibility with other serialized versions of 
+	// this class.
+	private static final long serialVersionUID = 1L;
+
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(PersistentContainer.class.getName());
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContextService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContextService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContextService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentContextService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.persistent;
+
+//import java.util.logging.Logger;
+
+//import javax.naming.InitialContext;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.base.ContextService;
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.IDataObject;
+import org.apache.ode.context.base.IDataObjectFactory;
+//import org.apache.ode.context.ejb.BPE_ObjectLocalHome;
+import org.apache.ode.context.ejb.EJBDataObjectFactory;
+import org.apache.ode.context.nonpersistent.TransientDataObjectFactory;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+
+public class PersistentContextService extends ContextService
+{
+
+	private UUIDService m_us; // generates unique handle identifiers
+//	private BPE_ObjectLocalHome m_objectHome;
+//	private InitialContext m_ictx;
+	private PersistentRootContainer m_root;
+
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(PersistentContextService.class.getName());
+
+	public IHandle createObjectHandle(Object iObject)
+		throws ContextServiceException
+	{
+		return (IHandle) createGlobalDataObject(iObject);
+	}
+
+	public void init(BPEProperties props, UUIDService us)
+	{
+		this.m_us = us;
+		m_props = props;
+	}
+
+	public IContainer getRoot() throws ContextServiceException
+	{
+		if (m_root == null)
+		{
+			m_root = new PersistentRootContainer(this);
+		}
+		return m_root;
+	}
+
+
+	protected IDataObject findPersistentDataObject(String iLocator)
+		throws ContextServiceException
+	{
+		IDataObject returnObject = getPersistentDataObjectFactory().find(iLocator);
+		return returnObject;
+	}
+
+	protected IDataObject createPersistentDataObject(String iName, Object iObject)
+		throws ContextServiceException
+	{
+
+		IDataObject newObject =
+			getPersistentDataObjectFactory().create(iName, iObject);
+		return (PersistentDataObject) newObject;
+	}
+
+	protected IDataObject createLocalDataObject(Object iObject)
+		throws ContextServiceException
+	{
+
+		IDataObject newObject = getLocalDataObjectFactory().create(iObject);
+		return newObject;
+	}
+
+	protected IDataObject createGlobalDataObject(Object iObject)
+		throws ContextServiceException
+	{
+		IDataObject newObject = getGlobalDataObjectFactory().create(iObject);
+		return newObject;
+	}
+
+	protected void removePersistentDataObject(String iLocator)
+		throws ContextServiceException
+	{
+		getPersistentDataObjectFactory().remove(iLocator);
+	}
+
+	private IDataObjectFactory getLocalDataObjectFactory()
+		throws ContextServiceException
+	{
+		if (m_localDataObjectFactory == null)
+		{
+			// If the context service is configured to use fine grained
+			// persistence, each data object is a separately
+			// peristable entity.  Otherwise local object will
+			// persisted along with the context tree entity.
+			String granularity = m_props.getProperty(BPEProperties.CTX_PERSISTENCE_GRANULARITY_KEY);
+			if ( (granularity!=null) && granularity.equals(BPEProperties.CTX_FINE))
+			{
+				m_localDataObjectFactory = getPersistentDataObjectFactory();
+			}
+			else
+			{
+				m_localDataObjectFactory = getTransientDataObjectFactory();
+			}
+		}
+		return m_localDataObjectFactory;
+	}
+
+	private IDataObjectFactory getGlobalDataObjectFactory()
+		throws ContextServiceException
+	{
+		if (m_globalDataObjectFactory == null)
+		{
+			// If the context service is configured to use monolithic
+			// persistence, all data objects even those designated
+			// as global are implemented as transient data objects
+			// and are persisted along with the contxt tree.
+			if (m_props
+				.getProperty(BPEProperties.CTX_PERSISTENCE_GRANULARITY_KEY)
+				.equals(BPEProperties.CTX_MONOLITHIC))
+			{
+				m_globalDataObjectFactory = getTransientDataObjectFactory();
+			}
+			else
+			{
+				m_globalDataObjectFactory = getPersistentDataObjectFactory();
+			}
+		}
+		return m_globalDataObjectFactory;
+	}
+
+	private IDataObjectFactory getPersistentDataObjectFactory()
+		throws ContextServiceException
+	{
+		if (m_persistentDataObjectFactory == null)
+		{
+			m_persistentDataObjectFactory = new EJBDataObjectFactory();
+			m_persistentDataObjectFactory.init(m_props, m_us);
+		}
+		return m_persistentDataObjectFactory;
+	}
+
+	private IDataObjectFactory getTransientDataObjectFactory()
+		throws ContextServiceException
+	{
+		if (m_transientDataObjectFactory == null)
+		{
+			m_transientDataObjectFactory = new TransientDataObjectFactory();
+			m_transientDataObjectFactory.init(m_props, m_us);
+		}
+		return m_transientDataObjectFactory;
+	}
+	
+	public void flush() throws ContextServiceException
+	{
+		PersistentDataObjectFactory pdoFactory = 
+			(PersistentDataObjectFactory)
+		getPersistentDataObjectFactory();
+		
+		pdoFactory.flush();
+	}
+
+	private IDataObjectFactory m_globalDataObjectFactory = null;
+	private IDataObjectFactory m_localDataObjectFactory = null;
+	private EJBDataObjectFactory m_persistentDataObjectFactory = null;
+	private TransientDataObjectFactory m_transientDataObjectFactory = null;
+	private BPEProperties m_props = new BPEProperties();
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.persistent;
+
+import org.apache.ode.context.base.DataObject;
+
+public abstract class PersistentDataObject extends DataObject
+{
+	
+    static final long serialVersionUID = 5175442988682761164L;
+    
+	protected PersistentDataObject(String id, Object iInternals)
+	{
+		setLocator(id);
+		setInternals(iInternals);
+	}
+
+	protected void setInternals(Object iInternals)
+	{
+		m_internals = iInternals;
+	}
+
+	protected Object getInternals()
+	{
+		return m_internals;
+	}
+
+	protected boolean isHollow()
+	{
+		return (m_internals == null);
+	}
+	
+	protected void fill(PersistentDataObject iPersistentDataObject)
+	{
+
+		setLocator(iPersistentDataObject.getLocator());
+		setInternals(iPersistentDataObject.getInternals());
+	}
+
+	public String getLocator()
+	{
+		return m_id;
+	}
+
+	protected void setLocator(String iID)
+	{
+		m_id = iID;
+	}
+
+	// attributes persisted as part of the context tree
+	private String m_id; // the primary key of the object in the DB
+
+	private transient Object m_internals = null;
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObjectFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObjectFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentDataObjectFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.persistent;
+
+//import java.util.logging.Logger;
+
+//import javax.naming.InitialContext;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.IDataObjectFactory;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+public abstract class PersistentDataObjectFactory implements IDataObjectFactory
+{
+
+	public void init(BPEProperties props, UUIDService us) throws ContextServiceException
+	{
+		this.m_us = us;
+		setProperties( props );
+
+	}
+
+	protected String getUUID() throws ContextServiceException
+	{
+			return m_us.getUUID();
+	}
+	
+	private void setProperties( BPEProperties iProperties )
+	{
+		m_properties = iProperties;
+	}
+	
+	protected BPEProperties getProperties()
+	{
+		if ( m_properties == null )
+		{
+			m_properties = new BPEProperties();	
+		}
+		return m_properties;
+	}
+	
+	protected abstract void flush() throws ContextServiceException;
+	
+	private BPEProperties m_properties = null;
+	
+
+
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(PersistentDataObjectFactory.class.getName());
+
+	private UUIDService m_us; // generates unique handle identifiers
+//	private InitialContext m_ictx;
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentNode.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentNode.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentNode.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentNode.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+/*
+ * Created on Apr 18, 2003
+ *
+ */
+package org.apache.ode.context.persistent;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+//import java.util.logging.Logger;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.DataObject;
+import org.apache.ode.context.base.SuperNode;
+
+/**
+ 	*
+	* An EJB implementation of INode
+	*
+ 	* @author waterman
+  	*/
+public class PersistentNode extends SuperNode
+{
+	
+	static final long serialVersionUID = 26152360502563739L;
+
+	PersistentNode()
+	{
+	}
+
+	PersistentNode(String name, PersistentContainer parent)
+		throws ContextServiceException
+	{
+		super(name, parent);
+	}
+
+	public void setContainer(PersistentContainer iContainer)
+		throws ContextServiceException
+	{
+		super.setContainer(iContainer);
+		setDirty(this);
+	}
+
+	public void setName(String iName) throws ContextServiceException
+	{
+		super.setName(iName);
+		setDirty(this);
+	}
+	
+	protected void setNameFromDeserialization( String iName ) throws ContextServiceException
+	{
+		super.setName(iName);
+	}
+	
+
+	/**
+	 * When a bean is pulled out of the DB we can init the parent without
+	 * setting all the dirty flags.
+	 * @param parent
+	 */
+	void init(PersistentContainer parent) throws ContextServiceException
+	{
+		super.setContainer(parent);
+
+	}
+
+	/**
+	 * Marks the context tree as dirty. This identifies context trees that
+	 * need to be persisted back into the DB
+	 *
+	 */
+	protected void setDirty(SuperNode child) throws ContextServiceException
+	{
+		PersistentContainer container = ((PersistentContainer) getContainer());
+		if (container != null)
+		{
+			container.setDirty(this);
+		}
+	}
+	
+	// Inform the context tree that it needs to lock itself
+	// if it has not done so already.
+	protected void lockTree(SuperNode child) throws ContextServiceException
+	{
+		PersistentContainer container = ((PersistentContainer) getContainer());
+		if (container != null)
+		{
+			container.lockTree(this);
+		}
+	}
+
+	PersistentContainer getPersistentContainer()
+	{
+		return (PersistentContainer) (getContainer());
+	}
+
+	/**
+	* Walks up the parent chain to the root node.
+	* @param child
+	* @return
+	*/
+	PersistentNode getRoot(PersistentNode child)
+	{
+
+		return getPersistentContainer().getRoot(this);
+
+	}
+
+	transient PersistentNode m_root = null;
+
+	void setRoot(PersistentNode iRoot)
+	{
+		m_root = iRoot;
+	}
+
+	/**
+	 * Walks up the parent chain to find the context service.
+	 * @return
+	 */
+	protected PersistentContextService getService()
+	{
+		if (m_service == null)
+		{
+			m_service = getPersistentContainer().getService();
+		}
+		return m_service;
+	}
+	
+	protected void setService( PersistentContextService iService )
+	{
+		m_service = iService;
+	}
+
+	// Factory methods for creating service-specific implemenations:
+
+	protected SuperNode createPartImpl() throws ContextServiceException
+	{
+		return new PersistentPart();
+	}
+
+	protected SuperNode createContainerImpl() throws ContextServiceException
+	{
+		PersistentContainer newContainer = new PersistentContainer();
+		return newContainer;
+	}
+
+	protected DataObject createHandle(Object iObject)
+		throws ContextServiceException
+	{
+		return (DataObject) getService().createLocalDataObject(iObject);
+	}
+	
+	protected void readNodeElements(ObjectInputStream s)
+		throws IOException, ClassNotFoundException
+	{
+		String name = (String) ( s.readObject() );
+		try
+		{
+			setNameFromDeserialization(name);
+		}
+		catch( ContextServiceException e )
+		{
+			throw new IOException(e.toString());
+		}
+	}
+		
+	protected void writeNodeElements( ObjectOutputStream s ) throws IOException
+	{
+		String name = getName();
+		s.writeObject(name);
+	}
+
+//	private static final Logger logger =
+//		Logger.getLogger(PersistentNode.class.getName());
+		
+
+
+
+	private transient PersistentContextService m_service = null;
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentPart.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentPart.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentPart.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentPart.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+/*
+ * Created on Apr 18, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.apache.ode.context.persistent;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+//import java.util.logging.Logger;
+
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.IPart;
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.DataObject;
+import org.apache.ode.context.ejb.BPE_ObjectLocal;
+//import org.apache.ode.context.ejb.EJBDataObject;
+import org.apache.ode.context.nonpersistent.TransientDataObject;
+
+/**
+ * An EJB implementation of IPart
+ * 
+ * @author waterman
+ */
+public class PersistentPart
+	extends PersistentNode
+	implements IPart, Serializable
+{
+
+	// Logging
+//	private static final Logger logger =
+//		Logger.getLogger(EJBDataObject.class.getName());
+
+	/**
+	 * @param name
+	 * @param parent
+	 */
+	PersistentPart(String name, PersistentContainer parent)
+		throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType(PART);
+	}
+
+	PersistentPart(
+		String name,
+		PersistentContainer parent,
+		BPE_ObjectLocal local)
+		throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType(PART);
+	}
+
+	PersistentPart(
+		PersistentPart part,
+		String name,
+		PersistentContainer parent)
+		throws ContextServiceException
+	{
+		super(name, parent);
+		setNodeType(PART);
+	}
+
+	PersistentPart() throws ContextServiceException
+	{
+		super();
+		setNodeType(PART);
+	}
+
+	protected void internalSetObject(Object iObject)
+		throws ContextServiceException
+	{
+		super.internalSetObject(iObject);
+	}
+
+	protected void internalSetObject(IHandle iObjectHandle)
+		throws ContextServiceException
+	{
+		super.internalSetObject(iObjectHandle);
+	}
+
+	// Implement IPart Facade. Any polymorphic enhancement
+	// to the base object should be done via the internal* 
+	// methods, not the facade methods.
+
+	public void setObject(Object iObject)
+		throws ContextServiceException
+	{
+		setReadOnly(false);
+		internalSetObject(iObject);
+		setDirty(this);
+	}
+	
+	public Object getObjectClone() throws ContextServiceException
+	{
+		return internalGetObjectClone();	
+	}
+
+	public void setObjectHandle(IHandle iObjectHandle) throws ContextServiceException
+	{
+		setReadOnly(true);
+		internalSetObject(iObjectHandle);
+		setDirty(this);
+	}
+
+	public Object getObjectForRead() throws ContextServiceException
+	{
+		
+
+		return internalGetObjectForRead();
+	}
+
+	public Object getObjectForReadWrite() throws ContextServiceException
+	{
+		// If the data object associated with the part is fused
+		// to the data tree, then we need to inform the tree
+		// that it is dirty.
+		if ( super.getHandle() instanceof TransientDataObject )
+		{
+			setDirty(this);
+		}
+		return internalGetObjectForReadWrite();
+	}
+	
+	private void writeObject(ObjectOutputStream s) throws IOException
+	{
+		//s.defaultWriteObject();
+		writeNodeElements(s);	
+		s.writeBoolean(getReadOnly());
+		s.writeObject(getHandleForSerialization());
+	}
+
+	private void readObject(ObjectInputStream s)
+		throws IOException, ClassNotFoundException
+	{
+		//s.defaultReadObject();
+		readNodeElements(s);
+		setReadOnly(s.readBoolean());
+		DataObject dataObject = (DataObject) s.readObject();
+		setHandleFromDeserialization(dataObject);
+	}
+
+	// Do not change this value unless you want to enforce
+	// incompatibility with other serialized versions of 
+	// this class.
+	private static final long serialVersionUID = 1L;
+
+	protected DataObject getHandle() throws ContextServiceException
+	{
+		DataObject returnHandle = (DataObject) super.getHandle();
+		if (returnHandle != null)
+		{
+			if (returnHandle instanceof PersistentDataObject)
+			{
+				PersistentDataObject pHandle = 
+				  ( PersistentDataObject ) ( returnHandle );
+
+				if ( pHandle.isHollow())
+				{
+					String locator = pHandle.getLocator();
+					PersistentDataObject solidHandle =
+						(PersistentDataObject) getService()
+							.findPersistentDataObject(
+							locator);
+					pHandle.fill(solidHandle);
+				}
+			}
+		}
+
+
+		return returnHandle;
+	}
+
+	protected void setHandle(DataObject iHandle) throws ContextServiceException
+	{
+		super.setHandle(iHandle);
+	}
+
+}

Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentRootContainer.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentRootContainer.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentRootContainer.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/persistent/PersistentRootContainer.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,384 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.context.persistent;
+
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.INode;
+import org.apache.ode.context.IPart;
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.IDataObject;
+import org.apache.ode.context.base.SuperNode;
+import org.apache.ode.lang.ResourceGetter;
+import org.apache.ode.util.TraceLog;
+
+/**
+ * @author waterman
+ *
+ * Implements the root container for an EJB persisted context.
+ * 
+ * A context tree is persisted as a serialized java object into a BPE_ObjectBean<br>
+ * <br>
+ * The EJBRootContainer holds the EJBContextService which holds the Entity bean.
+ * The EJBRootContainer invokes the entity bean finder methods to acquire data
+ * from the DB.
+ * <br>
+ * Each node ( process instance ) within a business process graph can reference
+ * a single process context tree. Data elements are scoped first by the process
+ * instance node and then by branches of the process context tree. A process
+ * context tree is persisted into the DB with it's primary key set to it's
+ * owning process instance node id. 
+ * 
+ */
+public class PersistentRootContainer extends PersistentContainer
+{
+	
+	static final long serialVersionUID = -8541967577729422105L;
+
+	// Logging
+	private static final Logger logger =
+		Logger.getLogger(PersistentRootContainer.class.getName());
+
+
+	PersistentRootContainer(PersistentContextService service)
+		throws ContextServiceException
+	{
+		super();
+		setService( service );
+	}
+
+	/**
+	 * Create a new persistent context tree off the root
+	 * 
+	 */
+	public IContainer createContainer(String iContainerLocator)
+		throws ContextServiceException
+	{
+		if (TraceLog.enabled())
+			TraceLog.println(
+				this.getClass(),
+				"Inside createContainer() : iContainerLocator = "
+					+ iContainerLocator);
+
+		// A tree may already be memory resident. By memory resident we mean
+		// deserialized from the entity bean and added to the root node as a
+		// child.	
+		IContainer ret = checkLocalCacheForContainer(iContainerLocator);
+
+		if (ret == null)
+		{
+
+			IDataObject dataObject =
+				getService().findPersistentDataObject(iContainerLocator);
+			if (dataObject != null)
+			{
+				PersistentContainer pc =
+					(PersistentContainer) (dataObject.getObjectForRead());
+
+				if (TraceLog.enabled())
+					TraceLog.println(
+						this.getClass(),
+						"Found child container with name = " + pc.getName());
+				initTree( pc, dataObject);
+				return pc;
+			}
+			else
+			{
+				PersistentContainer newContainer =
+					new PersistentContainer();
+				IDataObject newDataObject = getService().createPersistentDataObject(
+					iContainerLocator,
+					newContainer);
+				newDataObject.incrementRefCount();
+				initNewTree(newContainer, newDataObject, iContainerLocator);
+				return newContainer;
+
+			}
+
+		}
+		else
+		{
+			return ret;
+		}
+	}
+
+	/**
+	 * Create a new persistent part off the root container.
+	 * It should be atypical to add a Part to the Root node. Parts should really
+	 * be added to a container.
+	 * 
+	 */
+	public IPart createPart(String iPartLocator) throws ContextServiceException
+	{
+		IPart ret = checkLocalCacheForPart(iPartLocator);
+
+		if (ret == null)
+		{
+
+			IDataObject dataObject = getService().findPersistentDataObject(iPartLocator);
+			if (dataObject != null)
+			{
+				PersistentPart pp =
+					(PersistentPart) (dataObject.getObjectForRead());
+				initTree(pp, dataObject );
+				return  pp;
+			
+			}
+			else
+			{
+				PersistentPart newPart = new PersistentPart();
+				IDataObject newDataObject = getService().createPersistentDataObject(
+					iPartLocator,
+					newPart);
+				initNewTree( newPart, newDataObject, iPartLocator );
+				return newPart;
+			}
+
+		}
+		else
+		{
+			return ret;
+		}
+	}
+	
+	private void initNewTree( PersistentNode iNode, IDataObject iDataObject, String iName ) throws ContextServiceException
+	{
+		iNode.setName(iName);
+		initTree( iNode, iDataObject);
+	}
+	
+	private void initTree( PersistentNode iNode, IDataObject iDataObject ) 
+	  throws ContextServiceException
+	{
+		iNode.init(this);
+		iNode.setMemento(iDataObject);
+	} 
+
+	/** 
+	 * Looks for a child node in the BPEBLOB table where the input param is
+	 * the primary key of the table.
+	 * <P> 
+	 * It is anticipated that IChildLocator is the UUID of a business process
+	 * instance node. Each business process node will have one context tree.
+	 * 
+	 * @see org.apache.ode.context.IContainer#findChild(java.lang.String)
+	 */
+	public INode findChild(String iChildLocator) throws ContextServiceException
+	{
+		PersistentNode ret = checkLocalCacheForContainer(iChildLocator);
+
+		if (ret == null)
+		{
+			IDataObject dataObject = getService().findPersistentDataObject(iChildLocator);
+			if (dataObject != null)
+			{
+			    Object obj = dataObject.getObjectForRead();
+				ret = (PersistentNode) obj;
+				initTree(ret, dataObject);
+			}
+			
+		}
+
+		return ret;
+
+	}
+
+	/** 
+	 * Removes the context tree from the DB
+	 * 
+	 * 
+	 * @see org.apache.ode.context.IContainer#removeChild(java.lang.String)
+	 */
+	public void removeChild(String iChildLocator)
+		throws ContextServiceException
+	{
+		super.internalRemoveChild(iChildLocator);
+		getService().removePersistentDataObject(iChildLocator);	
+	}
+
+	/** 
+	 * You may copy and remove a persistent context tree but you may
+	 * not change the primary key.
+	 * 
+	 * @see org.apache.ode.context.IContainer#moveNode(org.apache.ode.context.INode, java.lang.String)
+	 */
+	public void moveNode(INode iSourceNode, String iTargetName)
+		throws ContextServiceException
+	{
+		ContextServiceException cse = new ContextServiceException("METHOD_UNSUPPORTED",
+			new Object[] {"moveNode",PersistentRootContainer.class.toString()});
+		cse.log(logger,Level.SEVERE);
+		throw cse;
+	}
+
+	/** 
+	 * Returns the cache children.  A more complete solution would
+	 * query the database for all persisted children.
+	 * 
+	 * @see org.apache.ode.context.IContainer#getChildren()
+	 */
+	public Collection getChildren() throws ContextServiceException
+	{
+		return super.getChildren();
+	}
+
+	/** 
+	 * The root container has no parent.
+	 * 
+	 * @see org.apache.ode.context.INode#getParent()
+	 */
+	public IContainer getParent() throws ContextServiceException
+	{
+		// The Root node does not have a parent
+		String msg =
+			ResourceGetter.getFormatted(
+				"METHOD_UNSUPPORTED",
+				new Object[] {
+					"getParent",
+					PersistentRootContainer.class.toString()});
+		logger.log(Level.WARNING, msg);
+		return null;
+	}
+
+	/**
+	 * Return the root node. The root is not really the current instance, it
+	 * is actually an EJBContainer node just beneath the current instance.
+	 * NOTE: EJBRootContainer is not persisteted however all it's children are. 
+	 * @param child
+	 * @return
+	 */
+
+	PersistentNode getRoot(PersistentNode child)
+	{
+		return child;
+	}
+
+	/**
+	 * The static name of the root node.
+	 * 
+	 * @see org.apache.ode.context.INode#getName()
+	 */
+	public String getName()
+	{
+		return "ROOT";
+	}
+
+	/**
+	 * Marks the context tree as dirty. This identifies context trees that
+	 * need to be persisted on {@link IContextService#update() update}
+	 *
+	 */
+	protected void setDirty(SuperNode child) throws ContextServiceException
+	{
+
+
+
+		// The child had better be in the collection.
+		// If not there is something seriously wrong.
+		
+		try
+		{
+			IDataObject dataObject = (IDataObject)( child.getMemento());
+			dataObject.setObject(child);	
+		}
+		catch (ContextServiceException e)
+		{
+			if (TraceLog.enabled())
+				TraceLog.println(
+					this.getClass(),
+					"Inside setDirty() : Exception occurred when attempting to mark data object as dirty : Data Object Locator = "
+						+ child.getName());
+			throw e;
+		}
+		
+
+	}
+	
+
+
+	private PersistentContainer checkLocalCacheForContainer(String iContainerLocator)
+		throws ContextServiceException
+	{
+
+		PersistentContainer ret = null;
+
+		//  see if it is in the local cache
+		INode tmp = super.findChild(iContainerLocator);
+		if (tmp != null)
+		{
+			// Make sure it is a container type
+			if (!(tmp instanceof PersistentContainer))
+			{
+				ContextServiceException cse = new ContextServiceException("TYPE_CAST",new Object[] { "IContainer",
+						((Object) tmp).getClass().getName() });
+				cse.log(logger,Level.SEVERE);
+				throw cse;
+
+			}
+			else
+			{
+				ret = (PersistentContainer) tmp;
+			}
+		}
+
+		return ret;
+	}
+
+	private PersistentPart checkLocalCacheForPart(String iPartLocator)
+		throws ContextServiceException
+	{
+
+		PersistentPart ret = null;
+
+		//  see if it is in the local cache
+		INode tmp = super.findChild(iPartLocator);
+		if (tmp != null)
+		{
+			// Make sure it is a part type
+			if (!(tmp instanceof PersistentPart))
+			{
+				ContextServiceException cse = new ContextServiceException("TYPE_CAST",new Object[] { "IContainer",
+						((Object) tmp).getClass().getName() });
+				cse.log(logger,Level.SEVERE);
+				throw cse;
+
+			}
+			else
+			{
+				ret = (PersistentPart) tmp;
+			}
+		}
+		return ret;
+	}
+
+//	private PersistentNode checkLocalCacheForNode(String iNodeLocator)
+//		throws ContextServiceException
+//	{
+//
+//		//  see if it is in the local cache
+//		return (PersistentNode) super.findChild(iNodeLocator);
+//
+//	}
+	
+	protected void lockTree(SuperNode child) throws ContextServiceException
+	{
+		// TODO: Brian - Lock the tree if it's not already locked.
+	}
+
+}