use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class SchemaValidatorTask method execute.
/**
* Execute the task
*/
@Override
public void execute() throws BuildException {
try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure(ssrBuilder);
final StandardServiceRegistry ssr = ssrBuilder.build();
try {
final MetadataSources metadataSources = new MetadataSources(ssrBuilder.build());
configure(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
configure(metadataBuilder, ssr);
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
new SchemaValidator().validate(metadata, ssr);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
} catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class HANASchemaMigrationTargetScriptCreationTest 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 SqlServerQuoteSchemaTest method test.
@Test
public void test() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
try {
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
try {
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("create table \\[my\\-schema\\]\\.\\[my_entity\\]");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} catch (IOException e) {
fail(e.getMessage());
}
ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntityUpdated.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
try {
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("alter table .*?\\.\\[my\\-schema\\]\\.\\[my_entity\\]");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} catch (IOException e) {
fail(e.getMessage());
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class SchemaExportTest method testHibernateMappingSchemaPropertyIsNotIgnored.
@Test
@TestForIssue(jiraKey = "HHH-10678")
@RequiresDialectFeature(value = DialectChecks.SupportSchemaCreation.class)
public void testHibernateMappingSchemaPropertyIsNotIgnored() throws Exception {
File output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource("org/hibernate/test/schemaupdate/mapping2.hbm.xml").buildMetadata();
metadata.validate();
final SchemaExport schemaExport = new SchemaExport();
schemaExport.setOutputFile(output.getAbsolutePath());
schemaExport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("create( (column|row))? table schema1.version");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContent, fileContentMatcher.find(), is(true));
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class SchemaUpdateFormatterTest method testSetFormat.
@Test
public void testSetFormat() 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(DELIMITER).setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String outputContent = new String(Files.readAllBytes(output.toPath()));
// Old Macs use \r as a new line delimiter
outputContent = outputContent.replaceAll("\r", "\n");
// On Windows, \r\n would become \n\n, so we eliminate duplicates
outputContent = outputContent.replaceAll("\n\n", "\n");
Assert.assertTrue(Pattern.compile(AFTER_FORMAT).matcher(outputContent).matches());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations