org.clazzes.util.jpa.provider
Class PersistenceUnitInfoImpl

java.lang.Object
  extended by org.clazzes.util.jpa.provider.PersistenceUnitInfoImpl
All Implemented Interfaces:
javax.persistence.spi.PersistenceUnitInfo, javax.security.auth.Destroyable

public class PersistenceUnitInfoImpl
extends java.lang.Object
implements javax.persistence.spi.PersistenceUnitInfo, javax.security.auth.Destroyable

A PersistenceUnitInfo implementation, which takes care for temporary class loader, an application class loader and enhancer support through the aop-util-agent.

If you enable full enhancer support through the aop-util-agent by setting the instrumentationKey property, please call the destroy() method when your bundle stops.

A typical usage of this class in a blueprint context is like follows:

   <bp:bean id="persistenceUnitInfo" class="org.clazzes.util.jpa.provider.PersistenceUnitInfoImpl"
          destroy-method="destroy">
   <bp:property name="temporaryClassLoaderClass" ref="temporaryClassLoaderClass"/>
   <bp:property name="classLoaderHint" value="org.example.SampleClass"/>
   <bp:property name="nonJtaDataSource" ref="dataSource"></bp:property>
   <bp:property name="persistenceUnitName" value="fancymail-server"/>
   <bp:property name="instrumentationKey" value="jpa-util-agent-instrumentation"/>
   <bp:property name="managedClassNames">
      <bp:list>
         <bp:value>org.example.entities.Entity1</bp:value>
         <bp:value>org.example.entities.Entity2</bp:value>
         <bp:value>org.example.entities.Entity3</bp:value>
      </bp:list>
   </bp:property>
   <bp:property name="properties">
     <bp:props>
       <bp:prop key="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
       <bp:prop key="openjpa.MetaDataRepository" value="Preload=true"/>
     </bp:props>
   </bp:property>
 </bp:bean>
 


Constructor Summary
PersistenceUnitInfoImpl()
           
 
Method Summary
 void addJarFile(java.net.URL jar)
           
 void addManagedClassName(java.lang.String name)
          Add a class name to the list of managed entites.
 void addMappingFileName(java.lang.String name)
           
 void addTransformer(javax.persistence.spi.ClassTransformer transformer)
          Add a class transformer to the Instrumentation instance provided by jpa-util-agent under the key getInstrumentationKey().
 void destroy()
          Remove all transformers registered in addTransformer(ClassTransformer) from the Instrumentation instance of jpa-util-agent.
 boolean excludeUnlistedClasses()
           
protected  void finalize()
           
 java.lang.ClassLoader getClassLoader()
          Return the application's class loader.
 java.lang.String getInstrumentationKey()
           
 java.util.List<java.net.URL> getJarFileUrls()
           
 javax.sql.DataSource getJtaDataSource()
           
 java.lang.String getJtaDataSourceName()
           
 java.util.List<java.lang.String> getManagedClassNames()
          Return the list of class names of managed entites.
 java.util.List<java.lang.String> getMappingFileNames()
           
 java.lang.ClassLoader getNewTempClassLoader()
          Instantiate a new temporary class loader, when setTemporaryClassLoaderClass(Class) has been set.
 javax.sql.DataSource getNonJtaDataSource()
           
 java.lang.String getNonJtaDataSourceName()
           
 java.lang.String getPersistenceProviderClassName()
           
 java.lang.String getPersistenceUnitName()
           
 java.net.URL getPersistenceUnitRootUrl()
           
 java.net.URL getPersistenceXmlFileUrl()
          The location of the persistence.xml resource.
 java.lang.String getPersistenceXMLSchemaVersion()
           
 java.util.Properties getProperties()
           
 javax.persistence.SharedCacheMode getSharedCacheMode()
           
 java.io.File getSourceFile()
           
 javax.persistence.spi.PersistenceUnitTransactionType getTransactionType()
          The transaction type.
 javax.persistence.ValidationMode getValidationMode()
           
 boolean isDestroyed()
           
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set the application class loader.
 void setClassLoaderHint(java.lang.Class<?> classLoaderHint)
          Set the class which is used to retrieve the application class loader.
 void setExcludeUnlistedClasses(boolean excludeUnlisted)
           
 void setInstrumentationKey(java.lang.String instrumentationKey)
           
 void setJarFileUrls(java.util.List<java.net.URL> jarFileUrls)
           
 void setJtaDataSource(javax.sql.DataSource ds)
          This method and setJtaDataSourceName(String) are mutually exclusive.
 void setJtaDataSourceName(java.lang.String jta)
          This method and setJtaDataSource(DataSource) are mutually exclusive.
 void setManagedClassNames(java.util.List<java.lang.String> managedClassNames)
          Set the list of class names of managed entites.
 void setMappingFileNames(java.util.List<java.lang.String> mappingFileNames)
           
 void setNonJtaDataSource(javax.sql.DataSource ds)
          This method and setJtaDataSourceName(String) are mutually exclusive.
 void setNonJtaDataSourceName(java.lang.String nonJta)
          This method and setNonJtaDataSource(DataSource) are mutually exclusive.
 void setPersistenceProviderClassName(java.lang.String providerClassName)
           
 void setPersistenceUnitName(java.lang.String emName)
           
 void setPersistenceUnitRootUrl(java.net.URL root)
           
 void setPersistenceXmlFileUrl(java.net.URL url)
          The location of the persistence.xml resource.
 void setPersistenceXMLSchemaVersion(java.lang.String version)
           
 void setProperties(java.util.Properties props)
           
 void setProperty(java.lang.String key, java.lang.String value)
           
 void setSharedCacheMode(javax.persistence.SharedCacheMode mode)
           
 void setTemporaryClassLoaderClass(java.lang.Class temporaryClassLoaderClass)
          The class of the temporary class laoder, which will be instantiated in getNewTempClassLoader().
 void setTransactionType(javax.persistence.spi.PersistenceUnitTransactionType transType)
          Set the transaction type.
 void setValidationMode(javax.persistence.ValidationMode mode)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceUnitInfoImpl

public PersistenceUnitInfoImpl()
Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the application's class loader.

Specified by:
getClassLoader in interface javax.persistence.spi.PersistenceUnitInfo
See Also:
setClassLoader(ClassLoader), setClassLoaderHint(Class)

getNewTempClassLoader

public java.lang.ClassLoader getNewTempClassLoader()
Instantiate a new temporary class loader, when setTemporaryClassLoaderClass(Class) has been set. Otherwise return the application class loader.

Specified by:
getNewTempClassLoader in interface javax.persistence.spi.PersistenceUnitInfo

getPersistenceUnitName

public java.lang.String getPersistenceUnitName()
Specified by:
getPersistenceUnitName in interface javax.persistence.spi.PersistenceUnitInfo

setPersistenceUnitName

public void setPersistenceUnitName(java.lang.String emName)

getPersistenceProviderClassName

public java.lang.String getPersistenceProviderClassName()
Specified by:
getPersistenceProviderClassName in interface javax.persistence.spi.PersistenceUnitInfo

setPersistenceProviderClassName

public void setPersistenceProviderClassName(java.lang.String providerClassName)

getTransactionType

public javax.persistence.spi.PersistenceUnitTransactionType getTransactionType()
The transaction type. The default value is PersistenceUnitTransactionType.RESOURCE_LOCAL.

Specified by:
getTransactionType in interface javax.persistence.spi.PersistenceUnitInfo

setTransactionType

public void setTransactionType(javax.persistence.spi.PersistenceUnitTransactionType transType)
Set the transaction type. The default value is PersistenceUnitTransactionType.RESOURCE_LOCAL.

Parameters:
transType - The transaction type.
See Also:
PersistenceUnitTransactionType.RESOURCE_LOCAL, PersistenceUnitTransactionType.JTA

getJtaDataSourceName

public java.lang.String getJtaDataSourceName()
Returns:
The JNDI name of the datasource when the transaction type is PersistenceUnitTransactionType.JTA.

setJtaDataSourceName

public void setJtaDataSourceName(java.lang.String jta)
This method and setJtaDataSource(DataSource) are mutually exclusive. You need to specify either a JNDI name or a datasource iself.

Parameters:
jta - The JNDI name of the datasource to set, when the transaction type is PersistenceUnitTransactionType.JTA.

getJtaDataSource

public javax.sql.DataSource getJtaDataSource()
Specified by:
getJtaDataSource in interface javax.persistence.spi.PersistenceUnitInfo
Returns:
The datasource to use when the transaction type is PersistenceUnitTransactionType.JTA.

setJtaDataSource

public void setJtaDataSource(javax.sql.DataSource ds)
This method and setJtaDataSourceName(String) are mutually exclusive. You need to specify either a JNDI name or a datasource iself.

Parameters:
ds - The datasource to use when the transaction type is PersistenceUnitTransactionType.JTA.

getNonJtaDataSourceName

public java.lang.String getNonJtaDataSourceName()
Returns:
The JNDI name of the datasource when the transaction type is PersistenceUnitTransactionType.RESOURCE_LOCAL.

setNonJtaDataSourceName

public void setNonJtaDataSourceName(java.lang.String nonJta)
This method and setNonJtaDataSource(DataSource) are mutually exclusive. You need to specify either a JNDI name or a datasource iself.

Parameters:
jta - The JNDI name of the datasource to set, when the transaction type is PersistenceUnitTransactionType.RESOURCE_LOCAL.

getNonJtaDataSource

public javax.sql.DataSource getNonJtaDataSource()
Specified by:
getNonJtaDataSource in interface javax.persistence.spi.PersistenceUnitInfo
Returns:
The datasource to use when the transaction type is PersistenceUnitTransactionType.RESOURCE_LOCAL.

setNonJtaDataSource

public void setNonJtaDataSource(javax.sql.DataSource ds)
This method and setJtaDataSourceName(String) are mutually exclusive. You need to specify either a JNDI name or a datasource iself.

Parameters:
ds - The datasource to use when the transaction type is PersistenceUnitTransactionType.RESOURCE_LOCAL.

getPersistenceUnitRootUrl

public java.net.URL getPersistenceUnitRootUrl()
Specified by:
getPersistenceUnitRootUrl in interface javax.persistence.spi.PersistenceUnitInfo

setPersistenceUnitRootUrl

public void setPersistenceUnitRootUrl(java.net.URL root)

excludeUnlistedClasses

public boolean excludeUnlistedClasses()
Specified by:
excludeUnlistedClasses in interface javax.persistence.spi.PersistenceUnitInfo

setExcludeUnlistedClasses

public void setExcludeUnlistedClasses(boolean excludeUnlisted)

getMappingFileNames

public java.util.List<java.lang.String> getMappingFileNames()
Specified by:
getMappingFileNames in interface javax.persistence.spi.PersistenceUnitInfo

addMappingFileName

public void addMappingFileName(java.lang.String name)

setMappingFileNames

public void setMappingFileNames(java.util.List<java.lang.String> mappingFileNames)

getJarFileUrls

public java.util.List<java.net.URL> getJarFileUrls()
Specified by:
getJarFileUrls in interface javax.persistence.spi.PersistenceUnitInfo

addJarFile

public void addJarFile(java.net.URL jar)

setJarFileUrls

public void setJarFileUrls(java.util.List<java.net.URL> jarFileUrls)

getManagedClassNames

public java.util.List<java.lang.String> getManagedClassNames()
Return the list of class names of managed entites.

Specified by:
getManagedClassNames in interface javax.persistence.spi.PersistenceUnitInfo

addManagedClassName

public void addManagedClassName(java.lang.String name)
Add a class name to the list of managed entites.

Parameters:
name - The name of an entity.

setManagedClassNames

public void setManagedClassNames(java.util.List<java.lang.String> managedClassNames)
Set the list of class names of managed entites.

Parameters:
managedClassNames - Class names of managed entites to set.

getProperties

public java.util.Properties getProperties()
Specified by:
getProperties in interface javax.persistence.spi.PersistenceUnitInfo

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)

setProperties

public void setProperties(java.util.Properties props)

addTransformer

public void addTransformer(javax.persistence.spi.ClassTransformer transformer)

Add a class transformer to the Instrumentation instance provided by jpa-util-agent under the key getInstrumentationKey().

If the instrumentation key is not set or the agent has not been loaded by the JVM, this method throws an UnsupportedOperationException.

Specified by:
addTransformer in interface javax.persistence.spi.PersistenceUnitInfo
Parameters:
transformer - The class transformer to add.

getPersistenceXmlFileUrl

public java.net.URL getPersistenceXmlFileUrl()
The location of the persistence.xml resource. May be null.


setPersistenceXmlFileUrl

public void setPersistenceXmlFileUrl(java.net.URL url)
The location of the persistence.xml resource. May be null.


getSourceFile

public java.io.File getSourceFile()

getPersistenceXMLSchemaVersion

public java.lang.String getPersistenceXMLSchemaVersion()
Specified by:
getPersistenceXMLSchemaVersion in interface javax.persistence.spi.PersistenceUnitInfo

setPersistenceXMLSchemaVersion

public void setPersistenceXMLSchemaVersion(java.lang.String version)

getValidationMode

public javax.persistence.ValidationMode getValidationMode()
Specified by:
getValidationMode in interface javax.persistence.spi.PersistenceUnitInfo

setValidationMode

public void setValidationMode(javax.persistence.ValidationMode mode)

getSharedCacheMode

public javax.persistence.SharedCacheMode getSharedCacheMode()
Specified by:
getSharedCacheMode in interface javax.persistence.spi.PersistenceUnitInfo

setSharedCacheMode

public void setSharedCacheMode(javax.persistence.SharedCacheMode mode)

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Set the application class loader. For convenience you may choose to call setClassLoaderHint(Class).

Parameters:
classLoader - The application class loader.

setClassLoaderHint

public void setClassLoaderHint(java.lang.Class<?> classLoaderHint)
Set the class which is used to retrieve the application class loader.

Parameters:
classLoaderHint - A class on which to call getClassLoader() in order to retrieve the application class loader. Please do no use an entity class, which has to be enhanced in this place.

setTemporaryClassLoaderClass

public void setTemporaryClassLoaderClass(java.lang.Class temporaryClassLoaderClass)
The class of the temporary class laoder, which will be instantiated in getNewTempClassLoader().


getInstrumentationKey

public java.lang.String getInstrumentationKey()
Returns:
the key for Agent.getInstrumentation(String). If set to null, addTransformer(ClassTransformer) throws an UnsupportedOperationException.

setInstrumentationKey

public void setInstrumentationKey(java.lang.String instrumentationKey)
Parameters:
instrumentationKey - the key for Agent.getInstrumentation(String)to set.

destroy

public void destroy()
             throws javax.security.auth.DestroyFailedException
Remove all transformers registered in addTransformer(ClassTransformer) from the Instrumentation instance of jpa-util-agent.

Specified by:
destroy in interface javax.security.auth.Destroyable
Throws:
javax.security.auth.DestroyFailedException

isDestroyed

public boolean isDestroyed()
Specified by:
isDestroyed in interface javax.security.auth.Destroyable

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright © 2011. All Rights Reserved.