EclipseLink JPA-RS 2.4.1, build 'v20121003-ad44345' 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.net.URI baseURI
          The URI of the Persistence context.
static java.lang.String CHANGE_NOTIFICATION_LISTENER
          This internal property is used to save a change listener on the session for later retreival.
protected  org.eclipse.persistence.jaxb.JAXBContext context
          The JAXBConext used to produce JSON or XML
protected  javax.persistence.EntityManagerFactory emf
          The EntityManagerFactory used to interact using JPA
 DatabaseEventListenerFactory eventListenerFactory
          A factory class that will provide listeners for events provided by the database Setting this provides a hook to allow applications that are capable of receiving events from the database to do so.
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)
           
 
Method Summary
protected  void addDynamicXMLMetadataSources(java.util.List<java.lang.Object> metadataSources, org.eclipse.persistence.sessions.server.Server session)
          This method is used to help construct a JAXBContext from an existing EntityManagerFactory.
 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  org.eclipse.persistence.jaxb.JAXBContext createDynamicJAXBContext(org.eclipse.persistence.sessions.server.Server session)
          Create a JAXBConext based on the EntityManagerFactory for this PersistenceContext
protected  javax.persistence.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(javax.persistence.spi.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.sessions.server.Server 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
 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)
           
 java.net.URI getBaseURI()
           
 java.lang.Class<?> getClass(java.lang.String entityName)
          Look-up the given entity name in the EntityManagerFactory and return the class is describes
 org.eclipse.persistence.descriptors.ClassDescriptor getDescriptor(java.lang.String entityName)
          Lookup the descriptor for the given entity name.
 org.eclipse.persistence.descriptors.ClassDescriptor getDescriptorForClass(java.lang.Class clazz)
           
 javax.persistence.EntityManagerFactory getEmf()
           
 org.eclipse.persistence.jaxb.JAXBContext getJAXBContext()
           
 org.eclipse.persistence.sessions.server.ServerSession getJpaSession()
           
 java.lang.String getName()
           
 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
 org.eclipse.persistence.dynamic.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
 org.eclipse.persistence.dynamic.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
 java.lang.Object query(java.util.Map<java.lang.String,java.lang.String> tenantId, java.lang.String name, java.util.Map<?,?> parameters)
          A part of the facade over the JPA API Run a query with the given name in JPA and return the result
 java.lang.Object query(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, boolean returnSingleResult, boolean executeUpdate)
          A part of the facade over the JPA API Run a query with the given name in JPA and return the result
 void remove(ChangeListener listener)
          Remove a given change listener.
 java.lang.Object removeAttribute(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)
           
protected  void removeMappingValueFromObject(java.lang.Object object, java.lang.Object attributeValue, org.eclipse.persistence.mappings.DatabaseMapping mapping, org.eclipse.persistence.mappings.DatabaseMapping partner)
           
 void setBaseURI(java.net.URI baseURI)
           
 void setEventListenerFactory(DatabaseEventListenerFactory eventListenerFactory)
          Static setter for the EVENT_LISTENER_FACTORY Part of the mechanism for plugging in code that can react to database events
protected  void setMappingValueInObject(java.lang.Object object, java.lang.Object attributeValue, org.eclipse.persistence.mappings.DatabaseMapping mapping, org.eclipse.persistence.mappings.DatabaseMapping partner)
           
 void stop()
          Stop the current application instance
 java.lang.String toString()
           
 java.lang.Object unmarshalEntity(java.lang.Class type, javax.ws.rs.core.MediaType acceptedMedia, java.io.InputStream in)
           
 java.lang.Object unmarshalEntity(java.lang.String type, javax.ws.rs.core.MediaType acceptedMedia, java.io.InputStream in)
           
 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)
           
protected  java.lang.Object wrap(java.lang.Object entity)
          Make adjustements to an unmarshalled entity based on what is found in the weaved fields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

eventListenerFactory

public DatabaseEventListenerFactory eventListenerFactory
A factory class that will provide listeners for events provided by the database Setting this provides a hook to allow applications that are capable of receiving events from the database to do so.


CHANGE_NOTIFICATION_LISTENER

public static final java.lang.String CHANGE_NOTIFICATION_LISTENER
This internal property is used to save a change listener on the session for later retreival.

See Also:
Constant Field Values

JPARS_CONTEXT

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

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 javax.persistence.EntityManagerFactory emf
The EntityManagerFactory used to interact using JPA


context

protected org.eclipse.persistence.jaxb.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)
Method Detail

setEventListenerFactory

public void setEventListenerFactory(DatabaseEventListenerFactory eventListenerFactory)
Static setter for the EVENT_LISTENER_FACTORY Part of the mechanism for plugging in code that can react to database events

Parameters:
eventListenerFactory -

addDynamicXMLMetadataSources

protected void addDynamicXMLMetadataSources(java.util.List<java.lang.Object> metadataSources,
                                            org.eclipse.persistence.sessions.server.Server 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 org.eclipse.persistence.jaxb.JAXBContext createDynamicJAXBContext(org.eclipse.persistence.sessions.server.Server session)
                                                                     throws javax.xml.bind.JAXBException,
                                                                            java.io.IOException
Create a JAXBConext based on the EntityManagerFactory for this PersistenceContext

Parameters:
session -
Returns:
Throws:
javax.xml.bind.JAXBException
java.io.IOException

createEntityManagerFactory

protected org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl createEntityManagerFactory(javax.persistence.spi.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 javax.persistence.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.sessions.server.Server 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


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)

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)

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.util.Map<java.lang.String,java.lang.Object> properties,
                                        java.lang.String attribute,
                                        java.lang.Object attributeValue,
                                        java.lang.String partner)

removeMappingValueFromObject

protected void removeMappingValueFromObject(java.lang.Object object,
                                            java.lang.Object attributeValue,
                                            org.eclipse.persistence.mappings.DatabaseMapping mapping,
                                            org.eclipse.persistence.mappings.DatabaseMapping partner)

getBaseURI

public java.net.URI getBaseURI()

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 org.eclipse.persistence.sessions.server.ServerSession getJpaSession()

getDescriptor

public org.eclipse.persistence.descriptors.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 org.eclipse.persistence.descriptors.ClassDescriptor getDescriptorForClass(java.lang.Class clazz)

getEmf

public javax.persistence.EntityManagerFactory getEmf()

getJAXBContext

public org.eclipse.persistence.jaxb.JAXBContext getJAXBContext()

getName

public java.lang.String getName()

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 org.eclipse.persistence.dynamic.DynamicEntity newEntity(java.lang.String type)
A convenience method to create a new dynamic entity of the given type

Parameters:
type -
Returns:

newEntity

public org.eclipse.persistence.dynamic.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:

query

public java.lang.Object query(java.util.Map<java.lang.String,java.lang.String> tenantId,
                              java.lang.String name,
                              java.util.Map<?,?> parameters)
A part of the facade over the JPA API Run a query with the given name in JPA and return the result

Parameters:
name -
parameters -
Returns:

query

public java.lang.Object query(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,
                              boolean returnSingleResult,
                              boolean executeUpdate)
A part of the facade over the JPA API Run a query with the given name in JPA and return the result

Parameters:
name -
parameters -
hints -
returnSingleResult -
Returns:

remove

public void remove(ChangeListener listener)
Remove a given change listener. Used in interacting with an application-provided mechanism for listenig to database events.

Parameters:
listener -

setBaseURI

public void setBaseURI(java.net.URI baseURI)

setMappingValueInObject

protected void setMappingValueInObject(java.lang.Object object,
                                       java.lang.Object attributeValue,
                                       org.eclipse.persistence.mappings.DatabaseMapping mapping,
                                       org.eclipse.persistence.mappings.DatabaseMapping partner)

stop

public void stop()
Stop the current application instance


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

unmarshalEntity

public java.lang.Object unmarshalEntity(java.lang.String type,
                                        javax.ws.rs.core.MediaType acceptedMedia,
                                        java.io.InputStream in)
                                 throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

unmarshalEntity

public java.lang.Object unmarshalEntity(java.lang.Class type,
                                        javax.ws.rs.core.MediaType acceptedMedia,
                                        java.io.InputStream in)
                                 throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

wrap

protected java.lang.Object wrap(java.lang.Object entity)
Make adjustements 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 javax.xml.bind.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:
javax.xml.bind.JAXBException

marshallEntity

public void marshallEntity(java.lang.Object object,
                           javax.ws.rs.core.MediaType mediaType,
                           java.io.OutputStream output,
                           boolean sendRelationships)
                    throws javax.xml.bind.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:
javax.xml.bind.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)

EclipseLink JPA-RS 2.4.1, build 'v20121003-ad44345' API Reference