Search in sources :

Example 56 with MetadataImplementor

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 57 with MetadataImplementor

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);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Set(org.hibernate.mapping.Set) ValueVisitor(org.hibernate.mapping.ValueVisitor) DependantValue(org.hibernate.mapping.DependantValue) MetadataSources(org.hibernate.boot.MetadataSources) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IdentifierBag(org.hibernate.mapping.IdentifierBag) OneToMany(org.hibernate.mapping.OneToMany) Any(org.hibernate.mapping.Any) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) MetadataBuildingContextTestingImpl(org.hibernate.testing.boot.MetadataBuildingContextTestingImpl) Array(org.hibernate.mapping.Array) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) OneToOne(org.hibernate.mapping.OneToOne) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) List(org.hibernate.mapping.List) Component(org.hibernate.mapping.Component) Map(org.hibernate.mapping.Map) Test(org.junit.Test)

Example 58 with MetadataImplementor

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;
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistry(org.hibernate.service.ServiceRegistry) File(java.io.File) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) PhysicalNamingStrategy(org.hibernate.boot.model.naming.PhysicalNamingStrategy) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 59 with MetadataImplementor

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);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) Skip(org.hibernate.testing.Skip) TestForIssue(org.hibernate.testing.TestForIssue)

Example 60 with MetadataImplementor

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)113 MetadataSources (org.hibernate.boot.MetadataSources)80 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)62 Test (org.junit.Test)56 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)52 SimpleValue (org.hibernate.mapping.SimpleValue)32 RootClass (org.hibernate.mapping.RootClass)31 PersistentClass (org.hibernate.mapping.PersistentClass)27 TestForIssue (org.hibernate.testing.TestForIssue)26 Table (org.hibernate.mapping.Table)23 Test (org.junit.jupiter.api.Test)23 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)22 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)20 Column (org.hibernate.mapping.Column)17 ArrayList (java.util.ArrayList)15 ServiceRegistry (org.hibernate.service.ServiceRegistry)15 File (java.io.File)14 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)14 Configuration (org.hibernate.cfg.Configuration)12 Property (org.hibernate.mapping.Property)11