Interface LocalEntityConnection

All Superinterfaces:
AutoCloseable, EntityConnection

public interface LocalEntityConnection extends 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.
  • Field Details

    • DEFAULT_CONNECTION_LOG_SIZE

      static final int DEFAULT_CONNECTION_LOG_SIZE
      See Also:
    • CONNECTION_LOG_SIZE

      static final 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 PropertyValue<Integer> QUERY_TIMEOUT_SECONDS
      Specifies the query timeout in seconds
      Value type: Integer
      Default value: 120
    • OPTIMISTIC_LOCKING

      static final 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 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

      DatabaseConnection databaseConnection()
      Returns:
      the underlying connection
    • iterator

      ResultIterator<Entity> iterator(Condition condition) throws 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:
      DatabaseException - in case of an exception
    • iterator

      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:
      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:
    • 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(Database database, Domain domain, User user) throws 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:
      DatabaseException - in case there is a problem connecting to the database
      AuthenticationException - in case of an authentication error
    • localEntityConnection

      static LocalEntityConnection localEntityConnection(Database database, Domain domain, Connection connection) throws 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:
      DatabaseException - in case there is a problem with the supplied connection
    • configureDatabase

      static Database configureDatabase(Database database, Domain domain) throws 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:
      DatabaseException - in case of an exception