Package com.isomorphic.jpa

# Class JPADSGenerator

java.lang.Object
com.isomorphic.jpa.JPADSGenerator

public class JPADSGenerator extends 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

  Modifier and Type
  Method
  Description
  `static Map<String,Map<String,Object>>`
  `generateFromPersistenceUnit(String persistenceUnitName)`
  Generates data source configurations for all entities mapped in specified persistent unit.
  `static Map<String,Object>`
  `getDataSourceConfigFromJPAClass(String className)`
  Returns data source configuration for specified class.
  `static Map<String,Object>`
  `getDataSourceConfigFromJPAClass(String className, boolean extended)`
  Returns data source configuration for specified class.
  `static Map<String,Object>`
  `getDataSourceConfigFromMetamodel(String className, jakarta.persistence.EntityManager em)`
  Returns data source configuration for specified class.
  `static Map<String,Object>`
  `getDataSourceConfigFromMetamodel(String className, jakarta.persistence.EntityManager em, boolean generateRelations, boolean extended)`
  Returns data source configuration for specified class.

- ## Method Details

  - ### getDataSourceConfigFromJPAClass

    public static Map<String,Object> getDataSourceConfigFromJPAClass(String className) throws Exception
    Returns data source configuration for specified class.
    Parameters:
      `className` - `String` Name of the class.
    Returns:
      `Map<String, Object>` data source configuration for specified class.
    Throws:
      `Exception` - when this feature is not available or generation failed.

  - ### getDataSourceConfigFromJPAClass

    public static Map<String,Object> getDataSourceConfigFromJPAClass(String className, boolean extended) throws Exception
    Returns data source configuration for specified class.
    Parameters:
      `className` - `String` Name of the class.
      `extended` - `boolean` Extended properties will be captured if set to `true`.
    Returns:
      `Map<String, Object>` data source configuration for specified class.
    Throws:
      `Exception` - when this feature is not available or generation failed.

  - ### generateFromPersistenceUnit

    public static Map<String,Map<String,Object>> generateFromPersistenceUnit(String persistenceUnitName) throws 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:
      `Exception` - when this feature is not available.

  - ### getDataSourceConfigFromMetamodel

    public static Map<String,Object> getDataSourceConfigFromMetamodel(String className, jakarta.persistence.EntityManager em) throws 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:
      `Exception` - when this feature is not available or generation failed.

  - ### getDataSourceConfigFromMetamodel

    public static Map<String,Object> getDataSourceConfigFromMetamodel(String className, jakarta.persistence.EntityManager em, boolean generateRelations, boolean extended) throws 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:
      `Exception` - when this feature is not available or generation failed.