use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class MigrationTest method testSameTableNameDifferentExplicitSchemas.
@Test
@TestForIssue(jiraKey = "HHH-9550")
public void testSameTableNameDifferentExplicitSchemas() {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(CustomerInfo.class).addAnnotatedClass(PersonInfo.class).buildMetadata();
// drop and then create the schema
new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.BOTH, metadata);
try {
// update the schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
// drop the schema
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class MigrationTest method testIndexCreationViaSchemaUpdate.
// /**
// * 3_Version.hbm.xml contains a named unique constraint and an un-named
// * unique constraint (will receive a randomly-generated name). Create
// * the original schema with 2_Version.hbm.xml. Then, run SchemaUpdate
// * TWICE using 3_Version.hbm.xml. Neither RECREATE_QUIETLY nor SKIP should
// * generate any exceptions.
// */
// @Test
// @TestForIssue( jiraKey = "HHH-8162" )
// public void testConstraintUpdate() {
// doConstraintUpdate(UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY);
// doConstraintUpdate(UniqueConstraintSchemaUpdateStrategy.RECREATE_QUIETLY);
// doConstraintUpdate(UniqueConstraintSchemaUpdateStrategy.SKIP);
// }
//
// private void doConstraintUpdate(UniqueConstraintSchemaUpdateStrategy strategy) {
// // original
// String resource1 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";
// // adds unique constraint
// String resource2 = "org/hibernate/test/schemaupdate/3_Version.hbm.xml";
//
// MetadataImplementor v1metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
// .addResource( resource1 )
// .buildMetadata();
// MetadataImplementor v2metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
// .addResource( resource2 )
// .buildMetadata();
//
// new SchemaExport( v1metadata ).execute( false, true, true, false );
//
// // adds unique constraint
// Configuration v2cfg = new Configuration();
// v2cfg.getProperties().put( AvailableSettings.UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY, strategy );
// v2cfg.addResource( resource2 );
// SchemaUpdate v2schemaUpdate = new SchemaUpdate( serviceRegistry, v2cfg );
// v2schemaUpdate.execute( true, true );
// assertEquals( 0, v2schemaUpdate.getExceptions().size() );
//
// Configuration v3cfg = new Configuration();
// v3cfg.getProperties().put( AvailableSettings.UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY, strategy );
// v3cfg.addResource( resource2 );
// SchemaUpdate v3schemaUpdate = new SchemaUpdate( serviceRegistry, v3cfg );
// v3schemaUpdate.execute( true, true );
// assertEquals( 0, v3schemaUpdate.getExceptions().size() );
//
// new SchemaExport( serviceRegistry, v3cfg ).drop( false, true );
// }
@Test
@TestForIssue(jiraKey = "HHH-9713")
public void testIndexCreationViaSchemaUpdate() {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(EntityWithIndex.class).buildMetadata();
// drop and then create the schema
new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.BOTH, metadata);
try {
// update the schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
// drop the schema
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class SchemaUpdateSQLServerTest method testSchemaUpdateAndValidation.
@Test
public void testSchemaUpdateAndValidation() throws Exception {
if (!SQLServerDialect.class.isAssignableFrom(Dialect.getDialect().getClass())) {
return;
}
new SchemaUpdate().setHaltOnError(true).execute(EnumSet.of(TargetType.DATABASE), metadata);
new SchemaValidator().validate(metadata);
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
final String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat("The update output file should be empty", fileContent, is(""));
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class SchemaUpdateTest method testSchemaUpdateAndValidation.
@Test
public void testSchemaUpdateAndValidation() throws Exception {
if (skipTest) {
SkipLog.reportSkip("skipping test because quoted names are not case-sensitive.");
return;
}
new SchemaUpdate().setHaltOnError(true).execute(EnumSet.of(TargetType.DATABASE), metadata);
new SchemaValidator().validate(metadata);
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
final String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat("The update output file should be empty", fileContent, is(""));
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class SchemaUpdateGeneratingOnlyScriptFileTest method testSchemaUpdateScriptGeneration.
@Test
public void testSchemaUpdateScriptGeneration() 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(";").setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("create( (column|row))? table test_entity");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations