|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.ujorm.orm.Session
public class Session
The ORM session.
Methods of the session are not thread safe.
| Field Summary | |
|---|---|
static String |
SQL_ILLEGAL
Exception SQL message prefix |
| Method Summary | ||
|---|---|---|
Transaction |
beginTransaction()
Create a new transaction or a sub-transaction. |
|
protected void |
call(DbProcedure procedure)
Call the stored procedure |
|
protected void |
checkNotNull(OrmUjo ujo,
String action)
Check the Ujo object to not null. |
|
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 Criterion |
createPkCriterion(OrmUjo bo)
Returns an criterion by a PrimaryKey |
|
|
createQuery(Class<UJO> aClass)
Create query for all table rows. |
|
|
createQuery(Class<UJO> aClass,
Criterion<UJO> criterion)
Deprecated. Use the method createQuery(Criterion, Class) rather. |
|
|
createQuery(Criterion<UJO> criterion)
The table class is derived from the first criterion column. |
|
|
createQuery(Criterion<UJO> criterion,
Class<UJO> aClass)
Create query. |
|
|
delete(Class<UJO> tableClass,
Criterion<UJO> criterion)
Delete all object object by the criterion from parameter. |
|
|
delete(Criterion<UJO> criterion)
Delete all object object by the criterion from parameter. |
|
protected
|
delete(MetaTable tableModel,
Criterion<UJO> 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. |
|
|
exists(Class<UJO> entity)
Returns true if exists any database row for the required entity. |
|
|
exists(Criterion<UJO> criterion)
Returns true if exists any database row with the required condition. |
|
protected
|
exists(MetaTable table,
Criterion<UJO> criterion,
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(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. |
|
|
getDatabase(Class<DB> dbType)
Returns a Database instance. |
|
SqlDialect |
getDialect(Class<? extends OrmUjo> ormType)
Check dialecttype |
|
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. |
|
|
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(Key... keys)
Convert a key array to a column list. |
|
MetaParams |
getParameters()
Returns parameters |
|
|
getRowCount(Query<UJO> query)
Returns a count of rows |
|
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 Corm type have got any from listed dialects |
|
boolean |
isClosed()
Is the session closed? |
|
boolean |
isRollbackOnly()
The rollback is allowed only. |
|
|
iterateInternal(RelationToMany key,
OrmUjo value)
Iterate key of values |
|
|
load(Class<UJO> tableType,
Object id)
Load UJO by a unique id. |
|
|
loadBy(UJO ujo)
Load UJO by a unique id. |
|
|
loadInternal(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,
Key<?,? extends OrmUjo> key)
Build new Forign 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)
INSERT object into table. |
|
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. |
|
int |
update(OrmUjo bo,
Criterion criterion)
Database Batch UPDATE of the modified columns along a criterion. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String SQL_ILLEGAL
| Method Detail |
|---|
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 <UJO extends OrmUjo> Query<UJO> createQuery(Class<UJO> aClass)
@Deprecated
public final <UJO extends OrmUjo> Query<UJO> createQuery(Class<UJO> aClass,
Criterion<UJO> criterion)
createQuery(Criterion, Class) rather.
createQuery(org.ujorm.criterion.Criterion, java.lang.Class),
createQuery(org.ujorm.criterion.Criterion)
public final <UJO extends OrmUjo> Query<UJO> createQuery(Criterion<UJO> criterion,
Class<UJO> aClass)
createQuery(Criteron)
without the Class parameter.
createQuery(org.ujorm.criterion.Criterion)public final <UJO extends OrmUjo> Query<UJO> createQuery(Criterion<UJO> criterion)
public final <UJO extends OrmUjo> boolean exists(Criterion<UJO> criterion)
true if exists any database row with the required condition.
public final <UJO extends OrmUjo> boolean exists(Class<UJO> entity)
true if exists any database row for the required entity.
protected final <UJO extends OrmUjo> boolean exists(MetaTable table,
Criterion<UJO> criterion,
Key pk)
true if exists any database row for the required criterion.
public MetaRelation2Many getBasicColumn(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.
IllegalStateException
public void save(List<? extends OrmUjo> bos)
throws IllegalStateException
multiLimit - 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 greather than multi limit so insert will be separated by more multirow inserts.
IllegalStateExceptionMetaParams.INSERT_MULTIROW_ITEM_LIMIT
public void save(List<? extends OrmUjo> bos,
int multiLimit)
throws IllegalStateException
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 greather than multi limit so insert will be separated by more multirow inserts.
IllegalStateException
public void save(OrmUjo bo)
throws IllegalStateException
IllegalStateException
public int update(OrmUjo bo)
throws IllegalStateException
modified columns for the selected object.
IllegalStateExceptionOrmUjo.readChangedProperties(boolean)
public int update(OrmUjo bo,
Criterion criterion)
modified columns along a criterion.
MetaParams.INHERITANCE_MODE for more information.
OrmUjo.readChangedProperties(boolean)public <UJO extends OrmUjo> int delete(Criterion<UJO> 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 <UJO extends OrmUjo> int delete(Class<UJO> tableClass,
Criterion<UJO> criterion)
tableClass - Type of table to deletecriterion - filter for deleting tables.
protected <UJO extends OrmUjo> int delete(MetaTable tableModel,
Criterion<UJO> criterion)
tableModel - Type of table to deletecriterion - filter for deleting tables.
protected void call(DbProcedure procedure)
protected List<MetaColumn> getOrmColumns(Key... keys)
protected Criterion createPkCriterion(OrmUjo bo)
public <UJO extends OrmUjo> long getRowCount(Query<UJO> query)
public JdbcStatement getStatement(Query query)
public <UJO extends OrmUjo> UjoIterator<UJO> iterateInternal(RelationToMany key,
OrmUjo value)
key - Table key type of the RelationToMany.value - A value type of OrmUjo
public final Connection getFirstConnection()
throws IllegalStateException
databaseIndex - The first database have got the index value: 0 .
IllegalStateException
public final Connection getFirstConnection(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.
IllegalStateException
public 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.
IllegalStateException
public 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 exception
public JdbcStatement getStatement(MetaDatabase database,
CharSequence sql,
boolean toModify)
throws SQLException
SQLException
public JdbcStatement getStatementCallable(MetaDatabase database,
String sql,
boolean toModify)
throws SQLException
SQLException
public <UJO extends OrmUjo> UJO load(Class<UJO> tableType,
Object id)
throws NoSuchElementException
tableType - Type of Ujoid - Value ID
NoSuchElementException
public <UJO extends OrmUjo> UJO loadBy(UJO ujo)
throws NoSuchElementException
null or no result is found
then the null value is returned.
tableType - Type of Ujoid - Value ID
NoSuchElementExceptionpublic 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 <UJO extends OrmUjo> UJO loadInternal(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;
NoSuchElementException
public void close()
throws IllegalStateException
close in interface CloseableIllegalStateException - The exception contains a bug from Connection close;public boolean isClosed()
public OrmUjo findCache(Class type,
Object pkey)
public OrmUjo findCache(Class type,
Object... pkeys)
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,
Key<?,? extends OrmUjo> key)
throws IllegalStateException
key - The key must be a relalation type of "many to one".
IllegalStateException - If a parameter key is not a foreign key.public final SqlDialect getDialect(Class<? extends OrmUjo> ormType)
public boolean hasDialect(Class<? extends OrmUjo> ormType,
Class<? extends SqlDialect>... dialects)
ormType - Entity typedialects - Entity dialect type
public 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 set
protected void checkNotNull(OrmUjo ujo,
String action)
throws IllegalArgumentException
ujo - action -
IllegalArgumentException - Throw the exception if a ujo argument is null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||