use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class UUIDBasedIdInterpretationTest method testBinaryRuntimeUsage.
@Test
@TestForIssue(jiraKey = "HHH-10564")
@RequiresDialect(H2Dialect.class)
public void testBinaryRuntimeUsage() {
StandardServiceRegistry ssr = buildStandardServiceRegistry(H2Dialect.class, true);
try {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UuidIdEntity.class).buildMetadata();
final SessionFactory sf = metadata.buildSessionFactory();
try {
Session s = sf.openSession();
try {
s.beginTransaction();
s.byId(UuidIdEntity.class).load(UUID.randomUUID());
s.getTransaction().commit();
} finally {
s.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class ConfigurationValidationTest method testInvalidConnectionProvider.
@Test(expected = ServiceException.class)
public void testInvalidConnectionProvider() {
ServiceRegistryImplementor serviceRegistry = null;
try {
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA).applySetting(Environment.MULTI_TENANT_CONNECTION_PROVIDER, "class.not.present.in.classpath").build();
new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory().close();
} finally {
if (serviceRegistry != null) {
try {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
} catch (Exception ignore) {
}
}
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class SchemaBasedMultiTenancyTest method setUp.
@Before
public void setUp() {
AbstractMultiTenantConnectionProvider multiTenantConnectionProvider = buildMultiTenantConnectionProvider();
Map settings = new HashMap();
settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(Environment.GENERATE_STATISTICS, "true");
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).addService(MultiTenantConnectionProvider.class, multiTenantConnectionProvider).build();
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Customer.class);
ms.addAnnotatedClass(Invoice.class);
Metadata metadata = ms.buildMetadata();
((RootClass) metadata.getEntityBinding(Customer.class.getName())).setCacheConcurrencyStrategy("read-write");
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase acmeTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, acmeProvider));
final GenerationTargetToDatabase jbossTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, jbossProvider));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
configure(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class Tests method testJpaJoinColumnPhysicalNaming.
@Test
@TestForIssue(jiraKey = "HHH-9961")
public void testJpaJoinColumnPhysicalNaming() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings(Environment.getProperties()).build();
try {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(Language.class);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE);
metadataBuilder.applyPhysicalNamingStrategy(PhysicalNamingStrategyImpl.INSTANCE);
final Metadata metadata = metadataBuilder.build();
((MetadataImplementor) metadata).validate();
final PersistentClass languageBinding = metadata.getEntityBinding(Language.class.getName());
final Property property = languageBinding.getProperty("fallBack");
Iterator itr = property.getValue().getColumnIterator();
assertTrue(itr.hasNext());
final Column column = (Column) itr.next();
assertFalse(itr.hasNext());
assertEquals("C_FALLBACK_ID", column.getName().toUpperCase(Locale.ROOT));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class SynchronizeTableNamingTest method testAnnotationHandling.
@Test
public void testAnnotationHandling() {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(DynamicEntity.class).getMetadataBuilder().applyPhysicalNamingStrategy(TestingPhysicalNamingStrategy.INSTANCE).build();
verify(metadata.getEntityBinding(DynamicEntity.class.getName()));
}
Aggregations