Search in sources :

Example 1 with JaxbHbmNamedNativeQueryType

use of org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType in project hibernate-orm by hibernate.

the class ModelBinder method bindBasicEntityValues.

private void bindBasicEntityValues(MappingDocument sourceDocument, AbstractEntitySourceImpl entitySource, PersistentClass entityDescriptor) {
    entityDescriptor.setEntityName(entitySource.getEntityNamingSource().getEntityName());
    entityDescriptor.setJpaEntityName(entitySource.getEntityNamingSource().getJpaEntityName());
    entityDescriptor.setClassName(entitySource.getEntityNamingSource().getClassName());
    entityDescriptor.setDiscriminatorValue(entitySource.getDiscriminatorMatchValue() != null ? entitySource.getDiscriminatorMatchValue() : entityDescriptor.getEntityName());
    // NOTE : entitySource#isLazy already accounts for MappingDefaults#areEntitiesImplicitlyLazy
    if (StringHelper.isNotEmpty(entitySource.getProxy())) {
        final String qualifiedProxyName = sourceDocument.qualifyClassName(entitySource.getProxy());
        entityDescriptor.setProxyInterfaceName(qualifiedProxyName);
        entityDescriptor.setLazy(true);
    } else if (entitySource.isLazy()) {
        entityDescriptor.setProxyInterfaceName(entityDescriptor.getClassName());
        entityDescriptor.setLazy(true);
    } else {
        entityDescriptor.setProxyInterfaceName(null);
        entityDescriptor.setLazy(false);
    }
    entityDescriptor.setAbstract(entitySource.isAbstract());
    sourceDocument.getMetadataCollector().addImport(entitySource.getEntityNamingSource().getEntityName(), entitySource.getEntityNamingSource().getEntityName());
    if (sourceDocument.getMappingDefaults().isAutoImportEnabled() && entitySource.getEntityNamingSource().getEntityName().indexOf('.') > 0) {
        sourceDocument.getMetadataCollector().addImport(StringHelper.unqualify(entitySource.getEntityNamingSource().getEntityName()), entitySource.getEntityNamingSource().getEntityName());
    }
    if (entitySource.getTuplizerClassMap() != null) {
        if (entitySource.getTuplizerClassMap().size() > 1) {
            DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfMultipleEntityModeSupport();
        }
        for (Map.Entry<EntityMode, String> tuplizerEntry : entitySource.getTuplizerClassMap().entrySet()) {
            entityDescriptor.addTuplizer(tuplizerEntry.getKey(), tuplizerEntry.getValue());
        }
    }
    if (StringHelper.isNotEmpty(entitySource.getXmlNodeName())) {
        DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
    }
    entityDescriptor.setDynamicInsert(entitySource.isDynamicInsert());
    entityDescriptor.setDynamicUpdate(entitySource.isDynamicUpdate());
    entityDescriptor.setBatchSize(entitySource.getBatchSize());
    entityDescriptor.setSelectBeforeUpdate(entitySource.isSelectBeforeUpdate());
    if (StringHelper.isNotEmpty(entitySource.getCustomPersisterClassName())) {
        try {
            entityDescriptor.setEntityPersisterClass(sourceDocument.getBootstrapContext().getClassLoaderAccess().classForName(entitySource.getCustomPersisterClassName()));
        } catch (ClassLoadingException e) {
            throw new MappingException(String.format(Locale.ENGLISH, "Unable to load specified persister class : %s", entitySource.getCustomPersisterClassName()), e, sourceDocument.getOrigin());
        }
    }
    bindCustomSql(sourceDocument, entitySource, entityDescriptor);
    final JdbcEnvironment jdbcEnvironment = sourceDocument.getMetadataCollector().getDatabase().getJdbcEnvironment();
    for (String tableName : entitySource.getSynchronizedTableNames()) {
        final Identifier physicalTableName = sourceDocument.getBuildingOptions().getPhysicalNamingStrategy().toPhysicalTableName(jdbcEnvironment.getIdentifierHelper().toIdentifier(tableName), jdbcEnvironment);
        entityDescriptor.addSynchronizedTable(physicalTableName.render(jdbcEnvironment.getDialect()));
    }
    for (FilterSource filterSource : entitySource.getFilterSources()) {
        String condition = filterSource.getCondition();
        if (condition == null) {
            final FilterDefinition filterDefinition = sourceDocument.getMetadataCollector().getFilterDefinition(filterSource.getName());
            if (filterDefinition != null) {
                condition = filterDefinition.getDefaultFilterCondition();
            }
        }
        entityDescriptor.addFilter(filterSource.getName(), condition, filterSource.shouldAutoInjectAliases(), filterSource.getAliasToTableMap(), filterSource.getAliasToEntityMap());
    }
    for (JaxbHbmNamedQueryType namedQuery : entitySource.getNamedQueries()) {
        NamedQueryBinder.processNamedQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
    }
    for (JaxbHbmNamedNativeQueryType namedQuery : entitySource.getNamedNativeQueries()) {
        NamedQueryBinder.processNamedNativeQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
    }
    entityDescriptor.setMetaAttributes(entitySource.getToolingHintContext().getMetaAttributeMap());
}
Also used : FilterDefinition(org.hibernate.engine.spi.FilterDefinition) Identifier(org.hibernate.boot.model.naming.Identifier) FilterSource(org.hibernate.boot.model.source.spi.FilterSource) JaxbHbmNamedNativeQueryType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType) JaxbHbmNamedQueryType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedQueryType) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) Map(java.util.Map) HashMap(java.util.HashMap) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) EntityMode(org.hibernate.EntityMode) MappingException(org.hibernate.boot.MappingException)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntityMode (org.hibernate.EntityMode)1 MappingException (org.hibernate.boot.MappingException)1 JaxbHbmNamedNativeQueryType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType)1 JaxbHbmNamedQueryType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedQueryType)1 Identifier (org.hibernate.boot.model.naming.Identifier)1 FilterSource (org.hibernate.boot.model.source.spi.FilterSource)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 FilterDefinition (org.hibernate.engine.spi.FilterDefinition)1