use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class OsgiSessionFactoryService method buildSessionFactory.
private Object buildSessionFactory(Bundle requestingBundle, OsgiClassLoader osgiClassLoader) {
final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
bsrBuilder.applyClassLoaderService(new OSGiClassLoaderServiceImpl(osgiClassLoader, osgiServiceUtil));
final Integrator[] integrators = osgiServiceUtil.getServiceImpls(Integrator.class);
for (Integrator integrator : integrators) {
bsrBuilder.applyIntegrator(integrator);
}
final StrategyRegistrationProvider[] strategyRegistrationProviders = osgiServiceUtil.getServiceImpls(StrategyRegistrationProvider.class);
for (StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviders) {
bsrBuilder.applyStrategySelectors(strategyRegistrationProvider);
}
final BootstrapServiceRegistry bsr = bsrBuilder.build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
// Allow bundles to put the config file somewhere other than the root level.
final BundleWiring bundleWiring = (BundleWiring) requestingBundle.adapt(BundleWiring.class);
final Collection<String> cfgResources = bundleWiring.listResources("/", "hibernate.cfg.xml", BundleWiring.LISTRESOURCES_RECURSE);
if (cfgResources.size() == 0) {
ssrBuilder.configure();
} else {
if (cfgResources.size() > 1) {
LOG.warn("Multiple hibernate.cfg.xml files found in the persistence bundle. Using the first one discovered.");
}
String cfgResource = "/" + cfgResources.iterator().next();
ssrBuilder.configure(cfgResource);
}
ssrBuilder.applySetting(AvailableSettings.JTA_PLATFORM, osgiJtaPlatform);
final StandardServiceRegistry ssr = ssrBuilder.build();
final MetadataBuilder metadataBuilder = new MetadataSources(ssr).getMetadataBuilder();
final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls(TypeContributor.class);
for (TypeContributor typeContributor : typeContributors) {
metadataBuilder.applyTypes(typeContributor);
}
return metadataBuilder.build().buildSessionFactory();
}
use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class BaseNonConfigCoreFunctionalTestCase method buildResources.
protected void buildResources() {
final StandardServiceRegistryBuilder ssrb = constructStandardServiceRegistryBuilder();
serviceRegistry = ssrb.build();
afterStandardServiceRegistryBuilt(serviceRegistry);
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
applyMetadataSources(metadataSources);
afterMetadataSourcesApplied(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
initialize(metadataBuilder);
configureMetadataBuilder(metadataBuilder);
metadata = (MetadataImplementor) metadataBuilder.build();
applyCacheSettings(metadata);
afterMetadataBuilt(metadata);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
initialize(sfb, metadata);
configureSessionFactoryBuilder(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
afterSessionFactoryBuilt(sessionFactory);
}
use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class IdentityGeneratorExtendsTest method testIdentifierGeneratorExtendsIdentityGenerator.
@Test
public void testIdentifierGeneratorExtendsIdentityGenerator() {
final MetadataSources sources = new MetadataSources(serviceRegistry());
sources.addAnnotatedClass(EntityBean.class);
final MetadataBuilder builder = sources.getMetadataBuilder();
final Metadata metadata = builder.build();
for (final Namespace ns : metadata.getDatabase().getNamespaces()) {
for (final org.hibernate.mapping.Table table : ns.getTables()) {
final KeyValue value = table.getIdentifierValue();
assertNotNull("IdentifierValue was null", value);
assertTrue(value.isIdentityColumn(metadata.getIdentifierGeneratorFactory(), getDialect()));
}
}
Session s = openSession();
s.beginTransaction();
s.save(new EntityBean());
s.getTransaction().commit();
s.close();
}
use of org.hibernate.boot.MetadataBuilder 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.MetadataBuilder in project hibernate-orm by hibernate.
the class SchemaUpdate method buildMetadata.
private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, ServiceRegistry serviceRegistry) throws Exception {
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (String filename : parsedArgs.hbmXmlFiles) {
metadataSources.addFile(filename);
}
for (String filename : parsedArgs.jarFiles) {
metadataSources.addJar(new File(filename));
}
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
if (parsedArgs.implicitNamingStrategyImplName != null) {
metadataBuilder.applyImplicitNamingStrategy(strategySelector.resolveStrategy(ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName));
}
if (parsedArgs.physicalNamingStrategyImplName != null) {
metadataBuilder.applyPhysicalNamingStrategy(strategySelector.resolveStrategy(PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName));
}
return (MetadataImplementor) metadataBuilder.build();
}
Aggregations