User: fleury
Date: 00/07/14 12:09:23
Modified: src/main/org/jboss/ejb/plugins
CMPFilePersistenceManager.java
Log:
Remove all the EJB calls from the persistence plugin. Only keep the storage ones.
Revision Changes Path
1.2 +49 -86
jboss/src/main/org/jboss/ejb/plugins/CMPFilePersistenceManager.java
Index: CMPFilePersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/CMPFilePersistenceManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CMPFilePersistenceManager.java 2000/04/22 14:30:12 1.1
+++ CMPFilePersistenceManager.java 2000/07/14 19:09:22 1.2
@@ -1,3 +1,4 @@
+
/*
* jBoss, the OpenSource EJB server
*
@@ -32,7 +33,7 @@
import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
-import org.jboss.ejb.EntityPersistenceManager;
+import org.jboss.ejb.EntityPersistenceStore;
import org.jboss.ejb.EntityEnterpriseContext;
/**
@@ -40,21 +41,24 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @version $Revision: 1.2 $
*/
public class CMPFilePersistenceManager
- implements EntityPersistenceManager
+ implements EntityPersistenceStore
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
EntityContainer con;
+ /* The Methods are taken care of by CMPPersistenceManager
Method ejbStore;
Method ejbLoad;
Method ejbActivate;
Method ejbPassivate;
Method ejbRemove;
+ */
File dir;
Field idField;
@@ -71,12 +75,15 @@
public void init()
throws Exception
{
+ // The methods are now taken care of by CMPPersistenceManager
+ /*
ejbStore = EntityBean.class.getMethod("ejbStore", new Class[0]);
ejbLoad = EntityBean.class.getMethod("ejbLoad", new Class[0]);
ejbActivate = EntityBean.class.getMethod("ejbActivate", new Class[0]);
ejbPassivate = EntityBean.class.getMethod("ejbPassivate", new Class[0]);
ejbRemove = EntityBean.class.getMethod("ejbRemove", new Class[0]);
-
+ */
+
String ejbName = con.getMetaData().getEjbName();
dir = new
File(getClass().getResource("/db/"+ejbName+"/db.properties").getFile()).getParentFile();
idField = con.getBeanClass().getField("id");
@@ -94,48 +101,28 @@
{
}
- public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
- throws RemoteException, CreateException
- {
- // Get methods
- try
- {
- Method createMethod = con.getBeanClass().getMethod("ejbCreate",
m.getParameterTypes());
- Method postCreateMethod = con.getBeanClass().getMethod("ejbPostCreate",
m.getParameterTypes());
-
- // Call ejbCreate
- createMethod.invoke(ctx.getInstance(), args);
- Object id = idField.get(ctx.getInstance());
-
- // Check exist
- if (getFile(id).exists())
- throw new DuplicateKeyException("Already exists:"+id);
-
- // Set id
- ctx.setId(id);
-
- // Lock instance in cache
- ((EntityContainer)con).getInstanceCache().insert(ctx);
-
- // Create EJBObject
- ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(id));
+ public Object createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
+ throws RemoteException, CreateException
+ {
+ try {
+
+ Object id = idField.get(ctx.getInstance());
+
+ // Check exist
+ if (getFile(id).exists())
+ throw new DuplicateKeyException("Already exists:"+id);
+
+ // Store to file
+ storeEntity(id, ctx.getInstance());
+
+ return id;
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new CreateException("Could not create entity:"+e);
+ }
+ }
- // Store to file
- storeEntity(ctx);
-
- postCreateMethod.invoke(ctx.getInstance(), args);
- } catch (InvocationTargetException e)
- {
- throw new CreateException("Create failed:"+e);
- } catch (NoSuchMethodException e)
- {
- throw new CreateException("Create methods not found:"+e);
- } catch (IllegalAccessException e)
- {
- throw new CreateException("Could not create entity:"+e);
- }
- }
-
public Object findEntity(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException
{
@@ -155,7 +142,7 @@
{
if (finderMethod.getName().equals("findAll"))
{
-// System.out.println("Find all entities");
+ // System.out.println("Find all entities");
String[] files = dir.list();
ArrayList result = new ArrayList();
@@ -177,14 +164,7 @@
public void activateEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
- // Call bean
- try
- {
- ejbActivate.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Activation failed", e);
- }
+ //Nothing to do
}
public void loadEntity(EntityEnterpriseContext ctx)
@@ -205,29 +185,20 @@
in.close();
- // Call bean
- ejbLoad.invoke(ctx.getInstance(), new Object[0]);
} catch (Exception e)
{
throw new ServerException("Load failed", e);
}
}
-
- public void storeEntity(EntityEnterpriseContext ctx)
- throws RemoteException
- {
-// System.out.println("Store entity");
+ private void storeEntity(Object id, Object obj)
+ throws RemoteException {
+
try
{
- // Call bean
- ejbStore.invoke(ctx.getInstance(), new Object[0]);
-
// Store fields
- ObjectOutputStream out = new CMPObjectOutputStream(new
FileOutputStream(getFile(ctx.getId())));
-
- Object obj = ctx.getInstance();
-
+ ObjectOutputStream out = new CMPObjectOutputStream(new
FileOutputStream(getFile(id)));
+
Field[] f = obj.getClass().getFields();
for (int i = 0; i < f.length; i++)
{
@@ -239,33 +210,25 @@
{
throw new ServerException("Store failed", e);
}
-
}
+
+ public void storeEntity(EntityEnterpriseContext ctx)
+ throws RemoteException
+ {
+// System.out.println("Store entity");
+
+ storeEntity(ctx.getId(), ctx.getInstance());
+ }
public void passivateEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
- // Call bean
- try
- {
- ejbPassivate.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Passivation failed", e);
- }
- }
+ // This plugin doesn't do anything specific
+ }
public void removeEntity(EntityEnterpriseContext ctx)
throws RemoteException, RemoveException
{
- try
- {
- // Call ejbRemove
- ejbRemove.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new RemoveException("Could not remove "+ctx.getId());
- }
// Remove file
if (!getFile(ctx.getId()).delete())