Groovy Documentation

org.codehaus.groovy.grails.orm.hibernate.cfg
[Java] Class GrailsHibernateUtil

java.lang.Object
  org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil

public class GrailsHibernateUtil
extends java.lang.Object

Utility methods for configuring Hibernate inside Grails.

Authors:
Graeme Rocher
Since:
0.4


Field Summary
static java.lang.String ARGUMENT_CACHE

static java.lang.String ARGUMENT_FETCH

static java.lang.String ARGUMENT_FETCH_SIZE

static java.lang.String ARGUMENT_FLUSH_MODE

static java.lang.String ARGUMENT_IGNORE_CASE

static java.lang.String ARGUMENT_LOCK

static java.lang.String ARGUMENT_MAX

static java.lang.String ARGUMENT_OFFSET

static java.lang.String ARGUMENT_ORDER

static java.lang.String ARGUMENT_READ_ONLY

static java.lang.String ARGUMENT_SORT

static java.lang.String ARGUMENT_TIMEOUT

static java.lang.String CONFIG_PROPERTY_CACHE_QUERIES

static java.lang.Class[] EMPTY_CLASS_ARRAY

static java.lang.String ORDER_ASC

static java.lang.String ORDER_DESC

 
Method Summary
static void autoAssociateBidirectionalOneToOnes(DefaultGrailsDomainClass domainClass, java.lang.Object target)

static GroovyAwareJavassistProxyFactory buildProxyFactory(org.hibernate.mapping.PersistentClass persistentClass)

static void cacheCriteriaByMapping(java.lang.Class targetClass, org.hibernate.Criteria criteria)

Configures the criteria instance to cache based on the configured mapping.

static void cacheCriteriaByMapping(GrailsApplication grailsApplication, java.lang.Class targetClass, org.hibernate.Criteria criteria)

static void configureHibernateDomainClasses(org.hibernate.SessionFactory sessionFactory, java.lang.String sessionFactoryName, GrailsApplication application)

static void configureInheritanceMappings(java.util.Map hibernateDomainClassMap)

static void enableDynamicFilterEnablerIfPresent(org.hibernate.SessionFactory sessionFactory, org.hibernate.Session session)

static void ensureCorrectGroovyMetaClass(java.lang.Object target, java.lang.Class persistentClass)

Ensures the meta class is correct for a given class

static org.hibernate.proxy.HibernateProxy getAssociationProxy(java.lang.Object obj, java.lang.String associationName)

Returns the proxy for a given association or null if it is not proxied

static java.util.List getDatasourceNames(GrailsDomainClass domainClass)

static java.lang.String getDefaultDataSource(GrailsDomainClass domainClass)

If a domain class uses more than one datasource, we need to know which one to use when calling a method without a namespace qualifier.

static org.hibernate.FetchMode getFetchMode(java.lang.Object object)

Retrieves the fetch mode for the specified instance; otherwise returns the default FetchMode.

static void incrementVersion(java.lang.Object target)

Increments the entities version number in order to force an update

static boolean isCacheQueriesByDefault()

static boolean isCacheQueriesByDefault(GrailsApplication grailsApplication)

static boolean isInitialized(java.lang.Object obj, java.lang.String associationName)

Checks whether an associated property is initialized and returns true if it is

static boolean isMappedWithHibernate(GrailsDomainClass domainClass)

static void populateArgumentsForCriteria(GrailsApplication grailsApplication, java.lang.Class targetClass, org.hibernate.Criteria c, java.util.Map argMap)

Populates criteria arguments for the given target class and arguments map

static void populateArgumentsForCriteria(java.lang.Class targetClass, org.hibernate.Criteria c, java.util.Map argMap)

Populates criteria arguments for the given target class and arguments map

static void populateArgumentsForCriteria(org.hibernate.Criteria c, java.util.Map argMap)

static void setObjectToReadWrite(java.lang.Object target, org.hibernate.SessionFactory sessionFactory)

Sets the target object to read-write, allowing Hibernate to dirty check it and auto-flush changes.

static void setObjectToReadyOnly(java.lang.Object target, org.hibernate.SessionFactory sessionFactory)

Sets the target object to read-only using the given SessionFactory instance.

static java.lang.Object unwrapIfProxy(java.lang.Object instance)

static java.lang.Object unwrapProxy(org.hibernate.proxy.HibernateProxy proxy)

Unwraps and initializes a HibernateProxy.

static boolean usesDatasource(GrailsDomainClass domainClass, java.lang.String dataSourceName)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

ARGUMENT_CACHE

public static final java.lang.String ARGUMENT_CACHE


ARGUMENT_FETCH

public static final java.lang.String ARGUMENT_FETCH


ARGUMENT_FETCH_SIZE

public static final java.lang.String ARGUMENT_FETCH_SIZE


ARGUMENT_FLUSH_MODE

public static final java.lang.String ARGUMENT_FLUSH_MODE


ARGUMENT_IGNORE_CASE

public static final java.lang.String ARGUMENT_IGNORE_CASE


ARGUMENT_LOCK

public static final java.lang.String ARGUMENT_LOCK


ARGUMENT_MAX

public static final java.lang.String ARGUMENT_MAX


ARGUMENT_OFFSET

public static final java.lang.String ARGUMENT_OFFSET


ARGUMENT_ORDER

public static final java.lang.String ARGUMENT_ORDER


ARGUMENT_READ_ONLY

public static final java.lang.String ARGUMENT_READ_ONLY


ARGUMENT_SORT

public static final java.lang.String ARGUMENT_SORT


ARGUMENT_TIMEOUT

public static final java.lang.String ARGUMENT_TIMEOUT


CONFIG_PROPERTY_CACHE_QUERIES

public static final java.lang.String CONFIG_PROPERTY_CACHE_QUERIES


EMPTY_CLASS_ARRAY

public static final java.lang.Class[] EMPTY_CLASS_ARRAY


ORDER_ASC

public static final java.lang.String ORDER_ASC


ORDER_DESC

public static final java.lang.String ORDER_DESC


 
Method Detail

autoAssociateBidirectionalOneToOnes

public static void autoAssociateBidirectionalOneToOnes(DefaultGrailsDomainClass domainClass, java.lang.Object target)


buildProxyFactory

public static GroovyAwareJavassistProxyFactory buildProxyFactory(org.hibernate.mapping.PersistentClass persistentClass)


cacheCriteriaByMapping

public static void cacheCriteriaByMapping(java.lang.Class targetClass, org.hibernate.Criteria criteria)
Configures the criteria instance to cache based on the configured mapping.
Parameters:
targetClass - The target class
criteria - The criteria


cacheCriteriaByMapping

public static void cacheCriteriaByMapping(@SuppressWarnings("unused") GrailsApplication grailsApplication, java.lang.Class targetClass, org.hibernate.Criteria criteria)


configureHibernateDomainClasses

public static void configureHibernateDomainClasses(org.hibernate.SessionFactory sessionFactory, java.lang.String sessionFactoryName, GrailsApplication application)


configureInheritanceMappings

@SuppressWarnings("rawtypes")
public static void configureInheritanceMappings(java.util.Map hibernateDomainClassMap)


enableDynamicFilterEnablerIfPresent

@SuppressWarnings("rawtypes")
public static void enableDynamicFilterEnablerIfPresent(org.hibernate.SessionFactory sessionFactory, org.hibernate.Session session)


ensureCorrectGroovyMetaClass

public static void ensureCorrectGroovyMetaClass(java.lang.Object target, java.lang.Class persistentClass)
Ensures the meta class is correct for a given class
Parameters:
target - The GroovyObject
persistentClass - The persistent class


getAssociationProxy

public static org.hibernate.proxy.HibernateProxy getAssociationProxy(java.lang.Object obj, java.lang.String associationName)
Returns the proxy for a given association or null if it is not proxied
Parameters:
obj - The object
associationName - The named assoication
Returns:
A proxy


getDatasourceNames

public static java.util.List getDatasourceNames(GrailsDomainClass domainClass)


getDefaultDataSource

public static java.lang.String getDefaultDataSource(GrailsDomainClass domainClass)
If a domain class uses more than one datasource, we need to know which one to use when calling a method without a namespace qualifier.
Parameters:
domainClass - the domain class
Returns:
the default datasource name


getFetchMode

public static org.hibernate.FetchMode getFetchMode(java.lang.Object object)
Retrieves the fetch mode for the specified instance; otherwise returns the default FetchMode.
Parameters:
object - The object, converted to a string
Returns:
The FetchMode


incrementVersion

public static void incrementVersion(java.lang.Object target)
Increments the entities version number in order to force an update
Parameters:
target - The target entity


isCacheQueriesByDefault

public static boolean isCacheQueriesByDefault()


isCacheQueriesByDefault

public static boolean isCacheQueriesByDefault(GrailsApplication grailsApplication)


isInitialized

public static boolean isInitialized(java.lang.Object obj, java.lang.String associationName)
Checks whether an associated property is initialized and returns true if it is
Parameters:
obj - The name of the object
associationName - The name of the association
Returns:
True if is initialized


isMappedWithHibernate

public static boolean isMappedWithHibernate(GrailsDomainClass domainClass)


populateArgumentsForCriteria

@SuppressWarnings("rawtypes")
public static void populateArgumentsForCriteria(GrailsApplication grailsApplication, java.lang.Class targetClass, org.hibernate.Criteria c, java.util.Map argMap)
Populates criteria arguments for the given target class and arguments map
Parameters:
grailsApplication - the GrailsApplication instance
targetClass - The target class
c - The criteria instance
argMap - The arguments map


populateArgumentsForCriteria

@Deprecated
@SuppressWarnings("rawtypes")
public static void populateArgumentsForCriteria(java.lang.Class targetClass, org.hibernate.Criteria c, java.util.Map argMap)
Populates criteria arguments for the given target class and arguments map
deprecated:
Use populateArgumentsForCriteria(org.codehaus.groovy.grails.commons.GrailsApplication, Class, org.hibernate.Criteria, java.util.Map) instead
Parameters:
targetClass - The target class
c - The criteria instance
argMap - The arguments map


populateArgumentsForCriteria

@SuppressWarnings("rawtypes")
public static void populateArgumentsForCriteria(org.hibernate.Criteria c, java.util.Map argMap)


setObjectToReadWrite

public static void setObjectToReadWrite(java.lang.Object target, org.hibernate.SessionFactory sessionFactory)
Sets the target object to read-write, allowing Hibernate to dirty check it and auto-flush changes.
Parameters:
target - The target object
sessionFactory - The SessionFactory instance
See Also:
setObjectToReadyOnly(Object, org.hibernate.SessionFactory)


setObjectToReadyOnly

public static void setObjectToReadyOnly(java.lang.Object target, org.hibernate.SessionFactory sessionFactory)
Sets the target object to read-only using the given SessionFactory instance. This avoids Hibernate performing any dirty checking on the object
Parameters:
target - The target object
sessionFactory - The SessionFactory instance
See Also:
setObjectToReadWrite(Object, org.hibernate.SessionFactory)


unwrapIfProxy

public static java.lang.Object unwrapIfProxy(java.lang.Object instance)


unwrapProxy

public static java.lang.Object unwrapProxy(org.hibernate.proxy.HibernateProxy proxy)
Unwraps and initializes a HibernateProxy.
Parameters:
proxy - The proxy
Returns:
the unproxied instance


usesDatasource

public static boolean usesDatasource(GrailsDomainClass domainClass, java.lang.String dataSourceName)


 

Groovy Documentation