com.caucho.amber.manager
Class AmberPersistenceUnit

java.lang.Object
  extended by com.caucho.amber.manager.AmberPersistenceUnit

public class AmberPersistenceUnit
extends java.lang.Object

Main interface between Resin and the connector. It's the top-level SPI class for creating the SPI ManagedConnections. The resource configuration in Resin's web.xml will use bean-style configuration to configure the ManagecConnectionFactory.


Constructor Summary
AmberPersistenceUnit(AmberContainer container, java.lang.String name)
           
 
Method Summary
 ListenerType addDefaultListener(java.lang.Class beanClass)
          Adds a default listener.
 void addEntityClass(java.lang.String className, java.lang.Class type)
          Add an entity.
 ListenerType addEntityListener(java.lang.String entityName, java.lang.Class listenerClass)
          Adds an entity listener.
 void addNamedNativeQuery(java.lang.String name, NamedNativeQueryConfig queryConfig)
          Adds a named native query.
 void addNamedQuery(java.lang.String name, java.lang.String query)
          Adds a named query.
 void addSqlResultSetMapping(java.lang.String resultSetName, SqlResultSetMappingConfig resultSet)
          Adds a sql result set mapping.
protected  void callListeners(int callbackIndex, Entity entity)
          Applies persistence unit default and entity listeners for @PreXxx, @PostXxx callbacks.
 void complete(java.util.ArrayList<AmberCompletion> completions)
          Completions affecting the cache.
 void configure()
          Configure lazy.
 AmberConnection createAmberConnection(boolean isExtended)
          Returns the cache connection.
 EmbeddableType createEmbeddable(java.lang.Class beanClass)
          Adds an embeddable type.
 EmbeddableType createEmbeddable(java.lang.String name, java.lang.Class beanClass)
          Adds an embeddable type.
 EntityType createEntity(java.lang.Class beanClass)
          Adds an entity.
 EntityType createEntity(java.lang.String name, java.lang.Class beanClass)
          Adds an entity.
 EnumType createEnum(java.lang.String name, java.lang.Class beanClass)
          Adds an enumerated type.
 GeneratorTableType createGeneratorTable(java.lang.String name)
          Adds a generator table.
 MappedSuperclassType createMappedSuperclass(java.lang.String name, java.lang.Class beanClass)
          Adds an entity.
 SequenceIdGenerator createSequenceGenerator(java.lang.String name, int size)
          Returns a sequence generator.
 AmberTable createTable(java.lang.String tableName)
          Creates a table.
 AmberType createType(java.lang.Class javaType)
          Creates a type.
 AmberType createType(java.lang.String typeName)
          Creates a type.
 void destroy()
          destroys the manager.
 void generate()
          Configure lazy.
 void generate(JavaClassGenerator javaGen)
          Configure lazy.
 AmberContainer getAmberContainer()
           
 CacheConnection getCacheConnection()
          Returns the cache connection.
 java.lang.Throwable getConfigException()
           
 java.lang.String getCreateColumnSQL(int sqlType, int length, int precision, int scale)
          New Version of getCreateTableSQL which returns the SQL for the table with the given SQL type but takes sqlType, length, precision, and scale.
 boolean getCreateDatabaseTables()
          Set true if database tables should be created automatically.
 javax.sql.DataSource getDataSource()
          Gets the data source.
 ListenerType getDefaultListener(java.lang.String className)
          Gets a default listener.
 EmbeddableType getEmbeddable(java.lang.String className)
          Returns a matching embeddable type.
 EmbeddableIntrospector getEmbeddableIntrospector()
          Returns the @Embeddable introspector.
 java.lang.ClassLoader getEnhancedLoader()
           
 EntityItem getEntity(EntityKey entityKey)
          Returns the entity with the given key.
 EntityItem getEntity(EntityType rootType, java.lang.Object key)
          Returns the entity with the given key.
 EntityType getEntityByInstanceClass(java.lang.String className)
          Returns a matching entity.
 AmberEntityHome getEntityHome(java.lang.String name)
          Returns the entity home.
 EntityItem getEntityItem(java.lang.String homeName, java.lang.Object key)
          Returns the entity item.
 ListenerType getEntityListener(java.lang.String className)
          Gets an entity listener.
 EntityManager getEntityManager()
           
 EntityType getEntityType(java.lang.Class cl)
           
 EntityType getEntityType(java.lang.String className)
          Returns a matching entity.
 java.lang.String getFalseLiteral()
          Returns the FALSE SQL literal, i.e., either "false" or "0".
 AmberGenerator getGenerator()
          Sets the generator.
 AmberEntityHome getHome(java.lang.Class cl)
          Returns an EntityHome.
 AmberEntityHome getHomeBySchema(java.lang.String name)
          Returns the entity home by the schema name.
 MappedSuperclassType getMappedSuperclass(java.lang.String className)
          Returns a matching mapped superclass.
 JdbcMetaData getMetaData()
          Returns the jdbc meta data.
 java.lang.String getName()
           
 NamedNativeQueryConfig getNamedNativeQuery(java.lang.String name)
          Returns the named native query.
 java.lang.String getNamedQuery(java.lang.String name)
          Returns the named query statement.
 ResultSetCacheChunk getQueryChunk(QueryCacheKey key)
          Returns the query result.
 java.sql.ResultSetMetaData getQueryMetaData(QueryCacheKey key)
          Returns the query meta data.
 AbstractQuery getQueryParseCache(java.lang.String sql)
          Returns the query cache.
 javax.sql.DataSource getReadDataSource()
          Gets the read data source.
 SqlResultSetMappingConfig getSqlResultSetMapping(java.lang.String resultSetName)
          Returns the sql result set mapping.
 long getTableCacheTimeout()
          Get the default table cache time.
 IdGenerator getTableGenerator(java.lang.String name)
          Returns a table generator.
 java.lang.ClassLoader getTempClassLoader()
           
 AmberConnection getThreadConnection(boolean isExtended)
          Returns the thread's amber connection.
 boolean getValidateDatabaseTables()
          Set true if database tables should be validated automatically.
 javax.sql.DataSource getXADataSource()
          Gets the xa data source.
 long getXid()
          Returns a new xid.
 boolean hasPositionFunction()
          Returns true if POSITION SQL function is allowed.
 boolean hasReturnGeneratedKeys()
          Returns true if generated keys are allowed.
 void init()
          Initialize the resource.
 void initEntityHomes()
           
 void initLoaders()
          Initialize the resource.
 void initTables()
          Configure lazy.
 void initType(AbstractEnhancedType type)
          Configures a type.
 boolean isJPA()
          Gets the JPA flag.
 boolean isJta()
          Return true for a jta-managed persistence unit
 java.lang.Class loadTempClass(java.lang.String className)
           
 EntityItem putEntity(java.lang.Class cl, java.lang.Object key, EntityItem entity)
          Sets the entity result.
 EntityItem putEntity(EntityType rootType, java.lang.Object key, EntityItem entity)
          Sets the entity result.
 void putQueryChunk(QueryCacheKey key, ResultSetCacheChunk chunk)
          Sets the query result.
 void putQueryMetaData(QueryCacheKey key, java.sql.ResultSetMetaData metaData)
          Sets the query meta data.
 void putQueryParseCache(java.lang.String sql, AbstractQuery query)
          Returns the query cache.
 IdGenerator putTableGenerator(java.lang.String name, IdGenerator gen)
          Sets a table generator.
 EntityItem removeEntity(EntityType rootType, java.lang.Object key)
          Remove the entity result.
 void removeThreadConnection()
          Unset the thread's amber connection.
 void setBytecodeGenerator(boolean isBytecodeGenerator)
          Set false for EJB-style generation.
 void setCreateDatabaseTables(boolean create)
          Set true if database tables should be created automatically.
 void setDataSource(javax.sql.DataSource dataSource)
          Sets the data source.
 void setEnhancedLoader(java.lang.ClassLoader loader)
          EJB/CMP needs to set a special enhanced loader.
 void setEntityMappingsList(java.util.ArrayList<EntityMappingsConfig> entityMappingsList)
          Sets the entity mappings config.
 void setJPA(boolean isJPA)
          Sets the JPA flag.
 void setJtaDataSource(javax.sql.DataSource dataSource)
          Sets the persistence.xml jta data source.
 void setJtaDataSourceName(java.lang.String name)
          Sets the persistence.xml jta data source.
 void setName(java.lang.String name)
           
 void setNonJtaDataSource(javax.sql.DataSource dataSource)
          Sets the persistence.xml non-jta data source.
 void setNonJtaDataSourceName(java.lang.String name)
          Sets the persistence.xml non-jta data source.
 void setReadDataSource(javax.sql.DataSource dataSource)
          Sets the read data source.
 void setTableCacheTimeout(long timeout)
          Set the default table cache time.
 void setValidateDatabaseTables(boolean validate)
          Set true if database tables should be validated automatically.
 void setXADataSource(javax.sql.DataSource dataSource)
          Sets the XA data source.
 java.lang.String toString()
           
 void updateCacheItem(EntityType rootType, java.lang.Object key, EntityItem cacheItem)
          Updates the cache item after commit.
 void updateFlushPriority()
          Updates global entity priorities for flushing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AmberPersistenceUnit

public AmberPersistenceUnit(AmberContainer container,
                            java.lang.String name)
Method Detail

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

getEntityManager

public EntityManager getEntityManager()

getAmberContainer

public AmberContainer getAmberContainer()

getTempClassLoader

public java.lang.ClassLoader getTempClassLoader()

getEnhancedLoader

public java.lang.ClassLoader getEnhancedLoader()

setEnhancedLoader

public void setEnhancedLoader(java.lang.ClassLoader loader)
EJB/CMP needs to set a special enhanced loader.


setDataSource

public void setDataSource(javax.sql.DataSource dataSource)
Sets the data source.


getDataSource

public javax.sql.DataSource getDataSource()
Gets the data source.


setReadDataSource

public void setReadDataSource(javax.sql.DataSource dataSource)
Sets the read data source.


getReadDataSource

public javax.sql.DataSource getReadDataSource()
Gets the read data source.


setXADataSource

public void setXADataSource(javax.sql.DataSource dataSource)
Sets the XA data source.


getXADataSource

public javax.sql.DataSource getXADataSource()
Gets the xa data source.


setJtaDataSourceName

public void setJtaDataSourceName(java.lang.String name)
Sets the persistence.xml jta data source.


setNonJtaDataSourceName

public void setNonJtaDataSourceName(java.lang.String name)
Sets the persistence.xml non-jta data source.


setJtaDataSource

public void setJtaDataSource(javax.sql.DataSource dataSource)
Sets the persistence.xml jta data source.


setNonJtaDataSource

public void setNonJtaDataSource(javax.sql.DataSource dataSource)
Sets the persistence.xml non-jta data source.


isJta

public boolean isJta()
Return true for a jta-managed persistence unit


getMetaData

public JdbcMetaData getMetaData()
Returns the jdbc meta data.


setCreateDatabaseTables

public void setCreateDatabaseTables(boolean create)
Set true if database tables should be created automatically.


getCreateDatabaseTables

public boolean getCreateDatabaseTables()
Set true if database tables should be created automatically.


setValidateDatabaseTables

public void setValidateDatabaseTables(boolean validate)
Set true if database tables should be validated automatically.


getValidateDatabaseTables

public boolean getValidateDatabaseTables()
Set true if database tables should be validated automatically.


setTableCacheTimeout

public void setTableCacheTimeout(long timeout)
Set the default table cache time.


getTableCacheTimeout

public long getTableCacheTimeout()
Get the default table cache time.


setBytecodeGenerator

public void setBytecodeGenerator(boolean isBytecodeGenerator)
Set false for EJB-style generation.


getXid

public long getXid()
Returns a new xid.


loadTempClass

public java.lang.Class loadTempClass(java.lang.String className)

createTable

public AmberTable createTable(java.lang.String tableName)
Creates a table.


getConfigException

public java.lang.Throwable getConfigException()

addEntityClass

public void addEntityClass(java.lang.String className,
                           java.lang.Class type)
                    throws ConfigException
Add an entity.

Parameters:
className - the class name
type - the JClass type if it is already verified as an Entity | Embeddable | MappedSuperclass
Throws:
ConfigException

addSqlResultSetMapping

public void addSqlResultSetMapping(java.lang.String resultSetName,
                                   SqlResultSetMappingConfig resultSet)
                            throws ConfigException
Adds a sql result set mapping.

Throws:
ConfigException

getSqlResultSetMapping

public SqlResultSetMappingConfig getSqlResultSetMapping(java.lang.String resultSetName)
Returns the sql result set mapping.


addNamedQuery

public void addNamedQuery(java.lang.String name,
                          java.lang.String query)
                   throws ConfigException
Adds a named query.

Throws:
ConfigException

getNamedQuery

public java.lang.String getNamedQuery(java.lang.String name)
Returns the named query statement.


addNamedNativeQuery

public void addNamedNativeQuery(java.lang.String name,
                                NamedNativeQueryConfig queryConfig)
                         throws ConfigException
Adds a named native query.

Throws:
ConfigException

getNamedNativeQuery

public NamedNativeQueryConfig getNamedNativeQuery(java.lang.String name)
Returns the named native query.


createEntity

public EntityType createEntity(java.lang.Class beanClass)
Adds an entity.


createEntity

public EntityType createEntity(java.lang.String name,
                               java.lang.Class beanClass)
Adds an entity.


createMappedSuperclass

public MappedSuperclassType createMappedSuperclass(java.lang.String name,
                                                   java.lang.Class beanClass)
Adds an entity.


createEmbeddable

public EmbeddableType createEmbeddable(java.lang.Class beanClass)
Adds an embeddable type.


createEmbeddable

public EmbeddableType createEmbeddable(java.lang.String name,
                                       java.lang.Class beanClass)
Adds an embeddable type.


createEnum

public EnumType createEnum(java.lang.String name,
                           java.lang.Class beanClass)
Adds an enumerated type.


getDefaultListener

public ListenerType getDefaultListener(java.lang.String className)
Gets a default listener.


addDefaultListener

public ListenerType addDefaultListener(java.lang.Class beanClass)
Adds a default listener.


getEntityListener

public ListenerType getEntityListener(java.lang.String className)
Gets an entity listener.


addEntityListener

public ListenerType addEntityListener(java.lang.String entityName,
                                      java.lang.Class listenerClass)
Adds an entity listener.


getTableGenerator

public IdGenerator getTableGenerator(java.lang.String name)
Returns a table generator.


putTableGenerator

public IdGenerator putTableGenerator(java.lang.String name,
                                     IdGenerator gen)
Sets a table generator.


createGeneratorTable

public GeneratorTableType createGeneratorTable(java.lang.String name)
Adds a generator table.


createSequenceGenerator

public SequenceIdGenerator createSequenceGenerator(java.lang.String name,
                                                   int size)
                                            throws ConfigException
Returns a sequence generator.

Throws:
ConfigException

initType

public void initType(AbstractEnhancedType type)
              throws java.lang.Exception
Configures a type.

Throws:
java.lang.Exception

generate

public void generate()
              throws java.lang.Exception
Configure lazy.

Throws:
java.lang.Exception

isJPA

public boolean isJPA()
Gets the JPA flag.


setJPA

public void setJPA(boolean isJPA)
Sets the JPA flag.


generate

public void generate(JavaClassGenerator javaGen)
              throws java.lang.Exception
Configure lazy.

Throws:
java.lang.Exception

getEmbeddableIntrospector

public EmbeddableIntrospector getEmbeddableIntrospector()
Returns the @Embeddable introspector.


configure

public void configure()
               throws java.lang.Exception
Configure lazy.

Throws:
java.lang.Exception

getEntityHome

public AmberEntityHome getEntityHome(java.lang.String name)
Returns the entity home.


getHomeBySchema

public AmberEntityHome getHomeBySchema(java.lang.String name)
Returns the entity home by the schema name.


getEmbeddable

public EmbeddableType getEmbeddable(java.lang.String className)
Returns a matching embeddable type.


getEntityType

public EntityType getEntityType(java.lang.Class cl)

getEntityType

public EntityType getEntityType(java.lang.String className)
Returns a matching entity.


getMappedSuperclass

public MappedSuperclassType getMappedSuperclass(java.lang.String className)
Returns a matching mapped superclass.


getEntityByInstanceClass

public EntityType getEntityByInstanceClass(java.lang.String className)
Returns a matching entity.


updateFlushPriority

public void updateFlushPriority()
Updates global entity priorities for flushing.


createType

public AmberType createType(java.lang.String typeName)
                     throws ConfigException
Creates a type.

Throws:
ConfigException

createType

public AmberType createType(java.lang.Class javaType)
                     throws ConfigException
Creates a type.

Throws:
ConfigException

getGenerator

public AmberGenerator getGenerator()
Sets the generator.


getFalseLiteral

public java.lang.String getFalseLiteral()
Returns the FALSE SQL literal, i.e., either "false" or "0".


hasPositionFunction

public boolean hasPositionFunction()
Returns true if POSITION SQL function is allowed.


hasReturnGeneratedKeys

public boolean hasReturnGeneratedKeys()
Returns true if generated keys are allowed.


setEntityMappingsList

public void setEntityMappingsList(java.util.ArrayList<EntityMappingsConfig> entityMappingsList)
Sets the entity mappings config.


init

public void init()
          throws ConfigException,
                 java.io.IOException
Initialize the resource.

Throws:
ConfigException
java.io.IOException

initLoaders

public void initLoaders()
                 throws ConfigException,
                        java.io.IOException
Initialize the resource.

Throws:
ConfigException
java.io.IOException

initEntityHomes

public void initEntityHomes()
                     throws AmberRuntimeException,
                            ConfigException
Throws:
AmberRuntimeException
ConfigException

initTables

public void initTables()
                throws ConfigException
Configure lazy.

Throws:
ConfigException

getCacheConnection

public CacheConnection getCacheConnection()
Returns the cache connection.


createAmberConnection

public AmberConnection createAmberConnection(boolean isExtended)
Returns the cache connection.


getThreadConnection

public AmberConnection getThreadConnection(boolean isExtended)
Returns the thread's amber connection.


removeThreadConnection

public void removeThreadConnection()
Unset the thread's amber connection.


getHome

public AmberEntityHome getHome(java.lang.Class cl)
Returns an EntityHome.


getQueryParseCache

public AbstractQuery getQueryParseCache(java.lang.String sql)
Returns the query cache.


putQueryParseCache

public void putQueryParseCache(java.lang.String sql,
                               AbstractQuery query)
Returns the query cache.


getQueryChunk

public ResultSetCacheChunk getQueryChunk(QueryCacheKey key)
Returns the query result.


getQueryMetaData

public java.sql.ResultSetMetaData getQueryMetaData(QueryCacheKey key)
Returns the query meta data.


callListeners

protected void callListeners(int callbackIndex,
                             Entity entity)
Applies persistence unit default and entity listeners for @PreXxx, @PostXxx callbacks.


putQueryChunk

public void putQueryChunk(QueryCacheKey key,
                          ResultSetCacheChunk chunk)
Sets the query result.


putQueryMetaData

public void putQueryMetaData(QueryCacheKey key,
                             java.sql.ResultSetMetaData metaData)
Sets the query meta data.


getEntityItem

public EntityItem getEntityItem(java.lang.String homeName,
                                java.lang.Object key)
                         throws AmberException
Returns the entity item.

Throws:
AmberException

getEntity

public EntityItem getEntity(EntityType rootType,
                            java.lang.Object key)
Returns the entity with the given key.


getEntity

public EntityItem getEntity(EntityKey entityKey)
Returns the entity with the given key.


putEntity

public EntityItem putEntity(EntityType rootType,
                            java.lang.Object key,
                            EntityItem entity)
Sets the entity result.


putEntity

public EntityItem putEntity(java.lang.Class cl,
                            java.lang.Object key,
                            EntityItem entity)
Sets the entity result.


removeEntity

public EntityItem removeEntity(EntityType rootType,
                               java.lang.Object key)
Remove the entity result.


updateCacheItem

public void updateCacheItem(EntityType rootType,
                            java.lang.Object key,
                            EntityItem cacheItem)
Updates the cache item after commit.


complete

public void complete(java.util.ArrayList<AmberCompletion> completions)
Completions affecting the cache.


destroy

public void destroy()
destroys the manager.


getCreateColumnSQL

public java.lang.String getCreateColumnSQL(int sqlType,
                                           int length,
                                           int precision,
                                           int scale)
New Version of getCreateTableSQL which returns the SQL for the table with the given SQL type but takes sqlType, length, precision, and scale.


toString

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