Search in sources :

Example 1 with JdbcEnvironment

use of org.hibernate.engine.jdbc.env.spi.JdbcEnvironment 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.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)

Example 2 with JdbcEnvironment

use of org.hibernate.engine.jdbc.env.spi.JdbcEnvironment in project hibernate-orm by hibernate.

the class DefaultUniqueDelegate method getAlterTableToAddUniqueKeyCommand.

@Override
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata) {
    final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
    final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(uniqueKey.getTable().getQualifiedTableName(), dialect);
    final String constraintName = dialect.quote(uniqueKey.getName());
    return "alter table " + tableName + " add constraint " + constraintName + " " + uniqueConstraintSql(uniqueKey);
}
Also used : JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 3 with JdbcEnvironment

use of org.hibernate.engine.jdbc.env.spi.JdbcEnvironment in project hibernate-orm by hibernate.

the class JdbcServicesImpl method configure.

@Override
public void configure(Map configValues) {
    this.jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
    assert jdbcEnvironment != null : "JdbcEnvironment was not found!";
    this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy(configValues);
    final boolean showSQL = ConfigurationHelper.getBoolean(Environment.SHOW_SQL, configValues, false);
    final boolean formatSQL = ConfigurationHelper.getBoolean(Environment.FORMAT_SQL, configValues, false);
    this.sqlStatementLogger = new SqlStatementLogger(showSQL, formatSQL);
    resultSetWrapper = new ResultSetWrapperImpl(serviceRegistry);
}
Also used : SqlStatementLogger(org.hibernate.engine.jdbc.spi.SqlStatementLogger) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 4 with JdbcEnvironment

use of org.hibernate.engine.jdbc.env.spi.JdbcEnvironment in project hibernate-orm by hibernate.

the class AbstractMultiTableBulkIdStrategyImpl method buildIdTableCreateStatement.

protected String buildIdTableCreateStatement(Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata) {
    final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
    final Dialect dialect = jdbcEnvironment.getDialect();
    StringBuilder buffer = new StringBuilder(getIdTableSupport().getCreateIdTableCommand()).append(' ').append(jdbcEnvironment.getQualifiedObjectNameFormatter().format(idTable.getQualifiedTableName(), dialect)).append(" (");
    Iterator itr = idTable.getColumnIterator();
    while (itr.hasNext()) {
        final Column column = (Column) itr.next();
        buffer.append(column.getQuotedName(dialect)).append(' ');
        buffer.append(column.getSqlType(dialect, metadata));
        if (column.isNullable()) {
            buffer.append(dialect.getNullColumnString());
        } else {
            buffer.append(" not null");
        }
        if (itr.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(") ");
    if (getIdTableSupport().getCreateIdTableStatementOptions() != null) {
        buffer.append(getIdTableSupport().getCreateIdTableStatementOptions());
    }
    return buffer.toString();
}
Also used : Column(org.hibernate.mapping.Column) Dialect(org.hibernate.dialect.Dialect) Iterator(java.util.Iterator) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 5 with JdbcEnvironment

use of org.hibernate.engine.jdbc.env.spi.JdbcEnvironment in project hibernate-orm by hibernate.

the class MultipleHiLoPerTableGenerator method configure.

@SuppressWarnings({ "StatementWithEmptyBody", "deprecation" })
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
    returnClass = type.getReturnedClass();
    final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
    qualifiedTableName = determineGeneratorTableName(params, jdbcEnvironment);
    segmentColumnName = determineSegmentColumnName(params, jdbcEnvironment);
    keySize = ConfigurationHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH);
    segmentName = ConfigurationHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE));
    valueColumnName = determineValueColumnName(params, jdbcEnvironment);
    //hilo config
    maxLo = ConfigurationHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
    if (maxLo >= 1) {
        hiloOptimizer = new LegacyHiLoAlgorithmOptimizer(returnClass, maxLo);
    }
}
Also used : LegacyHiLoAlgorithmOptimizer(org.hibernate.id.enhanced.LegacyHiLoAlgorithmOptimizer) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Aggregations

JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)29 Iterator (java.util.Iterator)6 Namespace (org.hibernate.boot.model.relational.Namespace)5 Dialect (org.hibernate.dialect.Dialect)5 Column (org.hibernate.mapping.Column)5 Table (org.hibernate.mapping.Table)5 Identifier (org.hibernate.boot.model.naming.Identifier)4 QualifiedName (org.hibernate.boot.model.relational.QualifiedName)3 Sequence (org.hibernate.boot.model.relational.Sequence)3 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityMode (org.hibernate.EntityMode)2 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)2 Database (org.hibernate.boot.model.relational.Database)2 InitCommand (org.hibernate.boot.model.relational.InitCommand)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)2 ExtractedDatabaseMetaData (org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData)2 FilterDefinition (org.hibernate.engine.spi.FilterDefinition)2