Module is.codion.framework.db.rmi
Package is.codion.framework.db.rmi
Interface RemoteEntityConnection
- All Superinterfaces:
AutoCloseable,Remote
A remote EntityConnection.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this connection.voidPerforms a commit and ends the current transactionbooleanintcount(is.codion.framework.db.EntityConnection.Count count) Counts the number of rows returned based on the given count conditionsintdelete(is.codion.framework.domain.entity.condition.Condition condition) Deletes the entities specified by the given condition Performs a commit unless a transaction is open.voiddelete(is.codion.framework.domain.entity.Entity.Key key) Deletes an entity according to the given primary key.voiddelete(Collection<is.codion.framework.domain.entity.Entity.Key> keys) Deletes the entities with the given primary keys.Map<is.codion.framework.domain.entity.EntityType,Collection<is.codion.framework.domain.entity.Entity>> dependencies(Collection<is.codion.framework.domain.entity.Entity> entities) Selects the entities that depend on the given entities via (non-soft) foreign keys, mapped to corresponding entityTypesis.codion.framework.domain.entity.Entitiesentities()<C extends is.codion.framework.db.EntityConnection,T, R>
Rexecute(is.codion.common.db.operation.FunctionType<C, T, R> functionType) Executes the function with the given type with no arguments<C extends is.codion.framework.db.EntityConnection,T, R>
Rexecute(is.codion.common.db.operation.FunctionType<C, T, R> functionType, T argument) Executes the function with the given type<C extends is.codion.framework.db.EntityConnection,T>
voidexecute(is.codion.common.db.operation.ProcedureType<C, T> procedureType) Executes the procedure with the given type with no arguments<C extends is.codion.framework.db.EntityConnection,T>
voidexecute(is.codion.common.db.operation.ProcedureType<C, T> procedureType, T argument) Executes the procedure with the given typeis.codion.framework.domain.entity.Entity.Keyinsert(is.codion.framework.domain.entity.Entity entity) Inserts the given entity, returning the primary key.Collection<is.codion.framework.domain.entity.Entity.Key>insert(Collection<is.codion.framework.domain.entity.Entity> entities) Inserts the given entities, returning the primary keys in the same order as they were received.is.codion.framework.domain.entity.EntityinsertSelect(is.codion.framework.domain.entity.Entity entity) Inserts the given entity, returning the inserted etity.Collection<is.codion.framework.domain.entity.Entity>insertSelect(Collection<is.codion.framework.domain.entity.Entity> entities) Inserts the given entities, returning the inserted entities.boolean<T,R, P> R report(is.codion.common.db.report.ReportType<T, R, P> reportType, P reportParameters) Takes a ReportType object using a JDBC datasource and returns an initialized ReportResult objectvoidPerforms a rollback and ends the current transactionList<is.codion.framework.domain.entity.Entity>select(is.codion.framework.db.EntityConnection.Select select) Selects entities based on the given select<T> List<T>select(is.codion.framework.domain.entity.attribute.Column<T> column) Selects ordered and distinct non-null values of the given column<T> List<T>select(is.codion.framework.domain.entity.attribute.Column<T> column, is.codion.framework.db.EntityConnection.Select select) Selects distinct non-null values of the given column.<T> List<T>select(is.codion.framework.domain.entity.attribute.Column<T> column, is.codion.framework.domain.entity.condition.Condition condition) Selects distinct non-null values of the given column.List<is.codion.framework.domain.entity.Entity>select(is.codion.framework.domain.entity.condition.Condition condition) Selects entities based on the given conditionis.codion.framework.domain.entity.Entityselect(is.codion.framework.domain.entity.Entity.Key key) Selects an entity by keyCollection<is.codion.framework.domain.entity.Entity>select(Collection<is.codion.framework.domain.entity.Entity.Key> keys) Selects entities based on the givenkeysis.codion.framework.domain.entity.EntityselectSingle(is.codion.framework.db.EntityConnection.Select select) Selects a single entity based on the specified selectis.codion.framework.domain.entity.EntityselectSingle(is.codion.framework.domain.entity.condition.Condition condition) Selects a single entity based on the specified conditionvoidsetQueryCacheEnabled(boolean queryCacheEnabled) Controls the enabled state of the query result cache.voidStarts a transaction on this connection.
NOTE: A transaction should ALWAYS be used in conjunction with a try/catch block,
in order for the transaction to be properly ended in case of an exception.
A transaction should always be started OUTSIDE the try/catch block.booleanintupdate(is.codion.framework.db.EntityConnection.Update update) Performs an update based on the given update, updating the columns found in theEntityConnection.Update.values()map, using the associated value.voidupdate(is.codion.framework.domain.entity.Entity entity) Updates the given entity based on its attribute values.voidupdate(Collection<is.codion.framework.domain.entity.Entity> entities) Updates the given entities based on their attribute values.is.codion.framework.domain.entity.EntityupdateSelect(is.codion.framework.domain.entity.Entity entity) Updates the given entity based on its attribute values.Collection<is.codion.framework.domain.entity.Entity>updateSelect(Collection<is.codion.framework.domain.entity.Entity> entities) Updates the given entities based on their attribute values.is.codion.common.user.Useruser()
-
Method Details
-
entities
- Returns:
- the underlying domain entities
- Throws:
RemoteException- in case of an exception
-
user
- Returns:
- the user being used by this connection
- Throws:
RemoteException- in case of an exception
-
connected
- Returns:
- true if this connection has been established and is valid
- Throws:
RemoteException- in case of an exception
-
close
Closes this connection.- Specified by:
closein interfaceAutoCloseable- Throws:
RemoteException- in case of an exception
-
transactionOpen
- Returns:
- true if a transaction is open, false otherwise
- Throws:
RemoteException- in case of exception
-
startTransaction
Starts a transaction on this connection.
NOTE: A transaction should ALWAYS be used in conjunction with a try/catch block,
in order for the transaction to be properly ended in case of an exception.
A transaction should always be started OUTSIDE the try/catch block.EntityConnection connection = connectionProvider().connection(); connection.startTransaction(); // Very important, should NOT be inside the try block try { connection.insert(entity); connection.commitTransaction(); } catch (DatabaseException e) { connection.rollbackTransaction(); throw e; } catch (Exception e) { // Very important to catch Exception connection.rollbackTransaction(); throw new RuntimeException(e); }- Throws:
IllegalStateException- if a transaction is already openRemoteException- in case of exception
-
rollbackTransaction
Performs a rollback and ends the current transaction- Throws:
IllegalStateException- in case a transaction is not openRemoteException- in case of a remote exception
-
commitTransaction
Performs a commit and ends the current transaction- Throws:
IllegalStateException- in case a transaction is not openRemoteException- in case of a remote exception
-
setQueryCacheEnabled
Controls the enabled state of the query result cache. The cache is cleared when disabled.- Parameters:
queryCacheEnabled- the result cache state- Throws:
RemoteException- in case of a remote exception
-
isQueryCacheEnabled
- Returns:
- true if the query cache is enabled
- Throws:
RemoteException- in case of a remote exception- See Also:
-
execute
<C extends is.codion.framework.db.EntityConnection,T, R executeR> (is.codion.common.db.operation.FunctionType<C, T, throws RemoteException, is.codion.common.db.exception.DatabaseExceptionR> functionType) Executes the function with the given type with no arguments- Type Parameters:
C- the connection typeT- the argument typeR- the return value type- Parameters:
functionType- the function type- Returns:
- the function return value
- Throws:
is.codion.common.db.exception.DatabaseException- in case anything goes wrong during the executionRemoteException- in case of a remote exception
-
execute
<C extends is.codion.framework.db.EntityConnection,T, R executeR> (is.codion.common.db.operation.FunctionType<C, T, throws RemoteException, is.codion.common.db.exception.DatabaseExceptionR> functionType, T argument) Executes the function with the given type- Type Parameters:
C- the connection typeT- the argument typeR- the return value type- Parameters:
functionType- the function typeargument- the function argument- Returns:
- the function return value
- Throws:
is.codion.common.db.exception.DatabaseException- in case anything goes wrong during the executionRemoteException- in case of a remote exception
-
execute
<C extends is.codion.framework.db.EntityConnection,T> void execute(is.codion.common.db.operation.ProcedureType<C, T> procedureType) throws RemoteException, is.codion.common.db.exception.DatabaseExceptionExecutes the procedure with the given type with no arguments- Type Parameters:
C- the connection typeT- the procedure argument type- Parameters:
procedureType- the procedure type- Throws:
is.codion.common.db.exception.DatabaseException- in case anything goes wrong during the executionRemoteException- in case of a remote exception
-
execute
<C extends is.codion.framework.db.EntityConnection,T> void execute(is.codion.common.db.operation.ProcedureType<C, T> procedureType, T argument) throws RemoteException, is.codion.common.db.exception.DatabaseExceptionExecutes the procedure with the given type- Type Parameters:
C- the connection typeT- the procedure argument type- Parameters:
procedureType- the procedure typeargument- the procedure argument- Throws:
is.codion.common.db.exception.DatabaseException- in case anything goes wrong during the executionRemoteException- in case of a remote exception
-
insert
is.codion.framework.domain.entity.Entity.Key insert(is.codion.framework.domain.entity.Entity entity) throws RemoteException, is.codion.common.db.exception.DatabaseException Inserts the given entity, returning the primary key. Performs a commit unless a transaction is open.- Parameters:
entity- the entity to insert- Returns:
- the primary key of the inserted entity
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionRemoteException- in case of a remote exception
-
insertSelect
is.codion.framework.domain.entity.Entity insertSelect(is.codion.framework.domain.entity.Entity entity) throws RemoteException, is.codion.common.db.exception.DatabaseException Inserts the given entity, returning the inserted etity. Performs a commit unless a transaction is open.- Parameters:
entity- the entity to insert- Returns:
- the inserted entity
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionRemoteException- in case of a remote exception
-
insert
Collection<is.codion.framework.domain.entity.Entity.Key> insert(Collection<is.codion.framework.domain.entity.Entity> entities) throws RemoteException, is.codion.common.db.exception.DatabaseException Inserts the given entities, returning the primary keys in the same order as they were received. Performs a commit unless a transaction is open.- Parameters:
entities- the entities to insert- Returns:
- the primary keys of the inserted entities
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionRemoteException- in case of a remote exception
-
insertSelect
Collection<is.codion.framework.domain.entity.Entity> insertSelect(Collection<is.codion.framework.domain.entity.Entity> entities) throws RemoteException, is.codion.common.db.exception.DatabaseException Inserts the given entities, returning the inserted entities. Performs a commit unless a transaction is open.- Parameters:
entities- the entities to insert- Returns:
- the inserted entities
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionRemoteException- in case of a remote exception
-
update
void update(is.codion.framework.domain.entity.Entity entity) throws RemoteException, is.codion.common.db.exception.DatabaseException Updates the given entity based on its attribute values. Returns the updated entity. Throws an exception if the given entity is unmodified. Performs a commit unless a transaction is open.- Parameters:
entity- the entity to update- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.common.db.exception.UpdateException- in case there is a mismatch between expected and actual number of updated rowsis.codion.common.db.exception.RecordModifiedException- in case the entity has been modified or deleted by another userRemoteException- in case of a remote exception
-
updateSelect
is.codion.framework.domain.entity.Entity updateSelect(is.codion.framework.domain.entity.Entity entity) throws RemoteException, is.codion.common.db.exception.DatabaseException Updates the given entity based on its attribute values. Returns the updated entity. Throws an exception if the given entity is unmodified. Performs a commit unless a transaction is open.- Parameters:
entity- the entity to update- Returns:
- the updated entity
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.common.db.exception.UpdateException- in case there is a mismatch between expected and actual number of updated rowsis.codion.common.db.exception.RecordModifiedException- in case the entity has been modified or deleted by another userRemoteException- in case of a remote exception
-
update
void update(Collection<is.codion.framework.domain.entity.Entity> entities) throws RemoteException, is.codion.common.db.exception.DatabaseException Updates the given entities based on their attribute values. Performs a commit unless a transaction is open.- Parameters:
entities- the entities to update- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionis.codion.common.db.exception.RecordModifiedException- in case an entity has been modified or deleted by another userRemoteException- in case of a remote exception
-
updateSelect
Collection<is.codion.framework.domain.entity.Entity> updateSelect(Collection<is.codion.framework.domain.entity.Entity> entities) throws RemoteException, is.codion.common.db.exception.DatabaseException Updates the given entities based on their attribute values. Returns the updated entities, in no particular order. Performs a commit unless a transaction is open.- Parameters:
entities- the entities to update- Returns:
- the updated entities
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionis.codion.common.db.exception.RecordModifiedException- in case an entity has been modified or deleted by another userRemoteException- in case of a remote exception
-
update
int update(is.codion.framework.db.EntityConnection.Update update) throws RemoteException, is.codion.common.db.exception.DatabaseException Performs an update based on the given update, updating the columns found in theEntityConnection.Update.values()map, using the associated value.- Parameters:
update- the update to perform- Returns:
- the number of affected rows
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a dabase exceptionRemoteException- in case of a remote exception
-
delete
void delete(is.codion.framework.domain.entity.Entity.Key key) throws RemoteException, is.codion.common.db.exception.DatabaseException Deletes an entity according to the given primary key. Performs a commit unless a transaction is open.- Parameters:
key- the primary key of the entity to delete- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.common.db.exception.DeleteException- in case no row or multiple rows were deletedRemoteException- in case of a remote exception
-
delete
void delete(Collection<is.codion.framework.domain.entity.Entity.Key> keys) throws RemoteException, is.codion.common.db.exception.DatabaseException Deletes the entities with the given primary keys. This method respects the iteration order of the given collection by first deleting all entities of the first entityType encountered, then all entities of the next entityType encountered and so on. This allows the deletion of multiple entities forming a master detail hierarchy, by having the detail entities appear before their master entities in the collection. Performs a commit unless a transaction is open.- Parameters:
keys- the primary keys of the entities to delete- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionis.codion.common.db.exception.DeleteException- in case the number of deleted rows does not match the number of keysRemoteException- in case of a remote exception
-
delete
int delete(is.codion.framework.domain.entity.condition.Condition condition) throws RemoteException, is.codion.common.db.exception.DatabaseException Deletes the entities specified by the given condition Performs a commit unless a transaction is open.- Parameters:
condition- the condition specifying the entities to delete- Returns:
- the number of deleted rows
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionRemoteException- in case of a remote exception
-
select
<T> List<T> select(is.codion.framework.domain.entity.attribute.Column<T> column) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects ordered and distinct non-null values of the given column- Type Parameters:
T- the value type- Parameters:
column- the column- Returns:
- all the values of the given column
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionIllegalArgumentException- in case the given column has not associated with a table columnUnsupportedOperationException- in case the entity uses a custom column clause or if the column represents an aggregate valueRemoteException- in case of a remote exception
-
select
<T> List<T> select(is.codion.framework.domain.entity.attribute.Column<T> column, is.codion.framework.domain.entity.condition.Condition condition) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects distinct non-null values of the given column. The result is ordered by the selected column.- Type Parameters:
T- the value type- Parameters:
column- columncondition- the condition- Returns:
- the values of the given column
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionIllegalArgumentException- in case the given column is not associated with a table columnUnsupportedOperationException- in case the entity uses a custom column clause or if the column represents an aggregate valueRemoteException- in case of a remote exception
-
select
<T> List<T> select(is.codion.framework.domain.entity.attribute.Column<T> column, is.codion.framework.db.EntityConnection.Select select) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects distinct non-null values of the given column. If the select provides no order by clause the result is ordered by the selected column.- Type Parameters:
T- the value type- Parameters:
column- the columnselect- the select to perform- Returns:
- the values of the given column
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionIllegalArgumentException- in case the given column is not associated with a table columnUnsupportedOperationException- in case the entity uses a custom column clause or if the column represents an aggregate valueRemoteException- in case of a remote exception
-
select
is.codion.framework.domain.entity.Entity select(is.codion.framework.domain.entity.Entity.Key key) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects an entity by key- Parameters:
key- the key of the entity to select- Returns:
- an entity having the key
key - Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionis.codion.common.db.exception.RecordNotFoundException- in case the entity was not foundis.codion.common.db.exception.MultipleRecordsFoundException- in case multiple entities were foundRemoteException- in case of a remote exception
-
selectSingle
is.codion.framework.domain.entity.Entity selectSingle(is.codion.framework.domain.entity.condition.Condition condition) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects a single entity based on the specified condition- Parameters:
condition- the condition specifying the entity to select- Returns:
- the entities based on the given condition
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.common.db.exception.RecordNotFoundException- in case the entity was not foundis.codion.common.db.exception.MultipleRecordsFoundException- in case multiple entities were foundRemoteException- in case of a remote exception
-
selectSingle
is.codion.framework.domain.entity.Entity selectSingle(is.codion.framework.db.EntityConnection.Select select) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects a single entity based on the specified select- Parameters:
select- the select to perform- Returns:
- the entities according to the given select
- Throws:
is.codion.common.db.exception.DatabaseException- if an exception occursis.codion.common.db.exception.RecordNotFoundException- in case the entity was not foundis.codion.common.db.exception.MultipleRecordsFoundException- in case multiple entities were foundRemoteException- in case of a remote exception
-
select
Collection<is.codion.framework.domain.entity.Entity> select(Collection<is.codion.framework.domain.entity.Entity.Key> keys) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects entities based on the givenkeys- Parameters:
keys- the keys used in the condition- Returns:
- entities based on
keys - Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionRemoteException- in case of a remote exception
-
select
List<is.codion.framework.domain.entity.Entity> select(is.codion.framework.domain.entity.condition.Condition condition) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects entities based on the given condition- Parameters:
condition- the condition specifying which entities to select- Returns:
- entities based to the given condition
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionRemoteException- in case of a remote exception
-
select
List<is.codion.framework.domain.entity.Entity> select(is.codion.framework.db.EntityConnection.Select select) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects entities based on the given select- Parameters:
select- the select to perform- Returns:
- entities based to the given select
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionRemoteException- in case of a remote exception
-
dependencies
Map<is.codion.framework.domain.entity.EntityType,Collection<is.codion.framework.domain.entity.Entity>> dependencies(Collection<is.codion.framework.domain.entity.Entity> entities) throws RemoteException, is.codion.common.db.exception.DatabaseException Selects the entities that depend on the given entities via (non-soft) foreign keys, mapped to corresponding entityTypes- Parameters:
entities- the entities for which to retrieve dependencies- Returns:
- the entities that depend on
entities - Throws:
IllegalArgumentException- in case the entities are not of the same typeis.codion.common.db.exception.DatabaseException- in case of a db exceptionRemoteException- in case of a remote exception
-
count
int count(is.codion.framework.db.EntityConnection.Count count) throws RemoteException, is.codion.common.db.exception.DatabaseException Counts the number of rows returned based on the given count conditions- Parameters:
count- the count conditions- Returns:
- the number of rows fitting the given count conditions
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionRemoteException- in case of a remote exception
-
report
<T,R, R reportP> (is.codion.common.db.report.ReportType<T, R, throws RemoteException, is.codion.common.db.exception.DatabaseException, is.codion.common.db.report.ReportExceptionP> reportType, P reportParameters) Takes a ReportType object using a JDBC datasource and returns an initialized ReportResult object- Type Parameters:
T- the report typeR- the report result typeP- the report parameters type- Parameters:
reportType- the report to fillreportParameters- the report parameters, if any- Returns:
- the filled result object
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a db exceptionis.codion.common.db.report.ReportException- in case of a report exceptionRemoteException- in case of a remote exception- See Also:
-
Report.fill(java.sql.Connection, Object)
-