use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project dropwizard by dropwizard.
the class SessionFactoryFactory method buildSessionFactory.
private SessionFactory buildSessionFactory(HibernateBundle<?> bundle, PooledDataSourceFactory dbConfig, ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
final BootstrapServiceRegistry bootstrapServiceRegistry = configureBootstrapServiceRegistryBuilder(new BootstrapServiceRegistryBuilder()).build();
final Configuration configuration = new Configuration(bootstrapServiceRegistry);
configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS, Boolean.toString(dbConfig.isAutoCommentsEnabled()));
configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
for (Map.Entry<String, String> property : properties.entrySet()) {
configuration.setProperty(property.getKey(), property.getValue());
}
addAnnotatedClasses(configuration, entities);
bundle.configure(configuration);
final ServiceRegistry registry = new StandardServiceRegistryBuilder(bootstrapServiceRegistry).addService(ConnectionProvider.class, connectionProvider).applySettings(configuration.getProperties()).build();
configure(configuration, registry);
return configuration.buildSessionFactory(registry);
}
use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.
the class DialectFactoryTest method setUp.
@Before
public void setUp() {
final BootstrapServiceRegistry bootReg = new BootstrapServiceRegistryBuilder().applyClassLoader(DialectFactoryTest.class.getClassLoader()).build();
registry = new StandardServiceRegistryBuilder(bootReg).build();
dialectFactory = new DialectFactoryImpl();
dialectFactory.injectServices((ServiceRegistryImplementor) registry);
}
use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SchemaExport method buildStandardServiceRegistry.
private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs commandLineArgs) throws Exception {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
if (commandLineArgs.cfgXmlFile != null) {
ssrBuilder.configure(commandLineArgs.cfgXmlFile);
}
Properties properties = new Properties();
if (commandLineArgs.propertiesFile != null) {
properties.load(new FileInputStream(commandLineArgs.propertiesFile));
}
ssrBuilder.applySettings(properties);
return ssrBuilder.build();
}
use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SchemaExportTask method doExecution.
private void doExecution() throws Exception {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
final MetadataSources metadataSources = new MetadataSources(bsr);
if (configurationFile != null) {
ssrBuilder.configure(configurationFile);
}
if (propertiesFile != null) {
ssrBuilder.loadProperties(propertiesFile);
}
ssrBuilder.applySettings(getProject().getProperties());
for (String fileName : getFiles()) {
if (fileName.endsWith(".jar")) {
metadataSources.addJar(new File(fileName));
} else {
metadataSources.addFile(fileName);
}
}
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DELIMITER, delimiter);
ExportType exportType = ExportType.interpret(drop, create);
Target output = Target.interpret(!quiet, !text);
if (output.doScript()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_ACTION, exportType.getAction());
final Object scriptTarget;
if (outputFile == null) {
scriptTarget = new OutputStreamWriter(System.out);
} else {
scriptTarget = outputFile;
}
if (exportType.doCreate()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET, scriptTarget);
}
if (exportType.doDrop()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET, scriptTarget);
}
}
if (output.doExport()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DATABASE_ACTION, exportType.getAction());
}
final StandardServiceRegistryImpl ssr = (StandardServiceRegistryImpl) ssrBuilder.build();
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(ssr);
ClassLoaderService classLoaderService = bsr.getService(ClassLoaderService.class);
if (implicitNamingStrategy != null) {
metadataBuilder.applyImplicitNamingStrategy((ImplicitNamingStrategy) classLoaderService.classForName(implicitNamingStrategy).newInstance());
}
if (physicalNamingStrategy != null) {
metadataBuilder.applyPhysicalNamingStrategy((PhysicalNamingStrategy) classLoaderService.classForName(physicalNamingStrategy).newInstance());
}
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
metadata.validate();
SchemaManagementToolCoordinator.process(metadata, ssr, ssr.getService(ConfigurationService.class).getSettings(), DelayedDropRegistryNotAvailableImpl.INSTANCE);
}
use of org.hibernate.boot.registry.BootstrapServiceRegistryBuilder in project wildfly by wildfly.
the class SFSBHibernateSFNaturalId method setupConfig.
public void setupConfig() {
try {
final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build()).configure("hibernate.cfg.xml").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true").applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").applySetting(AvailableSettings.DATASOURCE, "java:jboss/datasources/ExampleDS").build();
final Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
sessionFactory = metadata.buildSessionFactory();
} catch (Throwable ex) {
throw new RuntimeException("Could not setup config", ex);
}
}
Aggregations