use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class QueryReturnTest method testQueryReturn.
@Test
public void testQueryReturn() {
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
StandardServiceRegistry standardServiceRegistry = serviceRegistryBuilder.build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
try {
metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML)));
Metadata metadata = metadataSources.buildMetadata();
NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery");
Assert.assertNotNull(myQuery);
NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns();
Assert.assertNotNull(myQueryReturns);
Assert.assertEquals(1, myQueryReturns.length);
Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0]));
NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn) myQueryReturns[0];
Assert.assertEquals("e", myQueryRootReturn.getAlias());
Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName());
} finally {
if (standardServiceRegistry instanceof StandardServiceRegistryImpl) {
((StandardServiceRegistryImpl) standardServiceRegistry).destroy();
}
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class UniqueDelegateTest method testUniqueDelegateConsulted.
@Test
@TestForIssue(jiraKey = "HHH-10203")
public void testUniqueDelegateConsulted() {
final Metadata metadata = new MetadataSources(ssr).addResource("org/hibernate/test/hbm/uk/person_unique.hbm.xml").buildMetadata();
final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
new SchemaDropperImpl(ssr).doDrop(metadata, false, target);
// unique keys are not dropped explicitly
assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class CollectionPkTest method verifyPkNameUsed.
private void verifyPkNameUsed(String mappingResource, String expectedName) {
final Metadata metadata = new MetadataSources(ssr).addResource(mappingResource).buildMetadata();
final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
assertTrue("Expected foreign-key name [" + expectedName + "] not seen in schema creation output", target.containedText(expectedName));
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class DisabledForeignKeyTest method expandedTests.
@Test
@TestForIssue(jiraKey = "HHH-9704")
public void expandedTests() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
StandardServiceRegistry standardRegistry = registryBuilder.build();
try {
final MetadataSources sources = new MetadataSources(standardRegistry);
sources.addAnnotatedClass(ManyToManyOwner.class);
sources.addAnnotatedClass(ManyToManyTarget.class);
final MetadataImplementor metadata = (MetadataImplementor) sources.buildMetadata();
metadata.validate();
// export the schema
new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.BOTH, metadata);
try {
// update the schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
// drop the schema
new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.DROP, metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(standardRegistry);
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class ExtendsTest method testAllSeparateInOne.
@Test
public void testAllSeparateInOne() {
Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml").buildMetadata();
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Customer"));
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Person"));
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Employee"));
}
Aggregations