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 = Users.parseUser("scott:tiger");
    
     EntityConnection connection = LocalEntityConnections.localEntityConnection(domain, database, user);
    
     List<Entity> entities = connection.select(Conditions.condition(Domain.ENTITY_TYPE));
    
     connection.close();
     
    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
      • USE_OPTIMISTIC_LOCKING

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

      • setMethodLogger

        EntityConnection setMethodLogger​(MethodLogger methodLogger)
        Parameters:
        methodLogger - the MethodLogger to use
        Returns:
        this LocalEntityConnection instance
      • getMethodLogger

        MethodLogger getMethodLogger()
        Returns:
        the MethodLogger being used
      • getDatabaseConnection

        DatabaseConnection getDatabaseConnection()
        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

        LocalEntityConnection setOptimisticLockingEnabled​(boolean optimisticLocking)
        Parameters:
        optimisticLocking - true if optimistic locking should be enabled
        Returns:
        this LocalEntityConnection instance
      • isLimitForeignKeyFetchDepth

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

        LocalEntityConnection setLimitFetchDepth​(boolean limitFetchDepth)
        Parameters:
        limitFetchDepth - false to override the fetch depth limit provided by condition
        Returns:
        this LocalEntityConnection instance
        See Also:
        SelectCondition.fetchDepth(int)
      • getDomain

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

        static LocalEntityConnection localEntityConnection​(Domain domain,
                                                           Database database,
                                                           User user)
                                                    throws DatabaseException
        Constructs a new LocalEntityConnection instance
        Parameters:
        domain - the domain model
        database - the Database instance
        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​(Domain domain,
                                                           Database database,
                                                           Connection connection)
                                                    throws DatabaseException
        Constructs a new LocalEntityConnection instance
        Parameters:
        domain - the domain model
        database - the Database instance
        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:
        IllegalArgumentException - in case the given connection is invalid or disconnected
        DatabaseException - in case a validation statement is required but could not be created
        See Also:
        Database.supportsIsValid()