com.holonplatform.datastore.jdbc.internal

## Class DefaultJdbcDatastore

- java.lang.Object
- - com.holonplatform.core.internal.datastore.AbstractDatastore<X>
  - - com.holonplatform.core.internal.datastore.AbstractInitializableDatastore<JdbcDatastoreCommodityContext>
    - - com.holonplatform.datastore.jdbc.internal.DefaultJdbcDatastore

- All Implemented Interfaces:
    com.holonplatform.core.datastore.ConfigurableDatastore, com.holonplatform.core.datastore.DataContextBound, com.holonplatform.core.datastore.Datastore, com.holonplatform.core.datastore.DatastoreCommodityContext, com.holonplatform.core.datastore.DatastoreCommodityHandler, com.holonplatform.core.datastore.DatastoreCommodityRegistrar<JdbcDatastoreCommodityContext>, com.holonplatform.core.datastore.DatastoreExpressionResolverRegistrar, com.holonplatform.core.datastore.DatastoreOperations<com.holonplatform.core.datastore.Datastore.OperationResult,com.holonplatform.core.property.PropertyBox,com.holonplatform.core.datastore.bulk.BulkInsert,com.holonplatform.core.datastore.bulk.BulkUpdate,com.holonplatform.core.datastore.bulk.BulkDelete,com.holonplatform.core.query.Query>, com.holonplatform.core.datastore.transaction.Transactional, com.holonplatform.core.ExpressionResolver.ExpressionResolverHandler, com.holonplatform.core.ExpressionResolver.ExpressionResolverProvider, com.holonplatform.core.ExpressionResolver.ExpressionResolverSupport, ConnectionHandler, SQLContext, JdbcDatastoreCommodityContext, JdbcOperationContext, JdbcDatastore, Serializable

      public class DefaultJdbcDatastore
      extends com.holonplatform.core.internal.datastore.AbstractInitializableDatastore<JdbcDatastoreCommodityContext>
      implements JdbcDatastore, JdbcDatastoreCommodityContext

  Default `JdbcDatastore` implementation.

  The Datastore instance must be initialized using the `AbstractInitializableDatastore.initialize()` method before using it.

  Since:
    5.0.0
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    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.

    - ### Nested classes/interfaces inherited from interface com.holonplatform.datastore.jdbc.JdbcDatastore

      `JdbcDatastore.Builder<D extends JdbcDatastore>`

    - ### Nested classes/interfaces inherited from interface com.holonplatform.core.datastore.Datastore

      `com.holonplatform.core.datastore.Datastore.OperationResult, com.holonplatform.core.datastore.Datastore.OperationType`

    - ### Nested classes/interfaces inherited from interface com.holonplatform.core.datastore.DatastoreOperations

      `com.holonplatform.core.datastore.DatastoreOperations.WriteOption`

    - ### Nested classes/interfaces inherited from interface com.holonplatform.core.datastore.DatastoreCommodityContext

      `com.holonplatform.core.datastore.DatastoreCommodityContext.CommodityConfigurationException, com.holonplatform.core.datastore.DatastoreCommodityContext.CommodityNotAvailableException`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultJdbcDatastore()` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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)`

    - ### Methods inherited from class com.holonplatform.core.internal.datastore.AbstractInitializableDatastore

      `getInitializationClassLoader, initialize, isInitialized, setInitializationClassLoader`

    - ### Methods inherited from class com.holonplatform.core.internal.datastore.AbstractDatastore

      `addExpressionResolver, create, getAvailableCommodities, getCommodityFactoryType, getDataContextId, getExpressionResolvers, getExpressionResolverType, isTraceEnabled, registerCommodity, removeExpressionResolver, resolve, setDataContextId, setTraceEnabled, toString`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface com.holonplatform.datastore.jdbc.JdbcDatastore

      `builder`

    - ### Methods inherited from interface com.holonplatform.core.datastore.Datastore

      `bulkDelete, bulkInsert, bulkUpdate, delete, insert, isTransactional, query, query, refresh, requireTransactional, save, update`

    - ### Methods inherited from interface com.holonplatform.core.datastore.DatastoreCommodityHandler

      `create, getAvailableCommodities, hasCommodity`

    - ### Methods inherited from interface com.holonplatform.core.ExpressionResolver.ExpressionResolverSupport

      `addExpressionResolver, addExpressionResolvers, removeExpressionResolver`

    - ### Methods inherited from interface com.holonplatform.core.datastore.DataContextBound

      `getDataContextId`

    - ### Methods inherited from interface com.holonplatform.core.datastore.transaction.Transactional

      `withTransaction, withTransaction, withTransaction`

    - ### Methods inherited from interface com.holonplatform.core.datastore.DatastoreCommodityRegistrar

      `getCommodityFactoryType, registerCommodity`

    - ### Methods inherited from interface com.holonplatform.datastore.jdbc.context.JdbcOperationContext

      `getStatementConfigurator`

    - ### Methods inherited from interface com.holonplatform.datastore.jdbc.composer.SQLContext

      `getTypeConverter, getValueDeserializer, getValueSerializer`

    - ### Methods inherited from interface com.holonplatform.core.ExpressionResolver.ExpressionResolverProvider

      `getExpressionResolvers`

    - ### Methods inherited from interface com.holonplatform.datastore.jdbc.composer.ConnectionHandler

      `withConnection`

- - ### Constructor Detail

    - #### DefaultJdbcDatastore

          public DefaultJdbcDatastore()

      Constructor.

  - ### Method Detail

    - #### setTransactionFactory

          public void setTransactionFactory(JdbcTransactionFactory transactionFactory)

      Set the `JdbcTransactionFactory` to use to create a new JDBC transaction.
      Parameters:
        `transactionFactory` - the transaction factory to set (not null)

    - #### getConfiguration

          public Optional<com.holonplatform.jdbc.DataSourceConfigProperties> getConfiguration()

      Get the data source configuration properties.
      Returns:
        Optional data source configuration properties

    - #### setConfiguration

          public void setConfiguration(com.holonplatform.jdbc.DataSourceConfigProperties configuration,
                                       boolean buildDataSource)

      Set the data source configuration properties.
      Parameters:
        `configuration` - the data source configuration properties to set (not null)
        `buildDataSource` - Whether to build and set a `DataSource` using given configuration properties.

    - #### setDataSource

          public void setDataSource(DataSource dataSource)

      Set the `DataSource` to be used by this datastore to perform database operations.
      Parameters:
        `dataSource` - the `DataSource` to set (not null)

    - #### getDataSource

          public DataSource getDataSource()

      Description copied from interface: `JdbcDatastoreCommodityContext`
      Get the `DataSource` bound to the datastore.
      Specified by:
        `getDataSource` in interface `JdbcDatastoreCommodityContext`
      Returns:
        Datastore DataSource

    - #### setConnectionHandler

          public void setConnectionHandler(com.holonplatform.jdbc.JdbcConnectionHandler connectionHandler)

      Set the `JdbcConnectionHandler` to be used for Datastore JDBC connections handling.
      Parameters:
        `connectionHandler` - The connection handler to set (not null)

    - #### getDatabase

          public Optional<com.holonplatform.jdbc.DatabasePlatform> getDatabase()

      Description copied from interface: `JdbcDatastoreCommodityContext`
      Get the database type to which `DataSource` is connected.
      Specified by:
        `getDatabase` in interface `JdbcDatastoreCommodityContext`
      Returns:
        The `DatabasePlatform` of the `DataSource` database, empty if not available

    - #### setDatabase

          public void setDatabase(com.holonplatform.jdbc.DatabasePlatform database)

      Set the database platform
      Parameters:
        `database` - the database platform to set

    - #### getDialect

          public SQLDialect getDialect()

      Description copied from interface: `SQLContext`
      Get the `SQLDialect` to use.
      Specified by:
        `getDialect` in interface `SQLContext`
      Returns:
        The SQL dialect

    - #### setDialect

          public void setDialect(SQLDialect dialect)

      Set the SQL dialect
      Parameters:
        `dialect` - the dialect to set

    - #### getIdentifierResolutionStrategy

          public IdentifierResolutionStrategy getIdentifierResolutionStrategy()

      Description copied from interface: `JdbcOperationContext`
      Get the `IdentifierResolutionStrategy`.
      Specified by:
        `getIdentifierResolutionStrategy` in interface `JdbcOperationContext`
      Returns:
        the identifier resolution strategy

    - #### setIdentifierResolutionStrategy

          public void setIdentifierResolutionStrategy(IdentifierResolutionStrategy identifierResolutionStrategy)

      Set the `IdentifierResolutionStrategy`.
      Parameters:
        `identifierResolutionStrategy` - the identifier resolution strategy to set (not null)

    - #### withSharedConnection

          public <R> R withSharedConnection(Supplier<R> operations)

      Description copied from interface: `JdbcOperationContext`
      Execute given operations using a shared connection.
      Specified by:
        `withSharedConnection` in interface `JdbcOperationContext`
      Type Parameters:
        `R` - Operation result type
      Parameters:
        `operations` - Operations to execute (not null)
      Returns:
        Operation result

    - #### withConnection

          public <R> R withConnection(ConnectionOperation<R> operation)

      Description copied from interface: `ConnectionHandler`
      Execute given `ConnectionOperation` using a managed connection.
      Specified by:
        `withConnection` in interface `ConnectionHandler`
      Type Parameters:
        `R` - Operation result type
      Parameters:
        `operation` - Operation to execute (not null)
      Returns:
        Operation result

    - #### withTransaction

          public <R> R withTransaction(com.holonplatform.core.datastore.transaction.TransactionalOperation<R> operation,
                                       com.holonplatform.core.datastore.transaction.TransactionConfiguration transactionConfiguration)

      Specified by:
        `withTransaction` in interface `com.holonplatform.core.datastore.transaction.Transactional`

    - #### prepareStatement

          public PreparedStatement prepareStatement(SQLStatement statement,
                                                    Connection connection)

      Description copied from interface: `JdbcOperationContext`
      Create and configure a `PreparedStatement` using given `SQLStatement` and connection.
      Specified by:
        `prepareStatement` in interface `JdbcOperationContext`
      Parameters:
        `statement` - SQL statement (not null)
        `connection` - Connection (not null)
      Returns:
        The JDBC `PreparedStatement`

    - #### prepareInsertStatement

          public PreparedStatement prepareInsertStatement(SQLStatement statement,
                                                          Connection connection,
                                                          SQLPrimaryKey primaryKey)

      Description copied from interface: `JdbcOperationContext`
      Create and configure a `PreparedStatement` for an `INSERT` type operation, using given `SQLStatement` and connection.
      Specified by:
        `prepareInsertStatement` in interface `JdbcOperationContext`
      Parameters:
        `statement` - SQL statement (not null)
        `connection` - Connection (not null)
        `primaryKey` - Optional primary key to use to retrieve any auto-generated key
      Returns:
        The JDBC `PreparedStatement`

    - #### trace

          public void trace(String sql)

      Description copied from interface: `SQLContext`
      Trace given SQL statement.

      If tracing is enabled, the SQL statement is logged using the `INFO` level, otherwise it is logged using the `DEBUG` level.

      Specified by:
        `trace` in interface `SQLContext`
      Parameters:
        `sql` - SQL to trace

Copyright © 2019 The Holon Platform. All rights reserved.