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>> extends Object implements Module, Flushable
ApplicationContext.
The persistence unit is injected into the test object's annotated fields. This module also supports
flushing of the active persistence context.| Modifier and Type | Class and Description |
|---|---|
protected class |
OrmModule.OrmTestListener
The
TestListener for this module |
| Modifier and Type | Field and Description |
|---|---|
protected Map<ORM_CONFIG,ConfiguredOrmPersistenceUnit<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT>> |
configuredOrmPersistenceUnitCache
Cache for persistence units and its configuration.
|
protected String |
databaseName |
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
|
protected Set<DataSourceWrapper> |
wrappers |
| Constructor and Description |
|---|
OrmModule() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterInit() |
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 void |
getDatabaseName(Object testObject,
Method testMethod) |
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) |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetTestListenerprotected ORM_PERSISTENCE_UNIT_CONFIG_LOADER extends ResourceConfigLoader<ORM_CONFIG> persistenceUnitConfigLoader
protected OrmPersistenceUnitLoader<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT,ORM_CONFIG extends OrmConfig> ormPersistenceUnitLoader
OrmConfigprotected Map<ORM_CONFIG extends OrmConfig,ConfiguredOrmPersistenceUnit<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT>> configuredOrmPersistenceUnitCache
protected OrmSpringSupport<ORM_PERSISTENCE_UNIT,PROVIDER_CONFIGURATION_OBJECT> ormSpringSupport
protected String databaseName
protected Set<DataSourceWrapper> wrappers
public void init(Properties configuration)
protected 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 nullpublic PROVIDER_CONFIGURATION_OBJECT getConfigurationObject(Object testObject)
testObject - The test instance, not nullprotected 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 nullprotected ORM_CONFIG getPersistenceUnitConfig(Object testObject)
testObject - The test instance, not nullpublic boolean isPersistenceUnitConfiguredFor(Object testObject)
ApplicationContext or by using the annotation that
is applicable for the ORM implementation.testObject - The test instance, not nullEntityManagerFactory has been configured, false otherwisepublic ORM_PERSISTENCE_CONTEXT getPersistenceContext(Object testObject)
testObject - The test instance, not nullprotected abstract ORM_PERSISTENCE_CONTEXT doGetPersistenceContext(Object testObject)
testObject - The test instance, not nullprotected ORM_PERSISTENCE_CONTEXT getActivePersistenceContext(Object testObject)
testObject - The test instance, not nullprotected abstract ORM_PERSISTENCE_CONTEXT doGetActivePersistenceContext(Object testObject)
testObject - The test instance, not nullpublic 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()
Copyright © 2016. All Rights Reserved.