org.apache.openjpa.persistence
Class OpenJPAPersistence

java.lang.Object
  extended by javax.persistence.Persistence
      extended by org.apache.openjpa.persistence.OpenJPAPersistence

public class OpenJPAPersistence
extends Persistence

Static helper method for JPA users, including switching between OpenJPA native and Java Persistence APIs.

Since:
0.4.0
Author:
Abe White

Field Summary
static String EM_KEY
           
static String EMF_KEY
           
 
Fields inherited from class javax.persistence.Persistence
PERSISTENCE_PROVIDER, providers
 
Constructor Summary
OpenJPAPersistence()
           
 
Method Summary
static OpenJPAEntityManager cast(EntityManager em)
          Return the OpenJPA facade to the given entity manager.
static OpenJPAEntityManagerFactory cast(EntityManagerFactory emf)
          Return the OpenJPA facade to the given entity manager factory.
static OpenJPAQuery cast(Query q)
          Return the OpenJPA facade to the given query.
static void close(Object o)
          Close the given resource.
static OpenJPAEntityManagerFactory createEntityManagerFactory(String jndiLocation, Context context)
          Returns the EntityManagerFactory at the JNDI location specified by jndiLocation in the context context.
static OpenJPAEntityManagerFactory createEntityManagerFactory(String name, String resource)
          Returns a new OpenJPAEntityManagerFactory specified by name in an XML configuration file at the resource location resource.
static OpenJPAEntityManagerFactory createEntityManagerFactory(String name, String resource, Map map)
          Returns a new OpenJPAEntityManagerFactory specified by name in an XML configuration file at the resource location resource, applying the properties specified in map as overrides.
static Object fromOpenJPAObjectId(Object oid)
          Translate from a OpenJPA identity object to a Persistence one.
static Class fromOpenJPAObjectIdClass(Class oidClass)
          Translate from a OpenJPA identity class to a native one.
static OpenJPAEntityManager getEntityManager(Object o)
          Return the entity manager for the given object, if one can be determined from just the object alone.
static OpenJPAEntityManagerFactory getEntityManagerFactory()
          Returns the OpenJPAEntityManagerFactory specified by your OpenJPA defaults.
static OpenJPAEntityManagerFactory getEntityManagerFactory(Map map)
          Returns the OpenJPAEntityManagerFactory specified by your OpenJPA defaults, using map as overrides.
static ClassMetaData getMetaData(EntityManager em, Class cls)
          Returns the ClassMetaData associated with the persistent type cls.
static ClassMetaData getMetaData(EntityManagerFactory emf, Class cls)
          Returns the ClassMetaData associated with the persistent type cls.
static ClassMetaData getMetaData(Object o)
          Returns the ClassMetaData associated with the persistent object o.
static boolean isManagedType(EntityManager em, Class cls)
          Returns true if the specified class is an entity or embeddable type.
static boolean isManagedType(EntityManagerFactory emf, Class cls)
          Returns true if the specified class is an entity or embeddable type.
static Broker toBroker(EntityManager em)
          Return the underlying broker for the given entity manager facade.
static BrokerFactory toBrokerFactory(EntityManagerFactory emf)
          Return the underlying broker factory for the given persistence manager factory facade.
static OpenJPAEntityManager toEntityManager(Broker broker)
          Return a persistence manager facade to the given broker retaining previously associated persistence context type.
static OpenJPAEntityManagerFactory toEntityManagerFactory(BrokerFactory factory)
           
static Object toOpenJPAObjectId(ClassMetaData meta, Object oid)
          Translate from a Persistence identity object to a OpenJPA one.
static Collection toOpenJPAObjectIds(ClassMetaData meta, Collection oids)
          Return a collection of OpenJPA oids for the given native oid collection.
static Object[] toOpenJPAObjectIds(ClassMetaData meta, Object... oids)
          Return an array of OpenJPA oids for the given native oid array.
 
Methods inherited from class javax.persistence.Persistence
createEntityManagerFactory, createEntityManagerFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EM_KEY

public static final String EM_KEY
See Also:
Constant Field Values

EMF_KEY

public static final String EMF_KEY
See Also:
Constant Field Values
Constructor Detail

OpenJPAPersistence

public OpenJPAPersistence()
Method Detail

toEntityManagerFactory

public static OpenJPAEntityManagerFactory toEntityManagerFactory(BrokerFactory factory)

toBrokerFactory

public static BrokerFactory toBrokerFactory(EntityManagerFactory emf)
Return the underlying broker factory for the given persistence manager factory facade.


toEntityManager

public static OpenJPAEntityManager toEntityManager(Broker broker)
Return a persistence manager facade to the given broker retaining previously associated persistence context type.


toBroker

public static Broker toBroker(EntityManager em)
Return the underlying broker for the given entity manager facade.


cast

public static OpenJPAEntityManagerFactory cast(EntityManagerFactory emf)
Return the OpenJPA facade to the given entity manager factory.


cast

public static OpenJPAEntityManager cast(EntityManager em)
Return the OpenJPA facade to the given entity manager.


cast

public static OpenJPAQuery cast(Query q)
Return the OpenJPA facade to the given query.


getEntityManagerFactory

public static OpenJPAEntityManagerFactory getEntityManagerFactory()
Returns the OpenJPAEntityManagerFactory specified by your OpenJPA defaults. This method will return the same logical factory for each invocation.


getEntityManagerFactory

public static OpenJPAEntityManagerFactory getEntityManagerFactory(Map map)
Returns the OpenJPAEntityManagerFactory specified by your OpenJPA defaults, using map as overrides. This method will return the same logical factory for invocations with the same overrides.


createEntityManagerFactory

public static OpenJPAEntityManagerFactory createEntityManagerFactory(String name,
                                                                     String resource)
Returns a new OpenJPAEntityManagerFactory specified by name in an XML configuration file at the resource location resource. If name is null, uses the first resource found in the specified location, regardless of the name specified in the XML resource or the name of the jar that the resource is contained in. If resource is null, uses the spec-defined META-INF/persistence.xml resource. This method only resolves OpenJPAEntityManagerFactory instances.


createEntityManagerFactory

public static OpenJPAEntityManagerFactory createEntityManagerFactory(String name,
                                                                     String resource,
                                                                     Map map)
Returns a new OpenJPAEntityManagerFactory specified by name in an XML configuration file at the resource location resource, applying the properties specified in map as overrides. If name is null, uses the first resource found in the specified location, regardless of the name specified in the XML resource or the name of the jar that the resource is contained in. If resource is null, uses the spec-defined META-INF/persistence.xml resource. This method only resolves OpenJPAEntityManagerFactory instances.


createEntityManagerFactory

public static OpenJPAEntityManagerFactory createEntityManagerFactory(String jndiLocation,
                                                                     Context context)
Returns the EntityManagerFactory at the JNDI location specified by jndiLocation in the context context. If context is null, new InitialContext() will be used.


getEntityManager

public static OpenJPAEntityManager getEntityManager(Object o)
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 new), or that were created through OpenJPAEntityManager.createInstance(java.lang.Class).


getMetaData

public static ClassMetaData getMetaData(Object o)
Returns the ClassMetaData associated with the persistent object o.


getMetaData

public static ClassMetaData getMetaData(EntityManager em,
                                        Class cls)
Returns the ClassMetaData associated with the persistent type cls.


getMetaData

public static ClassMetaData getMetaData(EntityManagerFactory emf,
                                        Class cls)
Returns the ClassMetaData associated with the persistent type cls.


close

public static void close(Object o)
Close the given resource. The resource can be an extent iterator, query result, large result set relation, or any closeable OpenJPA component.


isManagedType

public static boolean isManagedType(EntityManager em,
                                    Class cls)
Returns true if the specified class is an entity or embeddable type.


isManagedType

public static boolean isManagedType(EntityManagerFactory emf,
                                    Class cls)
Returns true if the specified class is an entity or embeddable type.


fromOpenJPAObjectId

public static Object fromOpenJPAObjectId(Object oid)
Translate from a OpenJPA identity object to a Persistence one.


toOpenJPAObjectId

public static Object toOpenJPAObjectId(ClassMetaData meta,
                                       Object oid)
Translate from a Persistence identity object to a OpenJPA one.


toOpenJPAObjectIds

public static Object[] toOpenJPAObjectIds(ClassMetaData meta,
                                          Object... oids)
Return an array of OpenJPA oids for the given native oid array.


toOpenJPAObjectIds

public static Collection toOpenJPAObjectIds(ClassMetaData meta,
                                            Collection oids)
Return a collection of OpenJPA oids for the given native oid collection.


fromOpenJPAObjectIdClass

public static Class fromOpenJPAObjectIdClass(Class oidClass)
Translate from a OpenJPA identity class to a native one.



Copyright © 2006 Apache Software Foundation. All Rights Reserved.