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.
A factory for LocalEntityConnection instances.
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));
}
-
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
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<Integer> Specifies the buffer size to use when iterating over entities.static final PropertyValue<Boolean> Specifies whether the foreign key value graph depth should be limited by the foreign key reference depth setting instead of being fully populated.static 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: 120static final PropertyValue<Integer> Specifies the number of log traces to keep while tracing is enabled.Fields inherited from interface is.codion.framework.db.EntityConnection
MAXIMUM_BATCH_SIZE -
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseconfigureDatabase(Database database, Domain domain) Runs the database configuration for the given domain on the given database.database()Returns the underlying connection object.intReturns the buffer size used when iterating over entities with foreign keys to populate.voiditeratorBufferSize(int iteratorBufferSize) Sets the buffer size to use when iterating over entities with foreign keys to populate.booleanvoidlimitReferenceDepth(boolean limitReferenceDepth) static LocalEntityConnectionlocalEntityConnection(Database database, Domain domain, User user) Constructs a newLocalEntityConnectioninstancestatic LocalEntityConnectionlocalEntityConnection(Database database, Domain domain, Connection connection) Constructs a newLocalEntityConnectioninstance.booleanvoidoptimisticLocking(boolean optimisticLocking) intvoidqueryTimeout(int queryTimeout) voidsetConnection(@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.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, iterator, iterator, queryCache, queryCache, report, rollbackTransaction, select, select, select, select, select, select, select, selectSingle, selectSingle, startTransaction, transactionOpen, update, update, update, updateSelect, updateSelect, user
-
Field Details
-
TRACES
Specifies the number of log traces to keep while tracing is enabled.- Value type: Integer
- Default value: 50
-
QUERY_TIMEOUT
Specifies the query timeout in seconds- Value type: Integer
- Default value: 120
-
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
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
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
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 aDatabaseExceptionuntil a non-null connection is set.- Parameters:
connection- the connection
-
getConnection
@Nullable Connection getConnection()Returns the underlying connection object. UseEntityConnection.connected()to verify that the connection is available and valid.- Returns:
- the underlying connection object
-
localEntityConnection
Constructs a newLocalEntityConnectioninstance- Parameters:
database- the Database instancedomain- the domain modeluser- the user used for connecting to the database- Returns:
- a new
LocalEntityConnectioninstance - 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) Constructs a newLocalEntityConnectioninstance. Note that auto-commit is disabled on the given connection.- 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
LocalEntityConnectioninstance, 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
-