|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.unitils.orm.common.OrmModule<ORM_PERSISTENCE_UNIT,ORM_PERSISTENCE_CONTEXT,PROVIDER_CONFIGURATION_OBJECT,PERSISTENCE_UNIT_CONFIG_ANNOTATION,ORM_CONFIG,ORM_PERSISTENCE_UNIT_CONFIG_LOADER>
ORM_PERSISTENCE_UNIT - Type of the ORM persistence unitORM_PERSISTENCE_CONTEXT - Type of the ORM persistence contextPROVIDER_CONFIGURATION_OBJECT - Type of the implementation specific configuration objectPERSISTENCE_UNIT_CONFIG_ANNOTATION - Type of the annotation used for configuring and injecting the persistence unitORM_CONFIG - Type of the value object extending OrmConfig that contains all unitils specific persitence unit configurationORM_PERSISTENCE_UNIT_CONFIG_LOADER - Subtype of OrmPersistenceUnitLoader that loads the persistence unit based on the ORM_CONFIG.public abstract class OrmModule<ORM_PERSISTENCE_UNIT,ORM_PERSISTENCE_CONTEXT,PROVIDER_CONFIGURATION_OBJECT,PERSISTENCE_UNIT_CONFIG_ANNOTATION extends Annotation,ORM_CONFIG extends OrmConfig,ORM_PERSISTENCE_UNIT_CONFIG_LOADER extends ResourceConfigLoader<ORM_CONFIG>>
Base module defining common behavior for a module that provides object relational mapping support for tests.
This abstract module takes into account loading and caching of persistence units. A persistence unit
can be configured using unitils annotations or in a spring ApplicationContext.
The persistence unit is injected into the test object's annotated fields. This module also supports
flushing of the active persistence context.
| Nested Class Summary | |
|---|---|
protected class |
OrmModule.OrmTestListener
The TestListener for this module |
| Field Summary | |
|---|---|
protected Map<ORM_CONFIG,ConfiguredOrmPersistenceUnit<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT>> |
configuredOrmPersistenceUnitCache
Cache for persistence units and its configuration. |
protected OrmPersistenceUnitLoader<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT,ORM_CONFIG> |
ormPersistenceUnitLoader
Class that loads the persistence unit, given an object extending OrmConfig |
protected OrmSpringSupport<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT> |
ormSpringSupport
Support class that enables getting a configured persistence unit from a spring ApplicationContext configured in unitils. |
protected ORM_PERSISTENCE_UNIT_CONFIG_LOADER |
persistenceUnitConfigLoader
Class that loads the persistence unit configuration |
| Constructor Summary | |
|---|---|
OrmModule()
|
|
| Method Summary | |
|---|---|
void |
afterInit()
Gives the module the opportunity to performs initialization that can only work after all other modules have been initialized |
protected abstract ORM_PERSISTENCE_UNIT_CONFIG_LOADER |
createOrmConfigLoader()
|
protected abstract OrmPersistenceUnitLoader<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT,ORM_CONFIG> |
createOrmPersistenceUnitLoader()
|
protected abstract ORM_PERSISTENCE_CONTEXT |
doGetActivePersistenceContext(Object testObject)
Implementations of this method must return the persistence context object that is associated with the current transaction, if any. |
protected abstract ORM_PERSISTENCE_CONTEXT |
doGetPersistenceContext(Object testObject)
Implementations of this method must return a persistence context object, and must be associated with the current transaction active in unitils. |
void |
flushDatabaseUpdates(Object testObject)
Flushes all pending updates to the database. |
protected abstract void |
flushOrmPersistenceContext(ORM_PERSISTENCE_CONTEXT activePersistenceContext)
Flushes all pending update, using the given active persistence context |
protected ORM_PERSISTENCE_CONTEXT |
getActivePersistenceContext(Object testObject)
The currently active persistence context, if any. |
PROVIDER_CONFIGURATION_OBJECT |
getConfigurationObject(Object testObject)
Returns the ORM implementation specific configuration object. |
protected ConfiguredOrmPersistenceUnit<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT> |
getConfiguredPersistenceUnit(Object testObject)
Returns a wrapper for the persistence unit and any implementation specific configuration object for the given test object. |
protected DatabaseModule |
getDatabaseModule()
|
protected abstract String |
getOrmSpringSupportImplClassName()
|
ORM_PERSISTENCE_CONTEXT |
getPersistenceContext(Object testObject)
Returns an implementation specific persistence context, which is associated with the current transaction. |
ORM_PERSISTENCE_UNIT |
getPersistenceUnit(Object testObject)
Returns a configured ORM persistence unit for the given test object. |
protected abstract Class<ORM_PERSISTENCE_UNIT> |
getPersistenceUnitClass()
|
protected ORM_CONFIG |
getPersistenceUnitConfig(Object testObject)
|
protected abstract Class<PERSISTENCE_UNIT_CONFIG_ANNOTATION> |
getPersistenceUnitConfigAnnotationClass()
|
void |
init(Properties configuration)
Initializes the module with the given configuration settings. |
protected void |
initOrmSpringSupport()
Creates an instance of OrmSpringSupport, that
implements the dependency to the SpringModule. |
void |
injectOrmPersistenceUnitIntoTestObject(Object testObject)
Injects the persistence unit object into all fields and methods that are annotated with the annotation defined by getPersistenceUnitConfigAnnotationClass() |
boolean |
isPersistenceUnitConfiguredFor(Object testObject)
Indicates whether an ORM persistence unit has been configured for the given testObject. |
protected boolean |
isSpringModuleEnabled()
Verifies whether the SpringModule is enabled. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.unitils.core.Module |
|---|
getTestListener |
| Field Detail |
|---|
protected ORM_PERSISTENCE_UNIT_CONFIG_LOADER extends ResourceConfigLoader<ORM_CONFIG> persistenceUnitConfigLoader
protected OrmPersistenceUnitLoader<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT,ORM_CONFIG extends OrmConfig> ormPersistenceUnitLoader
OrmConfig
protected Map<ORM_CONFIG extends OrmConfig,ConfiguredOrmPersistenceUnit<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT>> configuredOrmPersistenceUnitCache
protected OrmSpringSupport<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT> ormSpringSupport
| Constructor Detail |
|---|
public OrmModule()
| Method Detail |
|---|
public void init(Properties configuration)
Module
init in interface Moduleconfiguration - The config, not nullpublic void afterInit()
Module
afterInit in interface Moduleprotected abstract ORM_PERSISTENCE_UNIT_CONFIG_LOADER createOrmConfigLoader()
ResourceConfigLoader that scans a test object for a persistence
unit configuration, and returns a specific subtype of OrmConfig that wraps this configurationprotected abstract Class<PERSISTENCE_UNIT_CONFIG_ANNOTATION> getPersistenceUnitConfigAnnotationClass()
protected abstract Class<ORM_PERSISTENCE_UNIT> getPersistenceUnitClass()
protected abstract OrmPersistenceUnitLoader<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT,ORM_CONFIG> createOrmPersistenceUnitLoader()
OrmPersistenceUnitLoader that can create a new persistence unit
based on an OrmConfig objectprotected abstract String getOrmSpringSupportImplClassName()
OrmSpringSupport that
is used by the ORM module implementationpublic ORM_PERSISTENCE_UNIT getPersistenceUnit(Object testObject)
ApplicationContext or by using the annotation that is applicable for the ORM implementation.
An exception is thrown if no persistence unit is configured. If possible, a cached instance is returned that was
created during a previous test.
testObject - The test instance, not null
public PROVIDER_CONFIGURATION_OBJECT getConfigurationObject(Object testObject)
testObject - The test instance, not null
protected ConfiguredOrmPersistenceUnit<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT> getConfiguredPersistenceUnit(Object testObject)
ApplicationContext or by using the
annotation that is applicable for the ORM implementation. An exception is thrown if no persistence unit is configured.
If possible, a cached instance is returned that was created during a previous test.
testObject - The test instance, not null
protected ORM_CONFIG getPersistenceUnitConfig(Object testObject)
testObject - The test instance, not null
public boolean isPersistenceUnitConfiguredFor(Object testObject)
ApplicationContext or by using the annotation that
is applicable for the ORM implementation.
testObject - The test instance, not null
EntityManagerFactory has been configured, false otherwisepublic ORM_PERSISTENCE_CONTEXT getPersistenceContext(Object testObject)
testObject - The test instance, not null
protected abstract ORM_PERSISTENCE_CONTEXT doGetPersistenceContext(Object testObject)
testObject - The test instance, not null
protected ORM_PERSISTENCE_CONTEXT getActivePersistenceContext(Object testObject)
testObject - The test instance, not null
protected abstract ORM_PERSISTENCE_CONTEXT doGetActivePersistenceContext(Object testObject)
testObject - The test instance, not null
public void flushDatabaseUpdates(Object testObject)
flushDatabaseUpdates in interface FlushabletestObject - The test instance, not nullprotected abstract void flushOrmPersistenceContext(ORM_PERSISTENCE_CONTEXT activePersistenceContext)
activePersistenceContext - Active persistence context, associated with the current transaction, not nullpublic void injectOrmPersistenceUnitIntoTestObject(Object testObject)
getPersistenceUnitConfigAnnotationClass()
testObject - The test object, not nullprotected void initOrmSpringSupport()
OrmSpringSupport, that
implements the dependency to the SpringModule. If the
SpringModule is not active, or if a dependency of
OrmSpringSupport could not be found in the classpath,
the instance is not loaded.
protected boolean isSpringModuleEnabled()
protected DatabaseModule getDatabaseModule()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||