public class DefaultJdbcDatastore extends com.holonplatform.core.internal.datastore.AbstractInitializableDatastore<JdbcDatastoreCommodityContext> implements JdbcDatastore, JdbcDatastoreCommodityContext
JdbcDatastore
implementation.
The Datastore instance must be initialized using the AbstractInitializableDatastore.initialize()
method before using it.
Modifier and Type | Class and Description |
---|---|
static class |
DefaultJdbcDatastore.AbstractBuilder<D extends JdbcDatastore,I extends DefaultJdbcDatastore>
Base
JdbcDatastore builder. |
static class |
DefaultJdbcDatastore.DefaultBuilder
Default
JdbcDatastore builder. |
JdbcDatastore.Builder<D extends JdbcDatastore>
com.holonplatform.core.datastore.Datastore.OperationResult, com.holonplatform.core.datastore.Datastore.OperationType
Constructor and Description |
---|
DefaultJdbcDatastore()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Optional<com.holonplatform.jdbc.DataSourceConfigProperties> |
getConfiguration()
Get the data source configuration properties.
|
Optional<com.holonplatform.jdbc.DatabasePlatform> |
getDatabase()
Get the database type to which
DataSource is connected. |
DataSource |
getDataSource()
Get the
DataSource bound to the datastore. |
SQLDialect |
getDialect()
Get the
SQLDialect to use. |
IdentifierResolutionStrategy |
getIdentifierResolutionStrategy()
Get the
IdentifierResolutionStrategy . |
PreparedStatement |
prepareInsertStatement(SQLStatement statement,
Connection connection,
SQLPrimaryKey primaryKey)
Create and configure a
PreparedStatement for an INSERT type operation, using given
SQLStatement and connection. |
PreparedStatement |
prepareStatement(SQLStatement statement,
Connection connection)
Create and configure a
PreparedStatement using given SQLStatement and connection. |
void |
setConfiguration(com.holonplatform.jdbc.DataSourceConfigProperties configuration,
boolean buildDataSource)
Set the data source configuration properties.
|
void |
setConnectionHandler(com.holonplatform.jdbc.JdbcConnectionHandler connectionHandler)
Set the
JdbcConnectionHandler to be used for Datastore JDBC connections handling. |
void |
setDatabase(com.holonplatform.jdbc.DatabasePlatform database)
Set the database platform
|
void |
setDataSource(DataSource dataSource)
Set the
DataSource to be used by this datastore to perform database operations. |
void |
setDialect(SQLDialect dialect)
Set the SQL dialect
|
void |
setIdentifierResolutionStrategy(IdentifierResolutionStrategy identifierResolutionStrategy)
Set the
IdentifierResolutionStrategy . |
void |
setTransactionFactory(JdbcTransactionFactory transactionFactory)
Set the
JdbcTransactionFactory to use to create a new JDBC transaction. |
void |
trace(String sql)
Trace given SQL statement.
|
<R> R |
withConnection(ConnectionOperation<R> operation)
Execute given
ConnectionOperation using a managed connection. |
<R> R |
withSharedConnection(Supplier<R> operations)
Execute given operations using a shared connection.
|
<R> R |
withTransaction(com.holonplatform.core.datastore.transaction.TransactionalOperation<R> operation,
com.holonplatform.core.datastore.transaction.TransactionConfiguration transactionConfiguration) |
getInitializationClassLoader, initialize, isInitialized, setInitializationClassLoader
addExpressionResolver, create, getAvailableCommodities, getCommodityFactoryType, getDataContextId, getExpressionResolvers, getExpressionResolverType, isTraceEnabled, registerCommodity, removeExpressionResolver, resolve, setDataContextId, setTraceEnabled, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
builder
bulkDelete, bulkInsert, bulkUpdate, delete, insert, isTransactional, query, query, refresh, requireTransactional, save, update
create, getAvailableCommodities, hasCommodity
addExpressionResolver, addExpressionResolvers, removeExpressionResolver
withTransaction, withTransaction, withTransaction
getCommodityFactoryType, registerCommodity
getStatementConfigurator
getTypeConverter, getValueDeserializer, getValueSerializer
getExpressionResolvers
withConnection
public void setTransactionFactory(JdbcTransactionFactory transactionFactory)
JdbcTransactionFactory
to use to create a new JDBC transaction.transactionFactory
- the transaction factory to set (not null)public Optional<com.holonplatform.jdbc.DataSourceConfigProperties> getConfiguration()
public void setConfiguration(com.holonplatform.jdbc.DataSourceConfigProperties configuration, boolean buildDataSource)
configuration
- the data source configuration properties to set (not null)buildDataSource
- Whether to build and set a DataSource
using given configuration properties.public void setDataSource(DataSource dataSource)
DataSource
to be used by this datastore to perform database operations.dataSource
- the DataSource
to set (not null)public DataSource getDataSource()
JdbcDatastoreCommodityContext
DataSource
bound to the datastore.getDataSource
in interface JdbcDatastoreCommodityContext
public void setConnectionHandler(com.holonplatform.jdbc.JdbcConnectionHandler connectionHandler)
JdbcConnectionHandler
to be used for Datastore JDBC connections handling.connectionHandler
- The connection handler to set (not null)public Optional<com.holonplatform.jdbc.DatabasePlatform> getDatabase()
JdbcDatastoreCommodityContext
DataSource
is connected.getDatabase
in interface JdbcDatastoreCommodityContext
DatabasePlatform
of the DataSource
database, empty if not availablepublic void setDatabase(com.holonplatform.jdbc.DatabasePlatform database)
database
- the database platform to setpublic SQLDialect getDialect()
SQLContext
SQLDialect
to use.getDialect
in interface SQLContext
public void setDialect(SQLDialect dialect)
dialect
- the dialect to setpublic IdentifierResolutionStrategy getIdentifierResolutionStrategy()
JdbcOperationContext
IdentifierResolutionStrategy
.getIdentifierResolutionStrategy
in interface JdbcOperationContext
public void setIdentifierResolutionStrategy(IdentifierResolutionStrategy identifierResolutionStrategy)
IdentifierResolutionStrategy
.identifierResolutionStrategy
- the identifier resolution strategy to set (not null)public <R> R withSharedConnection(Supplier<R> operations)
JdbcOperationContext
withSharedConnection
in interface JdbcOperationContext
R
- Operation result typeoperations
- Operations to execute (not null)public <R> R withConnection(ConnectionOperation<R> operation)
ConnectionHandler
ConnectionOperation
using a managed connection.withConnection
in interface ConnectionHandler
R
- Operation result typeoperation
- Operation to execute (not null)public <R> R withTransaction(com.holonplatform.core.datastore.transaction.TransactionalOperation<R> operation, com.holonplatform.core.datastore.transaction.TransactionConfiguration transactionConfiguration)
withTransaction
in interface com.holonplatform.core.datastore.transaction.Transactional
public PreparedStatement prepareStatement(SQLStatement statement, Connection connection)
JdbcOperationContext
PreparedStatement
using given SQLStatement
and connection.prepareStatement
in interface JdbcOperationContext
statement
- SQL statement (not null)connection
- Connection (not null)PreparedStatement
public PreparedStatement prepareInsertStatement(SQLStatement statement, Connection connection, SQLPrimaryKey primaryKey)
JdbcOperationContext
PreparedStatement
for an INSERT
type operation, using given
SQLStatement
and connection.prepareInsertStatement
in interface JdbcOperationContext
statement
- SQL statement (not null)connection
- Connection (not null)primaryKey
- Optional primary key to use to retrieve any auto-generated keyPreparedStatement
public void trace(String sql)
SQLContext
If tracing is enabled, the SQL statement is logged using the INFO
level, otherwise it is logged
using the DEBUG
level.
trace
in interface SQLContext
sql
- SQL to traceCopyright © 2019 The Holon Platform. All rights reserved.