use of org.hibernate.dialect.Dialect 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.dialect.Dialect in project hibernate-orm by hibernate.
the class AbstractTableBasedBulkIdHandler method generateIdSelect.
protected Select generateIdSelect(String tableAlias, ProcessedWhereClause whereClause) {
final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect();
final Select select = new Select(dialect);
final SelectValues selectClause = new SelectValues(dialect).addColumns(tableAlias, getTargetedQueryable().getIdentifierColumnNames(), getTargetedQueryable().getIdentifierColumnNames());
addAnyExtraIdSelectValues(selectClause);
select.setSelectClause(selectClause.render());
String rootTableName = getTargetedQueryable().getTableName();
String fromJoinFragment = getTargetedQueryable().fromJoinFragment(tableAlias, true, false);
String whereJoinFragment = getTargetedQueryable().whereJoinFragment(tableAlias, true, false);
select.setFromClause(rootTableName + ' ' + tableAlias + fromJoinFragment);
if (whereJoinFragment == null) {
whereJoinFragment = "";
} else {
whereJoinFragment = whereJoinFragment.trim();
if (whereJoinFragment.startsWith("and")) {
whereJoinFragment = whereJoinFragment.substring(4);
}
}
if (whereClause.getUserWhereClauseFragment().length() > 0) {
if (whereJoinFragment.length() > 0) {
whereJoinFragment += " and ";
}
}
select.setWhereClause(whereJoinFragment + whereClause.getUserWhereClauseFragment());
return select;
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class SequenceGenerator method registerExportables.
@Override
public void registerExportables(Database database) {
final Namespace namespace = database.locateNamespace(logicalQualifiedSequenceName.getCatalogName(), logicalQualifiedSequenceName.getSchemaName());
Sequence sequence = namespace.locateSequence(logicalQualifiedSequenceName.getObjectName());
if (sequence != null) {
sequence.validate(1, 1);
} else {
sequence = namespace.createSequence(logicalQualifiedSequenceName.getObjectName(), 1, 1);
}
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect();
this.sequenceName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(sequence.getName(), dialect);
this.sql = jdbcEnvironment.getDialect().getSequenceNextValString(sequenceName);
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class SequenceStyleGenerator method configure.
// Configurable implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
final Dialect dialect = jdbcEnvironment.getDialect();
this.identifierType = type;
boolean forceTableUse = ConfigurationHelper.getBoolean(FORCE_TBL_PARAM, params, false);
final QualifiedName sequenceName = determineSequenceName(params, dialect, jdbcEnvironment);
final int initialValue = determineInitialValue(params);
int incrementSize = determineIncrementSize(params);
final String optimizationStrategy = determineOptimizationStrategy(params, incrementSize);
incrementSize = determineAdjustedIncrementSize(optimizationStrategy, incrementSize);
if (dialect.supportsSequences() && !forceTableUse) {
if (!dialect.supportsPooledSequences() && OptimizerFactory.isPooledOptimizer(optimizationStrategy)) {
forceTableUse = true;
LOG.forcingTableUse();
}
}
this.databaseStructure = buildDatabaseStructure(type, params, jdbcEnvironment, forceTableUse, sequenceName, initialValue, incrementSize);
this.optimizer = OptimizerFactory.buildOptimizer(optimizationStrategy, identifierType.getReturnedClass(), incrementSize, ConfigurationHelper.getInt(INITIAL_PARAM, params, -1));
this.databaseStructure.prepare(optimizer);
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class TableGenerator method registerExportables.
@Override
public void registerExportables(Database database) {
final Dialect dialect = database.getJdbcEnvironment().getDialect();
final Namespace namespace = database.locateNamespace(qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName());
Table table = namespace.locateTable(qualifiedTableName.getObjectName());
if (table == null) {
table = namespace.createTable(qualifiedTableName.getObjectName(), false);
// todo : note sure the best solution here. do we add the columns if missing? other?
final Column segmentColumn = new ExportableColumn(database, table, segmentColumnName, StringType.INSTANCE, dialect.getTypeName(Types.VARCHAR, segmentValueLength, 0, 0));
segmentColumn.setNullable(false);
table.addColumn(segmentColumn);
// lol
table.setPrimaryKey(new PrimaryKey(table));
table.getPrimaryKey().addColumn(segmentColumn);
final Column valueColumn = new ExportableColumn(database, table, valueColumnName, LongType.INSTANCE);
table.addColumn(valueColumn);
}
// allow physical naming strategies a chance to kick in
this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(table.getQualifiedTableName(), dialect);
this.selectQuery = buildSelectQuery(dialect);
this.updateQuery = buildUpdateQuery();
this.insertQuery = buildInsertQuery();
}
Aggregations