local.tomas.hibernate
Class CommonHibernatePersistence

java.lang.Object
  extended by local.tomas.hibernate.CommonHibernatePersistence
All Implemented Interfaces:
local.tomas.util.versioning.VersionInterface

public abstract class CommonHibernatePersistence
extends Object
implements local.tomas.util.versioning.VersionInterface

Abstract base class for persistence handlers.

Author:
Teubner

Field Summary
protected  Map<String,String> configOverrides
          Configuration overrides mapping attributes to values.
protected  javax.persistence.EntityManagerFactory emf
          Entity manager factory
 
Constructor Summary
protected CommonHibernatePersistence(org.apache.commons.configuration.Configuration conf, String emfName)
          Create instance.
 
Method Summary
 String getCurrentVersion(String name)
          Get current version.
protected  org.hibernate.cfg.Configuration getHibernateConfiguration()
          Get Hibernate configuration.
 void postInitVersion(String name, String toVersion)
          Called after initializing version.
 void postUpdateVersion(String name, String fromVersion, String toVersion)
          Called after updating to version.
 void preInitVersion(String name, String toVersion)
          Called before initializing version.
 void preUpdateVersion(String name, String fromVersion, String toVersion)
          Called before updating to version.
 void setVersion(String name, String newVersion)
          Set Version of entiry.
protected  void supplyHibernateConfiguration(org.hibernate.cfg.Configuration cfg)
          Supply hibernate configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configOverrides

protected Map<String,String> configOverrides
Configuration overrides mapping attributes to values.


emf

protected javax.persistence.EntityManagerFactory emf
Entity manager factory

Constructor Detail

CommonHibernatePersistence

protected CommonHibernatePersistence(org.apache.commons.configuration.Configuration conf,
                                     String emfName)
                              throws HibernatePersistenceException
Create instance.

Parameters:
conf - configuration of this instance
emfName - entity manager factory name
Throws:
HibernatePersistenceException
Method Detail

getCurrentVersion

public String getCurrentVersion(String name)
                         throws local.tomas.util.versioning.VersionException
Get current version.

Specified by:
getCurrentVersion in interface local.tomas.util.versioning.VersionInterface
Parameters:
name - entity name
Returns:
current version of entiry
Throws:
local.tomas.util.versioning.VersionException

setVersion

public void setVersion(String name,
                       String newVersion)
                throws local.tomas.util.versioning.VersionException
Set Version of entiry.

Specified by:
setVersion in interface local.tomas.util.versioning.VersionInterface
Parameters:
name - entity name
newVersion - new version of entity
Throws:
local.tomas.util.versioning.VersionException

preInitVersion

public void preInitVersion(String name,
                           String toVersion)
                    throws local.tomas.util.versioning.VersionException
Called before initializing version. Tries a drop and performs a create on the Hibernate schema export.

Specified by:
preInitVersion in interface local.tomas.util.versioning.VersionInterface
Parameters:
name - entity name
toVersion - version to be initialized
Throws:
local.tomas.util.versioning.VersionException

postInitVersion

public void postInitVersion(String name,
                            String toVersion)
                     throws local.tomas.util.versioning.VersionException
Called after initializing version. Default implementation does nothing.

Specified by:
postInitVersion in interface local.tomas.util.versioning.VersionInterface
Parameters:
name - entity name
toVersion - version initialized
Throws:
local.tomas.util.versioning.VersionException

preUpdateVersion

public void preUpdateVersion(String name,
                             String fromVersion,
                             String toVersion)
                      throws local.tomas.util.versioning.VersionException
Called before updating to version. Executes hibernate schema update.

Specified by:
preUpdateVersion in interface local.tomas.util.versioning.VersionInterface
Parameters:
name - entity name
fromVersion - original version
toVersion - target version
Throws:
local.tomas.util.versioning.VersionException

postUpdateVersion

public void postUpdateVersion(String name,
                              String fromVersion,
                              String toVersion)
                       throws local.tomas.util.versioning.VersionException
Called after updating to version. Does nothing.

Specified by:
postUpdateVersion in interface local.tomas.util.versioning.VersionInterface
Parameters:
name - entity name
fromVersion - original version
toVersion - version reached
Throws:
local.tomas.util.versioning.VersionException

getHibernateConfiguration

protected org.hibernate.cfg.Configuration getHibernateConfiguration()
Get Hibernate configuration.

Returns:
hibernate configuration with configuration overrides applied.

supplyHibernateConfiguration

protected void supplyHibernateConfiguration(org.hibernate.cfg.Configuration cfg)
Supply hibernate configuration. Empty default implementation.

Parameters:
cfg - hibernate configuration


Copyright © 2012. All Rights Reserved.