use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class ForeignKeyMigrationTest method testMigrationOfForeignKeys.
@Test
@TestForIssue(jiraKey = "HHH-9716")
public // @FailureExpected( jiraKey = "HHH-9716" )
void testMigrationOfForeignKeys() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Box.class).addAnnotatedClass(Thing.class).buildMetadata();
metadata.validate();
// first create the schema...
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
try {
// try to update the just created schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
// clean up
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class ValueVisitorTest method testProperCallbacks.
@Test
public void testProperCallbacks() {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
final Table tbl = new Table();
final RootClass rootClass = new RootClass(metadataBuildingContext);
ValueVisitor vv = new ValueVisitorValidator();
MetadataBuildingContextTestingImpl metadataBuildingContext = new MetadataBuildingContextTestingImpl();
new Any(metadataBuildingContext, tbl).accept(vv);
new Array(metadataBuildingContext, rootClass).accept(vv);
new Bag(metadataBuildingContext, rootClass).accept(vv);
new Component(metadataBuildingContext, rootClass).accept(vv);
new DependantValue(metadataBuildingContext, tbl, null).accept(vv);
new IdentifierBag(metadataBuildingContext, rootClass).accept(vv);
new List(metadataBuildingContext, rootClass).accept(vv);
new ManyToOne(metadataBuildingContext, tbl).accept(vv);
new Map(metadataBuildingContext, rootClass).accept(vv);
new OneToMany(metadataBuildingContext, rootClass).accept(vv);
new OneToOne(metadataBuildingContext, tbl, rootClass).accept(vv);
new PrimitiveArray(metadataBuildingContext, rootClass).accept(vv);
new Set(metadataBuildingContext, rootClass).accept(vv);
new SimpleValue(metadataBuildingContext).accept(vv);
}
use of org.hibernate.boot.spi.MetadataImplementor in project zhcet-web by zhcet-amu.
the class Hibernate5DDLExporter method schemaExport.
private Hibernate5DDLExporter schemaExport(String fileName, String targetDirectory) throws Exception {
if (entityPackages == null && entityPackages.length == 0) {
System.out.println("Not packages selected");
System.exit(0);
}
File exportFile = createExportFileAndMakeDirectory(fileName, targetDirectory);
PhysicalNamingStrategy physicalNamingStrategy;
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, dialect).applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy").build();
MetadataImplementor metadata = (MetadataImplementor) mapAnnotatedClasses(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.setOutputFile(exportFile.getAbsolutePath());
schemaExport.setDelimiter(";");
schemaExport.setFormat(true);
schemaExport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, serviceRegistry);
((StandardServiceRegistryImpl) serviceRegistry).destroy();
System.out.println(exportFile.getAbsolutePath());
return this;
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class QuotedTableNameSchemaUpdateTest method testSchemaUpdateWithQuotedTableName.
@Test
@TestForIssue(jiraKey = "HHH-10820")
@Skip(condition = Skip.OperatingSystem.Windows.class, message = "On Windows, MySQL is case insensitive!")
public void testSchemaUpdateWithQuotedTableName() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(QuotedTable.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
new SchemaExport().setOutputFile(output.getAbsolutePath()).setFormat(false).create(EnumSet.of(TargetType.DATABASE), metadata);
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
final List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
assertThat("The update should recognize the existing table", sqlLines.isEmpty(), is(true));
new SchemaExport().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).drop(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class QuotedTableNameWithForeignKeysSchemaUpdateTest method testUpdateExistingSchema.
@Test
public void testUpdateExistingSchema() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/UserGroup.hbm.xml").buildMetadata();
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations