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(database, domain, user)) {
   List<Entity> customers = connection.select(Condition.all(Customer.TYPE));
 }
A factory for LocalEntityConnection instances.
  • Field Details

    • TRACES

      static final PropertyValue<Integer> TRACES
      Specifies the number of log traces to keep while tracing is enabled.
      • Value type: Integer
      • Default value: 50
    • QUERY_TIMEOUT

      static final PropertyValue<Integer> QUERY_TIMEOUT
      Specifies the query timeout in seconds
      • Value type: Integer
      • Default value: 120
    • ITERATOR_BUFFER_SIZE

      static final PropertyValue<Integer> ITERATOR_BUFFER_SIZE
      Specifies the buffer size to use when iterating over entities.

      When iterating, entities are fetched in batches of this size to allow for efficient population of foreign key references. Each batch has its foreign keys populated before the entities are returned via Iterator.next().

      Note that buffering is only performed when there are foreign keys to populate. If the select does not include any foreign keys (or all have reference depth 0), the iterator returns entities directly without buffering, minimizing memory overhead.

      See Also:
    • 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_REFERENCE_DEPTH

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

    • connection

      Connection connection()
      Returns:
      the underlying connection
      Throws:
      DatabaseException - in case this connection is closed
    • database

      Database database()
      Returns:
      the underlying database
    • optimisticLocking

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

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

      int iteratorBufferSize()
      Returns the buffer size used when iterating over entities with foreign keys to populate.
      Returns:
      the iterator buffer size
      See Also:
    • iteratorBufferSize

      void iteratorBufferSize(int iteratorBufferSize)
      Sets the buffer size to use when iterating over entities with foreign keys to populate.
      Parameters:
      iteratorBufferSize - the buffer size
      See Also:
    • limitReferenceDepth

      boolean limitReferenceDepth()
      Returns:
      true if foreign key reference depths are being limited
    • limitReferenceDepth

      void limitReferenceDepth(boolean limitReferenceDepth)
      Parameters:
      limitReferenceDepth - false to override the reference depth limit specified by conditions or entities
      See Also:
    • queryTimeout

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

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

      void setConnection(@Nullable Connection connection)
      Sets the internal connection to use, note that no validation or transaction checking is performed on the connection and auto-commit is assumed to be disabled. The connection is simply used 'as is'. Note that setting the connection to null causes all methods requiring it to throw a DatabaseException until a non-null connection is set.
      Parameters:
      connection - the connection
    • getConnection

      @Nullable Connection getConnection()
      Returns the underlying connection object. Use EntityConnection.connected() to verify that the connection is available and valid.
      Returns:
      the underlying connection object
    • localEntityConnection

      static LocalEntityConnection localEntityConnection(Database database, Domain domain, User user)
      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)
      Constructs a new LocalEntityConnection instance. Note that auto-commit is disabled on the given connection.
      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)
      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