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<Boolean> Specifies whether the foreign key value graph should be fully populated instead of being limited by the foreign key reference 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: 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.booleanvoidlimitForeignKeyReferenceDepth(boolean limitForeignKeyReferenceDepth) 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
-
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_REFERENCE_DEPTH
Specifies whether the foreign key value graph should be fully populated instead of being limited by the foreign key reference depth setting- 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
-
limitForeignKeyReferenceDepth
boolean limitForeignKeyReferenceDepth()- Returns:
- true if foreign key reference depths are being limited
-
limitForeignKeyReferenceDepth
void limitForeignKeyReferenceDepth(boolean limitForeignKeyReferenceDepth) - Parameters:
limitForeignKeyReferenceDepth- 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
-