use of org.hibernate.service.ServiceRegistry in project yyl_example by Relucent.
the class HibernateTest method main.
public static void main(String[] args) {
Configuration configuration = new Configuration().configure("/yyl/example/demo/hibernate/config/hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = null;
Session session = null;
try {
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
test1(sessionFactory);
test2(sessionFactory);
test3(sessionFactory);
} finally {
closeQuietly(session);
closeQuietly(sessionFactory);
}
}
use of org.hibernate.service.ServiceRegistry in project ice by JBEI.
the class HibernateUtil method initialize.
private static synchronized void initialize(Type type) {
if (sessionFactory == null) {
Logger.info("Initializing session factory for type " + type.name());
final Configuration configuration = new Configuration();
try {
if (type == Type.MOCK) {
configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configuration.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
configuration.setProperty("hibernate.connection.username", "sa");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
configuration.setProperty("hibernate.current_session_context_class", "org.hibernate.context.internal.ThreadLocalSessionContext");
configuration.setProperty("hibernate.hbm2ddl.auto", "update");
configuration.setProperty("hibernate.search.default.directory_provider", "org.hibernate.search.store.impl.RAMDirectoryProvider");
} else {
configuration.configure();
}
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Entry.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Plasmid.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Strain.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Part.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ArabidopsisSeed.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Link.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.SelectionMarker.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Sequence.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Feature.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.SequenceFeature.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.SequenceFeatureAttribute.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Comment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Account.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Attachment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Sample.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.AccountPreferences.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Group.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.TraceSequence.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.TraceSequenceAlignment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Configuration.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Storage.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Folder.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Parameter.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.AnnotationLocation.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.BulkUpload.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Permission.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Message.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Preference.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemotePartner.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Request.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Audit.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Experiment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ShotgunSequence.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Configuration.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ApiKey.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemoteClientModel.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemoteShareModel.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemoteAccessModel.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ManuscriptModel.class);
configuration.addAnnotatedClass(FeatureCurationModel.class);
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaMigrationTargetScriptCreationTest method tearDown.
@After
public void tearDown() {
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(TestEntity.class).buildMetadata();
metadata.validate();
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaUpdateHelper method toWriter.
public static void toWriter(Metadata metadata, Writer writer) {
final ServiceRegistry serviceRegistry = ((MetadataImplementor) metadata).getMetadataBuildingOptions().getServiceRegistry();
final Map settings = serviceRegistry.getService(ConfigurationService.class).getSettings();
settings.put(AvailableSettings.HBM2DDL_SCRIPTS_ACTION, Action.UPDATE);
// atm we reuse the CREATE scripts setting
settings.put(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET, writer);
SchemaManagementToolCoordinator.process(metadata, serviceRegistry, settings, DelayedDropRegistryNotAvailableImpl.INSTANCE);
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class BootstrapServiceRegistryImpl method destroy.
@Override
public void destroy() {
if (!active) {
return;
}
active = false;
destroy(classLoaderServiceBinding);
destroy(strategySelectorBinding);
destroy(integratorServiceBinding);
if (childRegistries != null) {
for (ServiceRegistry serviceRegistry : childRegistries) {
if (serviceRegistry instanceof ServiceRegistryImplementor) {
ServiceRegistryImplementor serviceRegistryImplementor = (ServiceRegistryImplementor) serviceRegistry;
serviceRegistryImplementor.destroy();
}
}
}
}
Aggregations