org.unitils.orm.hibernate
Class HibernateModule
java.lang.Object
org.unitils.orm.common.OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
org.unitils.orm.hibernate.HibernateModule
- All Implemented Interfaces:
- Module, Flushable
public class HibernateModule
- extends OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- implements Module, Flushable
Module providing support for unit tests for code that uses Hibernate. It offers an easy way of loading hibernate
SessionFactories and having them injected them into the test. It also offers a test to check whether the hibernate
mapping is consistent with the structure of the database.
A Hibernate SessionFactory is created when requested and injected into all fields or methods of the test
annotated with HibernateSessionFactory.
It is highly recommended to write a unit test that invokes HibernateUnitils.assertMappingWithDatabaseConsistent(),
This is a very useful test that verifies whether the mapping of all your Hibernate mapped objects still corresponds
with the actual structure of the database.
- Author:
- Filip Neven, Tim Ducheyne
| Methods inherited from class org.unitils.orm.common.OrmModule |
flushDatabaseUpdates, getActivePersistenceContext, getConfigurationObject, getConfiguredPersistenceUnit, getDatabaseModule, getPersistenceContext, getPersistenceUnit, getPersistenceUnitConfig, initOrmSpringSupport, injectOrmPersistenceUnitIntoTestObject, isPersistenceUnitConfiguredFor, isSpringModuleEnabled |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PROPKEY_CONFIGURATION_CLASS_NAME
public static final java.lang.String PROPKEY_CONFIGURATION_CLASS_NAME
- See Also:
- Constant Field Values
HibernateModule
public HibernateModule()
init
public void init(java.util.Properties configuration)
- Specified by:
init in interface Module- Overrides:
init in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Parameters:
configuration - The Unitils configuration, not null
afterInit
public void afterInit()
- Specified by:
afterInit in interface Module- Overrides:
afterInit in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
createOrmConfigLoader
protected HibernateAnnotationConfigLoader createOrmConfigLoader()
- Specified by:
createOrmConfigLoader in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Returns:
- A new instance of the
ResourceConfigLoader that scans a test object for a persistence
unit configuration, and returns a specific subtype of OrmConfig that wraps this configuration
getPersistenceUnitConfigAnnotationClass
protected java.lang.Class<HibernateSessionFactory> getPersistenceUnitConfigAnnotationClass()
- Specified by:
getPersistenceUnitConfigAnnotationClass in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Returns:
- The class of the annotation that is used for configuring and requesting injection of the
persistence unit
getPersistenceUnitClass
protected java.lang.Class<org.hibernate.SessionFactory> getPersistenceUnitClass()
- Specified by:
getPersistenceUnitClass in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Returns:
- The type of the persistence unit
createOrmPersistenceUnitLoader
protected OrmPersistenceUnitLoader<org.hibernate.SessionFactory,org.hibernate.cfg.Configuration,OrmConfig> createOrmPersistenceUnitLoader()
- Specified by:
createOrmPersistenceUnitLoader in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Returns:
- A new instance of
OrmPersistenceUnitLoader that can create a new persistence unit
based on an OrmConfig object
getOrmSpringSupportImplClassName
protected java.lang.String getOrmSpringSupportImplClassName()
- Specified by:
getOrmSpringSupportImplClassName in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Returns:
- The fully qualified classname of the concrete implementation of
OrmSpringSupport that
is used by the ORM module implementation
doGetPersistenceContext
protected org.hibernate.Session doGetPersistenceContext(java.lang.Object testObject)
- Description copied from class:
OrmModule
- Implementations of this method must return a persistence context object, and must be associated with the
current transaction active in unitils. The implementation can presume that a persistence unit is available,
so the method may not return null;
- Specified by:
doGetPersistenceContext in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Parameters:
testObject - The test instance, not null
- Returns:
- An implementation specific persistence context, not null
doGetActivePersistenceContext
protected org.hibernate.Session doGetActivePersistenceContext(java.lang.Object testObject)
- Description copied from class:
OrmModule
- Implementations of this method must return the persistence context object that is associated with the current
transaction, if any. The implementation can presume that a persistence unit is available. If no persistence
context is currently active, null is returned.
- Specified by:
doGetActivePersistenceContext in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Parameters:
testObject - The test instance, not null
- Returns:
- The currently active persistence context, if any
flushOrmPersistenceContext
protected void flushOrmPersistenceContext(org.hibernate.Session activeSession)
- Description copied from class:
OrmModule
- Flushes all pending update, using the given active persistence context
- Specified by:
flushOrmPersistenceContext in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- Parameters:
activeSession - Active persistence context, associated with the current transaction, not null
assertMappingWithDatabaseConsistent
public void assertMappingWithDatabaseConsistent(java.lang.Object testObject)
- Checks if the mapping of the Hibernate managed objects with the database is correct.
- Parameters:
testObject - The test instance, not null
getConfigurationObjectClass
public java.lang.Class<? extends org.hibernate.cfg.Configuration> getConfigurationObjectClass()
- Returns:
- The subclass of
org.hibernate.cfg.Configuration that is used for configuring hibernate
getDatabaseDialect
protected org.hibernate.dialect.Dialect getDatabaseDialect(org.hibernate.cfg.Configuration configuration)
- Gets the database dialect from the given Hibernate
Configuration
- Parameters:
configuration - The hibernate config, not null
- Returns:
- the database Dialect, not null
getDataSource
protected javax.sql.DataSource getDataSource()
getTestListener
public TestListener getTestListener()
- Specified by:
getTestListener in interface Module
- Returns:
- The TestListener associated with this module
Copyright © 2009. All Rights Reserved.