Class DataModelRegistry

java.lang.Object
io.jmix.datatools.datamodel.DataModelRegistry

@Component("datatl_DataModelProvider") public class DataModelRegistry extends Object
Provides information about entity data models organized by data stores.
  • Field Details

  • Constructor Details

    • DataModelRegistry

      public DataModelRegistry()
  • Method Details

    • getState

      protected DataModelRegistry.State getState()
    • hasContributors

      public boolean hasContributors()
      Returns whether any module contributes entities or attributes the JPA metadata cannot describe. When nothing does, the data model holds only JPA entities and the dynamic flag of every entity and attribute is false.
      Returns:
      true if at least one DataModelContributor is registered
    • reset

      public void reset()
      Make the registry to reload data models on the next request.
    • onMetadataGenerationRetired

      @EventListener public void onMetadataGenerationRetired(MetadataGenerationRetiredEvent event)
      Removes registry state cached for a retired metadata generation.
      Parameters:
      event - retired-generation event
    • checkInitialized

      protected void checkInitialized(DataModelRegistry.State state)
    • init

      protected void init(DataModelRegistry.State state)
    • constructDataModel

      protected void constructDataModel(DataModelRegistry.State state)
    • callContributor

      protected <R> @Nullable R callContributor(DataModelContributor contributor, String operation, Function<DataModelContributor,R> call)
      Invokes a contributor, isolating the rest of the data model from its failure.
      Returns:
      the contributor's result, or null if it returned null or threw
    • findDataModel

      protected @Nullable DataModel findDataModel(DataModelRegistry.State state, MetaClass metaClass)
    • resolveEntityDescriptor

      protected EntityDescriptor resolveEntityDescriptor(MetaClass entity)
    • createEntityDescription

      protected DataModel createEntityDescription(DataModelRegistry.State state, MetaClass entity, boolean isEmbeddable)
    • addContributedAttribute

      protected void addContributedAttribute(MetaClass entity, MetaProperty field, EntityDescriptor entityDescriptor, List<AttributeModel> attributeModelsList, Map<RelationType,List<Relation>> relationsMap)
    • constructContributedAttribute

      protected AttributeModel constructContributedAttribute(AttributeDescriptor descriptor, EntityDescriptor entityDescriptor)
    • getContributedColumnType

      protected String getContributedColumnType(String storeName, String tableName, String columnName)
    • addDatatypeAttribute

      protected void addDatatypeAttribute(MetaClass entity, boolean isEmbeddable, MetaProperty field, String fieldName, List<AttributeModel> attributeModelsList)
    • findEntityForField

      protected MetaClass findEntityForField(MetaClass entity, MetaProperty field)
      Finds the most appropriate MetaClass representation of the entity to which a given field belongs. It checks the declaring class of the field and navigates through the entity's inheritance hierarchy to locate the last JPA entity associated with the given field.

      NOTE: needed for inheritance strategy 'JOINED'.

      Parameters:
      entity - the initial MetaClass representing the starting point for the search in the hierarchy
      field - the MetaProperty representing the field whose associated entity is to be determined
      Returns:
      the MetaClass representing the most specific JPA entity associated with the field or the initial entity if no more specific JPA entity could be found
    • addEmbeddedAttribute

      protected void addEmbeddedAttribute(DataModelRegistry.State state, MetaClass entity, MetaProperty field, String fieldName, List<AttributeModel> attributeModelsList)
    • addManyToOneAttribute

      protected void addManyToOneAttribute(MetaClass entity, boolean isEmbeddable, MetaProperty field, String fieldName, List<AttributeModel> attributeModelsList, String dataStoreName, Map<RelationType,List<Relation>> relationsMap)
    • addOneToManyAttribute

      protected void addOneToManyAttribute(MetaClass entity, MetaProperty field, String fieldName, String dataStoreName, Map<RelationType,List<Relation>> relationsMap, List<AttributeModel> attributeModelsList)
    • addOneToOneAttribute

      protected void addOneToOneAttribute(MetaClass entity, boolean isEmbeddable, MetaProperty field, String fieldName, String dataStoreName, Map<RelationType,List<Relation>> relationsMap, List<AttributeModel> attributeModelsList)
    • addManyToManyAttribute

      protected void addManyToManyAttribute(MetaClass entity, MetaProperty field, String fieldName, String dataStoreName, Map<RelationType,List<Relation>> relationsMap, List<AttributeModel> attributeModelsList)
    • addElementCollectionAttribute

      protected void addElementCollectionAttribute(MetaClass entity, MetaProperty field, String fieldName, List<AttributeModel> attributeModelsList)
    • constructEntityModel

      protected EntityModel constructEntityModel(MetaClass entity, boolean isSystem, EntityDescriptor descriptor)
    • putRelation

      protected void putRelation(Map<RelationType,List<Relation>> relations, RelationType relationType, Relation relation)
    • constructAttribute

      protected AttributeModel constructAttribute(String fieldName, String fieldType)
    • createAttributeModel

      protected AttributeModel createAttributeModel(String fieldName, String fieldType, boolean dynamic)
    • constructAttribute

      protected AttributeModel constructAttribute(String fieldName, String fieldType, boolean isMandatory)
    • constructAttribute

      protected AttributeModel constructAttribute(String columnName, String fieldName, String fieldType, MetaClass entity, boolean isMandatory)
    • constructAttribute

      protected AttributeModel constructAttribute(List<String> columnNames, String fieldName, String fieldType, MetaClass entity, boolean isMandatory)
    • constructAttribute

      protected AttributeModel constructAttribute(String columnName, String fieldName, String fieldType, String dbType, boolean isMandatory)
    • getDatabaseColumnType

      protected String getDatabaseColumnType(String storeName, @Nullable String schemaName, @Nullable String catalogName, String tableName, String columnName)
    • getDatabaseColumnType

      protected String getDatabaseColumnType(MetaClass entity, String columnName)
    • applyRegister

      protected String applyRegister(String name, String storeName)
    • getCatalogName

      protected @Nullable String getCatalogName(jakarta.persistence.Table annotation)
    • getSchemaName

      protected @Nullable String getSchemaName(jakarta.persistence.Table annotation)
    • putDataModel

      protected void putDataModel(DataModelRegistry.State state, DataModel dataModel)
    • getDataStoreNames

      public Set<String> getDataStoreNames()
    • getDataModels

      public Map<String,Map<String,DataModel>> getDataModels()
      Retrieves an unmodifiable view of the internal data model storage. The returned map represents an organizational structure where the first-level keys are data store identifiers and the values are nested maps. The nested maps use entity names as keys and their corresponding DataModel objects as values.
      Returns:
      a map containing data store identifiers as keys, where each value is another map that maps entity names to their respective DataModel instances. The returned map is unmodifiable.
    • getDataModels

      public Map<String,DataModel> getDataModels(String dataStore)
      Retrieves the data models associated with a specific data store.
      Parameters:
      dataStore - the name of the data store whose data models are to be retrieved; must not be null
      Returns:
      a map where the keys are entity names and the values are the corresponding DataModel instances
    • isAnnotationPresent

      protected boolean isAnnotationPresent(MetaProperty field, Class<? extends Annotation> annotationClass)
    • hasJoinColumns

      protected boolean hasJoinColumns(MetaProperty field)
      Checks whether the given field declares join columns, regardless of whether their names are set explicitly. An owning side of an association always declares them, an inverse side never does.
      Parameters:
      field - the field to inspect
      Returns:
      true if the field declares at least one join column
    • getJoinColumnNames

      protected List<String> getJoinColumnNames(MetaProperty field)
      Returns names of the join columns declared on the given field. Supports both a single JoinColumn and a composite foreign key declared via JoinColumns: JoinColumn is repeatable, so it is not directly present on the field when wrapped into the container annotation.
      Parameters:
      field - the field to inspect
      Returns:
      names of the declared join columns, empty if the field has no explicitly named join column
    • getAnnotation

      protected <T extends Annotation> T getAnnotation(MetaProperty field, Class<T> annotationClass)
    • getElementTypeFromCollection

      protected String getElementTypeFromCollection(MetaProperty metaProperty)