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());
}
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);
}
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);
}
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();
}
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);
}
}
Aggregations