001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb;
023:
024: import java.lang.reflect.Method;
025: import java.rmi.RemoteException;
026: import java.util.Collection;
027:
028: import javax.ejb.RemoveException;
029:
030: /**
031: * This interface is implemented by any EntityBean persistence Store.
032: *
033: * <p>These stores just deal with the persistence aspect of storing java
034: * objects. They need not be aware of the EJB semantics. They act as
035: * delegatees for the CMPEntityPersistenceManager class.
036: *
037: * @see EntityPersistenceManager
038: *
039: * @author <a href="mailto:rickard.oberg@telkel.com">Rickard Öberg</a>
040: * @author <a href="mailto:marc.fleury@telkel.com">Marc Fleury</a>
041: * @author <a href="mailto:simone.bordet@compaq.com">Simone Bordet</a>
042: * @version $Revision: 57209 $
043: */
044: public interface EntityPersistenceStore extends ContainerPlugin {
045: /**
046: * Returns a new instance of the bean class or a subclass of the bean class.
047: *
048: * @return the new instance
049: *
050: * @throws Exception
051: */
052: Object createBeanClassInstance() throws Exception;
053:
054: /**
055: * Initializes the instance context.
056: *
057: * <p>This method is called before createEntity, and should
058: * resetStats the value of all cmpFields to 0 or null.
059: *
060: * @param ctx
061: */
062: void initEntity(EntityEnterpriseContext ctx);
063:
064: /**
065: * This method is called whenever an entity is to be created.
066: * The persistence manager is responsible for handling the results properly
067: * wrt the persistent store.
068: *
069: * @param m the create method in the home interface that was
070: * called
071: * @param args any create parameters
072: * @param instance the instance being used for this create call
073: * @return The primary key computed by CMP PM or null for BMP
074: *
075: * @throws Exception
076: */
077: Object createEntity(Method m, Object[] args,
078: EntityEnterpriseContext instance) throws Exception;
079:
080: /**
081: * This method is called after the createEntity.
082: * The persistence manager is responsible for handling the results properly
083: * wrt the persistent store.
084: *
085: * @param m the ejbPostCreate method in the bean class that was
086: * called
087: * @param args any create parameters
088: * @param instance the instance being used for this create call
089: * @return null
090: *
091: * @throws Exception
092: */
093: Object postCreateEntity(Method m, Object[] args,
094: EntityEnterpriseContext instance) throws Exception;
095:
096: /**
097: * This method is called when single entities are to be found. The
098: * persistence manager must find out whether the wanted instance is
099: * available in the persistence store, if so it returns the primary key of
100: * the object.
101: *
102: * @param finderMethod the find method in the home interface that was
103: * called
104: * @param args any finder parameters
105: * @param instance the instance to use for the finder call
106: * @return a primary key representing the found entity
107: *
108: * @throws RemoteException thrown if some system exception occurs
109: * @throws Exception thrown if some heuristic problem occurs
110: */
111: Object findEntity(Method finderMethod, Object[] args,
112: EntityEnterpriseContext instance,
113: GenericEntityObjectFactory factory) throws Exception;
114:
115: /**
116: * This method is called when collections of entities are to be found. The
117: * persistence manager must find out whether the wanted instances are
118: * available in the persistence store, and if so it must return a
119: * collection of primaryKeys.
120: *
121: * @param finderMethod the find method in the home interface that was
122: * called
123: * @param args any finder parameters
124: * @param instance the instance to use for the finder call
125: * @return an primary key collection representing the found
126: * entities
127: *
128: * @throws RemoteException thrown if some system exception occurs
129: * @throws Exception thrown if some heuristic problem occurs
130: */
131: Collection findEntities(Method finderMethod, Object[] args,
132: EntityEnterpriseContext instance,
133: GenericEntityObjectFactory factory) throws Exception;
134:
135: /**
136: * This method is called when an entity shall be activated.
137: *
138: * <p>With the PersistenceManager factorization most EJB calls should not
139: * exists However this calls permits us to introduce optimizations in
140: * the persistence store. Particularly the context has a
141: * "PersistenceContext" that a PersistenceStore can use (JAWS does for
142: * smart updates) and this is as good a callback as any other to set it
143: * up.
144: *
145: * @param instance the instance to use for the activation
146: *
147: * @throws RemoteException thrown if some system exception occurs
148: */
149: void activateEntity(EntityEnterpriseContext instance)
150: throws RemoteException;
151:
152: /**
153: * This method is called whenever an entity shall be load from the
154: * underlying storage. The persistence manager must load the state from
155: * the underlying storage and then call ejbLoad on the supplied instance.
156: *
157: * @param instance the instance to synchronize
158: *
159: * @throws RemoteException thrown if some system exception occurs
160: */
161: void loadEntity(EntityEnterpriseContext instance)
162: throws RemoteException;
163:
164: /**
165: * This method is used to determine if an entity should be stored.
166: *
167: * @param instance the instance to check
168: * @return true, if the entity has been modified
169: * @throws Exception thrown if some system exception occurs
170: */
171: boolean isStoreRequired(EntityEnterpriseContext instance)
172: throws Exception;
173:
174: /**
175: * This method is used to determined whether the instance was modified.
176: * NOTE, even if the method returns true the isStoreRequired for this same instance
177: * might return false, e.g. a CMR field that doesn't have a foreign key was modified.
178: *
179: * @param instance
180: * @return
181: * @throws Exception
182: */
183: boolean isModified(EntityEnterpriseContext instance)
184: throws Exception;
185:
186: /**
187: * This method is called whenever an entity shall be stored to the
188: * underlying storage. The persistence manager must call ejbStore on the
189: * supplied instance and then store the state to the underlying storage.
190: *
191: * @param instance the instance to synchronize
192: *
193: * @throws RemoteException thrown if some system exception occurs
194: */
195: void storeEntity(EntityEnterpriseContext instance)
196: throws RemoteException;
197:
198: /**
199: * This method is called when an entity shall be passivate. The persistence
200: * manager must call the ejbPassivate method on the instance.
201: *
202: * <p>See the activate discussion for the reason for exposing EJB callback
203: * calls to the store.
204: *
205: * @param instance the instance to passivate
206: *
207: * @throws RemoteException thrown if some system exception occurs
208: */
209: void passivateEntity(EntityEnterpriseContext instance)
210: throws RemoteException;
211:
212: /**
213: * This method is called when an entity shall be removed from the
214: * underlying storage. The persistence manager must call ejbRemove on the
215: * instance and then remove its state from the underlying storage.
216: *
217: * @param instance the instance to remove
218: *
219: * @throws RemoteException thrown if some system exception occurs
220: * @throws RemoveException thrown if the instance could not be removed
221: */
222: void removeEntity(EntityEnterpriseContext instance)
223: throws RemoteException, RemoveException;
224: }
|