Module is.codion.framework.db.local
Package is.codion.framework.db.local
Interface LocalEntityConnection
- All Superinterfaces:
AutoCloseable
,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(Condition.all(Customer.TYPE));
}
A factory for LocalEntityConnection instances.-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.framework.db.EntityConnection
EntityConnection.BatchCopy, EntityConnection.BatchInsert, EntityConnection.Count, EntityConnection.Select, EntityConnection.Transactional, EntityConnection.TransactionalResult<T>, EntityConnection.Update
-
Field Summary
Modifier and TypeFieldDescriptionstatic final PropertyValue<Integer>
Specifies the size of the (circular) log that is kept in memory for each connection Value type: Integer Default value: 40static final int
The default number of log entries to keep.static final PropertyValue<Boolean>
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 final PropertyValue<Boolean>
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 final PropertyValue<Integer>
Specifies the query timeout in seconds Value type: Integer Default value: 120Fields inherited from interface is.codion.framework.db.EntityConnection
DEFAULT_QUERY_TIMEOUT_SECONDS
-
Method Summary
Modifier and TypeMethodDescriptionstatic Database
configureDatabase
(Database database, Domain domain) Runs the database configuration for the given domain on the given database.int
boolean
boolean
iterator
(EntityConnection.Select select) Returns a result set iterator based on the given select.Returns a result set iterator based on the given query condition.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
setLimitForeignKeyFetchDepth
(boolean limitForeignKeyFetchDepth) void
setOptimisticLocking
(boolean optimisticLocking) Methods inherited from interface is.codion.framework.db.EntityConnection
close, commitTransaction, connected, count, delete, delete, delete, dependencies, entities, execute, execute, execute, execute, insert, insert, insertSelect, insertSelect, isQueryCacheEnabled, report, rollbackTransaction, select, select, select, select, select, select, select, selectSingle, selectSingle, setQueryCacheEnabled, startTransaction, transactionOpen, update, update, update, updateSelect, updateSelect, user
-
Field Details
-
DEFAULT_CONNECTION_LOG_SIZE
static final int DEFAULT_CONNECTION_LOG_SIZEThe default number of log entries to keep.- See Also:
-
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
Specifies the query timeout in seconds- Value type: Integer
- Default value: 120
-
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
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
Returns a result set iterator based on the given query condition. Remember to use try with resources or to callResultIterator.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 callResultIterator.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 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
-
configureDatabase
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 configuredomain
- the domain doing the configuring- Returns:
- the Database instance
- Throws:
DatabaseException
- in case of an exception
-