Interface RemoteEntityConnection

All Superinterfaces:
AutoCloseable, Remote

public interface RemoteEntityConnection extends Remote, AutoCloseable
A remote EntityConnection.
  • Method Details

    • entities

      Entities entities() throws RemoteException
      Returns:
      the underlying domain entities
      Throws:
      RemoteException - in case of an exception
    • user

      User user() throws RemoteException
      Returns:
      the user being used by this connection
      Throws:
      RemoteException - in case of an exception
    • connected

      boolean connected() throws RemoteException
      Returns:
      true if this connection has been established and is valid
      Throws:
      RemoteException - in case of an exception
    • close

      void close() throws RemoteException
      Closes this connection.
      Specified by:
      close in interface AutoCloseable
      Throws:
      RemoteException - in case of an exception
    • transactionOpen

      boolean transactionOpen() throws RemoteException
      Returns:
      true if a transaction is open, false otherwise
      Throws:
      RemoteException - in case of exception
    • startTransaction

      void startTransaction() throws RemoteException
      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 open
      RemoteException - in case of exception
    • rollbackTransaction

      void rollbackTransaction() throws RemoteException
      Performs a rollback and ends the current transaction
      Throws:
      DatabaseException - in case the rollback failed
      IllegalStateException - in case a transaction is not open
      RemoteException - in case of a remote exception
    • commitTransaction

      void commitTransaction() throws RemoteException
      Performs a commit and ends the current transaction
      Throws:
      DatabaseException - in case the commit failed
      IllegalStateException - in case a transaction is not open
      RemoteException - in case of a remote exception
    • setQueryCacheEnabled

      void setQueryCacheEnabled(boolean queryCacheEnabled) throws RemoteException
      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

      boolean isQueryCacheEnabled() throws RemoteException
      Returns:
      true if the query cache is enabled
      Throws:
      RemoteException - in case of a remote exception
      See Also:
    • execute

      <C extends EntityConnection, T, R> R execute(FunctionType<C,T,R> functionType) throws RemoteException
      Executes the function with the given type with no arguments
      Type Parameters:
      C - the connection type
      T - the argument type
      R - the return value type
      Parameters:
      functionType - the function type
      Returns:
      the function return value
      Throws:
      DatabaseException - in case anything goes wrong during the execution
      RemoteException - in case of a remote exception
    • execute

      <C extends EntityConnection, T, R> R execute(FunctionType<C,T,R> functionType, T argument) throws RemoteException
      Executes the function with the given type
      Type Parameters:
      C - the connection type
      T - the argument type
      R - the return value type
      Parameters:
      functionType - the function type
      argument - the function argument
      Returns:
      the function return value
      Throws:
      DatabaseException - in case anything goes wrong during the execution
      RemoteException - in case of a remote exception
    • execute

      <C extends EntityConnection, T> void execute(ProcedureType<C,T> procedureType) throws RemoteException
      Executes the procedure with the given type with no arguments
      Type Parameters:
      C - the connection type
      T - the procedure argument type
      Parameters:
      procedureType - the procedure type
      Throws:
      DatabaseException - in case anything goes wrong during the execution
      RemoteException - in case of a remote exception
    • execute

      <C extends EntityConnection, T> void execute(ProcedureType<C,T> procedureType, T argument) throws RemoteException
      Executes the procedure with the given type
      Type Parameters:
      C - the connection type
      T - the procedure argument type
      Parameters:
      procedureType - the procedure type
      argument - the procedure argument
      Throws:
      DatabaseException - in case anything goes wrong during the execution
      RemoteException - in case of a remote exception
    • insert

      Entity.Key insert(Entity entity) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      RemoteException - in case of a remote exception
    • insertSelect

      Entity insertSelect(Entity entity) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      RemoteException - in case of a remote exception
    • insert

      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:
      DatabaseException - in case of a db exception
      RemoteException - in case of a remote exception
    • insertSelect

      Collection<Entity> insertSelect(Collection<Entity> entities) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      RemoteException - in case of a remote exception
    • update

      void update(Entity entity) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      UpdateException - in case there is a mismatch between expected and actual number of updated rows
      RecordModifiedException - in case the entity has been modified or deleted by another user
      RemoteException - in case of a remote exception
    • updateSelect

      Entity updateSelect(Entity entity) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      UpdateException - in case there is a mismatch between expected and actual number of updated rows
      RecordModifiedException - in case the entity has been modified or deleted by another user
      RemoteException - in case of a remote exception
    • update

      void update(Collection<Entity> entities) throws RemoteException
      Updates the given entities based on their attribute values. Performs a commit unless a transaction is open.
      Parameters:
      entities - the entities to update
      Throws:
      DatabaseException - in case of a db exception
      RecordModifiedException - in case an entity has been modified or deleted by another user
      RemoteException - in case of a remote exception
    • updateSelect

      Collection<Entity> updateSelect(Collection<Entity> entities) throws RemoteException
      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:
      DatabaseException - in case of a db exception
      RecordModifiedException - in case an entity has been modified or deleted by another user
      RemoteException - in case of a remote exception
    • update

      int update(EntityConnection.Update update) throws RemoteException
      Performs an update based on the given update, updating the columns found in the EntityConnection.Update.values() map, using the associated value.
      Parameters:
      update - the update to perform
      Returns:
      the number of affected rows
      Throws:
      DatabaseException - in case of a dabase exception
      RemoteException - in case of a remote exception
    • delete

      void delete(Entity.Key key) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      DeleteException - in case no row or multiple rows were deleted
      RemoteException - in case of a remote exception
    • delete

      void delete(Collection<Entity.Key> keys) throws RemoteException
      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:
      DatabaseException - in case of a db exception
      DeleteException - in case the number of deleted rows does not match the number of keys
      RemoteException - in case of a remote exception
    • delete

      int delete(Condition condition) throws RemoteException
      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:
      DatabaseException - in case of a db exception
      RemoteException - in case of a remote exception
    • select

      <T> List<T> select(Column<T> column) throws RemoteException
      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:
      DatabaseException - in case of a db exception
      IllegalArgumentException - in case the given column has not associated with a table column
      UnsupportedOperationException - in case the entity uses a custom column clause or if the column represents an aggregate value
      RemoteException - in case of a remote exception
    • select

      <T> List<T> select(Column<T> column, Condition condition) throws RemoteException
      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 - column
      condition - the condition
      Returns:
      the values of the given column
      Throws:
      DatabaseException - in case of a database exception
      IllegalArgumentException - in case the given column is not associated with a table column
      UnsupportedOperationException - in case the entity uses a custom column clause or if the column represents an aggregate value
      RemoteException - in case of a remote exception
    • select

      <T> List<T> select(Column<T> column, EntityConnection.Select select) throws RemoteException
      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 column
      select - the select to perform
      Returns:
      the values of the given column
      Throws:
      DatabaseException - in case of a db exception
      IllegalArgumentException - in case the given column is not associated with a table column
      UnsupportedOperationException - in case the entity uses a custom column clause or if the column represents an aggregate value
      RemoteException - in case of a remote exception
    • select

      Entity select(Entity.Key key) throws RemoteException
      Selects an entity by key
      Parameters:
      key - the key of the entity to select
      Returns:
      an entity having the key key
      Throws:
      DatabaseException - in case of a db exception
      RecordNotFoundException - in case the entity was not found
      MultipleRecordsFoundException - in case multiple entities were found
      RemoteException - in case of a remote exception
    • selectSingle

      Entity selectSingle(Condition condition) throws RemoteException
      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:
      DatabaseException - in case of a database exception
      RecordNotFoundException - in case the entity was not found
      MultipleRecordsFoundException - in case multiple entities were found
      RemoteException - in case of a remote exception
    • selectSingle

      Entity selectSingle(EntityConnection.Select select) throws RemoteException
      Selects a single entity based on the specified select
      Parameters:
      select - the select to perform
      Returns:
      the entities according to the given select
      Throws:
      DatabaseException - if an exception occurs
      RecordNotFoundException - in case the entity was not found
      MultipleRecordsFoundException - in case multiple entities were found
      RemoteException - in case of a remote exception
    • select

      Selects entities based on the given keys
      Parameters:
      keys - the keys used in the condition
      Returns:
      entities based on keys
      Throws:
      DatabaseException - in case of a db exception
      RemoteException - in case of a remote exception
    • select

      List<Entity> select(Condition condition) throws RemoteException
      Selects entities based on the given condition
      Parameters:
      condition - the condition specifying which entities to select
      Returns:
      entities based to the given condition
      Throws:
      DatabaseException - in case of a database exception
      RemoteException - in case of a remote exception
    • select

      Selects entities based on the given select
      Parameters:
      select - the select to perform
      Returns:
      entities based to the given select
      Throws:
      DatabaseException - in case of a db exception
      RemoteException - in case of a remote exception
    • dependencies

      Map<EntityType,Collection<Entity>> dependencies(Collection<Entity> entities) throws RemoteException
      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 type
      DatabaseException - in case of a db exception
      RemoteException - in case of a remote exception
    • count

      int count(EntityConnection.Count count) throws RemoteException
      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:
      DatabaseException - in case of a db exception
      RemoteException - in case of a remote exception
    • report

      <T, R, P> R report(ReportType<T,R,P> reportType, P reportParameters) throws RemoteException
      Takes a ReportType object using a JDBC datasource and returns an initialized ReportResult object
      Type Parameters:
      T - the report type
      R - the report result type
      P - the report parameters type
      Parameters:
      reportType - the report to fill
      reportParameters - the report parameters, if any
      Returns:
      the filled result object
      Throws:
      DatabaseException - in case of a db exception
      ReportException - in case of a report exception
      RemoteException - in case of a remote exception
      See Also: