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);
}
}
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);
}
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);
}
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();
}
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());
}
Aggregations