Search in sources :

Example 26 with ServiceRegistry

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);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ServiceRegistry(org.hibernate.service.ServiceRegistry) Session(org.hibernate.Session)

Example 27 with ServiceRegistry

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);
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Example 28 with ServiceRegistry

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);
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistry(org.hibernate.service.ServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) After(org.junit.After)

Example 29 with 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);
}
Also used : ServiceRegistry(org.hibernate.service.ServiceRegistry) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map)

Example 30 with ServiceRegistry

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();
            }
        }
    }
}
Also used : ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Aggregations

ServiceRegistry (org.hibernate.service.ServiceRegistry)48 Test (org.junit.Test)27 MetadataSources (org.hibernate.boot.MetadataSources)18 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)17 Configuration (org.hibernate.cfg.Configuration)14 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)11 AnnotationException (org.hibernate.AnnotationException)6 MappingException (org.hibernate.MappingException)6 SessionFactory (org.hibernate.SessionFactory)6 Metadata (org.hibernate.boot.Metadata)6 TestForIssue (org.hibernate.testing.TestForIssue)5 Map (java.util.Map)4 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)4 HibernateException (org.hibernate.HibernateException)3 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)3 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)3 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2