org.riotfamily.riot.hibernate.support
Class HibernateUtils

java.lang.Object
  extended by org.riotfamily.riot.hibernate.support.HibernateUtils

public final class HibernateUtils
extends Object


Field Summary
static String LIVE_MODE_FILTER_NAME
           
static String PUBLISHED_PARAM_NAME
           
 
Method Summary
static void addEqOrNull(org.hibernate.Criteria c, String name, Object val)
           
static StringBuffer appendHql(StringBuffer hql, String expression, String term)
          Appends the given term to the StringBuffer.
static StringBuffer appendJoinsForSearch(StringBuffer hql, String alias, String[] propertyNames)
          Joins all path properties requested by the search property names Example: search should be foo.bar = :search -> join this.foo *
static Serializable convertId(Class<?> beanClass, String id, org.hibernate.SessionFactory sessionFactory)
           
static void enableLiveModeFilterIfNecessary(org.hibernate.Session session)
           
static
<T> T
get(org.hibernate.Session session, Class<T> beanClass, String id)
           
static String getExampleWhereClause(Class<?> entityClass, Object example, String alias, String[] propertyNames)
          Returns a HQL term that can be used within a where-clause to perform a query-by-example.
static String getIdAsString(org.hibernate.SessionFactory sessionFactory, Object bean)
           
static Class<? extends Serializable> getIdentifierClass(Class<?> beanClass, org.hibernate.SessionFactory sessionFactory)
           
static String getSearchWhereClause(String alias, String[] propertyNames, String searchParamName)
          Returns a HQL term that can be used within a where-clause to perform a search.
static boolean isLiveModeFilterDefined(org.hibernate.SessionFactory sf)
           
static boolean isPersistentProperty(org.hibernate.SessionFactory sessionFactory, Class<?> clazz, String propertyPath)
           
static void setCollectionValueParams(org.hibernate.Query query, String[] names, Class<?> entityClass, Object object)
          Sets collection values as individual query parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIVE_MODE_FILTER_NAME

public static final String LIVE_MODE_FILTER_NAME
See Also:
Constant Field Values

PUBLISHED_PARAM_NAME

public static final String PUBLISHED_PARAM_NAME
See Also:
Constant Field Values
Method Detail

get

public static <T> T get(org.hibernate.Session session,
                        Class<T> beanClass,
                        String id)

getIdentifierClass

public static Class<? extends Serializable> getIdentifierClass(Class<?> beanClass,
                                                               org.hibernate.SessionFactory sessionFactory)

convertId

public static Serializable convertId(Class<?> beanClass,
                                     String id,
                                     org.hibernate.SessionFactory sessionFactory)

getIdAsString

public static String getIdAsString(org.hibernate.SessionFactory sessionFactory,
                                   Object bean)

isPersistentProperty

public static boolean isPersistentProperty(org.hibernate.SessionFactory sessionFactory,
                                           Class<?> clazz,
                                           String propertyPath)

getExampleWhereClause

public static String getExampleWhereClause(Class<?> entityClass,
                                           Object example,
                                           String alias,
                                           String[] propertyNames)
Returns a HQL term that can be used within a where-clause to perform a query-by-example.

Since:
6.4

setCollectionValueParams

public static void setCollectionValueParams(org.hibernate.Query query,
                                            String[] names,
                                            Class<?> entityClass,
                                            Object object)
Sets collection values as individual query parameters. Use this method together with #getExampleWhereClause(Object, String, String[]) when your example contains collections.

The method iterates over the provides names array and inspects the given bean (or map). If there's a property (or map entry) of the type java.util.Collection, the methods iterates over the collection and sets a query parameter for each item. The name is suffixed with an underscore and the item's index.

Since:
6.4

getSearchWhereClause

public static String getSearchWhereClause(String alias,
                                          String[] propertyNames,
                                          String searchParamName)
Returns a HQL term that can be used within a where-clause to perform a search. Example: "(lower(<alias>.<property[0]>) like :<searchParamName> or lower(<alias>.<property[1]>) like :<searchParamName> or ...)"

Since:
6.4

appendJoinsForSearch

public static StringBuffer appendJoinsForSearch(StringBuffer hql,
                                                String alias,
                                                String[] propertyNames)
Joins all path properties requested by the search property names Example: search should be foo.bar = :search -> join this.foo *


appendHql

public static StringBuffer appendHql(StringBuffer hql,
                                     String expression,
                                     String term)
Appends the given term to the StringBuffer. If the buffer is not empty, the provided expression is inserted right before the term (surrounded by spaces).

Since:
6.4

addEqOrNull

public static void addEqOrNull(org.hibernate.Criteria c,
                               String name,
                               Object val)

isLiveModeFilterDefined

public static boolean isLiveModeFilterDefined(org.hibernate.SessionFactory sf)

enableLiveModeFilterIfNecessary

public static void enableLiveModeFilterIfNecessary(org.hibernate.Session session)