Example usage for org.hibernate.boot.registry StandardServiceRegistryBuilder applySettings

List of usage examples for org.hibernate.boot.registry StandardServiceRegistryBuilder applySettings

Introduction

In this page you can find the example usage for org.hibernate.boot.registry StandardServiceRegistryBuilder applySettings.

Prototype

@SuppressWarnings({ "unchecked", "UnusedDeclaration" })
public StandardServiceRegistryBuilder applySettings(Map settings) 

Source Link

Document

Apply a groups of setting values.

Usage

From source file:edu.nps.moves.mmowgli.hibernate.AbstractVHib.java

License:Open Source License

protected void init2() {
    if (initted2)
        return;//  ww w  .  ja  v  a  2s .c om
    initted2 = true;

    try {
        // Set up the mapping
        addAnnotatedClasses(getExampleMappedClass(), cnf);

        StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
        srb.applySettings(cnf.getProperties());
        srb.addService(EventListenerRegistry.class, new EventListenerRegistryImpl()); // have to add manually
        sr = srb.build();

        sf = cnf.buildSessionFactory(sr);
    } catch (Throwable ex) {
        commonInitCatch(ex);
    }
}

From source file:game.kalaha.util.HibernateUtil.java

License:Open Source License

private static SessionFactory buildSessionFactory() {
    try {//from   w  ww.  java2 s  . co m
        Configuration configuration = new Configuration().configure();

        StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

        serviceRegistryBuilder.applySettings(configuration.getProperties());

        ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
        return configuration.buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:mnzw.projekty.HiberUtil.java

public static SessionFactory getXMLSessionFactory() {
    try {//from  w  w  w  .java  2s  .c om
        File mappingDir = new File("src\\mnzw\\projekty\\mapowanie");
        Configuration config = new Configuration().configure();

        config.setProperty("hibernate.show_sql", "false");
        config.addDirectory(mappingDir);

        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
        registryBuilder.applySettings(config.getProperties());
        ServiceRegistry serviceRegistry = registryBuilder.build();

        SessionFactory sf = config.buildSessionFactory(serviceRegistry);

        return (sf);
    } catch (Throwable ex) {

        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:mnzw.projekty.HiberUtil.java

public static SessionFactory getANNSessionFactory() {
    try {/*w  w w . ja v  a2 s  . co m*/
        Configuration config = new Configuration().configure();
        config.setProperty("hibernate.show_sql", "false");

        config.addAnnotatedClass(Jezyki.class).addAnnotatedClass(JezykProgramowania.class)
                .addAnnotatedClass(Osoba.class).addAnnotatedClass(Kierownik.class)
                .addAnnotatedClass(Programista.class).addAnnotatedClass(Projekt.class)
                .addAnnotatedClass(Zapotrzebowanie.class).addAnnotatedClass(Zatrudnienie.class);

        config.setProperty("hibernate.show_sql", "false");
        //config.setProperty("hibernate.hbm2ddl.auto", "none");

        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
        registryBuilder.applySettings(config.getProperties());
        ServiceRegistry serviceRegistry = registryBuilder.build();

        SessionFactory sf = config.buildSessionFactory(serviceRegistry);

        return (sf);
    } catch (Throwable ex) {

        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:org.infinispan.test.hibernate.cache.commons.util.CacheTestUtil.java

License:LGPL

public static StandardServiceRegistryBuilder buildBaselineStandardServiceRegistryBuilder(String regionPrefix,
        boolean use2ndLevel, boolean useQueries, Class<? extends JtaPlatform> jtaPlatform) {
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();

    ssrb.applySettings(buildBaselineSettings(regionPrefix, use2ndLevel, useQueries, jtaPlatform));

    return ssrb;//from w  w  w .  ja  v  a2 s . com
}

From source file:org.infinispan.test.hibernate.cache.util.CacheTestUtil.java

License:LGPL

public static StandardServiceRegistryBuilder buildBaselineStandardServiceRegistryBuilder(String regionPrefix,
        Class regionFactory, boolean use2ndLevel, boolean useQueries,
        Class<? extends JtaPlatform> jtaPlatform) {
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();

    ssrb.applySettings(
            buildBaselineSettings(regionPrefix, regionFactory, use2ndLevel, useQueries, jtaPlatform));

    return ssrb;//  ww w.ja  v  a2s  . c  o  m
}

From source file:org.jooq.meta.extensions.jpa.JPADatabase.java

License:Apache License

@Override
protected DSLContext create0() {
    if (connection == null) {
        String packages = getProperties().getProperty("packages");

        if (isBlank(packages)) {
            packages = "";
            log.warn("No packages defined",
                    "It is highly recommended that you provide explicit packages to scan");
        }/* w w  w .  ja  va2 s. co m*/

        // [#9058] Properties use camelCase notation.
        boolean useAttributeConverters = Boolean.valueOf(getProperties().getProperty("useAttributeConverters",
                getProperties().getProperty("use-attribute-converters", "true")));
        String unqualifiedSchema = getProperties().getProperty("unqualifiedSchema", "none").toLowerCase();
        publicIsDefault = "none".equals(unqualifiedSchema);

        try {
            Properties info = new Properties();
            info.put("user", "sa");
            info.put("password", "");
            connection = new org.h2.Driver().connect("jdbc:h2:mem:jooq-meta-extensions-" + UUID.randomUUID(),
                    info);

            // [#6709] Apply default settings first, then allow custom overrides
            Map<String, Object> settings = new LinkedHashMap<>();
            settings.put("hibernate.dialect", HIBERNATE_DIALECT);
            settings.put("javax.persistence.schema-generation-connection", connection);
            settings.put("javax.persistence.create-database-schemas", true);

            // [#5607] JPADatabase causes warnings - This prevents them
            settings.put(AvailableSettings.CONNECTION_PROVIDER, connectionProvider());

            for (Entry<Object, Object> entry : getProperties().entrySet()) {
                String key = "" + entry.getKey();

                if (key.startsWith("hibernate.") || key.startsWith("javax.persistence."))
                    userSettings.put(key, entry.getValue());
            }
            settings.putAll(userSettings);

            StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
            builder.applySettings(settings);

            MetadataSources metadata = new MetadataSources(builder.applySettings(settings).build());

            ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
                    true);

            scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));

            // [#5845] Use the correct ClassLoader to load the jpa entity classes defined in the user project
            ClassLoader cl = Thread.currentThread().getContextClassLoader();

            for (String pkg : packages.split(","))
                for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim()))
                    metadata.addAnnotatedClass(Class.forName(def.getBeanClassName(), true, cl));

            // This seems to be the way to do this in idiomatic Hibernate 5.0 API
            // See also: http://stackoverflow.com/q/32178041/521799
            // SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata(), connection);
            // export.create(true, true);

            // Hibernate 5.2 broke 5.0 API again. Here's how to do this now:
            SchemaExport export = new SchemaExport();
            export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());

            if (useAttributeConverters)
                loadAttributeConverters(metadata.getAnnotatedClasses());
        } catch (Exception e) {
            throw new DataAccessException("Error while exporting schema", e);
        }
    }

    return DSL.using(connection);
}

From source file:org.lncc.martin.ct.dao.hibernate.HibernateUtil.java

License:Open Source License

public Session getConnection() {

    try {/*from   ww w  .ja  v a  2  s  . c om*/
        Configuration cfg = new Configuration().configure("hibernate.cfg.xml");

        StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder();
        sb.applySettings(cfg.getProperties());

        StandardServiceRegistry standardServiceRegistry = sb.build();

        sessionFactory = cfg.buildSessionFactory(standardServiceRegistry);

        return sessionFactory.openSession();

    } catch (Exception e) {
        System.out.println("Problemas ao criar Session Factory: " + e);
        return null;
    }
}

From source file:osdigital.dao.HibernateUtil.java

private static SessionFactory buildSessionFactory() {
    try {// ww  w . j av a2s . c  o  m
        Configuration cfg = new Configuration();
        cfg.configure("hibernate.cfg.xml");

        StandardServiceRegistryBuilder registradorServico = new StandardServiceRegistryBuilder();
        registradorServico.applySettings(cfg.getProperties());
        StandardServiceRegistry servico = registradorServico.build();
        return cfg.buildSessionFactory(servico);

    } catch (Throwable e) {
        // TODO: handle exception
        System.out.println("Criao inicial do Session Falhou. Erro !!" + e);
        throw new ExceptionInInitializerError(e);
    }

}

From source file:principal.HibernateUtil.java

private static SessionFactory buildSessionFactory() {
    try {/*w  w w .  j ava2 s . c o  m*/
        if (sessionFactory == null) {
            Configuration configuration = new Configuration()
                    .configure(HibernateUtil.class.getResource("/hibernate.cfg.xml"));
            StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
            serviceRegistryBuilder.applySettings(configuration.getProperties());
            ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        }
        return sessionFactory;
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed: " + ex);
        throw new ExceptionInInitializerError(ex);
    }
}