com.holonplatform.jpa.spring

## Annotation Type EnableJpaDatastore

-     @Target(value=TYPE)
       @Retention(value=RUNTIME)
       @Documented
       @Inherited
       @Import(value=com.holonplatform.jpa.spring.internal.JpaDatastoreRegistrar.class)
      public @interface EnableJpaDatastore

  Annotation to be used on Spring Configuration classes to setup a JPA `Datastore`.

  For successful `Datastore` registration, an `EntityManagerFactory` bean must be available in context. If no data context is specified, a bean named `entityManagerFactory` is required. Otherwise, an EntityManagerFactory bean named using pattern `dataContextId_entityManagerFactory` is required. A custom EntityManagerFactory bean name can be configured using `entityManagerFactoryReference()` attribute.

  The registered bean name will be `DEFAULT_DATASTORE_BEAN_NAME` if `dataContextId()` is not specified. Otherwise, the registered bean name will be the composition of the data context id and the default bean name using this pattern: `DEFAULT_DATASTORE_BEAN_NAME` + `_dataContextId`.

  Since:
    5.0.0
  See Also:
    `JpaDatastore`

- - ### Field Summary

    Fields
    Modifier and Type | Fields and Description
    --- | ---
    `static String` | `DEFAULT_DATASTORE_BEAN_NAME` Default `Datastore` registration bean name.

  - ### Optional Element Summary

    Optional Elements
    Modifier and Type | Optional Element and Description
    --- | ---
    `boolean` | `autoFlush` Get whether to enable the auto-flush mode.
    `String` | `dataContextId` Optional data context id to use to discriminate Datastores when more than one persistence source is configured, i.e. when multiple DataSources and JPA persistence units are configured in context.
    `String` | `entityManagerFactoryReference` Configures the name of the `EntityManagerFactory` bean definition to be used to create the `Datastore` registered using this annotation.
    `com.holonplatform.spring.internal.PrimaryMode` | `primary` Whether to qualify `Datastore` bean as `primary`, i.e. the preferential bean to be injected in a single-valued dependency when multiple candidates are present.
    `boolean` | `transactional` Get whether to add `Transactional` behaviour to transactional `Datastore` methods, to automatically create or partecipate in a transaction when methods are invoked.

- - ### Field Detail

    - #### DEFAULT_DATASTORE_BEAN_NAME

          public static final String DEFAULT_DATASTORE_BEAN_NAME

      Default `Datastore` registration bean name.

  - ### Element Detail

    - #### dataContextId

          public abstract String dataContextId

      Optional data context id to use to discriminate Datastores when more than one persistence source is configured, i.e. when multiple DataSources and JPA persistence units are configured in context.

      The configured data context id will be returned by the `DataContextBound.getDataContextId()` method of the registered `Datastore`.

      When a data context id is specified, the registered Datastore should be bound to the EntityManagerFactory with a persistence unit name which matches the data context id. During registration phase, if the data context id is not null/empty and a `entityManagerFactoryReference()` is not specified, an EntityManagerFactory bean is searched in context using the bean name pattern: `entityManagerFactory_[datacontextid]` where `[datacontextid]` is equal to `dataContextId()` attribute.

      Returns:
        Data context id
      Default:
        ""

  - - #### entityManagerFactoryReference

          public abstract String entityManagerFactoryReference

      Configures the name of the `EntityManagerFactory` bean definition to be used to create the `Datastore` registered using this annotation. See `dataContextId()` for informations about EntityManagerFactory bean lookup when a specific name is not configured.
      Returns:
        The name of the `EntityManagerFactory` bean definition to be used to create the `Datastore`
      Default:
        ""

  - - #### primary

          public abstract com.holonplatform.spring.internal.PrimaryMode primary

      Whether to qualify `Datastore` bean as `primary`, i.e. the preferential bean to be injected in a single-valued dependency when multiple candidates are present.

      When mode is `PrimaryMode.AUTO`, the registred Datastore bean is marked as primary only when the `EntityManagerFactory` bean to which is bound is registered as primary bean.

      Returns:
        Primary mode, defaults to `PrimaryMode.AUTO`
      Default:
        com.holonplatform.spring.internal.PrimaryMode.AUTO

  - - #### autoFlush

          public abstract boolean autoFlush

      Get whether to enable the auto-flush mode. When auto-flush mode is enabled, `EntityManager.flush()` is called after each Datastore data manipulation operation, such as `save` or `delete` operations.

      Default is `false`.

      Returns:
        `true` to enable the auto-flush mode, `false` to disable
      Default:
        false

  - - #### transactional

          public abstract boolean transactional

      Get whether to add `Transactional` behaviour to transactional `Datastore` methods, to automatically create or partecipate in a transaction when methods are invoked. Affected methods are:
      - `Datastore.refresh(com.holonplatform.core.datastore.DataTarget, com.holonplatform.core.property.PropertyBox)`
      - `Datastore.insert(com.holonplatform.core.datastore.DataTarget, com.holonplatform.core.property.PropertyBox, com.holonplatform.core.datastore.Datastore.WriteOption...)`
      - `Datastore.update(com.holonplatform.core.datastore.DataTarget, com.holonplatform.core.property.PropertyBox, com.holonplatform.core.datastore.Datastore.WriteOption...)`
      - `Datastore.save(com.holonplatform.core.datastore.DataTarget, com.holonplatform.core.property.PropertyBox, com.holonplatform.core.datastore.Datastore.WriteOption...)`
      - `Datastore.delete(com.holonplatform.core.datastore.DataTarget, com.holonplatform.core.property.PropertyBox, com.holonplatform.core.datastore.Datastore.WriteOption...)`
      Returns:
        Whether to add `Transactional` behaviour to transactional datastore methods. Defaults to `true`.
      Default:
        true

Copyright © 2017 The Holon Platform. All rights reserved.