use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class SchemaMigrationTargetScriptCreationTest method tearDown.
@After
public void tearDown() {
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(TestEntity.class).buildMetadata();
metadata.validate();
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class SchemaUpdateDelimiterTest method testSchemaUpdateApplyDelimiterToGeneratedSQL.
@Test
public void testSchemaUpdateApplyDelimiterToGeneratedSQL() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").build();
try {
File output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(EXPECTED_DELIMITER).setFormat(false).execute(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
for (String line : sqlLines) {
assertThat("The expected delimiter is not applied " + line, line.endsWith(EXPECTED_DELIMITER), is(true));
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class OracleLongLobTypeTest method check.
private void check(Class<? extends Dialect> dialectClass, Class entityClass, Class<? extends Type> binaryTypeClass, Class<? extends Type> charTypeClass, boolean preferLongRaw) {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, dialectClass.getName()).applySetting(Oracle12cDialect.PREFER_LONG_RAW, Boolean.toString(preferLongRaw)).applySetting("hibernate.temp.use_jdbc_metadata_defaults", false).build();
try {
final MetadataImplementor mappings = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(entityClass).buildMetadata();
mappings.validate();
final PersistentClass entityBinding = mappings.getEntityBinding(entityClass.getName());
assertThat(entityBinding.getProperty("binaryData").getType(), instanceOf(binaryTypeClass));
assertThat(entityBinding.getProperty("characterData").getType(), instanceOf(charTypeClass));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMismatchColumnType.
@Test
public void testMismatchColumnType() throws Exception {
MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NameColumn.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
Map<String, Object> settings = new HashMap<>();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(properties());
final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
try {
new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(IntegerNameColumn.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [varchar (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]", e.getMessage());
}
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
serviceRegistry.destroy();
connectionProvider.stop();
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class LegacySequenceExportTest method testMultipleUsesOfDefaultSequenceName.
@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfDefaultSequenceName() {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity1.class).addAnnotatedClass(Entity2.class).buildMetadata();
metadata.validate();
assertEquals(0, metadata.getDatabase().getAuxiliaryDatabaseObjects().size());
int count = 0;
for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
for (Sequence sequence : namespace.getSequences()) {
count++;
}
}
assertEquals(1, count);
}
Aggregations