User: slaboure
Date: 02/02/09 07:29:39
Modified: src/main/org/jboss/ejb/plugins
CMPClusteredInMemoryPersistenceManager.java
Log:
Was using the bad stream class
Revision Changes Path
1.5 +70 -70
jbossmx/src/main/org/jboss/ejb/plugins/CMPClusteredInMemoryPersistenceManager.java
Index: CMPClusteredInMemoryPersistenceManager.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jboss/ejb/plugins/CMPClusteredInMemoryPersistenceManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CMPClusteredInMemoryPersistenceManager.java 6 Jan 2002 16:04:22 -0000
1.4
+++ CMPClusteredInMemoryPersistenceManager.java 9 Feb 2002 15:29:39 -0000
1.5
@@ -30,7 +30,7 @@
* @see org.jboss.ha.framework.interfaces.DistributedState
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>.
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*
* <p><b>Revisions:</b>
*
@@ -42,31 +42,31 @@
public class CMPClusteredInMemoryPersistenceManager implements
org.jboss.ejb.EntityPersistenceStore
{
-
- // Constants -----------------------------------------------------
-
+
+ // Constants -----------------------------------------------------
+
// Attributes ----------------------------------------------------
-
- protected org.jboss.ejb.EntityContainer con = null;
+
+ protected org.jboss.ejb.EntityContainer con = null;
protected Field idField = null;
-
+
protected DistributedState ds = null;
-
+
protected String DS_CATEGORY = null;
-
+
/**
* Optional isModified method used by storeEntity
*/
protected Method isModified = null;
-
+
// Static --------------------------------------------------------
-
+
// Constructors --------------------------------------------------
-
+
public CMPClusteredInMemoryPersistenceManager ()
{
}
-
+
/**
* create the service, do expensive operations etc
*/
@@ -74,13 +74,13 @@
{
String name = "jboss:service=DistributedState,partitionName=DefaultPartition";
ds = (DistributedState)org.jboss.system.Registry.lookup (name);
-
+
String ejbName = con.getBeanMetaData ().getEjbName ();
-
+
this.DS_CATEGORY = "CMPClusteredInMemoryPersistenceManager-" + ejbName;
-
+
idField = con.getBeanClass ().getField ("id");
-
+
try
{
isModified = con.getBeanClass ().getMethod ("isModified", new Class[0]);
@@ -90,14 +90,14 @@
catch (NoSuchMethodException ignored)
{}
}
-
+
/**
* start the service, create is already called
*/
public void start () throws Exception
{
}
-
+
/**
* This callback is set by the container so that the plugin may access it
*
@@ -107,26 +107,26 @@
{
this.con = (org.jboss.ejb.EntityContainer)con;
}
-
+
/**
* stop the service
*/
public void stop ()
- {
+ {
}
-
-
+
+
/**
* destroy the service, tear down
*/
public void destroy ()
{
}
-
+
// Public --------------------------------------------------------
-
+
// EntityPersistenceStore implementation
----------------------------------------------
-
+
/**
* Returns a new instance of the bean class or a subclass of the bean class.
*
@@ -138,7 +138,7 @@
{
return con.getBeanClass ().newInstance ();
}
-
+
/**
* Initializes the instance context.
*
@@ -156,10 +156,10 @@
Class ejbClass = instance.getClass ();
Field cmpField;
Class cmpFieldType;
-
+
org.jboss.metadata.EntityMetaData metaData =
(org.jboss.metadata.EntityMetaData)con.getBeanMetaData ();
java.util.Iterator i= metaData.getCMPFields ();
-
+
while(i.hasNext ())
{
try
@@ -220,7 +220,7 @@
}
}
}
-
+
/**
* This method is called whenever an entity is to be created.
* The persistence manager is responsible for handling the results properly
@@ -238,16 +238,16 @@
{
try
{
-
+
Object id = idField.get (ctx.getInstance ());
-
+
// Check exist
if (this.ds.get (DS_CATEGORY, id.toString ()) != null)
throw new javax.ejb.DuplicateKeyException ("Already exists:"+id);
-
+
// Store to file
storeEntity (id, ctx.getInstance ());
-
+
return id;
}
catch (IllegalAccessException e)
@@ -255,7 +255,7 @@
throw new javax.ejb.CreateException ("Could not create entity:"+e);
}
}
-
+
/**
* This method is called when single entities are to be found. The
* persistence manager must find out whether the wanted instance is
@@ -277,13 +277,13 @@
{
if (this.ds.get (DS_CATEGORY, args[0].toString ()) == null)
throw new javax.ejb.FinderException (args[0]+" does not exist");
-
+
return args[0];
}
else
return null;
}
-
+
/**
* This method is called when collections of entities are to be found. The
* persistence manager must find out whether the wanted instances are
@@ -305,20 +305,20 @@
if (finderMethod.getName ().equals ("findAll"))
{
Collection tmpColl = this.ds.getAllKeys (DS_CATEGORY);
-
+
ArrayList result = null;
if (tmpColl == null)
result = new ArrayList ();
else
result = new ArrayList (tmpColl);
-
+
return new FinderResults (result,null,null,null);
} else
{
return new FinderResults (new ArrayList (),null,null,null);
}
}
-
+
/**
* This method is called when an entity shall be activated.
*
@@ -334,7 +334,7 @@
* @throws RemoteException thrown if some system exception occurs
*/
public void activateEntity (EntityEnterpriseContext instance) { }
-
+
/**
* This method is called whenever an entity shall be load from the
* underlying storage. The persistence manager must load the state from
@@ -349,26 +349,26 @@
try
{
// Read fields
-
- java.io.ObjectInputStream in = new
org.jboss.ejb.plugins.CMPInMemoryPersistenceManager.CMPObjectInputStream (
+
+ java.io.ObjectInputStream in = new
org.jboss.ejb.plugins.CMPClusteredInMemoryPersistenceManager.CMPObjectInputStream (
new java.io.ByteArrayInputStream ((byte[])this.ds.get (this.DS_CATEGORY,
ctx.getId ().toString ())));
-
+
Object obj = ctx.getInstance ();
-
+
Field[] f = obj.getClass ().getFields ();
for (int i = 0; i < f.length; i++)
{
f[i].set (obj, in.readObject ());
}
-
+
in.close ();
-
+
} catch (Exception e)
{
throw new EJBException ("Load failed", e);
}
}
-
+
/**
* This method is used to determine if an entity should be stored.
*
@@ -382,13 +382,13 @@
{
return true;
}
-
+
Object[] args =
{};
Boolean modified = (Boolean) isModified.invoke (ctx.getInstance (), args);
return modified.booleanValue ();
}
-
+
/**
* This method is called whenever an entity shall be stored to the
* underlying storage. The persistence manager must call ejbStore on the
@@ -409,7 +409,7 @@
throw new java.rmi.RemoteException (e.toString ());
}
}
-
+
/**
* This method is called when an entity shall be passivate. The persistence
* manager must call the ejbPassivate method on the instance.
@@ -425,7 +425,7 @@
{
// This plugin doesn't do anything specific
}
-
+
/**
* This method is called when an entity shall be removed from the
* underlying storage. The persistence manager must call ejbRemove on the
@@ -449,41 +449,41 @@
throw new javax.ejb.RemoveException (e.toString ());
}
}
-
+
// Y overrides ---------------------------------------------------
-
+
// Package protected ---------------------------------------------
-
+
// Protected -----------------------------------------------------
-
+
protected void storeEntity (Object id, Object obj) throws Exception
{
try
{
// Store fields
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream ();
- java.io.ObjectOutputStream out = new
org.jboss.ejb.plugins.CMPInMemoryPersistenceManager.CMPObjectOutputStream (baos);
-
+ java.io.ObjectOutputStream out = new
org.jboss.ejb.plugins.CMPClusteredInMemoryPersistenceManager.CMPObjectOutputStream
(baos);
+
Field[] f = obj.getClass ().getFields ();
for (int i = 0; i < f.length; i++)
{
out.writeObject (f[i].get (obj));
}
-
+
out.close ();
-
+
this.ds.set (this.DS_CATEGORY, id.toString (), baos.toByteArray (), false);
-
+
} catch (Exception e)
{
throw new EJBException ("Store failed", e);
}
}
-
+
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
-
+
static class CMPObjectOutputStream extends java.io.ObjectOutputStream
{
public CMPObjectOutputStream (java.io.OutputStream out) throws IOException
@@ -491,17 +491,17 @@
super (out);
enableReplaceObject (true);
}
-
+
protected Object replaceObject (Object obj)
throws IOException
{
if (obj instanceof javax.ejb.EJBObject)
return ((javax.ejb.EJBObject)obj).getHandle ();
-
+
return obj;
}
}
-
+
static class CMPObjectInputStream extends java.io.ObjectInputStream
{
public CMPObjectInputStream (java.io.InputStream in) throws IOException
@@ -509,15 +509,15 @@
super (in);
enableResolveObject (true);
}
-
+
protected Object resolveObject (Object obj)
throws IOException
{
if (obj instanceof javax.ejb.Handle)
return ((javax.ejb.Handle)obj).getEJBObject ();
-
+
return obj;
}
}
-
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development