EclipseLink 2.4.2, build 'v20130514-5956486' API Reference

org.eclipse.persistence.jpa.rs
Class PersistenceContext

java.lang.Object
  extended by org.eclipse.persistence.jpa.rs.PersistenceContext

public class PersistenceContext
extends java.lang.Object

A wrapper around the JPA and JAXB artifacts used to persist an application. A PersistenceContext provides the capability of using the same persistence unit in JPA to to interact with a Database or other JPA-capable data source and in JAXB to interact with either XML or JSON. A PersistenceContext can wrap either an existing persistence unit (EntityManagerFactory), or it can be used to bootstrap a fully dynamic persistence unit.

Author:
douglas.clarke, tom.ware

Field Summary
protected  java.util.List<XmlAdapter> adapters
           
protected  java.net.URI baseURI
          The URI of the Persistence context.
protected  JAXBContext context
          The JAXBConext used to produce JSON or XML
protected  EntityManagerFactory emf
          The EntityManagerFactory used to interact using JPA
static java.lang.String JPARS_CONTEXT
           
protected  java.lang.String name
          The name of the persistence context is used to look it up.
protected  TransactionWrapper transaction
           
 
Constructor Summary
protected PersistenceContext()
           
  PersistenceContext(java.lang.String emfName, org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl emf, java.net.URI defaultURI)
          Instantiates a new persistence context.
 
Method Summary
protected  void addDynamicXMLMetadataSources(java.util.List<java.lang.Object> metadataSources, org.eclipse.persistence.internal.sessions.AbstractSession session)
          This method is used to help construct a JAXBContext from an existing EntityManagerFactory.
 Query buildQuery(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String name, java.util.Map<?,?> parameters, java.util.Map<java.lang.String,?> hints)
           
protected  Query constructQuery(EntityManager em, java.lang.String name, java.util.Map<?,?> parameters, java.util.Map<java.lang.String,?> hints)
           
 void create(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.Object entity)
          A part of the facade over the JPA API Persist an entity in JPA and commit
protected  JAXBContext createDynamicJAXBContext(org.eclipse.persistence.internal.sessions.AbstractSession session)
          Create a JAXBContext based on the EntityManagerFactory for this PersistenceContext
protected  EntityManager createEntityManager(java.lang.String tenantId)
          A part of the facade over the JPA API Create an EntityManager from the EntityManagerFactory wrapped by this persistence context
protected  org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl createEntityManagerFactory(PersistenceUnitInfo info, java.util.Map<java.lang.String,?> properties)
          A part of the facade over the JPA API Create an EntityManagerFactory using the given PersistenceUnitInfo and properties
protected  java.util.Map<java.lang.String,java.lang.Object> createJAXBProperties(org.eclipse.persistence.internal.sessions.AbstractSession session)
          Build the set of properties used to create the JAXBContext based on the EntityManagerFactory that this PersistenceContext wraps
 void delete(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String type, java.lang.Object id)
          A part of the facade over the JPA API Delete the given entity in JPA and commit the changes
 boolean doesExist(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.Object entity)
          Does exist.
 void finalize()
          Finalize.
 java.lang.Object find(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String entityName, java.lang.Object id)
          A part of the facade over the JPA API Find an entity with the given name and id in JPA
 java.lang.Object find(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String entityName, java.lang.Object id, java.util.Map<java.lang.String,java.lang.Object> properties)
          A part of the facade over the JPA API Find an entity with the given name and id in JPA
 java.lang.Object find(java.lang.String entityName, java.lang.Object id)
          A part of the facade over the JPA API Find an entity with the given name and id in JPA
 java.lang.Object findAttribute(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String entityName, java.lang.Object id, java.util.Map<java.lang.String,java.lang.Object> properties, java.lang.String attribute)
          Find attribute.
protected  java.util.List<XmlAdapter> getAdapters()
           
 java.net.URI getBaseURI()
          Gets the base uri.
 java.lang.Class<?> getClass(java.lang.String entityName)
          Look-up the given entity name in the EntityManagerFactory and return the class is describes
 ClassDescriptor getDescriptor(java.lang.String entityName)
          Lookup the descriptor for the given entity name.
 ClassDescriptor getDescriptorForClass(java.lang.Class clazz)
          Gets the descriptor for class.
 EntityManagerFactory getEmf()
          Gets the emf.
 JAXBContext getJAXBContext()
          Gets the jAXB context.
 ClassDescriptor getJAXBDescriptorForClass(java.lang.Class clazz)
          Gets the jAXB descriptor for class.
 DatabaseSession getJpaSession()
          Gets the jpa session.
 java.lang.String getName()
          Gets the name.
 java.lang.String getVersion()
           
 boolean isWeavingEnabled()
           
 void marshallEntity(java.lang.Object object, javax.ws.rs.core.MediaType mediaType, java.io.OutputStream output)
          Marshall an entity to either JSON or XML Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links rather than attempting to marshall the data in those relationships
 void marshallEntity(java.lang.Object object, javax.ws.rs.core.MediaType mediaType, java.io.OutputStream output, boolean sendRelationships)
          Marshall an entity to either JSON or XML
 java.lang.Object merge(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.Object entity)
          A part of the facade over the JPA API Call jpa merge on the given object and commit If the passed object is a list, we will iterate through the list and merge each member
 DynamicEntity newEntity(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String type)
          A convenience method to create a new dynamic entity of the given type
 DynamicEntity newEntity(java.lang.String type)
          A convenience method to create a new dynamic entity of the given type
protected  void postMarshallEntity(java.lang.Object object)
           
protected  void preMarshallEntity(java.lang.Object object)
          Process an entity and add any additional data that needs to be added prior to marshalling This method will both single entities and lists of entities
protected  void preMarshallIndividualEntity(java.lang.Object entity)
          Add any data required prior to marshalling an entity to XML or JSON In general, this will only affect fields that have been weaved into the object
 int queryExecuteUpdate(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String name, java.util.Map<?,?> parameters, java.util.Map<java.lang.String,?> hints)
          Query execute update.
 java.util.List queryMultipleResults(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String name, java.util.Map<?,?> parameters, java.util.Map<java.lang.String,?> hints)
          Query multiple results.
 java.lang.Object removeAttribute(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String entityName, java.lang.Object id, java.lang.String attribute, java.lang.String listItemId, java.lang.Object entity, java.lang.String partner)
          Removes the attribute.
protected  void removeMappingValueFromObject(java.lang.Object object, java.lang.Object attributeValue, DatabaseMapping mapping, DatabaseMapping partner)
           
 void setBaseURI(java.net.URI baseURI)
          Sets the base uri.
protected  void setMappingValueInObject(java.lang.Object object, java.lang.Object attributeValue, DatabaseMapping mapping, DatabaseMapping partner)
           
 void setVersion(java.lang.String version)
           
 void stop()
          Stop the current application instance
 java.lang.String toString()
          To string.
 java.lang.Object unmarshalEntity(java.lang.Class type, javax.ws.rs.core.MediaType acceptedMedia, java.io.InputStream in)
          Marshall an entity to either JSON or XML
 java.lang.Object unmarshalEntity(java.lang.String type, javax.ws.rs.core.MediaType acceptedMedia, java.io.InputStream in)
          Marshall an entity to either JSON or XML Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links rather than attempting to marshall the data in those relationships
 java.lang.Object updateOrAddAttribute(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String entityName, java.lang.Object id, java.util.Map<java.lang.String,java.lang.Object> properties, java.lang.String attribute, java.lang.Object attributeValue, java.lang.String partner)
          Update or add attribute.
protected  java.lang.Object wrap(java.lang.Object entity)
          Make adjustments to an unmarshalled entity based on what is found in the weaved fields
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JPARS_CONTEXT

public static final java.lang.String JPARS_CONTEXT
See Also:
Constant Field Values

adapters

protected java.util.List<XmlAdapter> adapters

name

protected java.lang.String name
The name of the persistence context is used to look it up. By default it will be the persistence unit name of the JPA persistence unit.


emf

protected EntityManagerFactory emf
The EntityManagerFactory used to interact using JPA


context

protected JAXBContext context
The JAXBConext used to produce JSON or XML


baseURI

protected java.net.URI baseURI
The URI of the Persistence context. This is used to build Links in JSON and XML


transaction

protected TransactionWrapper transaction
Constructor Detail

PersistenceContext

protected PersistenceContext()

PersistenceContext

public PersistenceContext(java.lang.String emfName,
                          org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl emf,
                          java.net.URI defaultURI)
Instantiates a new persistence context.

Parameters:
emfName - the emf name
emf - the emf
defaultURI - the default uri
Method Detail

isWeavingEnabled

public boolean isWeavingEnabled()

getVersion

public java.lang.String getVersion()

setVersion

public void setVersion(java.lang.String version)

addDynamicXMLMetadataSources

protected void addDynamicXMLMetadataSources(java.util.List<java.lang.Object> metadataSources,
                                            org.eclipse.persistence.internal.sessions.AbstractSession session)
This method is used to help construct a JAXBContext from an existing EntityManagerFactory. For each package in the EntityManagerFactory, a MetadataSource that is capable of building a JAXBContext that creates the same mappings in JAXB is created. These MetadataSources are used to constuct the JAXContext that is used for JSON and XML translation

Parameters:
metadataSources -
persistenceUnitName -
session -

create

public void create(java.util.Map<java.lang.String,java.lang.String> tenantId,
                   java.lang.Object entity)
A part of the facade over the JPA API Persist an entity in JPA and commit

Parameters:
tenantId -
entity -

createDynamicJAXBContext

protected JAXBContext createDynamicJAXBContext(org.eclipse.persistence.internal.sessions.AbstractSession session)
                                        throws JAXBException,
                                               java.io.IOException
Create a JAXBContext based on the EntityManagerFactory for this PersistenceContext

Parameters:
session -
Returns:
Throws:
JAXBException
java.io.IOException

createEntityManagerFactory

protected org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl createEntityManagerFactory(PersistenceUnitInfo info,
                                                                                                   java.util.Map<java.lang.String,?> properties)
A part of the facade over the JPA API Create an EntityManagerFactory using the given PersistenceUnitInfo and properties

Parameters:
info -
properties -
Returns:

createEntityManager

protected EntityManager createEntityManager(java.lang.String tenantId)
A part of the facade over the JPA API Create an EntityManager from the EntityManagerFactory wrapped by this persistence context

Parameters:
tenantId -
Returns:

createJAXBProperties

protected java.util.Map<java.lang.String,java.lang.Object> createJAXBProperties(org.eclipse.persistence.internal.sessions.AbstractSession session)
                                                                         throws java.io.IOException
Build the set of properties used to create the JAXBContext based on the EntityManagerFactory that this PersistenceContext wraps

Parameters:
persistenceUnitName -
session -
Returns:
Throws:
java.io.IOException

delete

public void delete(java.util.Map<java.lang.String,java.lang.String> tenantId,
                   java.lang.String type,
                   java.lang.Object id)
A part of the facade over the JPA API Delete the given entity in JPA and commit the changes


doesExist

public boolean doesExist(java.util.Map<java.lang.String,java.lang.String> tenantId,
                         java.lang.Object entity)
Does exist.

Parameters:
tenantId - the tenant id
entity - the entity
Returns:
true, if successful

finalize

public void finalize()
Finalize.

Overrides:
finalize in class java.lang.Object

find

public java.lang.Object find(java.lang.String entityName,
                             java.lang.Object id)
A part of the facade over the JPA API Find an entity with the given name and id in JPA

Parameters:
entityName -
id -
Returns:

find

public java.lang.Object find(java.util.Map<java.lang.String,java.lang.String> tenantId,
                             java.lang.String entityName,
                             java.lang.Object id)
A part of the facade over the JPA API Find an entity with the given name and id in JPA

Parameters:
tenantId -
entityName -
id -
Returns:

find

public java.lang.Object find(java.util.Map<java.lang.String,java.lang.String> tenantId,
                             java.lang.String entityName,
                             java.lang.Object id,
                             java.util.Map<java.lang.String,java.lang.Object> properties)
A part of the facade over the JPA API Find an entity with the given name and id in JPA

Parameters:
tenantId -
entityName -
id -
properties - - query hints used on the find
Returns:

findAttribute

public java.lang.Object findAttribute(java.util.Map<java.lang.String,java.lang.String> tenantId,
                                      java.lang.String entityName,
                                      java.lang.Object id,
                                      java.util.Map<java.lang.String,java.lang.Object> properties,
                                      java.lang.String attribute)
Find attribute.

Parameters:
tenantId - the tenant id
entityName - the entity name
id - the id
properties - the properties
attribute - the attribute
Returns:
the object

updateOrAddAttribute

public java.lang.Object updateOrAddAttribute(java.util.Map<java.lang.String,java.lang.String> tenantId,
                                             java.lang.String entityName,
                                             java.lang.Object id,
                                             java.util.Map<java.lang.String,java.lang.Object> properties,
                                             java.lang.String attribute,
                                             java.lang.Object attributeValue,
                                             java.lang.String partner)
Update or add attribute.

Parameters:
tenantId - the tenant id
entityName - the entity name
id - the id
properties - the properties
attribute - the attribute
attributeValue - the attribute value
partner - the partner
Returns:
the object

removeAttribute

public java.lang.Object removeAttribute(java.util.Map<java.lang.String,java.lang.String> tenantId,
                                        java.lang.String entityName,
                                        java.lang.Object id,
                                        java.lang.String attribute,
                                        java.lang.String listItemId,
                                        java.lang.Object entity,
                                        java.lang.String partner)
Removes the attribute.

Parameters:
tenantId - the tenant id
entityName - the entity name
id - the id
properties - the properties
attribute - the attribute
attributeValue - the attribute value
partner - the partner
Returns:
the object

removeMappingValueFromObject

protected void removeMappingValueFromObject(java.lang.Object object,
                                            java.lang.Object attributeValue,
                                            DatabaseMapping mapping,
                                            DatabaseMapping partner)

getBaseURI

public java.net.URI getBaseURI()
Gets the base uri.

Returns:
the base uri

getClass

public java.lang.Class<?> getClass(java.lang.String entityName)
Look-up the given entity name in the EntityManagerFactory and return the class is describes

Parameters:
entityName -
Returns:

getJpaSession

public DatabaseSession getJpaSession()
Gets the jpa session.

Returns:
the jpa session

getDescriptor

public ClassDescriptor getDescriptor(java.lang.String entityName)
Lookup the descriptor for the given entity name. This method will look first in the EntityManagerFactory wrapped by this persistence context and return that descriptor. If one does not exist, it search the JAXBContext and return a descriptor from there.

Parameters:
entityName -
Returns:

getDescriptorForClass

public ClassDescriptor getDescriptorForClass(java.lang.Class clazz)
Gets the descriptor for class.

Parameters:
clazz - the clazz
Returns:
the descriptor for class

getJAXBDescriptorForClass

public ClassDescriptor getJAXBDescriptorForClass(java.lang.Class clazz)
Gets the jAXB descriptor for class.

Parameters:
clazz - the clazz
Returns:
the jAXB descriptor for class

getEmf

public EntityManagerFactory getEmf()
Gets the emf.

Returns:
the emf

getJAXBContext

public JAXBContext getJAXBContext()
Gets the jAXB context.

Returns:
the jAXB context

getName

public java.lang.String getName()
Gets the name.

Returns:
the name

merge

public java.lang.Object merge(java.util.Map<java.lang.String,java.lang.String> tenantId,
                              java.lang.Object entity)
A part of the facade over the JPA API Call jpa merge on the given object and commit If the passed object is a list, we will iterate through the list and merge each member

Parameters:
tenantId -
entity -
Returns:

newEntity

public DynamicEntity newEntity(java.lang.String type)
A convenience method to create a new dynamic entity of the given type

Parameters:
type -
Returns:

newEntity

public DynamicEntity newEntity(java.util.Map<java.lang.String,java.lang.String> tenantId,
                               java.lang.String type)
A convenience method to create a new dynamic entity of the given type

Parameters:
tenantId -
type -
Returns:

queryExecuteUpdate

public int queryExecuteUpdate(java.util.Map<java.lang.String,java.lang.String> tenantId,
                              java.lang.String name,
                              java.util.Map<?,?> parameters,
                              java.util.Map<java.lang.String,?> hints)
Query execute update.

Parameters:
tenantId - the tenant id
name - the name
parameters - the parameters
hints - the hints
Returns:
the int

queryMultipleResults

public java.util.List queryMultipleResults(java.util.Map<java.lang.String,java.lang.String> tenantId,
                                           java.lang.String name,
                                           java.util.Map<?,?> parameters,
                                           java.util.Map<java.lang.String,?> hints)
Query multiple results.

Parameters:
tenantId - the tenant id
name - the name
parameters - the parameters
hints - the hints
Returns:
the list

constructQuery

protected Query constructQuery(EntityManager em,
                               java.lang.String name,
                               java.util.Map<?,?> parameters,
                               java.util.Map<java.lang.String,?> hints)

buildQuery

public Query buildQuery(java.util.Map<java.lang.String,java.lang.String> tenantId,
                        java.lang.String name,
                        java.util.Map<?,?> parameters,
                        java.util.Map<java.lang.String,?> hints)

setBaseURI

public void setBaseURI(java.net.URI baseURI)
Sets the base uri.

Parameters:
baseURI - the new base uri

setMappingValueInObject

protected void setMappingValueInObject(java.lang.Object object,
                                       java.lang.Object attributeValue,
                                       DatabaseMapping mapping,
                                       DatabaseMapping partner)

stop

public void stop()
Stop the current application instance


toString

public java.lang.String toString()
To string.

Overrides:
toString in class java.lang.Object
Returns:
the string

unmarshalEntity

public java.lang.Object unmarshalEntity(java.lang.String type,
                                        javax.ws.rs.core.MediaType acceptedMedia,
                                        java.io.InputStream in)
                                 throws JAXBException
Marshall an entity to either JSON or XML Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links rather than attempting to marshall the data in those relationships

Parameters:
object -
mediaType -
output -
Throws:
JAXBException

unmarshalEntity

public java.lang.Object unmarshalEntity(java.lang.Class type,
                                        javax.ws.rs.core.MediaType acceptedMedia,
                                        java.io.InputStream in)
                                 throws JAXBException
Marshall an entity to either JSON or XML

Parameters:
object -
mediaType -
output -
sendRelationships - if this is set to true, relationships will be sent as links instead of sending the actual objects in the relationships
Throws:
JAXBException

wrap

protected java.lang.Object wrap(java.lang.Object entity)
Make adjustments to an unmarshalled entity based on what is found in the weaved fields

Parameters:
entity -
Returns:

marshallEntity

public void marshallEntity(java.lang.Object object,
                           javax.ws.rs.core.MediaType mediaType,
                           java.io.OutputStream output)
                    throws JAXBException
Marshall an entity to either JSON or XML Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links rather than attempting to marshall the data in those relationships

Parameters:
object -
mediaType -
output -
Throws:
JAXBException

marshallEntity

public void marshallEntity(java.lang.Object object,
                           javax.ws.rs.core.MediaType mediaType,
                           java.io.OutputStream output,
                           boolean sendRelationships)
                    throws JAXBException
Marshall an entity to either JSON or XML

Parameters:
object -
mediaType -
output -
sendRelationships - if this is set to true, relationships will be sent as links instead of sending the actual objects in the relationships
Throws:
JAXBException

preMarshallEntity

protected void preMarshallEntity(java.lang.Object object)
Process an entity and add any additional data that needs to be added prior to marshalling This method will both single entities and lists of entities

Parameters:
object -

preMarshallIndividualEntity

protected void preMarshallIndividualEntity(java.lang.Object entity)
Add any data required prior to marshalling an entity to XML or JSON In general, this will only affect fields that have been weaved into the object

Parameters:
entity -

postMarshallEntity

protected void postMarshallEntity(java.lang.Object object)

getAdapters

protected java.util.List<XmlAdapter> getAdapters()
                                          throws JPARSException
Throws:
JPARSException

EclipseLink 2.4.2, build 'v20130514-5956486' API Reference