Java Code Examples for org.hibernate.service.ServiceRegistryBuilder#applySetting()

The following examples show how to use org.hibernate.service.ServiceRegistryBuilder#applySetting() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateFabric.java    From r-course with MIT License 5 votes vote down vote up
/**
 * Configuration of session factory with Fabric integration.
 */
public static SessionFactory createSessionFactory(String fabricUrl, String username, String password, String fabricUser, String fabricPassword)
        throws Exception {
    // creating this here allows passing needed params to the constructor
    FabricMultiTenantConnectionProvider connProvider = new FabricMultiTenantConnectionProvider(fabricUrl, "employees", "employees", username, password,
            fabricUser, fabricPassword);
    ServiceRegistryBuilder srb = new ServiceRegistryBuilder();
    srb.addService(org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider.class, connProvider);
    srb.applySetting("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");

    Configuration config = new Configuration();
    config.setProperty("hibernate.multiTenancy", "DATABASE");
    config.addResource("com/mysql/fabric/demo/employee.hbm.xml");
    return config.buildSessionFactory(srb.buildServiceRegistry());
}
 
Example 2
Source File: HibernateFabric.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configuration of session factory with Fabric integration.
 */
public static SessionFactory createSessionFactory(String fabricUrl, String username, String password, String fabricUser, String fabricPassword)
        throws Exception {
    // creating this here allows passing needed params to the constructor
    FabricMultiTenantConnectionProvider connProvider = new FabricMultiTenantConnectionProvider(fabricUrl, "employees", "employees", username, password,
            fabricUser, fabricPassword);
    ServiceRegistryBuilder srb = new ServiceRegistryBuilder();
    srb.addService(org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider.class, connProvider);
    srb.applySetting("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");

    Configuration config = new Configuration();
    config.setProperty("hibernate.multiTenancy", "DATABASE");
    config.addResource("com/mysql/fabric/demo/employee.hbm.xml");
    return config.buildSessionFactory(srb.buildServiceRegistry());
}
 
Example 3
Source File: HibernateL2CacheConfigurationSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(igniteInstanceName);

    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);
    builder.applySetting("hibernate.show_sql", false);

    return cfg.buildSessionFactory(builder.buildServiceRegistry());
}
 
Example 4
Source File: HibernateL2CacheStrategySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param accessType Cache access typr.
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(accessType, igniteInstanceName);

    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);
    builder.applySetting("hibernate.show_sql", false);

    return cfg.buildSessionFactory(builder.buildServiceRegistry());
}
 
Example 5
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Hibernate registry builder.
 */
protected ServiceRegistryBuilder registryBuilder() {
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    return builder;
}
 
Example 6
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Starts Hibernate.
 *
 * @param accessType Cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(accessType, igniteInstanceName);

    ServiceRegistryBuilder builder = registryBuilder();

    builder.applySetting("hibernate.show_sql", false);

    return cfg.buildSessionFactory(builder.buildServiceRegistry());
}
 
Example 7
Source File: HibernateL2CacheMultiJvmTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
SessionFactory startHibernate(String igniteInstanceName) {
    log.info("Start hibernate on node: " + igniteInstanceName);

    Configuration cfg = hibernateConfiguration(igniteInstanceName);

    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    return cfg.buildSessionFactory(builder.buildServiceRegistry());
}