001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.pm.ejb.lib;
018:
019: import org.objectweb.perseus.persistence.api.PersistenceException;
020: import org.objectweb.speedo.mim.api.FetchPlanItf;
021: import org.objectweb.speedo.mim.api.PersistentObjectItf;
022: import org.objectweb.speedo.mim.lib.SpeedoFetchPlan;
023: import org.objectweb.speedo.pm.ejb.api.EJBPOManagerItf;
024: import org.objectweb.speedo.pm.lib.AbstractPOManager;
025:
026: import java.util.Collection;
027: import java.util.Map;
028:
029: import javax.persistence.EntityTransaction;
030: import javax.persistence.FlushModeType;
031: import javax.persistence.LockModeType;
032: import javax.persistence.Query;
033: import javax.persistence.TransactionRequiredException;
034:
035: /**
036: *
037: * TODO: runtimeException thrown by the methods will cause the current
038: * transaction to rollback
039: * @author S.Chassande-Barrioz
040: */
041: public class EJBPOManager extends AbstractPOManager implements
042: EJBPOManagerItf {
043:
044: private FlushModeType flushMode;
045:
046: /**
047: *
048: */
049: public EJBPOManager() {
050: super ();
051: }
052:
053: public FetchPlanItf speedoGetFetchPlan() {
054: if (fetchPlan == null) {
055: fetchPlan = new SpeedoFetchPlan();
056: }
057: return fetchPlan;
058: }
059:
060: /**
061: * Make an instance managed and persistent
062: * @param entity
063: * @throws java.lang.IllegalArgumentException if not an entity or entity
064: * is detached
065: * @throws javax.persistence.TransactionRequiredException if there is no
066: * transaction
067: * @see javax.persistence.EntityManager#persist(java.lang.Object)
068: */
069: public void persist(Object entity) {
070: //TODO implement EJBPOM.persist(Object)
071: }
072:
073: /**
074: * Merge the state of the given entry into the current persistence context
075: * @param entity
076: * @return the instance that the state was merge to
077: * @throws java.lang.IllegalArgumentException if instance is not an entity
078: * or is a removed instance
079: * @throws javax.persistence.TransactionRequiredException if there is no
080: * transaction
081: * @see javax.persistence.EntityManager#merge(java.lang.Object)
082: */
083: public Object merge(Object entity) {
084: //TODO implement EJBPOM.merge(Object)
085: return null;
086: }
087:
088: /**
089: * Remove the instance
090: * @param entity
091: * @throws java.lang.IllegalArgumentException if not an entity or if
092: * a detached entity
093: * @throws javax.persistence.TransactionRequiredException if there is no
094: * transaction
095: * @see javax.persistence.EntityManager#remove(java.lang.Object)
096: */
097: public void remove(Object entity) {
098: //TODO implement EJBPOM.remove(Object)
099: }
100:
101: /**
102: * Find by primary key
103: * @param entityClass
104: * @param primaryKey
105: * @return the found entity instance or null if the entity does not exist
106: * throws
107: * @throws java.lang.IllegalArgumentException if the first argument does not
108: * denote an entity type or the second argument is not a valid type for that
109: * entity'primary key
110: * @see javax.persistence.EntityManager#find(java.lang.Class, java.lang.Object)
111: */
112: public Object find(Class entityClass, Object primaryKey) {
113: //TODO implement EJBPOM.find(Class, Object)
114: return null;
115: }
116:
117: /**
118: * Get an instance, whoose state may be lazily fetched. If the requested
119: * instance does not exist in the database, throws
120: * javax.persistence.EntityNotFoundException when the instance state is
121: * first accessed. (The container is permitted to throw
122: * EntityNotFoundException when get is called.)
123: * The application shoud not expect that the instance state will be
124: * availlable upon detachment, unless it was accessed by the application
125: * while the entity manager was open.
126: * @param entityClass
127: * @param primaryKey
128: * @return the found entity instance
129: * @throws java.lang.IllegalArgumentException if the first argument does not
130: * denote an entity type or the second argument is not a valid type for that
131: * entity'primary key
132: * @throws javax.persistence.EntityNotFoundException if the entity state
133: * cannot be accessed
134: * @see javax.persistence.EntityManager#getReference(java.lang.Class, java.lang.Object)
135: */
136: public Object getReference(Class entityClass, Object primaryKey) {
137: //TODO implement EJBPOM.getReference(Class, Object)
138: return null;
139: }
140:
141: /**
142: * Synchronize the persistence context to the underlying database.
143: * @throws javax.persistence.TransactionRequiredException if there is no
144: * transaction
145: * @throws javax.persistence.PersistenceException if there the flush fails
146: * @see javax.persistence.EntityManager#flush()
147: */
148: public void flush() {
149: if (!tx.isActive()) {
150: throw new TransactionRequiredException(
151: "transaction required for the flush operation");
152: }
153: try {
154: speedoFlush();
155: } catch (PersistenceException e) {
156: throw new javax.persistence.PersistenceException(e);
157: }
158: }
159:
160: /**
161: * Refresh the state of the instanc from the database overwriting chages
162: * mades to the entity, if any.
163: * @param entity
164: * @throws java.lang.IllegalArgumentException if not an entity or entity is
165: * not managed.
166: * @throws javax.persistence.TransactionRequiredException if there is no
167: * transaction
168: * @throws javax.persistence.EntityNotFoundException if there is no longer
169: * exists in the database
170: * @see javax.persistence.EntityManager#refresh(java.lang.Object)
171: */
172: public void refresh(Object entity) {
173: //TODO implement EJBPOM.refresh(Object)
174: }
175:
176: /**
177: * Check if the instance belongs to the current persistence context
178: * @param entity
179: * @throws java.lang.IllegalArgumentException if not an entity
180: * @see javax.persistence.EntityManager#contains(java.lang.Object)
181: */
182: public boolean contains(Object entity) {
183: //TODO implement EJBPOM.contains(Object)
184: return false;
185: }
186:
187: /**
188: * closes an application-managed EntityManager. This method can only be
189: * called when the EntityManaged is not associated with an active
190: * transaction. After an EntityManager has been closed, all methodes on the
191: * EntityManager instance will throw the IllegalStateException except for
192: * isOpen, which will return false;
193: * @throws java.lang.IllegalStateException if the EntityManager is
194: * associated with an active transaction or if the EntityManager is
195: * container-managed.
196: * @see javax.persistence.EntityManager#close()
197: */
198: public void close() {
199: closePOManager();
200: }
201:
202: /**
203: * Indicates whether the EntityManager is open.
204: * @return true until the EntityManager has been closed.
205: * @see javax.persistence.EntityManager#isOpen()
206: */
207: public boolean isOpen() {
208: return !isPOMClosed();
209: }
210:
211: /**
212: * Returns the resource-level transaction object. The EntityTransaction
213: * instance may be used serially to bein and commit multiple transactions.
214: * @return EntityTransaction instance
215: * @throws java.lang.IllegalStateException if invoked on a JTA EntityManager
216: * or an EntityManager that has been closed.
217: * @see javax.persistence.EntityManager#getTransaction()
218: */
219: public EntityTransaction getTransaction() {
220: return (EntityTransaction) tx;
221: }
222:
223: /**
224: * @see javax.persistence.EntityManager#setFlushMode(javax.persistence.FlushModeType)
225: */
226: public void setFlushMode(FlushModeType fmt) {
227: this .flushMode = fmt;
228: }
229:
230: /**
231: * Create an instance of Query for executing an EJB QL statement
232: * @param ejbqlString an EJB QL query string
233: * @return the new query instance
234: * @throws IllegalArgumentException if query string is not valid
235: * @see javax.persistence.EntityManager#createQuery(java.lang.String)
236: */
237: public Query createQuery(String ejbqlString) {
238: //TODO implement EJBPOM.createQuery(String)
239: return null;
240: }
241:
242: /**
243: * Create an instance of Query for executing a named query (EJB QL or
244: * native SQL).
245: * @param name the name of a query defined in metadata
246: * @return the new query instance
247: * @throws IllegalArgumentException if query string is not valid
248: * @see javax.persistence.EntityManager#createNamedQuery(java.lang.String)
249: */
250: public Query createNamedQuery(String name) {
251: //TODO implement EJBPOM.createNamedQuery(String)
252: return null;
253: }
254:
255: /**
256: * Create an instance of Query for executing a native SQL statement.
257: * @param sqlString an EJB QL query string
258: * @return the new query instance
259: * @throws IllegalArgumentException if query string is not valid
260: * @see javax.persistence.EntityManager#createNativeQuery(java.lang.String)
261: */
262: public Query createNativeQuery(String sqlString) {
263: //TODO implement EJBPOM.createNativeQuery(String)
264: return null;
265: }
266:
267: /**
268: * Create an instance of Query for executing a native SQL statement.
269: * @param sqlString an EJB QL query string
270: * @param resultClass the class of the resulting instances
271: * @return the new query instance
272: * @throws IllegalArgumentException if query string is not valid
273: * @see javax.persistence.EntityManager#createNativeQuery(java.lang.String, java.lang.Class)
274: */
275: public Query createNativeQuery(String sqlString, Class resultClass) {
276: //TODO implement EJBPOM.createNativeQuery(String, Class)
277: return null;
278: }
279:
280: /**
281: * Create an instance of Query for executing a native SQL statement.
282: * @param sqlString an EJB QL query string
283: * @param resultSetMapping the class of the resulting instances
284: * @return the new query instance
285: * @throws IllegalArgumentException if query string is not valid
286: * @see javax.persistence.EntityManager#createNativeQuery(java.lang.String, java.lang.String)
287: */
288: public Query createNativeQuery(String sqlString,
289: String resultSetMapping) {
290: //TODO implement EJBPOM.createNativeQuery(String, String)
291: return null;
292: }
293:
294: public void clear() {
295: // TODO Auto-generated method stub
296:
297: }
298:
299: public FlushModeType getFlushMode() {
300: // TODO Auto-generated method stub
301: return null;
302: }
303:
304: public void lock(Object arg0, LockModeType arg1) {
305: // TODO Auto-generated method stub
306:
307: }
308:
309: public void speedoDeletePersistent(Object o) {
310: //TODO implement EJBPOM.speedoDeletePersistent(Object)
311: }
312:
313: public void speedoDeletePersistent(Object oid, Class pc) {
314: //TODO implement EJBPOM.speedoDeletePersistent(Object,class)
315: }
316:
317: public Object speedoAttachCopy(Object detached, Map map) {
318: //TODO implement EJBPOM.speedoAttachCopy(Object, boolean, map)
319: return null;
320: }
321:
322: public Object speedoDetachCopy(PersistentObjectItf sp, Map map,
323: Collection fgHints) {
324: //TODO implement EJBPOM.speedoDetachCopy(PersistentObjectItf, Map, Collection)
325: return null;
326: }
327:
328: public Object speedoMakePersistent(PersistentObjectItf sp, Map map) {
329: //TODO implement EJBPOM.speedoDeletePersistent(Object)
330: return null;
331: }
332:
333: public void speedoRefresh(PersistentObjectItf sp, Map map,
334: Collection fgHints) {
335: //TODO implement EJBPOM.speedoMakePersistent(PersistentObjectItf, Map)
336:
337: }
338:
339: public void speedoRetrieve(PersistentObjectItf sp, Map map,
340: Collection fgHints) {
341: //TODO implement EJBPOM.speedoRetrieve(PersistentObjectItf, Map, Collection)
342: }
343:
344: }
|