Module is.codion.framework.db.core
Package is.codion.framework.db
Interface EntityConnectionProvider
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
HttpEntityConnectionProvider,LocalEntityConnectionProvider,RemoteEntityConnectionProvider
- All Known Implementing Classes:
AbstractEntityConnectionProvider
Provides a managed
EntityConnection instance with automatic reconnection handling.
EntityConnectionProvider serves as the primary entry point for database access in Codion applications. It manages connection lifecycle, handles reconnection for both local and remote connections, and provides a consistent interface regardless of the underlying connection type.
Connection Types
CONNECTION_TYPE_LOCAL- Direct JDBC connectionCONNECTION_TYPE_REMOTE- RMI-based remote connectionCONNECTION_TYPE_HTTP- HTTP-based remote connection
Basic Usage
// Local connection
EntityConnectionProvider provider = LocalEntityConnectionProvider.builder()
.domainType(DOMAIN)
.user(User.parse("scott:tiger"))
.build();
// Remote connection
EntityConnectionProvider provider = RemoteEntityConnectionProvider.builder()
.domainType(DOMAIN)
.hostname("localhost")
.port(2223)
.registryPort(1099)
.user(User.parse("scott:tiger"))
.build();
// Use the connection
try (EntityConnectionProvider connProvider = provider) {
EntityConnection connection = connProvider.connection();
List<Entity> customers = connection.select(all(Customer.TYPE));
}
Configuration-based Creation
// Configure via system properties
System.setProperty("codion.client.connectionType", "remote");
System.setProperty("codion.client.domainType", "chinook:Chinook");
// Create provider based on configuration
EntityConnectionProvider provider = EntityConnectionProvider.builder()
.user(User.parse("scott:tiger"))
.build();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceEntityConnectionProvider.Builder<T extends EntityConnectionProvider,B extends EntityConnectionProvider.Builder<T, B>> BuildsEntityConnectionProviderinstances. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<String> Specifies whether the client should connect locally, via rmi or http, accepted values: local, remote, http Value type: String Default value:CONNECTION_TYPE_LOCALstatic final PropertyValue<DomainType> Specifies the domain type required for a client connection Value type: is.codion.framework.domain.DomainType Default value: nullstatic final StringIndicates a http database connectionstatic final StringIndicates a local database connectionstatic final StringIndicates a remote database connectionstatic final PropertyValue<String> Specifies a connection provider description, overriding the default one which usually provides a hostname or other connection based information. -
Method Summary
Modifier and TypeMethodDescriptionstatic EntityConnectionProvider.Builder<?, ?> builder()Creates a connection provider builder based on system configuration.clientId()voidclose()Closes the underlying connection and performs cleanup if requiredProvides a EntityConnection object, is responsible for returning a healthy EntityConnection object, that is, it must reconnect an invalid connection whether remotely or locallyReturns a String specifying the type of connection provided by this connection providerbooleanentities()Returns the domain entities this connection is based onuser()
-
Field Details
-
CONNECTION_TYPE_LOCAL
Indicates a local database connection- See Also:
-
CONNECTION_TYPE_REMOTE
Indicates a remote database connection- See Also:
-
CONNECTION_TYPE_HTTP
Indicates a http database connection- See Also:
-
CLIENT_DOMAIN_TYPE
Specifies the domain type required for a client connection- Value type: is.codion.framework.domain.DomainType
- Default value: null
-
CLIENT_CONNECTION_TYPE
Specifies whether the client should connect locally, via rmi or http, accepted values: local, remote, http- Value type: String
- Default value:
CONNECTION_TYPE_LOCAL
- See Also:
-
DESCRIPTION
Specifies a connection provider description, overriding the default one which usually provides a hostname or other connection based information.- Value type: String
- Default value: null
- See Also:
-
-
Method Details
-
entities
Entities entities()Returns the domain entities this connection is based on- Returns:
- the underlying domain entities
-
connection
EntityConnection connection()Provides a EntityConnection object, is responsible for returning a healthy EntityConnection object, that is, it must reconnect an invalid connection whether remotely or locally- Returns:
- a EntityConnection instance
-
connectionType
String connectionType()Returns a String specifying the type of connection provided by this connection provider- Returns:
- a String specifying the type of connection, e.g. "local" or "remote"
-
description
- Returns:
- a description of the database provider or an empty Optional in case no description is provided
- See Also:
-
connectionValid
boolean connectionValid()- Returns:
- true if a connection has been establised and the connection is in a valid state
-
connected
Observer<EntityConnection> connected()- Returns:
- an observer notified when a connection is established
-
close
void close()Closes the underlying connection and performs cleanup if required- Specified by:
closein interfaceAutoCloseable- See Also:
-
user
User user()- Returns:
- the user used by this connection provider
-
domainType
DomainType domainType()- Returns:
- the domain type
-
clientId
UUID clientId()- Returns:
- the UUID identifying this client connection
-
clientType
- Returns:
- the String identifying the client type for this connection provider
-
clientVersion
- Returns:
- the client version
-
builder
Creates a connection provider builder based on system configuration.// Configure connection type and domain System.setProperty("codion.client.connectionType", "remote"); System.setProperty("codion.client.domainType", "Chinook"); // Create builder based on configuration EntityConnectionProvider provider = EntityConnectionProvider.builder() .user(User.parse("scott:tiger")) .build();- Returns:
- an unconfigured
EntityConnectionProvider.Builderinstance, based on theCLIENT_CONNECTION_TYPEandCLIENT_DOMAIN_TYPEconfiguration values - Throws:
IllegalStateException- in case the required connection provider builder is not available on the classpath- See Also:
-