final class HibernateAdapter extends Object
getSession()
.
Session factory is configured from provided configuration object, see Config
class for format description.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CONFIG
Defualt Hibernate configuration resource is used when Config object is not provided, that is, is null.
|
private static js.log.Log |
log
Class logger.
|
private org.hibernate.SessionFactory |
sessionFactory
Hibernate session factory.
|
private static String |
TEST_PERIOD
Database connection keep alive period, set to half hour.
|
private static String |
TEST_QUERY
Query for database connection keep alive transaction.
|
private ThreadLocal<TransactionImpl> |
transactionsCache
Keep current on working transaction on thread local variable.
|
private int |
transactionTimeout
Hibernate transaction timeout.
|
Constructor and Description |
---|
HibernateAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
config(js.lang.Config config)
Hibernate adapter initialization.
|
TransactionImpl |
createTransaction(boolean readOnly)
Create a database handler.
|
void |
destroy()
Destroy Hibernate session factory and releases database resources.
|
void |
destroyTransaction()
Remote transaction from transactions cache.
|
<T> T |
getSession() |
org.hibernate.SessionFactory |
getSessionFactory()
Get session factory.
|
private static org.hibernate.cfg.Configuration |
hibernateConfiguration(js.lang.Config config)
Configure Hibernate from j(s)-lib configuration object.
|
private static final js.log.Log log
public static final String DEFAULT_CONFIG
config(Config)
.private static final String TEST_PERIOD
private static final String TEST_QUERY
private final ThreadLocal<TransactionImpl> transactionsCache
private org.hibernate.SessionFactory sessionFactory
Transaction
implementation.private int transactionTimeout
hibernate.transaction.timeout
property, if exists.public void config(js.lang.Config config) throws js.lang.ConfigException, org.hibernate.HibernateException
Scan and register mappings files in the configured package(s). For Hibernate mappings there are
mappings
child elements into configuration object. There can be a not limited number of
mappings
elements but usually it is a single one. A mapping element has package
and
files-pattern
attributes. Files pattern is optional with default *.hbm.xml
.
config
- configuration object, possible null.js.lang.ConfigException
- if configuration object is not well formed.org.hibernate.HibernateException
- if a property is not recognized by Hibernate session factory builder.private static org.hibernate.cfg.Configuration hibernateConfiguration(js.lang.Config config)
config
- configuration object.public org.hibernate.SessionFactory getSessionFactory()
public TransactionImpl createTransaction(boolean readOnly)
TransactionImpl
and store it on current thread so that it can be
retrieved by application code. This method is invoked by TransactionManagerImpl
when start a new
transaction. Note that created handler is valid only on current transaction boundaries.readOnly
- if this flag is true create a read-only transaction, supporting only database select operations.public void destroyTransaction()
public <T> T getSession()
public void destroy()
Copyright © 2019. All rights reserved.