com.holonplatform.datastore.jpa.internal

## Class DefaultJpaDatastore

- java.lang.Object
- - com.holonplatform.core.internal.datastore.AbstractDatastore<X>
  - - com.holonplatform.core.internal.datastore.AbstractInitializableDatastore<JpaDatastoreCommodityContext>
    - - com.holonplatform.datastore.jpa.internal.DefaultJpaDatastore

- 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<JpaDatastoreCommodityContext>, 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, JpaDatastoreCommodityContext, EntityManagerHandler, JpaContext, JpaOperationContext, JpaDatastore, Serializable

      public class DefaultJpaDatastore
      extends com.holonplatform.core.internal.datastore.AbstractInitializableDatastore<JpaDatastoreCommodityContext>
      implements JpaDatastore, JpaDatastoreCommodityContext

  Default `JpaDatastore` 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` | `DefaultJpaDatastore.AbstractBuilder<D extends JpaDatastore,I extends DefaultJpaDatastore>` Default `JpaDatastore.Builder`.
    `static class` | `DefaultJpaDatastore.DefaultBuilder` Default `JpaDatastore.Builder`.

    - ### Nested classes/interfaces inherited from interface com.holonplatform.datastore.jpa.JpaDatastore

      `JpaDatastore.Builder<D extends JpaDatastore>, JpaDatastore.EntityManagerFinalizer, JpaDatastore.EntityManagerInitializer, JpaDatastore.EntityManagerLifecycleHandler`

    - ### 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`

  - ### Field Summary

    - ### Fields inherited from interface com.holonplatform.datastore.jpa.JpaDatastore

      `QUERY_PARAMETER_FLUSH_MODE, QUERY_PARAMETER_LOCK_MODE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultJpaDatastore()` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `com.holonplatform.core.beans.BeanIntrospector` | `getBeanIntrospector()` Get the `BeanIntrospector` to use to introspect entity beans.
    `ORMDialect` | `getDialect()` Get the `ORMDialect` to use.
    `javax.persistence.EntityManagerFactory` | `getEntityManagerFactory()` Get the EntityManagerFactory.
    `Optional<ORMPlatform>` | `getORMPlatform()` Get the ORM platform, if detected.
    `boolean` | `isAutoFlush()` Checks whether to auto-flush mode is enabled.
    `void` | `setAutoFlush(boolean autoFlush)` Set whether to auto-flush mode is enabled.
    `void` | `setDialect(ORMDialect dialect)` Set the ORM dialect
    `void` | `setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)` Set EntityManagerFactory to obtain EntityManager references
    `void` | `setEntityManagerFinalizer(JpaDatastore.EntityManagerFinalizer entityManagerFinalizer)` Sets the `EntityManager` finalizer to use after Datastore operations execution.
    `void` | `setEntityManagerInitializer(JpaDatastore.EntityManagerInitializer entityManagerInitializer)` Sets the `EntityManager` instance provider for Datastore operations execution
    `void` | `setORMPlatform(ORMPlatform platform)` Set the `ORMPlatform`.
    `void` | `setTransactionFactory(JpaTransactionFactory transactionFactory)` Set the `JpaTransactionFactory` to use to create a new JPA transaction.
    `void` | `trace(String jpql)` Trace given JPQL statement.
    `void` | `traceOperation(String operation)` Trace given JPA operation.
    `<R> R` | `withEntityManager(EntityManagerOperation<R> operation)` Execute given `operation` using an `EntityManager` instance provided by the Datastore and return the operation result.
    `<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.jpa.JpaDatastore

      `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.jpa.context.JpaContext

      `getValueDeserializer, getValueSerializer`

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

      `getExpressionResolvers`

    - ### Methods inherited from interface com.holonplatform.datastore.jpa.context.EntityManagerHandler

      `withEntityManager`

- - ### Constructor Detail

    - #### DefaultJpaDatastore

          public DefaultJpaDatastore()

      Constructor.

  - ### Method Detail

    - #### setEntityManagerFactory

          public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)

      Set EntityManagerFactory to obtain EntityManager references
      Parameters:
        `entityManagerFactory` - EntityManagerFactory to set, must be not `null`

    - #### getEntityManagerFactory

          public javax.persistence.EntityManagerFactory getEntityManagerFactory()

      Description copied from interface: `JpaContext`
      Get the EntityManagerFactory.
      Specified by:
        `getEntityManagerFactory` in interface `JpaContext`
      Returns:
        The EntityManagerFactory

    - #### isAutoFlush

          public boolean isAutoFlush()

      Description copied from interface: `JpaOperationContext`
      Checks whether to auto-flush mode is enabled. When auto-flush mode is enabled, `EntityManager.flush()` is called after each Datastore data manipulation operation, such as `save` or `delete`.
      Specified by:
        `isAutoFlush` in interface `JpaOperationContext`
      Returns:
        `true` if auto-flush mode is enabled, `false` otherwise

    - #### setAutoFlush

          public void setAutoFlush(boolean autoFlush)

      Set whether to auto-flush mode is enabled. When auto-flush mode is enabled, `EntityManager.flush()` is called after each Datastore data manipulation operation, such as `save` or `delete`.
      Parameters:
        `autoFlush` - `true` to enable the auto-flush mode, `false` to disable

    - #### getDialect

          public ORMDialect getDialect()

      Description copied from interface: `JpaContext`
      Get the `ORMDialect` to use.
      Specified by:
        `getDialect` in interface `JpaContext`
      Returns:
        The ORM dialect

    - #### setDialect

          public void setDialect(ORMDialect dialect)

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

    - #### getBeanIntrospector

          public com.holonplatform.core.beans.BeanIntrospector getBeanIntrospector()

      Description copied from interface: `JpaOperationContext`
      Get the `BeanIntrospector` to use to introspect entity beans.
      Specified by:
        `getBeanIntrospector` in interface `JpaOperationContext`
      Returns:
        BeanIntrospector (not null)

    - #### trace

          public void trace(String jpql)

      Description copied from interface: `JpaContext`
      Trace given JPQL statement.

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

      Specified by:
        `trace` in interface `JpaContext`
      Parameters:
        `jpql` - JPQL to trace

    - #### traceOperation

          public void traceOperation(String operation)

      Description copied from interface: `JpaContext`
      Trace given JPA operation.

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

      Specified by:
        `traceOperation` in interface `JpaContext`
      Parameters:
        `operation` - Operation to trace

    - #### getORMPlatform

          public Optional<ORMPlatform> getORMPlatform()

      Description copied from interface: `JpaContext`
      Get the ORM platform, if detected.
      Specified by:
        `getORMPlatform` in interface `JpaContext`
      Returns:
        Optional ORM platform

    - #### setORMPlatform

          public void setORMPlatform(ORMPlatform platform)

      Set the `ORMPlatform`.
      Parameters:
        `platform` - the platform to set

    - #### setEntityManagerInitializer

          public void setEntityManagerInitializer(JpaDatastore.EntityManagerInitializer entityManagerInitializer)

      Sets the `EntityManager` instance provider for Datastore operations execution
      Parameters:
        `entityManagerInitializer` - the EntityManagerInitializer to set

    - #### setEntityManagerFinalizer

          public void setEntityManagerFinalizer(JpaDatastore.EntityManagerFinalizer entityManagerFinalizer)

      Sets the `EntityManager` finalizer to use after Datastore operations execution.
      Parameters:
        `entityManagerFinalizer` - the EntityManagerFinalizer to set

    - #### withEntityManager

          public <R> R withEntityManager(EntityManagerOperation<R> operation)

      Description copied from interface: `EntityManagerHandler`
      Execute given `operation` using an `EntityManager` instance provided by the Datastore and return the operation result.

      The `EntityManager` lifecycle is managed by the JPA Datastore, including creation and closing.

      Specified by:
        `withEntityManager` in interface `EntityManagerHandler`
      Type Parameters:
        `R` - Operation result type
      Parameters:
        `operation` - The 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`

    - #### setTransactionFactory

          public void setTransactionFactory(JpaTransactionFactory transactionFactory)

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

Copyright © 2019 The Holon Platform. All rights reserved.