Interface EntityConnection

    • Method Detail

      • getDomain

        Domain getDomain()
        Returns:
        the underlying domain model
      • getUser

        User getUser()
        Returns:
        the user being used by this connection
      • isConnected

        boolean isConnected()
        Returns:
        true if the connection has been established and is valid
      • disconnect

        void disconnect()
        Performs a rollback and disconnects this connection
      • isTransactionOpen

        boolean isTransactionOpen()
        Returns:
        true if a transaction is open, false otherwise
      • beginTransaction

        void beginTransaction()
        Begins a transaction on this connection
        Throws:
        IllegalStateException - if a transaction is already open
      • rollbackTransaction

        void rollbackTransaction()
        Performs a rollback and ends the current transaction
        Throws:
        IllegalStateException - in case a transaction is not open
      • commitTransaction

        void commitTransaction()
        Performs a commit and ends the current transaction
        Throws:
        IllegalStateException - in case a transaction is not open
      • executeFunction

        <T> T executeFunction​(String functionId,
                              Object... arguments)
                       throws DatabaseException
        Executes the function with the given id
        Type Parameters:
        T - the result type
        Parameters:
        functionId - the function ID
        arguments - the arguments, if any
        Returns:
        the function return arguments
        Throws:
        DatabaseException - in case anything goes wrong during the execution
      • executeProcedure

        void executeProcedure​(String procedureId,
                              Object... arguments)
                       throws DatabaseException
        Executes the procedure with the given id
        Parameters:
        procedureId - the procedure ID
        arguments - the arguments, if any
        Throws:
        DatabaseException - in case anything goes wrong during the execution
      • insert

        Entity.Key insert​(Entity entity)
                   throws DatabaseException
        Inserts the given entity, returning the primary key of the inserted entity. 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
      • insert

        List<Entity.Key> insert​(List<Entity> entities)
                         throws DatabaseException
        Inserts the given entities, returning a list containing the primary keys of the inserted entities 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 key values of the inserted entities
        Throws:
        DatabaseException - in case of a database exception
      • update

        Entity update​(Entity entity)
               throws DatabaseException
        Updates the given entity according to its properties. 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
      • update

        List<Entity> update​(List<Entity> entities)
                     throws DatabaseException
        Updates the given entities according to their properties. Returns the updated entities, in no particular order. Throws an exception if any of the given entities is unmodified. Performs a commit unless a transaction is open.
        Parameters:
        entities - the entities to update
        Returns:
        the updated entities, in no particular order
        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 an entity has been modified or deleted by another user
      • delete

        boolean delete​(Entity.Key entityKey)
                throws DatabaseException
        Deletes the entity with the given primary key. Performs a commit unless a transaction is open.
        Parameters:
        entityKey - the primary key of the entity to delete
        Returns:
        true if a record was deleted, false otherwise
        Throws:
        DatabaseException - in case of a database exception
      • delete

        int delete​(List<Entity.Key> entityKeys)
            throws DatabaseException
        Deletes the entities with the given primary keys. Performs a commit unless a transaction is open.
        Parameters:
        entityKeys - the primary keys of the entities to delete
        Returns:
        the number of deleted rows
        Throws:
        DatabaseException - in case of a database exception
      • delete

        int delete​(EntityCondition condition)
            throws 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:
        DatabaseException - in case of a database exception
      • selectValues

        <T> List<T> selectValues​(String propertyId,
                                 EntityCondition condition)
                          throws DatabaseException
        Selects ordered and distinct non-null values of the given property, note that the given property must be of type ColumnProperty.
        Type Parameters:
        T - the value type
        Parameters:
        propertyId - the ID of the property
        condition - the condition
        Returns:
        the values in the given column (Property)
        Throws:
        DatabaseException - in case of a database exception
        IllegalArgumentException - in case the given property is not a column based property
        UnsupportedOperationException - in case the entity is based on a select query
      • select

        List<Entity> select​(EntitySelectCondition condition)
                     throws DatabaseException
        Selects entities according to the specified condition
        Parameters:
        condition - the condition specifying which entities to select
        Returns:
        entities according to the given condition
        Throws:
        DatabaseException - in case of a database exception
      • select

        List<Entity> select​(String entityId,
                            String propertyId,
                            Object... values)
                     throws DatabaseException
        Selects entities according to one property (propertyId), using values as a condition
        Parameters:
        entityId - the entity type
        propertyId - the ID of the condition property
        values - the property values to use as condition
        Returns:
        entities of the type entityId according to propertyId and values
        Throws:
        DatabaseException - in case of a database exception
      • selectRowCount

        int selectRowCount​(EntityCondition condition)
                    throws DatabaseException
        Selects the number of rows returned according to the given condition
        Parameters:
        condition - the search condition
        Returns:
        the number of rows fitting the given condition
        Throws:
        DatabaseException - in case of a database exception
      • writeBlob

        void writeBlob​(Entity.Key primaryKey,
                       String blobPropertyId,
                       byte[] blobData)
                throws DatabaseException
        Writes blobData in the blob field specified by the property identified by propertyId for the given entity
        Parameters:
        primaryKey - the primary key of the entity for which to write the blob field
        blobPropertyId - the ID of the blob property
        blobData - the blob data
        Throws:
        UpdateException - in case multiple rows were affected
        DatabaseException - in case of a database exception
      • readBlob

        byte[] readBlob​(Entity.Key primaryKey,
                        String blobPropertyId)
                 throws DatabaseException
        Reads the blob specified by the property identified by propertyId from the given entity, returns null if no blob data is found.
        Parameters:
        primaryKey - the primary key of the entity
        blobPropertyId - the ID of the blob property
        Returns:
        a byte array containing the blob data or null if no blob data is found
        Throws:
        DatabaseException - in case of a database exception