@Beta public interface DataConnection
It contains metadata needed to connect, and might or might not maintain
a physical connection or connections, depending on the connector. The connection
might be an instance of Connection
, or of a driver or client to a
3rd party system etc.
Every connection obtained from a DataConnection must be closed. Otherwise, the data link cannot be closed and the connection will leak.
DataConnection is supposed to be used in Jet jobs or SQL mappings where the same connection metadata, or even the same connection is to be reused.
DataConnection is closely related to Jet connectors (sources and sinks) and
to SqlConnector
s. While the DataConnection handles initialization,
maintenance and closing of connections to the external system, the
connections read and write actual data from/into them.
Instances of DataConnections should be obtained by calling
DataConnectionService.getAndRetainDataConnection(java.lang.String, java.lang.Class<T>)
method.
Conceptually, there are 3 types of sharing of the underlying instance between multiple (concurrent) Jet jobs or SQL queries:
When a DataConnection is closed, connections obtained from should continue to be functional, until all connections are returned. Replacing of a DataConnection is handled as remove+create.
Implementations of DataConnection must provide a constructor with a single argument
of type DataConnectionConfig
. The constructor must not throw an exception
under any circumstances. Any resource allocation should be done either asynchronously
or lazily when the underlying instance is requested.
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Called by the member when shutting down.
|
DataConnectionConfig |
getConfig()
Returns the configuration of this DataConnection.
|
String |
getName()
Returns the name of this data connection as specified in the
DataConnectionConfig or the CREATE DATA CONNECTION
command. |
Collection<DataConnectionResource> |
listResources()
Returns list of
DataConnectionResource s accessible via this DataConnection. |
default Map<String,String> |
options()
Returns the properties / options this DataConnection was created with.
|
void |
release()
Release a retained data connection.
|
Collection<String> |
resourceTypes()
Returns the list of possible values for
DataConnectionResource.type() ,
that will be returned when listResources() is called. |
void |
retain()
Prevents the data connection from being closed.
|
@Nonnull String getName()
DataConnectionConfig
or the CREATE DATA CONNECTION
command.@Nonnull Collection<DataConnectionResource> listResources()
DataConnectionResource
s accessible via this DataConnection.
It is not strictly required that the data connection lists all resources; a resource can be used even if it is not listed. For example, the list of resources in Oracle database might not include tables available through a database link. In fact, it might list no resources at all, perhaps if the security in the target system prevents reading of such a list.
The returned list contains up-to-date list of resources. Any changes (added or removed resources) must be reflected in subsequent calls to this method.
@Nonnull Collection<String> resourceTypes()
DataConnectionResource.type()
,
that will be returned when listResources()
is called. Returned values are case-insensitive,
e.g. DataConnectionResource.type()
may return MY_RES
and this method my_res
.@Nonnull DataConnectionConfig getConfig()
@Nonnull default Map<String,String> options()
void retain()
Note that the DataConnection also isn't closed until all shared connections obtained from it are returned. This feature, together with the lock allows the processor to avoid concurrent close while it is using the connection.
IllegalStateException
- fi the data connection is already closedvoid release()
retain()
call, otherwise the data connection will leak.void destroy()
Copyright © 2024 Hazelcast, Inc.. All rights reserved.