com.isomorphic.jpa

## Class JPA2DSGenerator

- java.lang.Object
- - com.isomorphic.jpa.JPA2DSGenerator

-     public class JPA2DSGenerator
      extends java.lang.Object

  Methods for JPA entities data source generation.

  There are two methods:
  - `getDataSourceConfigFromJPAClass(String className)` - generates configuration for JPA 1.0 data source. Processes only annotated classes (does not support entity mapping specified in external XML file). Class has to be annotated with one of these annotations: Entity, MappedSuperclass, Embeddable.
  - `generateFromPersistenceUnit (String persistenceUnitName)` - generates configuration for JPA 2.0 data source for all entities mapped in specified persistence unit. This method requires JPA 2.0. Make sure you use JPA provider with JPA 2.0 implementation.
  Data source contains all properties but only supported properties are correctly generated see `dsTypeForJavaType` method description for supported types.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.util.Map` | `generateFromPersistenceUnit(java.lang.String persistenceUnitName)` Generates data source configurations for all entities mapped in specified persistent unit. Works only with JPA 2.0 implementation.
    `static java.util.Map` | `getDataSourceConfigFromMetamodel(java.lang.String className, javax.persistence.EntityManager em)` Returns data source configuration for specified class. Plural fields (one-to-many relations) will be generated. Works only with JPA 2.0 implementation.
    `static java.util.Map` | `getDataSourceConfigFromMetamodel(java.lang.String className, javax.persistence.EntityManager em, boolean generateRelations, boolean extended)` Returns data source configuration for specified class. Works only with JPA 2.0 implementation.

- - ### Method Detail

    - #### generateFromPersistenceUnit

          public static java.util.Map generateFromPersistenceUnit(java.lang.String persistenceUnitName)
                                                           throws java.lang.Exception

      Generates data source configurations for all entities mapped in specified persistent unit.

      Works only with JPA 2.0 implementation.
      Parameters:
        `persistenceUnitName` - `String` Name of persistence unit to be inspected.
      Returns:
        `Map<String, Map<String, Object>>` key is data source id; value is complete data source configuration.
      Throws:
        `java.lang.Exception` - when this feature is not available.

    - #### getDataSourceConfigFromMetamodel

          public static java.util.Map getDataSourceConfigFromMetamodel(java.lang.String className,
                                                                       javax.persistence.EntityManager em)
                                                                throws java.lang.Exception

      Returns data source configuration for specified class.

      Plural fields (one-to-many relations) will be generated.

      Works only with JPA 2.0 implementation.
      Parameters:
        `className` - `String` Name of the class.
        `em` - `EntityManager` with JPA2 meta-model.
      Returns:
        `Map<String, Object>` data source configuration for specified class.
      Throws:
        `java.lang.Exception` - when this feature is not available or generation failed.

    - #### getDataSourceConfigFromMetamodel

          public static java.util.Map getDataSourceConfigFromMetamodel(java.lang.String className,
                                                                       javax.persistence.EntityManager em,
                                                                       boolean generateRelations,
                                                                       boolean extended)
                                                                throws java.lang.Exception

      Returns data source configuration for specified class.

      Works only with JPA 2.0 implementation.
      Parameters:
        `className` - `String` Name of the class.
        `em` - `EntityManager` with JPA2 meta-model.
        `generateRelations` - `boolean` `true` - relation fields will be generated; `false` - relation fields will be skipped.
        `extended` - `boolean` Extended properties will be captured if set to `true`.
      Returns:
        `Map<String, Object>` data source configuration for specified class.
      Throws:
        `java.lang.Exception` - when this feature is not available or generation failed.