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 [17/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/IContextService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IContextService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IContextService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IContextService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,79 @@
+/*
+ * 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;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+/**
+ *
+ * The context service is the entry point for interacting with a process context.
+ * An implementation is created through the ContextServiceFactory. There may be
+ * N number of implementations however all implementations fall into two categories.
+ * <BR>
+ * 1) Transient <BR>
+ * 2) Transactional <BR>
+ * <P>
+ * A transient context service implementation will create an in memory context tree and
+ * exists for the life of the reference.
+ * <P>
+ * A transactional context service will create a persistent context tree that is
+ * transactional.
+ * <P>
+ * The root container name is used as the primary key of the context
+ * tree and used to re-acquire a context tree. A transactional context service will join the current transaction of
+ * the current thread.
+ * <BR>
+ * @author lorenz/waterman
+ *
+ * @see org.apache.ode.context.base.ContextServiceFactory
+ * @see org.apache.ode.context.IContainer
+ */
+
+public interface IContextService
+{
+
+ /**
+ *
+ * @see IPart#setObject(IHandle)
+ *
+ * @param iObject an object that is independant of the context tree
+ * @return a handle to the iObject
+ * @throws ContextServiceException
+ * @throws UnsupportedOperationException
+ */
+ IHandle createObjectHandle( Object iObject ) throws ContextServiceException;
+
+ /**
+ * This is the entry point to a process context tree. Once the root container
+ * has been acquired, specific subtrees can be queried by name.
+ *
+ * @see IContainer#findChild(String)
+ *
+ * @return the root container
+ * @throws ContextServiceException
+ */
+ IContainer getRoot() throws ContextServiceException;
+ /**
+ * Allows an implementation to initialize/acquire any resources.
+ *
+ * @param props - holds initialization properties
+ * @throws ContextServiceException
+ */
+ void init(BPEProperties props, UUIDService us)throws ContextServiceException;
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IHandle.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IHandle.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IHandle.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IHandle.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+
+public interface IHandle extends Serializable
+{
+ static final long serialVersionUID = -8452451531253548434L;
+
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/INode.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/INode.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/INode.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/INode.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import org.apache.ode.context.base.ContextServiceException;
+
+/**
+ *
+ * The base class for all nodes within the context tree.
+ *
+* @author lorenz/waterman
+ */
+public interface INode
+{
+ /**
+ * Acquire a reference to the node's parent container. A node may only
+ * belong to one parent.
+ *
+ * @return a parent container
+ */
+ public IContainer getContainer() throws ContextServiceException;
+
+ /**
+ * The node name must be unique within the scope of it's parent.
+ *
+ * @return the name of the node
+ */
+ public String getName() throws ContextServiceException;
+
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IPart.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IPart.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IPart.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/IPart.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;
+
+import org.apache.ode.context.base.ContextServiceException;
+
+/**
+ * IPart holds a data object that will be scoped within the process context
+ * tree. IPart can hold either the data object itself or a reference to a data
+ * object ( {@link IHandle IHandle} ).
+ * <P>
+ * IParts are created by {@link IContainer#createPart(String) IContainer.createPart}
+ *
+ * @author lorenz/waterman
+ */
+public interface IPart extends INode
+{
+ /**
+ * Sets the object into the process context tree. The object becomes part
+ * of the tree. When the context tree is serialized the data object is serialized
+ * as part of the tree.
+ *
+ * @param iObject a {@link Serializable Serializable} Java Object
+ * @param iTreatAsReadOnly is only relevent if iObject supports the {@link IAccessControl IAccessControl} interface
+ */
+ public void setObject( Object iObject) throws ContextServiceException;
+ /**
+ * Sets an object reference into the process context tree. A reference to
+ * a data object becomes part of the tree. When the context tree is
+ * serialized a data object reference is serialized as part of the tree.
+ * <P>
+ * This is not a supported method for transient implementations. IHandle only
+ * makes sense for transactional persistance mechanisms.
+ *
+ * @param iObjectHandle as acquired from {@link IContextService#createObjectHandle(Object) IContextService.createObjectHandle}
+ *
+ */
+ public void setObjectHandle( IHandle iObjectHandle ) throws ContextServiceException;
+ /**
+ * A read only copy of the data object. Because Java does not support a const
+ * attribute the client application is responsible for enforcing the readonly
+ * property. If the client application mutates the returned object and the
+ * object is shared by other IPart nodes, the user is aware the data will
+ * change for all referencing IPart nodes.
+ *
+ * @return the data object as inserted into the context via {@link #setObject(IHandle) setObject(IHandle)} or {@link #setObject(Object, boolean) setObject(Object)}
+ * @throws ContextServiceException
+ */
+ public Object getObjectForRead() throws ContextServiceException;
+ /**
+ * A writeable data object. A deep copy of the object is returned. To support this
+ * feature the data object must implement the {@link IAccessControl IAccessControl} and {@link ICloneable ICloneable}
+ * interfaces. If the data object does not support the above interfaces an
+ * exception is thrown.
+ *
+ * @return the data object as inserted into the context via {@link #setObject(IHandle) setObject(IHandle)} or {@link #setObject(Object, boolean) setObject(Object)}
+ */
+ public Object getObjectForReadWrite() throws ContextServiceException;
+ public Object getObjectClone() throws ContextServiceException;
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,25 @@
+/*
+ * 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.base;
+
+import org.apache.ode.context.IContextService;
+
+public abstract class ContextService implements IContextService
+{
+
+
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceException.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceException.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceException.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceException.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,60 @@
+/*
+ * 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 9, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.apache.ode.context.base;
+
+
+import org.apache.ode.util.BPException;
+
+/**
+ * The default context service exception.
+ * <P>
+ * When the exception is instantiated it will log the message into the
+ * log file as SEVERE.
+ *
+ * @author waterman
+ */
+public class ContextServiceException extends BPException
+{
+
+ static final long serialVersionUID = -6779320869553670322L;
+
+ /**
+ * @param message_id
+ * @param msgParams
+ */
+ public ContextServiceException(String message_id, Object[] msgParams) {
+ super(message_id, msgParams);
+ }
+
+ /**
+ * @param message_id
+ * @param msgParams
+ * @param cause
+ */
+ public ContextServiceException(
+ String message_id,
+ Object[] msgParams,
+ Throwable cause) {
+ super(message_id, msgParams, cause);
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextServiceFactory.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.base;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.ode.context.IContextService;
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+public class ContextServiceFactory {
+ private static Logger logger =
+ Logger.getLogger(ContextServiceFactory.class.getName());
+
+ public static IContextService createContextService(
+ BPEProperties props,
+ UUIDService us)
+ throws ContextServiceException {
+ String persistence =
+ props.getProperty(BPEProperties.CTX_PERSISTENCE_KEY);
+ if (persistence.equals(BPEProperties.CTX_TRANSIENT)) {
+ return createContextService(props, us, ContextTypeEnum.TRANSIENT);
+ } else {
+ return createContextService(props, us, ContextTypeEnum.PERSISTENT);
+
+ }
+
+ }
+
+ public static IContextService createContextService(
+ BPEProperties props,
+ UUIDService us,
+ ContextTypeEnum type)
+ throws ContextServiceException {
+ IContextService cs = null;
+ String className = null;
+
+ try {
+
+ if (type == ContextTypeEnum.TRANSIENT) {
+ className = props.getTransientContextServiceClass();
+ } else {
+ if (type == ContextTypeEnum.PERSISTENT) {
+ className = props.getPersistentContextServiceClass();
+ }
+ }
+
+ // load the implementation
+ Class instClass = java.lang.Class.forName(className);
+ // try to instantiate the subclass
+ cs = (IContextService) instClass.newInstance();
+ // initialize
+ cs.init(props, us);
+
+ } catch (ClassNotFoundException e) {
+ ContextServiceException bpx =
+ new ContextServiceException(
+ "CLASS_NOT_FOUND",
+ new Object[] { className });
+ bpx.log(logger, Level.SEVERE);
+ throw bpx;
+ } catch (InstantiationException e) {
+ ContextServiceException bpx =
+ new ContextServiceException(
+ "NATIVE_EXCEPTION",
+ new Object[] { "InstantiationException" },
+ e);
+ bpx.log(logger, Level.SEVERE);
+ throw bpx;
+ } catch (IllegalAccessException e) {
+ ContextServiceException bpx =
+ new ContextServiceException(
+ "NATIVE_EXCEPTION",
+ new Object[] { "IllegalAccessException" },
+ e);
+ bpx.log(logger, Level.SEVERE);
+ throw bpx;
+ }
+
+ return cs;
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextTypeEnum.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextTypeEnum.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextTypeEnum.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextTypeEnum.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,71 @@
+/*
+ * 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.base;
+
+
+/** An enumeration of the possible process states:
+ * <P>
+ * UNSTARTED,STARTED,PAUSED,FINISHED,TERMINATED */
+public class ContextTypeEnum
+{
+ private String value;
+ private static final String TRANSIENT_VALUE = "TRANSIENT";
+ private static final String PERSISTENT_VALUE = "PERSISTENT";
+
+ private ContextTypeEnum()
+ {
+ // Prevent non-class create
+ }
+
+ /** @param */
+ private ContextTypeEnum(String value)
+ {
+ this.value = value;
+ }
+
+ public static final ContextTypeEnum TRANSIENT = new ContextTypeEnum(TRANSIENT_VALUE);
+ public static final ContextTypeEnum PERSISTENT = new ContextTypeEnum(PERSISTENT_VALUE);
+
+ public java.lang.String getValue()
+ {
+ return value;
+ }
+
+
+ /** Because this object will be used over a remote interface the default implementation based on object reference will be over written. */
+ public int hashCode()
+ {
+ return value.hashCode();
+ }
+
+ /** Because this object will be used over a remote interface the default implementation based on object reference will be over written.
+ *
+ * @param obj */
+ public boolean equals(Object obj)
+ {
+ if ( obj instanceof ContextTypeEnum ) {
+ return value.equals(((ContextTypeEnum)obj).value);
+ }
+ return false;
+ }
+
+ public static ContextTypeEnum getType(String value) {
+ if ( value.equals(TRANSIENT_VALUE) ) return TRANSIENT;
+ if ( value.equals(PERSISTENT_VALUE) ) return PERSISTENT;
+ return null;
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextUtil.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextUtil.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextUtil.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/ContextUtil.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,48 @@
+/*
+ * 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.base;
+
+import org.apache.ode.context.IAccessControl;
+import org.apache.ode.context.ICloneable;
+
+public class ContextUtil
+{
+ public static void setReadOnly( Object iObject, boolean iTreatAsReadOnly )
+ {
+ if ( iObject instanceof IAccessControl )
+ {
+ IAccessControl ac = ( IAccessControl ) ( iObject );
+ ac.setReadOnly( true );
+ }
+ }
+
+ public static Object cloneObject( Object iObject ) throws ContextServiceException
+ {
+ if ( iObject == null )
+ {
+ return null;
+ }
+
+ if ( iObject instanceof String )
+ {
+ return new String( (String) ( iObject ) );
+ }
+
+ ICloneable cloneable = ( ICloneable ) ( iObject );
+ return cloneable.cloneObject();
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/DataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/DataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/DataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/DataObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,25 @@
+/*
+ * 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.base;
+
+import org.apache.ode.context.IHandle;
+
+public abstract class DataObject implements IHandle, IDataObject
+{
+
+ static final long serialVersionUID = 6837703006545093065L;
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,26 @@
+/*
+ * 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.base;
+
+public interface IDataObject
+{
+ public void decrementRefCount() throws ContextServiceException;
+ public void incrementRefCount() throws ContextServiceException;
+ public long getRefCount() throws ContextServiceException;
+ public void setObject(Object obj) throws ContextServiceException;
+ public Object getObjectForRead() throws ContextServiceException;
+ public Object getObjectForReadWrite() throws ContextServiceException;
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObjectFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObjectFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/IDataObjectFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,29 @@
+/*
+ * 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.base;
+
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.uuid.UUIDService;
+
+public interface IDataObjectFactory
+{
+ public void init( BPEProperties iProperties, UUIDService us ) throws ContextServiceException;
+ public IDataObject find(String iLocator ) throws ContextServiceException;
+ public IDataObject create(String iLocator, Object iData) throws ContextServiceException;
+ public IDataObject create(Object iData) throws ContextServiceException;
+ public void remove( String iLocator ) throws ContextServiceException;
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/INoThrowDataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/INoThrowDataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/INoThrowDataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/INoThrowDataObject.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.base;
+
+/**
+ * This class is a mirror of IDataObject which does not throw exceptions.
+ * ContextServiceException relies on the jdk1.4 logger. Jaguar
+ * manager would not deploy beans which throw ContextServiceException
+ * because jaguar manager requires jdk1.3 for normal operation.
+ * Jaguar manager is buggy when run with jdk1.4.
+ */
+public interface INoThrowDataObject
+{
+ public void decrementRefCount();
+ public void incrementRefCount();
+ public long getRefCount();
+ public void setObject(Object obj);
+ public Object getObjectForRead();
+ public Object getObjectForReadWrite();
+ //public Object getObjectForReadWriteWithLock();
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/SuperNode.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/SuperNode.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/SuperNode.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/SuperNode.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,497 @@
+/*
+ * 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.base;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.ode.context.IAccessControl;
+import org.apache.ode.context.IContainer;
+import org.apache.ode.context.IHandle;
+import org.apache.ode.context.INode;
+import org.apache.ode.context.IPart;
+
+public abstract class SuperNode implements INode, Serializable, IAccessControl
+{
+ static final long serialVersionUID = -6214541427211735637L;
+
+ protected SuperNode()
+ {
+ }
+
+ protected SuperNode(String iName, SuperNode iContainer)
+ throws ContextServiceException
+ {
+ init(iName, iContainer);
+ }
+
+ public void init(String iName, SuperNode iContainer)
+ throws ContextServiceException
+ {
+ setName(iName);
+ setContainer(iContainer);
+ }
+
+ // Begin implementing methods required for INode implementation
+
+ protected void setContainer(SuperNode iContainer)
+ throws ContextServiceException
+ {
+ if (iContainer != null)
+ {
+ INode child = iContainer.internalFindChild(this.getName());
+ if ( (child != null) && ( child != this ))
+ {
+ iContainer.removeNode(this.getName());
+ }
+ iContainer.addChild(this);
+ }
+ }
+
+ protected void detach() throws ContextServiceException
+ {
+ SuperNode container = (SuperNode) (getContainer());
+ if (container != null)
+ {
+ container.detachChildNode(this);
+ }
+ }
+
+ protected void setName(String iName) throws ContextServiceException
+ {
+ m_name = iName;
+ }
+
+ /**
+ * @see org.apache.ode.context.INode#getParent()
+ */
+ public IContainer getContainer()
+ {
+ return (IContainer) (m_parent);
+ }
+
+ /**
+ * @see org.apache.ode.context.INode#getName()
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ // Begin implementing part methods
+
+ protected void internalSetObject(Object iDataObject)
+ throws ContextServiceException
+ {
+ // Create a new handle to wrap the new data object
+ DataObject newHandle = createHandle(iDataObject);
+ setHandle(newHandle);
+ }
+
+ protected void internalSetObject(IHandle iObjectHandle)
+ throws ContextServiceException
+ {
+ setHandle((DataObject) (iObjectHandle));
+ }
+
+ protected Object internalGetObjectForRead() throws ContextServiceException
+ {
+ DataObject handle = getHandle();
+ if ( handle == null )
+ {
+ return null;
+ }
+ Object returnObject = handle.getObjectForRead();
+ ContextUtil.setReadOnly(returnObject, true);
+ return returnObject;
+ }
+
+ protected void cloneUponWrite() throws ContextServiceException
+ {
+ // Determine whether or not we need to clone the dataobject. If the dataobject has a reference count > 1. We need to clone the
+ // dataobject in this case because we don't want changes to one part to
+ // affect other parts. This the copy-on-write behaviour described in the design.
+ if ( getHandle() == null ) {
+ return;
+ }
+ boolean weNeedToCloneDataObject =
+ (getHandle().getRefCount() > 1 || (getReadOnly() == true));
+
+ if (weNeedToCloneDataObject)
+ {
+
+ Object newDataObject =
+ ContextUtil.cloneObject(getRawObjectForRead());
+
+ internalSetObject(newDataObject);
+
+ setReadOnly(false);
+
+ setDirty(this);
+ }
+ }
+
+ protected Object internalGetObjectClone() throws ContextServiceException
+ {
+ return ContextUtil.cloneObject(getRawObjectForRead());
+ }
+
+ protected Object internalGetObjectForReadWrite()
+ throws ContextServiceException
+ {
+
+ cloneUponWrite();
+ return getRawObjectForReadWrite();
+
+ }
+
+ protected DataObject getHandle() throws ContextServiceException
+ {
+ return m_handle;
+ }
+
+ protected DataObject getHandleForSerialization()
+ {
+ return m_handle;
+ }
+
+ protected void setHandleFromDeserialization( DataObject iHandle )
+ {
+ m_handle = iHandle;
+ }
+
+ protected Object getRawObjectForRead() throws ContextServiceException
+ {
+ return getHandle().getObjectForRead();
+ }
+
+ public Object getRawObjectForReadWrite() throws ContextServiceException
+ {
+ if ( getHandle() == null ) {
+ return null;
+ }
+ Object rawObject = getHandle().getObjectForReadWrite();
+ ContextUtil.setReadOnly(rawObject, false);
+ return rawObject;
+ }
+
+ protected void setHandle(DataObject iHandle) throws ContextServiceException
+ {
+ if (m_handle != null)
+ {
+ // Let other users of the current handle know that we are no longer using it
+ // by decrementing the current handle's reference count.
+ getHandle().decrementRefCount();
+ }
+ m_handle = iHandle;
+ if (m_handle != null)
+ {
+ m_handle.incrementRefCount();
+ }
+
+ }
+
+ protected abstract DataObject createHandle(Object iObject)
+ throws ContextServiceException;
+
+ // Begin implementing container methods
+
+ protected abstract SuperNode createPartImpl()
+ throws ContextServiceException;
+
+ protected abstract SuperNode createContainerImpl()
+ throws ContextServiceException;
+
+ /**
+ * @see org.apache.ode.context.IContainer#createContainer(java.lang.String)
+ */
+ protected IContainer internalCreateContainer(String iContainerLocator)
+ throws ContextServiceException
+ {
+ SuperNode ret = (SuperNode) (getChild(iContainerLocator));
+ if (ret == null)
+ {
+ ret = createContainerImpl();
+ ret.init(iContainerLocator, this);
+ }
+ else
+ {
+ if (!(ret instanceof IContainer))
+ {
+ ContextServiceException cse = new ContextServiceException("TYPE_CAST",new Object[] { "IContainer", "IPart" });
+ cse.log(logger,Level.SEVERE);
+ throw cse;
+ }
+ }
+ return (IContainer) ret;
+
+ }
+
+ /**
+ * @see org.apache.ode.context.IContainer#createPart(java.lang.String)
+ */
+ protected IPart internalCreatePart(String iPartLocator)
+ throws ContextServiceException
+ {
+ SuperNode ret = (SuperNode) (getChild(iPartLocator));
+ if (ret == null)
+ {
+ ret = createPartImpl();
+ ret.init(iPartLocator, this);
+ }
+ else
+ {
+ if (!(ret instanceof IPart))
+ {
+ ContextServiceException cse = new ContextServiceException("TYPE_CAST",new Object[] { "IContainer", "IPart" });
+ cse.log(logger,Level.SEVERE);
+ throw cse;
+ }
+ }
+ return (IPart) ret;
+
+ }
+
+ /**
+ * @see org.apache.ode.context.IContainer#findChild(java.lang.String)
+ */
+ protected INode internalFindChild(String iChildLocator)
+ throws ContextServiceException
+ {
+ return getChild(iChildLocator);
+ }
+
+ /**
+ * @see org.apache.ode.context.IContainer#removeChild(java.lang.String)
+ */
+ protected void internalRemoveChild(String iChildLocator)
+ throws ContextServiceException
+ {
+
+ removeNode(iChildLocator);
+ }
+
+ protected void removeNotify() throws ContextServiceException
+ {
+ DataObject dataObject = (DataObject) (getHandle());
+ if (dataObject != null)
+ {
+ dataObject.decrementRefCount();
+ }
+ if (m_childCollection != null)
+ {
+ Iterator iterator = m_childCollection.values().iterator();
+ while (iterator.hasNext())
+ {
+ SuperNode sn = (SuperNode) (iterator.next());
+ sn.removeNotify();
+ }
+ }
+
+ }
+
+ /**
+ * @see org.apache.ode.context.IContainer#moveNode(org.apache.ode.context.INode, java.lang.String)
+ */
+ protected void internalMoveNode(INode iSourceNode, String iTargetName)
+ throws ContextServiceException
+ {
+ SuperNode aNode = (SuperNode) (iSourceNode);
+
+ // Detach the source node from it's parent container.
+ aNode.detach();
+
+ // Change the name of the node.
+ aNode.setName(iTargetName);
+
+ aNode.setContainer(this);
+ }
+
+ protected void detachChildNode(SuperNode iChild)
+ throws ContextServiceException
+ {
+ iChild.setContainer(null);
+ getInternalChildCollection().remove(iChild.getName());
+ }
+
+ /**
+ * @see org.apache.ode.context.IContainer#getChildren()
+ */
+ protected Collection internalGetChildren() throws ContextServiceException
+ {
+ // Don't return m_childCollection because doing so
+ // would break encapsulation.
+ return Collections.unmodifiableCollection(
+ getInternalChildCollection().values());
+ }
+
+ protected void addChild(SuperNode iNode) throws ContextServiceException
+ {
+ getInternalChildCollection().put(iNode.getName(), iNode);
+ iNode.setParent(this);
+
+ }
+
+ private void setParent( SuperNode iParent)
+ {
+ m_parent = iParent;
+ }
+
+ private SuperNode getChild(String iChildLocator)
+ {
+ if ( m_childCollection != null )
+ {
+ return (SuperNode) m_childCollection.get(iChildLocator);
+ }
+ return null;
+ }
+
+ private void removeNode(String iChildLocator)
+ throws ContextServiceException
+ {
+ SuperNode childNode = (SuperNode) getChild(iChildLocator);
+ if (childNode != null)
+ {
+ childNode.removeNotify();
+ }
+
+ getInternalChildCollection().remove(iChildLocator);
+ }
+
+ protected void internalCopyNode(INode iSourceNode, String iTargetName)
+ throws ContextServiceException
+ {
+ SuperNode sourceNode = (SuperNode) (iSourceNode);
+ if (sourceNode instanceof IPart)
+ {
+ copyPart(sourceNode, iTargetName);
+ }
+ else
+ {
+ copyContainer(sourceNode, iTargetName);
+ }
+
+ }
+
+ protected void copyPart(SuperNode iPart, String iTargetName)
+ throws ContextServiceException
+ {
+ SuperNode newPart = createPartImpl();
+ newPart.setName(iTargetName);
+ SuperNode sourcePart = iPart;
+ DataObject dataObject = (DataObject) (sourcePart.getHandle());
+ newPart.setHandle(dataObject);
+ newPart.setContainer(this);
+ }
+
+ protected void copyContainer(SuperNode iContainer, String iTargetName)
+ throws ContextServiceException
+ {
+// SuperNode container = (SuperNode) (iContainer);
+ SuperNode newContainer = createContainerImpl();
+ newContainer.setName(iTargetName);
+ Iterator iterator = iContainer.internalGetChildren().iterator();
+ while (iterator.hasNext())
+ {
+ Object next = iterator.next();
+ INode node = (INode) (next);
+ newContainer.internalCopyNode(node, node.getName());
+ }
+
+ newContainer.setContainer(this);
+ }
+
+ protected HashMap getInternalChildCollection()
+ {
+ if (m_childCollection == null)
+ {
+ m_childCollection = new HashMap();
+ }
+ return m_childCollection;
+ }
+
+ protected Collection getInternalChildCollectionForSerialization()
+ {
+ if ( m_childCollection != null )
+ {
+ return m_childCollection.values();
+ }
+ return null;
+ }
+
+ public int getNodeType()
+ {
+ return m_nodeType;
+ }
+
+ protected void setNodeType(int iNodeType) throws ContextServiceException
+ {
+ m_nodeType = iNodeType;
+ }
+
+ protected void setDirty(SuperNode iNode) throws ContextServiceException
+ {
+ }
+
+ // Access Control method
+ public void setReadOnly(boolean iIsReadOnly)
+ {
+ m_isReadOnly = iIsReadOnly;
+ }
+
+ // Acess control method
+ public boolean getReadOnly()
+ {
+ return m_isReadOnly;
+ }
+
+
+ // The memento accessor and mutator methods allow for the
+ // storage and retrieval of an object which may be
+ // useful to the context service.
+
+ public void setMemento( Object iMemento)
+ {
+ m_memento = iMemento;
+ }
+
+ public Object getMemento()
+ {
+ return m_memento;
+ }
+
+
+
+ transient private Object m_memento;
+ transient private SuperNode m_parent = null;
+ transient private int m_nodeType = PART;
+ transient private HashMap m_childCollection = null;
+ transient private String m_name = null;
+ transient protected boolean m_isReadOnly = false;
+ transient protected DataObject m_handle = null;
+
+ public static final int PART = 1;
+ public static final int CONTAINER = 2;
+
+ private static final Logger logger =
+ Logger.getLogger(SuperNode.class.getName());
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/TestUtil.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/TestUtil.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/TestUtil.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/base/TestUtil.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.base;
+
+import org.apache.ode.context.INode;
+import org.apache.ode.context.ejb.EJBDataObject;
+
+// A little class that lets the test routines get at protected data. to
+// check things like reference count.
+public class TestUtil
+{
+ public static long getRefCount( INode node ) throws Exception
+ {
+ SuperNode sn = ( SuperNode ) ( node );
+ if ( sn.getHandle() == null ) {
+ return 0;
+ }
+ return sn.getHandle().getRefCount();
+ }
+
+ public static String getDataObjectImp( INode node ) throws Exception
+ {
+ SuperNode sn = ( SuperNode ) ( node );
+ if ( sn.getHandle() == null ) {
+ return null;
+ }
+ return sn.getHandle().getClass().getName();
+ }
+
+ public static String getDataObjectID( INode node ) throws Exception
+ {
+ SuperNode sn = ( SuperNode ) ( node );
+ DataObject handle = sn.getHandle();
+ if ( handle instanceof EJBDataObject )
+ {
+ EJBDataObject edo = ( EJBDataObject ) ( handle );
+ return edo.getLocator();
+ }
+ else
+ {
+ return "N/A";
+ }
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_CMPObjectBean.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_CMPObjectBean.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_CMPObjectBean.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_CMPObjectBean.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,623 @@
+/*
+ * 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.
+*/
+/***********************************************************************
+ * Module: BPE_CMPBLOBBean.java
+ * Author: waterman
+ * Purpose: Defines the Class BPE_CMPBLOBBean
+ ***********************************************************************/
+
+package org.apache.ode.context.ejb;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.EJBException;
+import javax.ejb.EntityContext;
+
+import org.apache.ode.context.base.INoThrowDataObject;
+import org.apache.ode.util.ObjectInputStreamContextClassLoader;
+import org.apache.ode.util.TraceLog;
+
+/**
+ * This is the CMP Object bean. It is responsible for
+ * persisting a byte array which is tagged with an updatecount
+ * and a reference count. Additionally it maitains a cached
+ * version of the object created by deserializing the byte
+ * array. This caching has a significant performance impact
+ * since deserializing the object graph is expensive.
+ *
+ * @ejb.bean
+ * type="CMP"
+ * name="BPE_CMPBLOB"
+ * jndi-name="BPE/BPE_CMPBLOB"
+ * local-jndi-name="BPE/BPE_CMPBLOB"
+ * view-type="local"
+ * cmp-version="2.x"
+ * schema="CMPBLOB"
+ * primkey-field="id"
+ *
+ * @ejb.persistence
+ * table-name="BPE_BPE_CMPBLOB"
+ *
+ * @ejb.transaction type="Required"
+ *
+ * @ejb.pk
+ * class="java.lang.String"
+ * @ejb.interface
+ * generate="false"
+ *
+ * @ejb.home
+ * local-class="org.apache.ode.context.ejb.BPE_ObjectLocalHome"
+ * @ejb.interface
+ * local-class="org.apache.ode.context.ejb.BPE_ObjectLocal"
+ *
+ * @jboss.table-name table-name="CMPBLOB"
+ *
+ *
+ *
+ */
+
+public abstract class BPE_CMPObjectBean
+implements javax.ejb.EntityBean, INoThrowDataObject {
+
+ static final long serialVersionUID = -6675363464240432410L;
+
+ /**
+ *
+ *@ejb.interface-method
+ * @ejb.persistence column-name="id"
+ * @ejb.pk-field
+ */
+ public abstract java.lang.String getId();
+ /**
+ * @ejb.interface-method
+ * @param id
+ */
+ public abstract void setId(java.lang.String id);
+
+ /**
+ *
+ *@ejb.interface-method
+ * @ejb.persistence column-name="data"
+ */
+ public abstract byte[] getData();
+
+ /**
+ * @ejb.interface-method
+ */
+ public abstract void setData(byte[] data);
+
+ /**
+ *
+ *@ejb.interface-method
+ * @ejb.persistence column-name="refcount"
+ */
+ public abstract long getRefCount();
+ /**
+ * @ejb.interface-method
+ */
+ public abstract void setRefCount(long refCount);
+
+ /**
+ *
+ *@ejb.interface-method
+ * @ejb.persistence column-name="dataupdatecount"
+ */
+ public abstract long getDataUpdateCount();
+ /**
+ * @ejb.interface-method
+ */
+ public abstract void setDataUpdateCount(long updateCount);
+
+
+ /**
+ * Constructor.
+ */
+ public BPE_CMPObjectBean() {
+ }
+
+ /** A container invokes this method when the instance is taken out of the pool
+ * of available instances to become associated with a specific EJB object.
+ *
+ * @exception javax.ejb.EJBException */
+ public void ejbActivate() throws javax.ejb.EJBException
+ {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::ejbActivate()");
+ init();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::ejbActivate()");
+ }
+
+ /** A container invokes this method to instruct the instance to synchronize its state.
+ *
+ * @exception javax.ejb.EJBException */
+ public void ejbLoad() throws javax.ejb.EJBException
+ {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::ejbLoad()");
+ restoreCachedState();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::ejbLoad()");
+ }
+
+ /**
+ * It's possible that the deserialized object corresponding to
+ * the blob is already held in cache. If there is an object
+ * in cache with the same id and the same updatecount as this CMP
+ * then use the object held in the cache rather than performing
+ * and expensive deserialization of the object from the byte array.
+ */
+ private void restoreCachedState( )
+ {
+ String id = getId();
+ long updateCount = getDataUpdateCount();
+
+ prepareContextClassLoader();
+ CachedObject cobj = ( CachedObject )
+ objectCache.get( id );
+
+ if ( ( cobj != null ) &&
+ ( cobj.getUpdateCount() == updateCount ) )
+ {
+ m_object = cobj.getObject();
+
+ m_objectStale = false;
+ }
+ else
+ {
+ m_objectStale = true;
+ }
+ m_currentDataUpdateCount = updateCount;
+ }
+
+
+ /**
+ * The caching mechanism assumes that the ContextClassLoader
+ * is set on the current thread. EAServer does not always
+ * set the context classloader, so we need to check here and
+ * set it if it is not set.
+ */
+ private void prepareContextClassLoader()
+ {
+
+ ClassLoader contextClassLoader =
+ Thread.currentThread().getContextClassLoader();
+ if ( contextClassLoader == null )
+ {
+ Thread.currentThread().
+ setContextClassLoader(m_contextClassLoader);
+ }
+ }
+
+ /**
+ * Cache the deserialized object associated with the current CMP. The
+ * cached object may be recalled at a later date in order to avoid
+ * an expensive deserialization of the object from a byte array.
+ */
+ private void cacheState()
+ {
+ prepareContextClassLoader();
+ CachedObject co = new CachedObject(m_object, getDataUpdateCount());
+ objectCache.put( getId(), co );
+ }
+
+ /** A container invokes this method on an instance before the instance becomes
+ * disassociated with a specific EJB object.
+ *
+ * @exception javax.ejb.EJBException */
+ public void ejbPassivate() throws javax.ejb.EJBException
+ {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::ejbPassivate()");
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::ejbPassivate()");
+ }
+
+ /** A container invokes this method before it removes the EJB object that is currently
+ * associated with the instance.
+ *
+ * @exception javax.ejb.RemoveException
+ * @exception javax.ejb.EJBException */
+ public void ejbRemove()
+ throws javax.ejb.RemoveException, javax.ejb.EJBException
+ {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::ejbRemove()");
+ prepareContextClassLoader();
+ objectCache.remove( getId() );
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::ejbRemove()");
+ }
+
+ /** A container invokes this method to instruct the instance to synchronize its state
+ * by storing it to the underlying database.
+ *
+ * @exception javax.ejb.EJBException */
+ public void ejbStore() throws javax.ejb.EJBException
+ {
+
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::ejbStore()");
+ // Update the CMP store only if the data has changed.
+ if (isDirty()) {
+ // We don't want to modify the update count if
+ // it was already set when the object
+ // was inserted via ejbCreate().
+
+ if (getShouldIncrementUpdateCountOnStore() == true) {
+ m_currentDataUpdateCount++;
+ internalSetDataUpdateCount(m_currentDataUpdateCount++);
+ } else {
+ setShouldIncrementUpdateCountOnStore( true );
+ }
+
+
+ marshalToStorage();
+ internalClearDirtyDataBit();
+ }
+
+
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::ejbStore()");
+
+ }
+
+ /**
+ * Set the update count associated with the CMP. The update count
+ * is used to distinguish between cached versions of the deserialized
+ * object. The updatecount held in the database represents the freshest
+ * version. An updatecount different from the one held in the database
+ * indicates a stale object which must deserialized from the byte
+ * array contained in the database.
+ * @param dataUpdateCount
+ */
+ private void internalSetDataUpdateCount( long dataUpdateCount )
+ {
+ long generatedUpdateCount = ObjectCache.GetUpdateCount( dataUpdateCount );
+ setDataUpdateCount( generatedUpdateCount );
+ }
+
+ /**
+ * Serialize the object into a byte array in preparation for storage
+ * in the database.
+ *
+ * @return
+ * @throws IOException
+ */
+ private byte[] getObjectAsByteArray() throws IOException
+ {
+ // Serialize the java object
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::getObjectAsByteArray()");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(internalGetObject());
+ oos.close();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::getObjectAsByteArray()");
+ return baos.toByteArray();
+ }
+
+ /**
+ * Convert the object into a byte array and store it in the database.
+ */
+ protected void marshalToStorage() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::marshalToStorage()");
+ try {
+ byte[] byteArray = getObjectAsByteArray();
+ setData(byteArray);
+ cacheState();
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, "", e);
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::marshalToStorage()");
+ throw new EJBException(e);
+ }
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::marshalToStorage()");
+ }
+
+ /** Set the associated entity context.
+ *
+ * @param ctx
+ * @exception javax.ejb.EJBException */
+ public void setEntityContext(EntityContext ctx)
+ throws javax.ejb.EJBException
+ {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::setEntityContext(EntityContext ctx)");
+ //this.ejbContext = ctx;
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::setEntityContext(EntityContext ctx)");
+ }
+
+ /** Unset the associated entity context.
+ *
+ * @exception javax.ejb.EJBException */
+ public void unsetEntityContext() throws javax.ejb.EJBException
+ {
+ if (TraceLog.enabled()) enterTrace("unsetEntityContext()");
+ //this.ejbContext = null;
+ if (TraceLog.enabled()) exitTrace("unsetEntityContext()");
+ }
+
+ /**
+ * Create a new entity and initialize it's members.
+ * @param id
+ * @param iObject
+ * @return
+ * @throws javax.ejb.CreateException
+ */
+ public String ejbCreate(java.lang.String id, Object iObject)
+ throws javax.ejb.CreateException
+ {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::BPE_CMPObjectBean::ejbCreate(java.lang.String id, Object iObject)");
+
+
+ init();
+ setId(id);
+ internalSetDataUpdateCount(1);
+ setShouldIncrementUpdateCountOnStore(false);
+ setObjectNow(iObject);
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::BPE_CMPObjectBean::ejbCreate(java.lang.String id, Object iObject)");
+
+ return id;
+ }
+
+ /**
+ * Assign default values to members.
+ */
+ private void init() {
+ m_object = null;
+ m_currentDataUpdateCount = -1;
+ m_dirtyDataBit = false;
+ m_objectStale = true;
+ m_shouldIncrementUpdateCountOnStore = true;
+ if ( objectCache == null )
+ {
+ objectCache = new ObjectCache();
+ }
+ }
+
+ /** @param id
+ * @param data */
+ public void ejbPostCreate(java.lang.String id, Object iObject) {
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.apache.ode.context.base.INoThrowDataObject#decrementRefCount()
+ */
+ public void decrementRefCount() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::decrementRefCount()");
+ setRefCount(getRefCount() - 1);
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::decrementRefCount()");
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ode.context.base.INoThrowDataObject#incrementRefCount()
+ */
+ public void incrementRefCount() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::incrementRefCount()");
+
+ setRefCount(getRefCount() + 1);
+
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::incrementRefCount()");
+ }
+
+ /**
+ * Returns true if the deserialized object is
+ * stale and needs to be recreated.
+ */
+ private boolean isObjectStale() {
+ return m_objectStale;
+ }
+
+ /**
+ * Returns a fresh deserialized java object. Performs
+ * deserialization as necessary.
+ * @return
+ */
+ private Object internalGetFreshObject() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::internalGetFreshObject()");
+ // The underlying byte array may have changed. If it has then we
+ // need to deserialize the object from the underlying byte array.
+ if (isObjectStale()) {
+ restoreCachedState();
+ if (isObjectStale())
+ {
+ marshalFromStorage();
+ m_objectStale = false;
+ }
+ }
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::internalGetFreshObject()");
+ return m_object;
+ }
+
+ /**
+ * Deserialize the object from a byte array.
+ */
+ protected void marshalFromStorage() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::marshalFromStorage()");
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(getData());
+ ObjectInputStream ois = new ObjectInputStreamContextClassLoader(bais);
+ internalSetObject(ois.readObject());
+ ois.close();
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, "", e);
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::marshalFromStorage()");
+ throw new EJBException(e);
+ } catch (ClassNotFoundException e) {
+ logger.log(Level.SEVERE, "", e);
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::marshalFromStorage()");
+ throw new EJBException(e);
+ }
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::marshalFromStorage()");
+ }
+
+ /**
+ * Get the object with read-only intent.
+ * @ejb.interface-method
+ * @jboss.method-attributes read-only="true"
+ */
+ public Object getObjectForRead() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::getObjectForRead()");
+ Object obj = internalGetFreshObject();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::getObjectForRead()");
+ return obj;
+ }
+
+ /* Get the object with read-write intent.
+ * (non-Javadoc)
+ * @see org.apache.ode.context.base.INoThrowDataObject#getObjectForReadWrite()
+ */
+ public Object getObjectForReadWrite() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::getObjectForReadWrite()");
+ internalSetDirtyDataBit();
+ Object obj = internalGetFreshObject();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::getObjectForReadWrite()");
+ return obj;
+
+ }
+
+ /* Set the object associated with the CMP. The object will be written
+ * to the database when the ejbStore method is called.
+ * (non-Javadoc)
+ * @see org.apache.ode.context.base.INoThrowDataObject#setObject(java.lang.Object)
+ */
+ public void setObject(Object data) {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::setObject( Object data ) ");
+
+ if ( data instanceof FlushCommand )
+ {
+ marshalToStorage();
+ }
+ else
+ {
+ internalSetObject(data);
+ internalSetDirtyDataBit();
+ }
+
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::setObject( Object data ) ");
+ }
+
+ /**
+ * Set the object associated with the CMP and immediately persist it to the
+ * database.
+ * @param data
+ */
+ public void setObjectNow(Object data) {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::setObjectNow()");
+ internalSetObject(data);
+ marshalToStorage();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::setObjectNow()");
+ }
+
+ /**
+ * Set the object and add it to the cache.
+ * @param iData
+ */
+ protected void internalSetObject(Object iData) {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::internalSetObject()");
+ m_object = iData;
+ cacheState();
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::internalSetObject()");
+ }
+
+ /**
+ * Get the deserialized object.
+ * @return
+ */
+ protected Object internalGetObject() {
+
+ return m_object;
+ }
+
+ /**
+ * Mark the cmp as dirty which means that the object must be serialized
+ * to a byte array and written to the database when ejbStore is called.
+ */
+ protected void internalSetDirtyDataBit() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::internalSetDirtyBit()");
+ m_dirtyDataBit = true;
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::internalSetDirtyBit()");
+ }
+
+ /**
+ * Mark the cmp as clean which means that there is no need to persist
+ * the object to the database when ejbStore() is called.
+ */
+ protected void internalClearDirtyDataBit() {
+ if (TraceLog.enabled()) enterTrace("BPE_CMPObjectBean::internalClearDirtyBit()");
+ m_dirtyDataBit = false;
+ if (TraceLog.enabled()) exitTrace("BPE_CMPObjectBean::internalClearDirtyBit()");
+ }
+
+ /**
+ * returns true if the cmp is dirty and needs to be synced with the database.
+ */
+ protected boolean isDirty() {
+
+ return m_dirtyDataBit;
+ }
+
+ protected void enterTrace(String iFunction) {
+ if (TraceLog.enabled()) {
+ TraceLog.println(getDumpState(iFunction) + " Enter " + iFunction);
+ }
+ }
+
+ protected void exitTrace(String iFunction) {
+
+ if (TraceLog.enabled()) {
+ TraceLog.println(getDumpState(iFunction) + " Exit " + iFunction);
+ }
+
+ }
+
+ protected String getDumpScope(String iFunction) {
+ return /*BPE_CMPObjectBean.class.toString() + "::" + */
+ iFunction + " | ";
+ }
+
+ protected String getDumpState(String iFunction) {
+ return "(TODO)"; //TODO
+ }
+
+ /**
+ * Set a value which indicates whether or not the update count
+ * should be incremented when ejbStore() is called. There is
+ * no need to increment the update count if the object is created
+ * during this transaction.
+ *
+ * @param shouldIncrement
+ */
+ protected void setShouldIncrementUpdateCountOnStore(boolean shouldIncrement) {
+ m_shouldIncrementUpdateCountOnStore = shouldIncrement;
+ }
+
+
+ /**
+ * Returns true if the update count should be incremented
+ * during ejbStore().
+ */
+ protected boolean getShouldIncrementUpdateCountOnStore() {
+ return m_shouldIncrementUpdateCountOnStore;
+ }
+
+ protected java.lang.Object m_object = null;
+ private ClassLoader m_contextClassLoader;
+ private long m_currentDataUpdateCount = -1;
+ private boolean m_dirtyDataBit = false;
+ private boolean m_objectStale = true;
+ private boolean m_shouldIncrementUpdateCountOnStore = true;
+// private EntityContext ejbContext;
+ private ObjectCache objectCache;
+ protected static final Logger logger =
+ Logger.getLogger(BPE_CMPObjectBean.class.getName());
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocal.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocal.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocal.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocal.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.
+*/
+/***********************************************************************
+ * Module: BPE_PCLOBLocal.java
+ * Author: waterman
+ * Purpose: Defines the Interface BPE_PCLOBLocal
+ ***********************************************************************/
+
+package org.apache.ode.context.ejb;
+
+import org.apache.ode.context.base.INoThrowDataObject;
+
+public interface BPE_ObjectLocal extends javax.ejb.EJBLocalObject, INoThrowDataObject
+{
+ /**
+ * Returns the unique id of the data. This is the primary key field.
+ *
+ * @return a UUID identifier
+ */
+ public java.lang.String getId();
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocalHome.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocalHome.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocalHome.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/BPE_ObjectLocalHome.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.
+*/
+/***********************************************************************
+ * Module: BPE_PCLOBLocalHome.java
+ * Author: waterman
+ * Purpose: Defines the Interface BPE_PCLOBLocalHome
+ ***********************************************************************/
+
+package org.apache.ode.context.ejb;
+
+
+public interface BPE_ObjectLocalHome extends javax.ejb.EJBLocalHome
+{
+ /**
+ * Returns a reference
+ *
+ * @param key
+ * @exception javax.ejb.FinderException */
+ BPE_ObjectLocal findByPrimaryKey(String key) throws javax.ejb.FinderException;
+
+ BPE_ObjectLocal create(java.lang.String ID, Object data) throws javax.ejb.CreateException;
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/CachedObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/CachedObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/CachedObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/CachedObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+/**
+ * This class represents a deserialized object which
+ * is cached by the CMP object bean for performance reasons.
+ *
+ * The object contains a raw object and an associated
+ * updatecount which is used to detect if the cached
+ * object is stale.
+ */
+public class CachedObject
+{
+ public CachedObject( Object object, long updateCount )
+ {
+ setObject(object);
+ setUpdateCount(updateCount);
+ }
+
+ public Object getObject()
+ {
+ return Object;
+ }
+
+ public void setObject(Object object)
+ {
+ Object = object;
+ }
+
+ public long getUpdateCount()
+ {
+ return updateCount;
+ }
+
+ public void setUpdateCount(long updateCount)
+ {
+ this.updateCount = updateCount;
+ }
+
+ private long updateCount;
+ private Object Object;
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,93 @@
+/*
+ * 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 10, 2003
+ *
+
+ */
+package org.apache.ode.context.ejb;
+
+import java.io.Serializable;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.persistent.PersistentDataObject;
+
+/**
+ * @author waterman
+ *
+ * A handle to an EJB persisted data object. The handle holds a reference to a piece
+ * of persisted data. The handle is on the leaf node of a process context tree and
+ * is serialized as part of the tree.
+ * <P>
+ * The handle will persist any Java Serializable/Externalizable object.<BR>
+ *
+ */
+public class EJBDataObject extends PersistentDataObject implements Serializable
+{
+
+ static final long serialVersionUID = 925277168317272542L;
+
+ EJBDataObject(String id, BPE_ObjectLocal local)
+ throws ContextServiceException
+ {
+ super( id, local );
+ }
+
+ public void setObject(Object obj) throws ContextServiceException
+ {
+ getEJBLocal().setObject(obj);
+ }
+
+ private BPE_ObjectLocal getEJBLocal() throws ContextServiceException
+ {
+ return ( BPE_ObjectLocal ) ( getInternals() );
+ }
+
+ public Object getObjectForRead() throws ContextServiceException
+ {
+ return getEJBLocal().getObjectForRead();
+ }
+
+ public Object getObjectForReadWrite() throws ContextServiceException
+ {
+ return getEJBLocal().getObjectForReadWrite();
+ }
+
+ public void decrementRefCount() throws ContextServiceException
+ {
+ getEJBLocal().decrementRefCount();
+ }
+
+ public void incrementRefCount() throws ContextServiceException
+ {
+ getEJBLocal().incrementRefCount();
+ }
+
+ public long getRefCount() throws ContextServiceException
+ {
+ return getEJBLocal().getRefCount();
+ }
+
+ public void flush() throws ContextServiceException
+ {
+ FlushCommand mtsc = new FlushCommand();
+ getEJBLocal().setObject(mtsc);
+ }
+
+
+
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactory.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;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.FinderException;
+import javax.ejb.RemoveException;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.IDataObject;
+
+public class EJBDataObjectFactory extends EJBDataObjectFactoryBase
+{
+
+
+ BPE_ObjectLocalHome getObjectHome() throws ContextServiceException
+ {
+ return (BPE_ObjectLocalHome) getLocalHome
+ (getEJBHomeJNDIName());
+ }
+
+ protected EJBLocalObject findObject( String iLocator ) throws ContextServiceException, FinderException
+ {
+ return getObjectHome().findByPrimaryKey(iLocator);
+ }
+
+ protected void removeObject( String iLocator ) throws RemoveException, ContextServiceException
+ {
+ try
+ {
+ EJBLocalObject ejbl = findObject(iLocator);
+ if ( ejbl != null ) {
+ getObjectHome().remove(iLocator);
+ }
+ }
+ catch( javax.ejb.EJBException e )
+ {
+ // If the object wasn't there then no worries.
+ }
+ catch ( FinderException e ) {
+ // ignore
+ }
+ }
+
+ protected EJBLocalObject createNewLocalObject(
+ String iLocator,
+ Object iData)
+ throws CreateException, ContextServiceException
+ {
+ return getObjectHome().create(iLocator, iData);
+ }
+
+ protected IDataObject createNewDataObject(
+ String iLocator,
+ EJBLocalObject iLocalObject)
+ throws ContextServiceException
+ {
+ return new EJBDataObject(iLocator, (BPE_ObjectLocal) (iLocalObject));
+ }
+
+ private String getEJBHomeJNDIName()
+ {
+ if ( m_home == null )
+ {
+ m_home = getProperties().getDataObjectFactoryEJBHome();
+ }
+ return m_home;
+ }
+
+ private String m_home = null;
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactoryBase.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactoryBase.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactoryBase.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/EJBDataObjectFactoryBase.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,212 @@
+/*
+ * 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.HashMap;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.FinderException;
+import javax.ejb.RemoveException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.context.base.IDataObject;
+import org.apache.ode.context.persistent.PersistentDataObjectFactory;
+
+public abstract class EJBDataObjectFactoryBase
+ extends PersistentDataObjectFactory
+{
+
+ public IDataObject create(Object iData) throws ContextServiceException
+ {
+ String aUUID = getUUID();
+ IDataObject returnObject = createNewDataObject1(aUUID, iData);
+
+ return returnObject;
+ }
+
+ protected abstract IDataObject createNewDataObject(
+ String iLocator,
+ EJBLocalObject iLocal)
+ throws ContextServiceException;
+
+ protected EJBLocalHome getLocalHome(String iJNDIName)
+ throws ContextServiceException
+ {
+
+ if (m_localHome == null)
+ {
+ try
+ {
+ if (m_ictx == null)
+ {
+ m_ictx = new InitialContext();
+ }
+ m_localHome = (EJBLocalHome) m_ictx.lookup(iJNDIName);
+ }
+ catch (NamingException e)
+ {
+ ContextServiceException cse = new ContextServiceException("JNDI_LOOKUP",new Object[] { iJNDIName }, e);
+ cse.log(logger,Level.SEVERE);
+ throw cse;
+
+ }
+
+ }
+
+ return m_localHome;
+ }
+
+ protected EJBLocalObject createLocalObject(String id, Object obj)
+ throws ContextServiceException
+ {
+ EJBLocalObject ret = null;
+
+ try
+ {
+ ret = createNewLocalObject(id, obj);
+ } catch (CreateException e) {
+ ContextServiceException bpx = new ContextServiceException("NATIVE_EXCEPTION",new Object[] {"CreateException"},e);
+ bpx.log(logger,Level.SEVERE);
+ throw bpx;
+ }
+
+ return ret;
+ }
+
+ public void remove(String iLocator) throws ContextServiceException
+ {
+ try
+ {
+ m_localCache.remove(iLocator);
+ removeObject(iLocator);
+ }
+ catch (EJBException e)
+ {
+ ContextServiceException bpx = new ContextServiceException("NATIVE_EXCEPTION",new Object[] {"EJBException"},e);
+ bpx.log(logger,Level.SEVERE);
+ throw bpx;
+
+ }
+ catch (RemoveException e)
+ {
+ ContextServiceException bpx = new ContextServiceException("NATIVE_EXCEPTION",new Object[] {"RemoveException"},e);
+ bpx.log(logger,Level.SEVERE);
+ throw bpx;
+
+ }
+ }
+
+ public IDataObject create(String iLocator, Object iData)
+ throws ContextServiceException
+ {
+ IDataObject returnObject = find(iLocator);
+ if (returnObject != null)
+ {
+ returnObject.setObject(iData);
+ }
+ else
+ {
+ returnObject = createNewDataObject1(iLocator, iData);
+ }
+ return returnObject;
+
+ }
+
+ protected IDataObject createNewDataObject1(String iLocator, Object iData)
+ throws ContextServiceException
+ {
+
+ EJBLocalObject objectLocal = createLocalObject(iLocator, iData);
+
+ IDataObject newDataObject = createNewDataObject(iLocator, objectLocal);
+ m_localCache.put(iLocator, newDataObject);
+
+ return newDataObject;
+ }
+
+ protected void flush() throws ContextServiceException
+ {
+ Iterator iter = m_localCache.values().iterator();
+ while( iter.hasNext())
+ {
+ EJBDataObject ejbdo = ( EJBDataObject)(iter.next());
+ ejbdo.flush();
+ }
+ }
+
+
+ public IDataObject find(String iLocator) throws ContextServiceException
+ {
+ Object foundObject = m_localCache.get(iLocator);
+ if (foundObject != null)
+ {
+ return (IDataObject) (foundObject);
+ }
+
+ EJBLocalObject objectLocal = null;
+ try
+ {
+ objectLocal = findObject(iLocator);
+ IDataObject newDataObject = createNewDataObject(iLocator, objectLocal);
+ m_localCache.put(iLocator, newDataObject);
+ }
+ catch (FinderException e)
+ {
+
+ /*
+ logger.log(
+ Level.WARNING,
+ ResourceGetter.getFormatted(
+ "EJB_FIND_PRIMARY",
+ new Object[] { iLocator }),
+ e);
+ */
+ return null;
+
+ }
+ return createNewDataObject(iLocator, objectLocal);
+ }
+
+ protected abstract EJBLocalObject createNewLocalObject(
+ String iLocator,
+ Object iData)
+ throws CreateException, ContextServiceException;
+
+ protected abstract void removeObject(String iLocator)
+ throws RemoveException, ContextServiceException;
+
+ protected abstract EJBLocalObject findObject(String iLocator)
+ throws ContextServiceException, FinderException;
+
+ private InitialContext m_ictx;
+
+ private EJBLocalHome m_localHome;
+
+ private HashMap m_localCache = new HashMap();
+
+ // Logging
+ private static final Logger logger =
+ Logger.getLogger(EJBDataObjectFactoryBase.class.getName());
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/FlushCommand.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/FlushCommand.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/FlushCommand.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/context/ejb/FlushCommand.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,24 @@
+/*
+ * 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.io.Serializable;
+
+
+public class FlushCommand implements Serializable
+{
+ static final long serialVersionUID = 6082617257026241764L;
+}