public class HibernateQuerier extends Object implements Querier
Querier
for Hibernate connection to the database.
The querier should first be initialized with the init method, then persistent classes should
be added to the configuration and finally the buildSessionFactory()
method
should be called. The configuration should be set in the jwig.properties file. Specifically
the three properties hibernate.connection.username, hibernate.connection.password, and
hibernate.connection.url should be set for jwig to be able to connect to the database.
If all persistent classes are added in the WebApp
constructors, JWIG will
handle calling the appropriate init methods.Constructor and Description |
---|
HibernateQuerier() |
Modifier and Type | Method and Description |
---|---|
static void |
buildSessionFactory()
Build the session factory from the data in the configuration.
|
void |
close() |
static void |
destroy()
Closes the session factory and releases all resources.
|
Class<? extends Persistable> |
getBaseType(Persistable p)
If the querier implementation uses an instrumented class for representing a persistable type, then the
non-instrumented class of the object must be returned by this method.
|
<E extends Persistable> |
getClass(E p)
Returns the class object of a persistable.
|
static Configuration |
getConfig()
Gets the current configuration for Hibernate that will be used to build the session factory.
|
static SessionFactory |
getFactory()
Gets the session factory from the querier.
|
Integer |
getIdFromProperty(Class<? extends Persistable> clazz,
String property,
String value) |
<E extends Persistable> |
getObject(Class<E> aClass,
Integer id)
Returns the instance of the given class uniquely determined by its ID.
|
<E extends Persistable> |
getObject(Class<E> aClass,
Integer id,
boolean notify) |
String |
getPropertyFromId(Class<? extends Persistable> clazz,
String property,
Integer id) |
static void |
init(Properties ps)
Creates configuration and reads the hibernate properties from jwig.properties in the webapp root folder.
|
boolean |
isNoNull() |
void |
postInit()
Called during initialization of the system.
|
void |
preInit(Properties properties)
Called during initialization of the system.
|
void |
setNoNull(boolean noNull)
If noNull is set then an exception will be thrown if no object with the given Id
exists when querying with getObject.
|
public static void buildSessionFactory()
public static void destroy()
public Class<? extends Persistable> getBaseType(Persistable p)
Querier
getBaseType
in interface Querier
public <E extends Persistable> Class<E> getClass(E p)
Querier
public static Configuration getConfig()
public static SessionFactory getFactory()
public Integer getIdFromProperty(Class<? extends Persistable> clazz, String property, String value)
getIdFromProperty
in interface Querier
public <E extends Persistable> E getObject(Class<E> aClass, Integer id) throws NoSuchObjectException
Querier
getObject
in interface Querier
aClass
- the class of the objectid
- the ID of the objectNoSuchObjectException
public <E extends Persistable> E getObject(Class<E> aClass, Integer id, boolean notify)
public String getPropertyFromId(Class<? extends Persistable> clazz, String property, Integer id)
getPropertyFromId
in interface Querier
public static void init(Properties ps)
public boolean isNoNull()
public void postInit()
Querier
postInit
in interface Querier
Querier.preInit(java.util.Properties)
public void preInit(Properties properties)
Querier
preInit
in interface Querier
Querier.postInit()
public void setNoNull(boolean noNull)
noNull
- Copyright © 2008-2012 Anders Møller & Mathias Schwarz.