Module is.codion.framework.db.local
Package is.codion.framework.db.local
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface is.codion.framework.db.EntityConnection
EntityConnection.CopyEntities, EntityConnection.InsertEntities
-
-
Field Summary
Fields Modifier and Type Field Description static 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: 40static int
DEFAULT_CONNECTION_LOG_SIZE
static 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: truestatic 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: truestatic PropertyValue<Integer>
QUERY_TIMEOUT_SECONDS
Specifies the query timeout in seconds
Value type: Integer
Default value: 120
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description DatabaseConnection
databaseConnection()
Domain
domain()
int
getDefaultQueryTimeout()
boolean
isLimitForeignKeyFetchDepth()
boolean
isOptimisticLockingEnabled()
ResultIterator<Entity>
iterator(Condition condition)
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.static LocalEntityConnection
localEntityConnection(Database database, Domain domain, User user)
Constructs a new LocalEntityConnection instancestatic LocalEntityConnection
localEntityConnection(Database database, Domain domain, Connection connection)
Constructs a new LocalEntityConnection instancevoid
setDefaultQueryTimeout(int queryTimeout)
void
setLimitFetchDepth(boolean limitFetchDepth)
void
setOptimisticLockingEnabled(boolean optimisticLocking)
-
Methods inherited from interface is.codion.framework.db.EntityConnection
beginTransaction, close, commitTransaction, delete, delete, delete, entities, executeFunction, executeFunction, executeProcedure, executeProcedure, fillReport, insert, insert, isConnected, isQueryCacheEnabled, isTransactionOpen, readBlob, rollbackTransaction, rowCount, select, select, select, select, select, select, select, selectDependencies, selectSingle, selectSingle, setQueryCacheEnabled, update, update, update, user, writeBlob
-
-
-
-
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. CallingResultIterator.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 instancedomain
- the domain modeluser
- the user used for connecting to the database- Returns:
- a new LocalEntityConnection instance
- Throws:
DatabaseException
- in case there is a problem connecting to the databaseAuthenticationException
- 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 instancedomain
- the domain modelconnection
- 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
-
-