use of org.hibernate.boot.model.relational.SqlStringGenerationContext in project hibernate-orm by hibernate.
the class HibernateSequenceTest method testHibernateSequenceSchema.
@Test
public void testHibernateSequenceSchema(SessionFactoryScope scope) {
EntityPersister persister = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(HibernateSequenceEntity.class.getName());
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue(SequenceStyleGenerator.class.isInstance(generator));
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
SqlStringGenerationContext sqlStringGenerationContext = scope.getSessionFactory().getSqlStringGenerationContext();
assertEquals(Table.qualify(null, SCHEMA_NAME, "HibernateSequenceEntity_SEQ"), sqlStringGenerationContext.format(seqGenerator.getDatabaseStructure().getPhysicalName()));
}
use of org.hibernate.boot.model.relational.SqlStringGenerationContext in project hibernate-orm by hibernate.
the class TestExtraPhysicalTableTypes method buildInformationExtractorJdbcDatabaseMetaDataImplTest.
private InformationExtractorJdbcDatabaseMetaDataImplTest buildInformationExtractorJdbcDatabaseMetaDataImplTest(DdlTransactionIsolator ddlTransactionIsolator) throws SQLException {
Database database = metadata.getDatabase();
SqlStringGenerationContext sqlStringGenerationContext = SqlStringGenerationContextImpl.forTests(database.getJdbcEnvironment());
DatabaseInformation dbInfo = new DatabaseInformationImpl(ssr, database.getJdbcEnvironment(), sqlStringGenerationContext, ddlTransactionIsolator, database.getServiceRegistry().getService(SchemaManagementTool.class));
ExtractionContextImpl extractionContext = new ExtractionContextImpl(ssr, database.getJdbcEnvironment(), sqlStringGenerationContext, ssr.getService(JdbcServices.class).getBootstrapJdbcConnectionAccess(), (ExtractionContext.DatabaseObjectAccess) dbInfo);
return new InformationExtractorJdbcDatabaseMetaDataImplTest(extractionContext);
}
use of org.hibernate.boot.model.relational.SqlStringGenerationContext in project hibernate-orm by hibernate.
the class AbstractSchemaMigratorTest method testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName.
@Test
@TestForIssue(jiraKey = "HHH-13779")
public void testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName() {
final AbstractSchemaMigrator schemaMigrator = new AbstractSchemaMigrator(null, null) {
@Override
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, ContributableMatcher contributableInclusionFilter, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget[] targets) {
return null;
}
};
final TableInformation existingTableInformation = mock(TableInformation.class);
final ArrayList<ForeignKeyInformation.ColumnReferenceMapping> columnReferenceMappings = new ArrayList<>();
final TableInformation destinationTableInformation = mock(TableInformation.class);
doReturn(new QualifiedTableName(toIdentifier("catalog"), toIdentifier("schema"), // Table name is lower case
toIdentifier("referenced_table"))).when(destinationTableInformation).getName();
columnReferenceMappings.add(new ForeignKeyInformationImpl.ColumnReferenceMappingImpl(new // column name is lower case
ColumnInformationImpl(// column name is lower case
null, // column name is lower case
toIdentifier("referencing_column"), 0, "typeName", 255, 0, TruthValue.TRUE), new ColumnInformationImpl(destinationTableInformation, null, 1, "typeName", 0, 0, TruthValue.TRUE)));
doReturn(singletonList(new ForeignKeyInformationImpl(toIdentifier("FKp8mpamfw2inhj88hwhty1eipm"), columnReferenceMappings))).when(existingTableInformation).getForeignKeys();
final boolean existInDatabase = schemaMigrator.equivalentForeignKeyExistsInDatabase(existingTableInformation, "REFERENCING_COLUMN", // Table and column names are UPPER-case here, to prove the test
"REFERENCED_TABLE");
assertThat("Expected ForeignKey pre-existence check to be case-insensitive", existInDatabase, is(true));
}
use of org.hibernate.boot.model.relational.SqlStringGenerationContext in project hibernate-orm by hibernate.
the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.
@Test
public void testCreateTableOnUpdate() throws SQLException {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
Database database = metadata.getDatabase();
TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), "orm", new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
tableStructure.registerExportables(database);
// lets make sure the InitCommand is there
assertEquals(1, database.getDefaultNamespace().getTables().size());
Table table = database.getDefaultNamespace().getTables().iterator().next();
SqlStringGenerationContext context = SqlStringGenerationContextImpl.forTests(database.getJdbcEnvironment(), null, null);
assertEquals(1, table.getInitCommands(context).size());
final TargetImpl target = new TargetImpl();
ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return ssr.getService(ConfigurationService.class).getSettings();
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
@Override
public SchemaFilter getSchemaFilter() {
return SchemaFilter.ALL;
}
}, ContributableMatcher.ALL, new TargetDescriptor() {
@Override
public EnumSet<TargetType> getTargetTypes() {
return EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE);
}
@Override
public ScriptTargetOutput getScriptTargetOutput() {
return target;
}
});
assertTrue(target.found);
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
Aggregations