Search in sources :

Example 21 with MetadataSources

use of org.hibernate.boot.MetadataSources 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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) HibernateException(org.hibernate.HibernateException) MetadataSources(org.hibernate.boot.MetadataSources) FileNotFoundException(java.io.FileNotFoundException) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException) HibernateException(org.hibernate.HibernateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 22 with MetadataSources

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

the class SequenceHiLoGeneratorNoIncrementTest method setUp.

@Before
public void setUp() throws Exception {
    serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    generator = new SequenceStyleGenerator();
    // Build the properties used to configure the id generator
    Properties properties = new Properties();
    properties.setProperty(SequenceStyleGenerator.SEQUENCE_PARAM, TEST_SEQUENCE);
    properties.setProperty(SequenceStyleGenerator.OPT_PARAM, "legacy-hilo");
    // JPA allocationSize of 1
    properties.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "0");
    properties.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() {

        @Override
        protected MetadataBuildingContext getBuildingContext() {
            return new MetadataBuildingContextTestingImpl(serviceRegistry);
        }
    });
    generator.configure(StandardBasicTypes.LONG, properties, serviceRegistry);
    final Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
    generator.registerExportables(metadata.getDatabase());
    sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    sequenceValueExtractor = new SequenceValueExtractor(sessionFactory.getDialect(), TEST_SEQUENCE);
}
Also used : MetadataBuildingContextTestingImpl(org.hibernate.testing.boot.MetadataBuildingContextTestingImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) Properties(java.util.Properties) Before(org.junit.Before)

Example 23 with MetadataSources

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

the class SequenceHiLoGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    MetadataBuildingContext buildingContext = new MetadataBuildingContextTestingImpl(serviceRegistry);
    Properties properties = new Properties();
    properties.setProperty(SequenceGenerator.SEQUENCE, TEST_SEQUENCE);
    properties.setProperty(SequenceHiLoGenerator.MAX_LO, "3");
    properties.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, buildingContext.getObjectNameNormalizer());
    generator = new SequenceHiLoGenerator();
    generator.configure(StandardBasicTypes.LONG, properties, serviceRegistry);
    Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
    generator.registerExportables(metadata.getDatabase());
    sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    sequenceValueExtractor = new SequenceValueExtractor(sessionFactory.getDialect(), TEST_SEQUENCE);
}
Also used : MetadataBuildingContextTestingImpl(org.hibernate.testing.boot.MetadataBuildingContextTestingImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) Properties(java.util.Properties) Before(org.junit.Before)

Example 24 with MetadataSources

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

the class MetadataTest method testBuildingMetamodelWithParameterizedCollection.

@Test
@SuppressWarnings({ "unchecked" })
public void testBuildingMetamodelWithParameterizedCollection() {
    Metadata metadata = new MetadataSources().addAnnotatedClass(WithGenericCollection.class).buildMetadata();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory();
    MetamodelImpl metamodel = new MetamodelImpl(sfi);
    metamodel.initialize((MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED);
    sfi.close();
}
Also used : MetamodelImpl(org.hibernate.metamodel.internal.MetamodelImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 25 with MetadataSources

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

the class GetAndIsVariantGetterTest method testAnnotationsFieldAccess.

@Test
@TestForIssue(jiraKey = "HHH-10309")
public void testAnnotationsFieldAccess() {
    // this one should be ok because the AccessType is FIELD
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(AnotherEntity.class).buildMetadata();
    assertNotNull(metadata.getEntityBinding(AnotherEntity.class.getName()).getIdentifier());
    assertNotNull(metadata.getEntityBinding(AnotherEntity.class.getName()).getIdentifierProperty());
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test) 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