Interface LocalEntityConnection

All Superinterfaces:
AutoCloseable, is.codion.framework.db.EntityConnection

public interface LocalEntityConnection extends is.codion.framework.db.EntityConnection
EntityConnection implementation based on a local JDBC connection.
 Domain domain = new Domain();
 Database database = new H2DatabaseFactory().createDatabase("jdbc:h2:file:/path/to/database");
 User user = User.parse("scott:tiger");

 try (EntityConnection connection = LocalEntityConnection.localEntityConnection(database, domain, user)) {
   List<Entity> customers = connection.select(all(Customer.TYPE));
 }
 
A factory for LocalEntityConnection instances.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface is.codion.framework.db.EntityConnection

    is.codion.framework.db.EntityConnection.Copy, is.codion.framework.db.EntityConnection.Count, is.codion.framework.db.EntityConnection.Insert, is.codion.framework.db.EntityConnection.Select, is.codion.framework.db.EntityConnection.Update
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final is.codion.common.property.PropertyValue<Integer>
    Specifies the size of the (circular) log that is kept in memory for each connection
    Value type: Integer
    Default value: 40
    static final int
     
    static final is.codion.common.property.PropertyValue<Boolean>
    Specifies whether the foreign key value graph should be fully populated instead of being limited by the foreign key fetch depth setting.
    Value type: Boolean
    Default value: true
    static final is.codion.common.property.PropertyValue<Boolean>
    Specifies whether optimistic locking should be performed, that is, if entities should be selected for update and checked for modification before being updated
    Value type: Boolean
    Default value: true
    static final is.codion.common.property.PropertyValue<Integer>
    Specifies the query timeout in seconds
    Value type: Integer
    Default value: 120

    Fields inherited from interface is.codion.framework.db.EntityConnection

    DEFAULT_QUERY_TIMEOUT_SECONDS
  • Method Summary

    Modifier and Type
    Method
    Description
    static is.codion.common.db.database.Database
    configureDatabase(is.codion.common.db.database.Database database, is.codion.framework.domain.Domain domain)
    Runs the database configuration for the given domain on the given database.
    is.codion.common.db.connection.DatabaseConnection
     
    int
     
    boolean
     
    boolean
     
    is.codion.common.db.result.ResultIterator<is.codion.framework.domain.entity.Entity>
    iterator(is.codion.framework.db.EntityConnection.Select select)
    Returns a result set iterator based on the given select.
    is.codion.common.db.result.ResultIterator<is.codion.framework.domain.entity.Entity>
    iterator(is.codion.framework.domain.entity.condition.Condition condition)
    Returns a result set iterator based on the given query condition.
    localEntityConnection(is.codion.common.db.database.Database database, is.codion.framework.domain.Domain domain, is.codion.common.user.User user)
    Constructs a new LocalEntityConnection instance
    localEntityConnection(is.codion.common.db.database.Database database, is.codion.framework.domain.Domain domain, Connection connection)
    Constructs a new LocalEntityConnection instance
    void
    setDefaultQueryTimeout(int queryTimeout)
     
    void
    setLimitForeignKeyFetchDepth(boolean limitForeignKeyFetchDepth)
     
    void
    setOptimisticLocking(boolean optimisticLocking)
     

    Methods inherited from interface is.codion.framework.db.EntityConnection

    close, commitTransaction, connected, count, delete, delete, delete, dependencies, entities, execute, execute, execute, execute, insert, insert, insertSelect, insertSelect, isQueryCacheEnabled, report, rollbackTransaction, select, select, select, select, select, select, select, selectSingle, selectSingle, setQueryCacheEnabled, startTransaction, transactionOpen, update, update, update, updateSelect, updateSelect, user
  • Field Details

    • DEFAULT_CONNECTION_LOG_SIZE

      static final int DEFAULT_CONNECTION_LOG_SIZE
      See Also:
    • CONNECTION_LOG_SIZE

      static final is.codion.common.property.PropertyValue<Integer> CONNECTION_LOG_SIZE
      Specifies the size of the (circular) log that is kept in memory for each connection
      Value type: Integer
      Default value: 40
    • QUERY_TIMEOUT_SECONDS

      static final is.codion.common.property.PropertyValue<Integer> QUERY_TIMEOUT_SECONDS
      Specifies the query timeout in seconds
      Value type: Integer
      Default value: 120
    • OPTIMISTIC_LOCKING

      static final is.codion.common.property.PropertyValue<Boolean> OPTIMISTIC_LOCKING
      Specifies whether optimistic locking should be performed, that is, if entities should be selected for update and checked for modification before being updated
      Value type: Boolean
      Default value: true
    • LIMIT_FOREIGN_KEY_FETCH_DEPTH

      static final is.codion.common.property.PropertyValue<Boolean> LIMIT_FOREIGN_KEY_FETCH_DEPTH
      Specifies whether the foreign key value graph should be fully populated instead of being limited by the foreign key fetch depth setting.
      Value type: Boolean
      Default value: true
  • Method Details

    • databaseConnection

      is.codion.common.db.connection.DatabaseConnection databaseConnection()
      Returns:
      the underlying connection
    • iterator

      is.codion.common.db.result.ResultIterator<is.codion.framework.domain.entity.Entity> iterator(is.codion.framework.domain.entity.condition.Condition condition) throws is.codion.common.db.exception.DatabaseException
      Returns a result set iterator based on the given query condition. Remember to use try with resources or to call ResultIterator.close() in order to close underlying resources.
      Parameters:
      condition - the query condition
      Returns:
      an iterator for the given query condition
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of an exception
    • iterator

      is.codion.common.db.result.ResultIterator<is.codion.framework.domain.entity.Entity> iterator(is.codion.framework.db.EntityConnection.Select select) throws is.codion.common.db.exception.DatabaseException
      Returns a result set iterator based on the given select. Remember to use try with resources or to call ResultIterator.close() in order to close underlying resources.
      Parameters:
      select - the query select
      Returns:
      an iterator for the given query select
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of an exception
    • isOptimisticLocking

      boolean isOptimisticLocking()
      Returns:
      true if optimistic locking is enabled
    • setOptimisticLocking

      void setOptimisticLocking(boolean optimisticLocking)
      Parameters:
      optimisticLocking - true if optimistic locking should be enabled
    • isLimitForeignKeyFetchDepth

      boolean isLimitForeignKeyFetchDepth()
      Returns:
      true if foreign key fetch depths are being limited
    • setLimitForeignKeyFetchDepth

      void setLimitForeignKeyFetchDepth(boolean limitForeignKeyFetchDepth)
      Parameters:
      limitForeignKeyFetchDepth - false to override the fetch depth limit specified by conditions or entities
      See Also:
      • EntityConnection.Select.Builder.fetchDepth(int)
    • getDefaultQueryTimeout

      int getDefaultQueryTimeout()
      Returns:
      the default query timeout being used
    • setDefaultQueryTimeout

      void setDefaultQueryTimeout(int queryTimeout)
      Parameters:
      queryTimeout - the query timeout in seconds
    • localEntityConnection

      static LocalEntityConnection localEntityConnection(is.codion.common.db.database.Database database, is.codion.framework.domain.Domain domain, is.codion.common.user.User user) throws is.codion.common.db.exception.DatabaseException
      Constructs a new LocalEntityConnection instance
      Parameters:
      database - the Database instance
      domain - the domain model
      user - the user used for connecting to the database
      Returns:
      a new LocalEntityConnection instance
      Throws:
      is.codion.common.db.exception.DatabaseException - in case there is a problem connecting to the database
      is.codion.common.db.exception.AuthenticationException - in case of an authentication error
    • localEntityConnection

      static LocalEntityConnection localEntityConnection(is.codion.common.db.database.Database database, is.codion.framework.domain.Domain domain, Connection connection) throws is.codion.common.db.exception.DatabaseException
      Constructs a new LocalEntityConnection instance
      Parameters:
      database - the Database instance
      domain - the domain model
      connection - the connection object to base the entity connection on, it is assumed to be in a valid state
      Returns:
      a new LocalEntityConnection instance, wrapping the given connection
      Throws:
      is.codion.common.db.exception.DatabaseException - in case there is a problem with the supplied connection
    • configureDatabase

      static is.codion.common.db.database.Database configureDatabase(is.codion.common.db.database.Database database, is.codion.framework.domain.Domain domain) throws is.codion.common.db.exception.DatabaseException
      Runs the database configuration for the given domain on the given database. Prevents multiple runs for the same domain/database combination.
      Parameters:
      database - the database to configure
      domain - the domain doing the configuring
      Returns:
      the Database instance
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of an exception