public class Session extends Object implements Closeable
| Modifier and Type | Field and Description |
|---|---|
static String |
SQL_ILLEGAL
Exception SQL message prefix
|
| Modifier and Type | Method and Description |
|---|---|
Transaction |
beginTransaction()
Create a new transaction or a sub-transaction.
|
protected void |
call(DbProcedure procedure)
Call the stored procedure
|
void |
clearCache()
Clear the cache.
|
void |
clearCache(CachePolicy policy)
Clear cache and change its policy.
|
void |
close()
Close and release all DB connections.
|
void |
commit()
Make a commit for all databases.
|
void |
commit(boolean commit)
Make commit/rollback for all 'production' databases.
|
void |
commitTransaction()
Make a commit om all databases for the current transaction level.
|
protected org.ujorm.criterion.Criterion |
createPkCriterion(OrmUjo bo)
Returns an criterion by a PrimaryKey
|
<U extends OrmUjo> |
createQuery(Class<U> aClass)
Create query for all table rows.
|
<U extends OrmUjo> |
createQuery(Class<U> aClass,
org.ujorm.criterion.Criterion<U> criterion)
Deprecated.
Use the method
createQuery(Criterion, Class) rather. |
<U extends OrmUjo> |
createQuery(org.ujorm.criterion.Criterion<U> criterion)
The table class is derived from the first criterion column.
|
<U extends OrmUjo> |
createQuery(org.ujorm.criterion.Criterion<U> criterion,
Class<U> aClass)
Create query.
|
<U extends OrmUjo> |
delete(Class<U> tableClass,
org.ujorm.criterion.Criterion<U> criterion)
Delete all object object by the criterion from parameter.
|
<U extends OrmUjo> |
delete(org.ujorm.criterion.Criterion<U> criterion)
Delete all object object by the criterion from parameter.
|
<T extends OrmUjo> |
delete(List<T> bos)
Delete all objects of the same type from database.
|
protected <U extends OrmUjo> |
delete(MetaTable tableModel,
org.ujorm.criterion.Criterion<U> criterion)
Delete all objects object form parameter
Warning: method does not remove deleted object from internal cache, however you can call method clearCache() to release all objects from the cache. |
int |
delete(OrmUjo bo)
Delete an optional object from the parameters.
|
<U extends OrmUjo> |
exists(Class<U> entity)
Returns
true if exists any database row for the required entity. |
<U extends OrmUjo> |
exists(org.ujorm.criterion.Criterion<U> criterion)
Returns
true if exists any database row with the required condition. |
protected <U extends OrmUjo> |
exists(MetaTable table,
org.ujorm.criterion.Criterion<U> criterion,
org.ujorm.Key pk)
Returns
true if exists any database row for the required criterion. |
OrmUjo |
findCache(Class type,
Object... pkeys)
Find object from internal cache
|
OrmUjo |
findCache(Class type,
Object pkey)
Find object from internal cache
|
MetaRelation2Many |
getBasicColumn(org.ujorm.criterion.Criterion criterion)
Returns the first "basic" column of criterion.
|
Connection |
getConnection(int databaseIndex,
boolean toModify)
Get a Connection for a required databse by a database order number (index).
|
Connection |
getConnection(MetaDatabase database,
boolean toModify)
Get or create a Connection for a required database with an autocommit na false.
|
<DB extends OrmUjo> |
getDatabase(Class<DB> dbType)
Returns a Database instance.
|
SqlDialect |
getDialect(Class<? extends OrmUjo> ormType)
Check dialect type
|
Connection |
getFirstConnection()
Get the first Connection where an autocommit is set to false.
|
Connection |
getFirstConnection(boolean toModify)
Get the first Connection where an autocommit is set to false.
|
<DB extends OrmUjo> |
getFirstDatabase()
Returns the first Database instance.
|
OrmHandler |
getHandler()
Returns a handler
|
LazyLoading |
getLazyLoading()
Enable a lazy-loading of related Ujo object.
|
protected List<MetaColumn> |
getOrmColumns(org.ujorm.Key... keys)
Convert a key array to a column list.
|
MetaParams |
getParameters()
Returns parameters
|
<U extends OrmUjo> |
getRowCount(Query<U> query)
Returns a count of rows
|
Connection |
getSeqConnection(MetaDatabase database)
Get sequence connection for a required database with an autocommit na false.
|
JdbcStatement |
getStatement(MetaDatabase database,
CharSequence sql,
boolean toModify)
Create new statement and assigng Savepoint for a trnasaction sase.
|
JdbcStatement |
getStatement(Query query)
Run SQL SELECT by query.
|
JdbcStatement |
getStatementCallable(MetaDatabase database,
String sql,
boolean toModify)
Create new statement
|
Transaction |
getTransaction()
Returns the current transaction
|
boolean |
hasDialect(Class<? extends OrmUjo> ormType,
Class<? extends SqlDialect>... dialects)
Returns true, if ORM type have got any from listed dialects
|
protected void |
checkNotNull(OrmUjo ujo,
String action)
Check the Ujo object to not null.
|
boolean |
isClosed()
Is the session closed?
|
boolean |
isRollbackOnly()
The rollback is allowed only.
|
<U extends OrmUjo> |
iterateInternal(RelationToMany key,
OrmUjo value)
Iterate key of values
|
<U extends OrmUjo> |
load(Class<U> tableType,
Object id)
Load UJO by a unique id.
|
<U extends OrmUjo> |
loadBy(U ujo)
Load UJO by a unique id.
|
<U extends OrmUjo> |
loadInternal(org.ujorm.Key relatedProperty,
Object id,
boolean mandatory)
Load UJO by a unique id.
|
void |
markForRolback() |
static Session |
newClosedSession(OrmHandler handler)
Create the closed session
|
ForeignKey |
readFK(OrmUjo ujo,
org.ujorm.Key<?,? extends OrmUjo> key)
Build new Foreign key.
|
boolean |
reload(OrmUjo ujo)
Reload values of the persistent object.
|
void |
rollback()
Make a rollback for all databases.
|
void |
rollbackTransaction()
Make a rollback on all databases for the current transaction level.
|
void |
save(List<? extends OrmUjo> bos)
INSERT object into table using the Multirow inserts.
|
void |
save(List<? extends OrmUjo> bos,
int multiLimit)
INSERT object into table using the Multirow inserts.
|
void |
save(OrmUjo bo)
Save all persistent attributes into DB table by an INSERT SQL statement.
|
void |
saveOrUpdate(OrmUjo bo)
Make a statement INSERT or UPDATE into a database table
according to attribute
Session. |
void |
setLazyLoading(LazyLoading lazyLoadingEnabled)
Enable a lazy-loading of related Ujo object.
|
int |
update(OrmUjo bo)
Database UPDATE of the
modified columns for the selected object. |
<U extends OrmUjo> |
update(U bo,
org.ujorm.criterion.Criterion<U> criterion)
Database Batch UPDATE of the
modified columns along a criterion. |
public static final String SQL_ILLEGAL
public Transaction beginTransaction() throws IllegalStateException
IllegalStateException - Throw the Exception if a Transaction is runningpublic Transaction getTransaction()
null if no transaction is running.public final OrmHandler getHandler()
public void commitTransaction()
public void commit()
public void rollbackTransaction()
public final void rollback()
public final void commit(boolean commit)
throws IllegalStateException
commit - if parameters is false than make a rollback.IllegalStateExceptionpublic <U extends OrmUjo> Query<U> createQuery(Class<U> aClass)
@Deprecated public final <U extends OrmUjo> Query<U> createQuery(Class<U> aClass, org.ujorm.criterion.Criterion<U> criterion)
createQuery(Criterion, Class) rather.public final <U extends OrmUjo> Query<U> createQuery(org.ujorm.criterion.Criterion<U> criterion, Class<U> aClass)
createQuery(Criterion)
without the Class parameter.public final <U extends OrmUjo> Query<U> createQuery(org.ujorm.criterion.Criterion<U> criterion)
public final <U extends OrmUjo> boolean exists(org.ujorm.criterion.Criterion<U> criterion)
true if exists any database row with the required condition.public final <U extends OrmUjo> boolean exists(Class<U> entity)
true if exists any database row for the required entity.protected final <U extends OrmUjo> boolean exists(MetaTable table, org.ujorm.criterion.Criterion<U> criterion, org.ujorm.Key pk)
true if exists any database row for the required criterion.public MetaRelation2Many getBasicColumn(org.ujorm.criterion.Criterion criterion)
public final <DB extends OrmUjo> DB getFirstDatabase()
public <DB extends OrmUjo> DB getDatabase(Class<DB> dbType)
public void saveOrUpdate(OrmUjo bo) throws IllegalStateException
Session. Related objects
must be saved using an another call of the method.
The method cleans all flags of modified attributes.IllegalStateExceptionpublic void save(List<? extends OrmUjo> bos) throws IllegalStateException
bos - Business objectsIllegalStateExceptionMetaParams.INSERT_MULTIROW_ITEM_LIMITpublic void save(List<? extends OrmUjo> bos, int multiLimit) throws org.ujorm.core.IllegalUjormException
bos - List of the business object of the same class. If the list must not contain object of different typesmultiLimit - Row limit for the one insert.
If the value will be out of range <1,bos.size()> than the value will be corrected.
If the list item count is greater than multi limit so insert will be separated by more multirow inserts.IllegalStateExceptionorg.ujorm.core.IllegalUjormExceptionpublic void save(OrmUjo bo) throws IllegalStateException
IllegalStateExceptionpublic int update(OrmUjo bo) throws IllegalStateException
modified columns for the selected object.
The method cleans all flags of modified attributes.IllegalStateExceptionOrmUjo.readChangedProperties(boolean)public <U extends OrmUjo> int update(U bo, org.ujorm.criterion.Criterion<U> criterion)
modified columns along a criterion.
The method cleans all flags of modified attributes.
MetaParams.INHERITANCE_MODE for more information.OrmUjo.readChangedProperties(boolean)public <U extends OrmUjo> int delete(org.ujorm.criterion.Criterion<U> criterion)
MetaParams.INHERITANCE_MODE for more information.criterion - filter for deleting tables.public int delete(OrmUjo bo)
bo - Business object to delete, or the null argument as a result of some nullable relation.null.public <T extends OrmUjo> int delete(List<T> bos)
bos - Business objects to delete, the the null argument is not allowed
and the null items are not allowed too.empty.public <U extends OrmUjo> int delete(Class<U> tableClass, org.ujorm.criterion.Criterion<U> criterion)
tableClass - Type of table to deletecriterion - filter for deleting tables.protected <U extends OrmUjo> int delete(MetaTable tableModel, org.ujorm.criterion.Criterion<U> criterion)
tableModel - Type of table to deletecriterion - filter for deleting tables.protected void call(DbProcedure procedure)
protected List<MetaColumn> getOrmColumns(org.ujorm.Key... keys)
protected org.ujorm.criterion.Criterion createPkCriterion(OrmUjo bo)
public JdbcStatement getStatement(Query query)
public <U extends OrmUjo> UjoIterator<U> iterateInternal(RelationToMany key, OrmUjo value)
key - Table key type of the RelationToMany.value - A value type of OrmUjopublic final Connection getFirstConnection() throws IllegalStateException
IllegalStateExceptionpublic final Connection getFirstConnection(boolean toModify) throws IllegalStateException
toModify - By the value false is disabled to assign savepoints in an active transaction.IllegalStateExceptionpublic final Connection getConnection(int databaseIndex, boolean toModify) throws IllegalStateException
databaseIndex - The first database have got the index value: 0 .toModify - By the value false is disabled to assign savepoints in an active transaction.IllegalStateExceptionpublic final Connection getConnection(MetaDatabase database, boolean toModify) throws IllegalStateException
database - Database meta-modeltoModify - By the value false is disabled to assign savepoints in an active transaction.IllegalStateException - An envelope for a run-time SQL exceptionpublic final Connection getSeqConnection(MetaDatabase database) throws IllegalStateException
IllegalStateExceptionpublic JdbcStatement getStatement(MetaDatabase database, CharSequence sql, boolean toModify) throws SQLException
SQLExceptionpublic JdbcStatement getStatementCallable(MetaDatabase database, String sql, boolean toModify) throws SQLException
SQLExceptionpublic <U extends OrmUjo> U load(Class<U> tableType, Object id) throws NoSuchElementException
tableType - Type of Ujoid - Value IDNoSuchElementExceptionpublic <U extends OrmUjo> U loadBy(U ujo) throws NoSuchElementException
null or no result is found
then the null value is returned.ujo - Ujo objectNoSuchElementExceptionpublic boolean reload(OrmUjo ujo)
ExtendedOrmUjo than foreign keys are reloaded
else a lazy initialization is loaded - for the first key depth.ujo - The persistent object to relading values.public <U extends OrmUjo> U loadInternal(org.ujorm.Key relatedProperty, Object id, boolean mandatory) throws NoSuchElementException
relatedProperty - Related keyid - Valid IDmandatory - If result is mandatory then the method throws an exception if no object was found else returns null;NoSuchElementExceptionpublic void close()
throws IllegalStateException
close in interface Closeableclose in interface AutoCloseableIllegalStateException - The exception contains a bug from Connection close;public boolean isClosed()
public void clearCache()
public final void clearCache(CachePolicy policy)
public final MetaParams getParameters()
public boolean isRollbackOnly()
true if an inner session attribute is true or
a related transaction have got the status equals {link Status#STATUS_ROLLEDBACK}.public void markForRolback()
public ForeignKey readFK(OrmUjo ujo, org.ujorm.Key<?,? extends OrmUjo> key) throws org.ujorm.core.IllegalUjormException
key - The key must be a relation type of "many to one".IllegalStateException - If a parameter key is not a foreign key.org.ujorm.core.IllegalUjormExceptionpublic final SqlDialect getDialect(Class<? extends OrmUjo> ormType)
public boolean hasDialect(Class<? extends OrmUjo> ormType, Class<? extends SqlDialect>... dialects)
ormType - Entity typedialects - Entity dialect typepublic static Session newClosedSession(OrmHandler handler)
public LazyLoading getLazyLoading()
MetaParams#LAZY_LOADING_ENABLED.public void setLazyLoading(LazyLoading lazyLoadingEnabled)
MetaParams#LAZY_LOADING_ENABLED.lazyLoadingEnabled - the lazyLoadingEnabled to setprotected void checkNotNull(OrmUjo ujo, String action) throws IllegalArgumentException
ujo - action - IllegalArgumentException - Throw the exception if a ujo argument is null.Copyright 2013, Pavel Ponec