/** * Extracts the broker from the given persistence capable instance. * @param pc a persistence capable instance * @return null if a Broker can notbe extracted */ protected Broker getBroker(PersistenceCapable pc) { if (pc == null) return null; Object ctx = pc.pcGetGenericContext(); return ctx instanceof Broker ? (Broker)ctx : null; }
/** * Extracts the broker from the given persistence capable instance. * @param pc a persistence capable instance * @return null if a Broker can notbe extracted */ protected Broker getBroker(PersistenceCapable pc) { if (pc == null) return null; Object ctx = pc.pcGetGenericContext(); return ctx instanceof Broker ? (Broker)ctx : null; }
/** * Extracts the broker from the given persistence capable instance. * @param pc a persistence capable instance * @return null if a Broker can notbe extracted */ protected Broker getBroker(PersistenceCapable pc) { if (pc == null) return null; Object ctx = pc.pcGetGenericContext(); return ctx instanceof Broker ? (Broker)ctx : null; }
/** * Extracts the broker from the given persistence capable instance. * @param pc a persistence capable instance * @return null if a Broker can notbe extracted */ protected Broker getBroker(PersistenceCapable pc) { if (pc == null) return null; Object ctx = pc.pcGetGenericContext(); return ctx instanceof Broker ? (Broker)ctx : null; }
/** * Return the state manager for the given instance, or null. * * @param assertThisContext if true, thow an exception if the given * object is managed by another broker */ protected StateManagerImpl getStateManagerImpl(Object obj, boolean assertThisContext) { if (ImplHelper.isManageable(obj)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf); if (pc.pcGetGenericContext() == this) return (StateManagerImpl) pc.pcGetStateManager(); if (assertThisContext && pc.pcGetGenericContext() != null) throw new UserException(_loc.get("not-managed", Exceptions.toString(obj))).setFailedObject(obj); } return null; }
/** * Determines whether the specified state manager is managed by an open * broker within the persistence unit of the provided EMF instance. * @param emf OpenJPAEntityManagerFactory * @param sm StateManager * @return true if this state manager is managed by a broker within * this persistence unit. */ public static boolean isManagedBy(OpenJPAEntityManagerFactory emf, Object entity) { // Assert a valid emf was provided, it is open, and the entity is PC if (emf == null || !emf.isOpen() || !ImplHelper.isManageable(entity)) { return false; } // Assert the context is a broker PersistenceCapable pc = (PersistenceCapable)entity; if (!(pc.pcGetGenericContext() instanceof Broker)) { return false; } // Assert the broker is available and open Broker broker = (Broker)pc.pcGetGenericContext(); if (broker == null || broker.isClosed()) { return false; } // Assert the emf associated with the PC is the same as the provided emf OpenJPAEntityManagerFactory eemf = JPAFacadeHelper.toEntityManagerFactory(broker.getBrokerFactory()); if (eemf == emf && eemf.isOpen()) { return true; } return false; }
/** * Return the entity manager for the given object, if one can be determined * from just the object alone. This method will succeed for instances that * are enhanced, that were loaded from the database (rather than * being constructed with <code>new</code>), or that were created through * {@link OpenJPAEntityManager#createInstance}. */ public static OpenJPAEntityManager getEntityManager(Object o) { try { if (ImplHelper.isManageable(o)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(o, null); if (pc != null) return JPAFacadeHelper.toEntityManager( (Broker) pc.pcGetGenericContext()); } return null; } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); } }
/** * Return the entity manager for the given object, if one can be determined * from just the object alone. This method will succeed for instances that * are enhanced, that were loaded from the database (rather than * being constructed with <code>new</code>), or that were created through * {@link OpenJPAEntityManager#createInstance}. */ public static OpenJPAEntityManager getEntityManager(Object o) { try { if (ImplHelper.isManageable(o)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(o, null); if (pc != null) return JPAFacadeHelper.toEntityManager( (Broker) pc.pcGetGenericContext()); } return null; } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); } }
/** * Return the entity manager for the given object, if one can be determined * from just the object alone. This method will succeed for instances that * are enhanced, that were loaded from the database (rather than * being constructed with <code>new</code>), or that were created through * {@link OpenJPAEntityManager#createInstance}. */ public static OpenJPAEntityManager getEntityManager(Object o) { try { if (ImplHelper.isManageable(o)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(o, null); if (pc != null) return JPAFacadeHelper.toEntityManager( (Broker) pc.pcGetGenericContext()); } return null; } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); } }
/** * Return the entity manager for the given object, if one can be determined * from just the object alone. This method will succeed for instances that * are enhanced, that were loaded from the database (rather than * being constructed with <code>new</code>), or that were created through * {@link OpenJPAEntityManager#createInstance}. */ public static OpenJPAEntityManager getEntityManager(Object o) { try { if (ImplHelper.isManageable(o)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(o, null); if (pc != null) return JPAFacadeHelper.toEntityManager( (Broker) pc.pcGetGenericContext()); } return null; } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); } }
/** * Return the entity manager for the given object, if one can be determined * from just the object alone. This method will succeed for instances that * are enhanced, that were loaded from the database (rather than * being constructed with <code>new</code>), or that were created through * {@link OpenJPAEntityManager#createInstance}. */ public static OpenJPAEntityManager getEntityManager(Object o) { try { if (ImplHelper.isManageable(o)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(o, null); if (pc != null) return JPAFacadeHelper.toEntityManager( (Broker) pc.pcGetGenericContext()); } return null; } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); } }
/** * Return the state manager for the given instance, or null. * * @param assertThisContext if true, thow an exception if the given * object is managed by another broker */ protected StateManagerImpl getStateManagerImpl(Object obj, boolean assertThisContext) { if (ImplHelper.isManageable(obj)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf); BrokerImpl pcBroker = (BrokerImpl)pc.pcGetGenericContext(); if (pcBroker == this || isFromWriteBehindCallback()) return (StateManagerImpl) pc.pcGetStateManager(); if (assertThisContext && pcBroker != null) throw new UserException(_loc.get("not-managed", Exceptions.toString(obj))).setFailedObject(obj); } return null; }
/** * Return the state manager for the given instance, or null. * * @param assertThisContext if true, thow an exception if the given * object is managed by another broker */ protected StateManagerImpl getStateManagerImpl(Object obj, boolean assertThisContext) { if (ImplHelper.isManageable(obj)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf); BrokerImpl pcBroker = (BrokerImpl)pc.pcGetGenericContext(); if (pcBroker == this || isFromWriteBehindCallback()) return (StateManagerImpl) pc.pcGetStateManager(); if (assertThisContext && pcBroker != null) throw new UserException(_loc.get("not-managed", Exceptions.toString(obj))).setFailedObject(obj); } return null; }
/** * Return the state manager for the given instance, or null. * * @param assertThisContext if true, thow an exception if the given * object is managed by another broker */ protected StateManagerImpl getStateManagerImpl(Object obj, boolean assertThisContext) { if (ImplHelper.isManageable(obj)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf); BrokerImpl pcBroker = (BrokerImpl)pc.pcGetGenericContext(); if (pcBroker == this || isFromWriteBehindCallback()) return (StateManagerImpl) pc.pcGetStateManager(); if (assertThisContext && pcBroker != null) throw new UserException(_loc.get("not-managed", Exceptions.toString(obj))).setFailedObject(obj); } return null; }
/** * Disallows setting an object id field to a managed instance. */ void assertNotManagedObjectId(Object val) { if (val != null && (ImplHelper.toPersistenceCapable(val, getContext().getConfiguration())).pcGetGenericContext()!= null) throw translate(new InvalidStateException(_loc.get ("managed-oid", Exceptions.toString(val), Exceptions.toString(getManagedInstance()))). setFailedObject(getManagedInstance())); }
/** * Return the state manager for the given instance, or null. * * @param assertThisContext if true, thow an exception if the given * object is managed by another broker */ protected StateManagerImpl getStateManagerImpl(Object obj, boolean assertThisContext) { if (ImplHelper.isManageable(obj)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf); BrokerImpl pcBroker = (BrokerImpl)pc.pcGetGenericContext(); if (pcBroker == this || isFromWriteBehindCallback()) return (StateManagerImpl) pc.pcGetStateManager(); if (assertThisContext && pcBroker != null) throw new UserException(_loc.get("not-managed", Exceptions.toString(obj))).setFailedObject(obj); } return null; }
/** * Disallows setting an object id field to a managed instance. */ void assertNotManagedObjectId(Object val) { if (val != null && (ImplHelper.toPersistenceCapable(val, getContext().getConfiguration())).pcGetGenericContext()!= null) throw translate(new InvalidStateException(_loc.get ("managed-oid", Exceptions.toString(val), Exceptions.toString(getManagedInstance()))). setFailedObject(getManagedInstance())); }
/** * Disallows setting an object id field to a managed instance. */ void assertNotManagedObjectId(Object val) { if (val != null && (ImplHelper.toPersistenceCapable(val, getContext().getConfiguration())).pcGetGenericContext()!= null) throw translate(new InvalidStateException(_loc.get ("managed-oid", Exceptions.toString(val), Exceptions.toString(getManagedInstance()))). setFailedObject(getManagedInstance())); }
/** * Disallows setting an object id field to a managed instance. */ void assertNotManagedObjectId(Object val) { if (val != null && (ImplHelper.toPersistenceCapable(val, getContext().getConfiguration())).pcGetGenericContext()!= null) throw translate(new InvalidStateException(_loc.get ("managed-oid", Exceptions.toString(val), Exceptions.toString(getManagedInstance()))). setFailedObject(getManagedInstance())); }
/** * Disallows setting an object id field to a managed instance. */ void assertNotManagedObjectId(Object val) { if (val != null && (ImplHelper.toPersistenceCapable(val, getContext().getConfiguration())).pcGetGenericContext()!= null) throw translate(new InvalidStateException(_loc.get ("managed-oid", Exceptions.toString(val), Exceptions.toString(getManagedInstance()))). setFailedObject(getManagedInstance())); }