Search in sources :

Example 6 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class UniqueConstraintDropTest method setUp.

@Before
public void setUp() throws Exception {
    output = File.createTempFile("update_script", ".sql");
    output.deleteOnExit();
    ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").applySetting(Environment.FORMAT_SQL, "false").applySetting(Environment.SHOW_SQL, "true").build();
    metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/uniqueconstraint/TestEntity.hbm.xml").buildMetadata();
    metadata.validate();
    tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    options = new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return configurationValues;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    };
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map) Before(org.junit.Before)

Example 7 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class JoinTableWithDefaultSchemaTest method testGetTableDataForJoinTableWithDefaultSchema.

@Test
@TestForIssue(jiraKey = "HHH-10978")
@RequiresDialect(SQLServerDialect.class)
public void testGetTableDataForJoinTableWithDefaultSchema() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CATALOG, "hibernate_orm_test").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false").build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Task.class).addAnnotatedClass(Project.class).buildMetadata();
        metadata.validate();
        // first create the schema...
        new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
        try {
            // validate the schema
            new SchemaValidator().validate(metadata);
        } finally {
            // cleanup
            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) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 8 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class LongVarcharValidationTest method testValidation.

@Test
public void testValidation() {
    MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Translation.class).buildMetadata();
    metadata.validate();
    // create the schema
    createSchema(metadata);
    try {
        doValidation(metadata);
    } finally {
        dropSchema(metadata);
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Test(org.junit.Test)

Example 9 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class SynonymValidationTest method testSynonymUsingIndividuallySchemaValidator.

@Test
public void testSynonymUsingIndividuallySchemaValidator() {
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.ENABLE_SYNONYMS, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, JdbcMetadaAccessStrategy.INDIVIDUALLY).build();
    try {
        final MetadataSources metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(TestEntityWithSynonym.class);
        metadataSources.addAnnotatedClass(TestEntity.class);
        new SchemaValidator().validate(metadataSources.buildMetadata());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) Test(org.junit.Test)

Example 10 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class BasicModelingTest method testMetamodelBuilding.

@Test
@TestForIssue(jiraKey = "HHH-9042")
public void testMetamodelBuilding() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Person.class).getMetadataBuilder().applyAttributeConverter(SexConverter.class).build();
        ((MetadataImpl) metadata).validate();
        PersistentClass personBinding = metadata.getEntityBinding(Person.class.getName());
        assertNotNull(personBinding);
        PersistentClass personAuditBinding = metadata.getEntityBinding(Person.class.getName() + "_AUD");
        assertNotNull(personAuditBinding);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : MetadataImpl(org.hibernate.boot.internal.MetadataImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) AbstractEnversTest(org.hibernate.envers.test.AbstractEnversTest) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)187 Test (org.junit.Test)133 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)104 Metadata (org.hibernate.boot.Metadata)87 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)73 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)58 TestForIssue (org.hibernate.testing.TestForIssue)47 PersistentClass (org.hibernate.mapping.PersistentClass)36 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)30 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)19 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)18 Before (org.junit.Before)18 Property (org.hibernate.mapping.Property)17 File (java.io.File)14 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)14 Map (java.util.Map)13 MetadataBuilder (org.hibernate.boot.MetadataBuilder)12 Type (org.hibernate.type.Type)12 SimpleValue (org.hibernate.mapping.SimpleValue)11