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(Conditions.condition(Customer.TYPE));
     }
     
    A factory class for creating LocalEntityConnection instances.
    • Field Detail

      • DEFAULT_CONNECTION_LOG_SIZE

        static final int DEFAULT_CONNECTION_LOG_SIZE
        See Also:
        Constant Field Values
      • 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_ENABLED

        static final PropertyValue<Boolean> OPTIMISTIC_LOCKING_ENABLED
        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 Detail

      • 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, this iterator closes all underlying resources in case of an exception and when it finishes iterating. Calling ResultIterator.close() is required if the iterator has not been exhausted and is always recommended.
        Parameters:
        condition - the query condition
        Returns:
        an iterator for the given query condition
        Throws:
        DatabaseException - in case of an exception
      • isOptimisticLockingEnabled

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

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

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

        void setLimitFetchDepth​(boolean limitFetchDepth)
        Parameters:
        limitFetchDepth - false to override the fetch depth limit provided by condition
        See Also:
        SelectCondition.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
      • domain

        Domain domain()
        Returns:
        the underlying domain model
      • 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