Java 类org.hibernate.boot.registry.StandardServiceRegistry 实例源码

项目:module-template    文件:HbConnectionTest.java   
@BeforeClass
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
项目:pipe    文件:Hib.java   
private static void init() {
    // 从hibernate.cfg.xml文件初始化
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        // build 一个sessionFactory
        sessionFactory = new MetadataSources(registry)
                .buildMetadata()
                .buildSessionFactory();
    } catch (Exception e) {
        e.printStackTrace();
        // 错误则打印输出,并销毁
        StandardServiceRegistryBuilder.destroy(registry);
    }
}
项目:lams    文件:MetadataBuilderImpl.java   
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
    if ( serviceRegistry == null ) {
        throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
    }

    if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
        return ( StandardServiceRegistry ) serviceRegistry;
    }
    else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
        log.debugf(
                "ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
                        "if attempt is made to build SessionFactory"
        );
        return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
    }
    else {
        throw new HibernateException(
                String.format(
                        "Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
                        serviceRegistry.getClass().getName()
                )
        );
    }
}
项目:training-sample    文件:HibernateUserDao.java   
public HibernateUserDao() {
    // hibernate5
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had
        // trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);
    }

    // hibernate4
    // try {
    // // Create the SessionFactory from hibernate.cfg.xml
    // sessionFactory = new
    // Configuration().configure().buildSessionFactory();
    // } catch (Throwable ex) {
    // // Make sure you log the exception, as it might be swallowed
    // System.err.println("Initial SessionFactory creation failed." + ex);
    // throw new ExceptionInInitializerError(ex);
    // }
}
项目:hska-vis-legacy    文件:HibernateUtil.java   
public static SessionFactory getSessionFactory() {
    if (sessionFactory == null) {
        StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure() // configures settings from hibernate.cfg.xml
                .build();
        try {
            sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
        } catch (Exception e) {
            // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
            // so destroy it manually.
            StandardServiceRegistryBuilder.destroy(registry);
            throw new RuntimeException(e);
        }
    }
    return sessionFactory;
}
项目:Java_Good    文件:HbConnectionTest.java   
@BeforeClass
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
项目:Java_Good    文件:HbConnectionTest.java   
@BeforeClass
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
项目:VoxelGamesLib    文件:HibernatePersistenceProvider.java   
@Override
public void start() {
    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url)
            .applySetting("hibernate.dialect", config.persistence.dialect)
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            .build();

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
项目:Java-education    文件:HibernateSessionFactory.java   
/**
 * Created by admin on 10.01.2017.
 * @return SessionFactory
 */
protected static SessionFactory buildSessionFactory() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);

        throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
    }
    return sessionFactory;
}
项目:Java-education    文件:HibernateSessionFactory.java   
/**
 * Created by admin on 30.12.2016.
 * create factory
 * @return SessionFactory
 */
protected static SessionFactory buildSessionFactory() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);

        throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
    }
    return sessionFactory;
}
项目:Java-education    文件:HibernateSessionFactory.java   
/**
 * Created by admin on 10.01.2017.
 * @return SessionFactory
 */
protected static SessionFactory buildSessionFactory() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);

        throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
    }
    return sessionFactory;
}
项目:java_pft    文件:HbConnectionTest.java   
@BeforeClass
protected void setUp() throws Exception {
  // A SessionFactory is set up once for an application!
  final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
          .configure() // configures settings from hibernate.cfg.xml
          .build();
  try {
    sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
  }
  catch (Exception e) {
    e.printStackTrace();
    // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
    // so destroy it manually.
    StandardServiceRegistryBuilder.destroy( registry );
  }
}
项目:dropwizard-db-sharding-bundle    文件:LookupDaoTest.java   
private SessionFactory buildSessionFactory(String dbName) {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect",
            "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.connection.driver_class",
            "org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.current_session_context_class", "managed");
    configuration.addAnnotatedClass(TestEntity.class);
    configuration.addAnnotatedClass(Phone.class);
    configuration.addAnnotatedClass(Transaction.class);
    configuration.addAnnotatedClass(Audit.class);

    StandardServiceRegistry serviceRegistry
            = new StandardServiceRegistryBuilder().applySettings(
                        configuration.getProperties()).build();
    return configuration.buildSessionFactory(serviceRegistry);
}
项目:dropwizard-db-sharding-bundle    文件:CacheableLookupDaoTest.java   
private SessionFactory buildSessionFactory(String dbName) {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect",
            "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.connection.driver_class",
            "org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.current_session_context_class", "managed");
    configuration.addAnnotatedClass(TestEntity.class);
    configuration.addAnnotatedClass(Phone.class);
    configuration.addAnnotatedClass(Transaction.class);
    configuration.addAnnotatedClass(Audit.class);

    StandardServiceRegistry serviceRegistry
            = new StandardServiceRegistryBuilder().applySettings(
                        configuration.getProperties()).build();
    return configuration.buildSessionFactory(serviceRegistry);
}
项目:dropwizard-db-sharding-bundle    文件:WrapperDaoTest.java   
private SessionFactory buildSessionFactory(String dbName) {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect",
            "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.connection.driver_class",
            "org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.current_session_context_class", "managed");
    configuration.addAnnotatedClass(Order.class);
    configuration.addAnnotatedClass(OrderItem.class);

    StandardServiceRegistry serviceRegistry
            = new StandardServiceRegistryBuilder().applySettings(
            configuration.getProperties()).build();
    return configuration.buildSessionFactory(serviceRegistry);
}
项目:dropwizard-db-sharding-bundle    文件:RelationalDaoTest.java   
private SessionFactory buildSessionFactory(String dbName) {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect",
            "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.connection.driver_class",
            "org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.setProperty("hibernate.current_session_context_class", "managed");
    configuration.addAnnotatedClass(RelationalEntity.class);

    StandardServiceRegistry serviceRegistry
            = new StandardServiceRegistryBuilder().applySettings(
            configuration.getProperties()).build();
    return configuration.buildSessionFactory(serviceRegistry);
}
项目:JAVA_rep1    文件:ContactDeleteFromGroupTests.java   
@BeforeClass
public void setUpDb() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
项目:JAVA_rep1    文件:ContactAddToGroupTests.java   
@BeforeClass
public void setUpDb() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
项目:JAVA_rep1    文件:HbConnectionTest.java   
@BeforeClass
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    }
    catch (Exception e) {
        e.printStackTrace();
        // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy( registry );
    }
}
项目:dorset-framework    文件:HibernateServiceTest.java   
@Test
public void testCreationOfSessionFactory() {
    Properties props = getProperties();
    Config conf = ConfigFactory.parseProperties(props);

    hs = new HibernateService(conf);
    SessionFactory sf = hs.getSessionFactory();
    assertNotNull(sf);
    assertFalse(sf.isClosed());

    // traverse through the session factory to get at configuration values
    SessionFactoryOptions sfo = sf.getSessionFactoryOptions();
    StandardServiceRegistry ssr = sfo.getServiceRegistry();
    ConfigurationService cs = ssr.getService(ConfigurationService.class);
    assertEquals(props.getProperty("hibernate.connection.driver_class"), cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.connection.url"), cs.getSetting("hibernate.connection.url", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.dialect"), cs.getSetting("hibernate.dialect", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.hbm2ddl.auto"), cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING));

    // check mapping
    ClassMetadata cm = sf.getClassMetadata(TestObject.class);
    String[] names = cm.getPropertyNames();
    assertEquals(1, names.length);
    assertEquals("name", names[0]);
    assertEquals("string", cm.getPropertyType("name").getName());
}
项目:owsi-core-parent    文件:InterceptorAwareHibernatePersistenceProvider.java   
/**
 * 2017-05-24 · reworked from SpringHibernateJpaPersistenceProvider so that we can inject a custom
 * {@link EntityManagerFactoryBuilderImpl}; previous implementation that overrides
 * {@link InterceptorAwareHibernatePersistenceProvider#getEntityManagerFactoryBuilder} no longer works
 * as there are several paths with various arguments and the overloaded one was no longer called.
 */
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
    return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(info), properties) {
        @Override
        protected void populate(SessionFactoryBuilder sfBuilder, StandardServiceRegistry ssr) {
            super.populate(sfBuilder, ssr);

            if (InterceptorAwareHibernatePersistenceProvider.this.interceptor != null) {
                LOGGER.warn("Installing our Spring managed interceptor.");
                sfBuilder.applyInterceptor(InterceptorAwareHibernatePersistenceProvider.this.interceptor);
            }
        }
    }.build();
}
项目:livingdoc-confluence    文件:HibernateDatabase.java   
public HibernateDatabase(Properties properties) throws HibernateException {

        StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(properties).build();
        MetadataSources metadataSources = new MetadataSources(registry);
        metadataSources.addAnnotatedClass(SystemInfo.class)
            .addAnnotatedClass(Project.class)
            .addAnnotatedClass(Runner.class)
            .addAnnotatedClass(Repository.class)
            .addAnnotatedClass(RepositoryType.class)
            .addAnnotatedClass(SystemUnderTest.class)
            .addAnnotatedClass(Requirement.class)
            .addAnnotatedClass(Specification.class)
            .addAnnotatedClass(Reference.class)
            .addAnnotatedClass(Execution.class);

        this.properties = properties;
        this.metadata = metadataSources.buildMetadata();

    }
项目:java_pft    文件:HbConnectionTest.java   
@BeforeClass
protected void setUp() throws Exception {
  // A SessionFactory is set up once for an application!
  final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
          .configure() // configures settings from hibernate.cfg.xml
          .build();
  try {
    sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
  }
  catch (Exception e) {
    e.printStackTrace();
    // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
    // so destroy it manually.
    StandardServiceRegistryBuilder.destroy( registry );
  }
}
项目:sdcct    文件:SdcctEntityManagerFactoryFactoryBean.java   
@Override
public EntityManagerFactoryImpl build() {
    SessionFactoryImpl sessionFactory =
        ((SessionFactoryImpl) (SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory = ((EntityManagerFactoryImpl) super.build()))
            .getSessionFactory());
    StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();

    serviceRegistry.getService(EntityManagerFactoryRef.class).setEntityManagerFactory(SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory);

    ContextHelper.getSearchintegratorBySFI(sessionFactory).getIndexBindings().replaceAll((entityClass, entityIndexBinding) -> {
        MutableEntityIndexBinding newEntityIndexBinding =
            new DefaultMutableEntityIndexBinding(entityIndexBinding.getSelectionStrategy(), entityIndexBinding.getSimilarity(),
                entityIndexBinding.getIndexManagers(), SdcctEntityManagerFactoryFactoryBean.this.entityIndexingInterceptor);
        newEntityIndexBinding.setDocumentBuilderIndexedEntity(entityIndexBinding.getDocumentBuilder());

        return newEntityIndexBinding;
    });

    serviceRegistry.getService(DbMetadataService.class);

    return SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory;
}
项目:dorset-framework    文件:HibernateServiceTest.java   
@Test
public void testCreationOfSessionFactory() {
    Properties props = getProperties();
    Config conf = ConfigFactory.parseProperties(props);

    hs = new HibernateService(conf);
    SessionFactory sf = hs.getSessionFactory();
    assertNotNull(sf);
    assertFalse(sf.isClosed());

    // traverse through the session factory to get at configuration values
    SessionFactoryOptions sfo = sf.getSessionFactoryOptions();
    StandardServiceRegistry ssr = sfo.getServiceRegistry();
    ConfigurationService cs = ssr.getService(ConfigurationService.class);
    assertEquals(props.getProperty("hibernate.connection.driver_class"), cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.connection.url"), cs.getSetting("hibernate.connection.url", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.dialect"), cs.getSetting("hibernate.dialect", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.hbm2ddl.auto"), cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING));

    // check mapping
    ClassMetadata cm = sf.getClassMetadata(TestObject.class);
    String[] names = cm.getPropertyNames();
    assertEquals(1, names.length);
    assertEquals("name", names[0]);
    assertEquals("string", cm.getPropertyType("name").getName());
}
项目:juddi    文件:App.java   
/**
 * Method that actually creates the file.
 *
 * @param dbDialect to use
 */
private void generate(Dialect dialect) {

        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
        ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
        StandardServiceRegistry standardServiceRegistry = ssrb.build();

        MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
        for (Class clzz : jpaClasses) {
                metadataSources.addAnnotatedClass(clzz);
        }

        Metadata metadata = metadataSources.buildMetadata();

        SchemaExport export = new SchemaExport();

        export.setDelimiter(";");
        export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
        //export.execute(true, false, false, true);
        export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
项目:db-bootstrap    文件:HibernateTestUtil.java   
public static SessionFactory getSessionFactory() {
    try {
        if (sessionFactory == null) {
            BootstrapServiceRegistryBuilder serviceRegistryBuilder = new BootstrapServiceRegistryBuilder();
            serviceRegistryBuilder.with(HibernateTestUtil.class.getClassLoader());

            StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(serviceRegistryBuilder.build())
                    .configure( "META-INF/hibernate.cfg.xml" )
                    .build();
            Metadata metadata = new MetadataSources( standardRegistry ).buildMetadata();

            sessionFactory = metadata.getSessionFactoryBuilder()
                    .build();
        }
    } catch (Throwable ex) {
        throw new ExceptionInInitializerError(ex);
    }
    return sessionFactory;
}
项目:sqlite-dialect    文件:SQLiteMetadataBuilderInitializer.java   
@Override
public void contribute(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) {
    DialectResolver dialectResolver = serviceRegistry.getService(DialectResolver.class);

    if ((dialectResolver instanceof DialectResolverSet)) {
        ((DialectResolverSet) dialectResolver).addResolver(resolver);
    }
}
项目:sqlite-dialect    文件:SQLiteMetadataBuilderInitializerTest.java   
@Before
public void setup() {
    initializer = new SQLiteMetadataBuilderInitializer();

    metadataBuilder = mock(MetadataBuilder.class);
    registry = mock(StandardServiceRegistry.class);
    resolver = mock(DialectResolverSet.class);

    when(registry.getService(DialectResolver.class)).thenReturn(resolver);
}
项目:dataj    文件:HibernateDataTest.java   
@Before
public void setUp() throws Exception {

    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
            .applySetting("hibernate.connection.url", "jdbc:h2:mem:test")
            .applySetting("hibernate.hbm2ddl.auto", "create-drop")
            .build();

    sessionFactory = new MetadataSources(serviceRegistry)
            .addAnnotatedClass(CountryData.class)
            .addAnnotatedClass(CityData.class)
            .buildMetadata()
            .buildSessionFactory();
}
项目:module-template    文件:DbHelper.java   
public DbHelper() {
    // A SessionFactory is set up once for an application!
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure("hibernate.cfg.xml") // configures settings from hibernate.cfg.xml
            .build();
    sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
}
项目:training-sample    文件:HibernateUtil.java   
public static SessionFactory buildSessionFactory() {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        // The registry would be destroyed by the SessionFactory, but we had
        // trouble building the SessionFactory
        // so destroy it manually.
        StandardServiceRegistryBuilder.destroy(registry);
    }
    return sessionFactory;
}
项目:JavaEE    文件:App.java   
/**
 * Creating a session
 * @return org.hibernate.Session
 */
private Session createHibernateSession() {
    try {
        Map<String, String> settings = new HashMap<String, String>();
        settings.put("hibernate.connection.driver_class", "org.sqlite.JDBC");
        settings.put("hibernate.connection.url", "jdbc:sqlite:mysqlite.db");
        settings.put("hibernate.connection.username", "");
        settings.put("hibernate.connection.password", "");
        settings.put("hibernate.show_sql", "true");
        settings.put("hibernate.hbm2ddl.auto", "update");

        StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .applySettings(settings)
                .build();

        MetadataSources sources = new MetadataSources(registry)
                .addAnnotatedClass(Person.class);

        Metadata metadata = sources
                .getMetadataBuilder()
                .build();

        SessionFactory sessionFactory = metadata
                .getSessionFactoryBuilder()
                .build();

        session = sessionFactory.openSession();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return null;
    }
    System.out.println("Session created successfully.");
    return session;
}
项目:hibernateMaster    文件:SingleFactoryEngine.java   
@Override
    public SessionFactory buildFactory(String configFile) {
        try {
            //configuration = new Configuration().configure(configFile);
//          StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
//          .applySettings(configuration.getProperties());
//          SessionFactory factory2 = configuration.buildSessionFactory(builder.build());


            StandardServiceRegistry standardRegistry = new   StandardServiceRegistryBuilder()
                    .configure(configFile)
                    .build();

            MetadataSources metadataSources = new MetadataSources( standardRegistry );

            DomainScanner instanceFromProperties = getScanner(configFile);
            List<Class<? extends BaseDatabaseDomain>> scan = instanceFromProperties.scan(configFile);
            for(Class<? extends BaseDatabaseDomain> temp:scan){
                metadataSources.addAnnotatedClass(temp);
            }

        //  new HibernateUtil().scanDomain(metadataSources);

            Metadata metadata = metadataSources.getMetadataBuilder()
                .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )
                .build();

            SessionFactory factory2 = metadata.getSessionFactoryBuilder().build();


            return factory2;
            /*ProxoolConnectionProvider aConnectionProvider;*/
        } catch (Exception e) {
            steed.util.logging.LoggerFactory.getLogger().error("创建sessionFactory失败",e);
        }
        return null;
    }
项目:Java_Good    文件:DbHelper.java   
public DbHelper() {

        // A SessionFactory is set up once for an application!
        final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure() // configures settings from hibernate.cfg.xml
                .build();
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    }
项目:Java_Good    文件:DbHelper.java   
public DbHelper() {

        // A SessionFactory is set up once for an application!
        final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure() // configures settings from hibernate.cfg.xml
                .build();
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    }
项目:ssh-example    文件:TestHibernate.java   
@Before
public void setUp() throws Exception {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
    }
}
项目:jstudy    文件:DbHelper.java   
@SuppressWarnings("WeakerAccess")
public DbHelper() {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
}
项目:jstudy    文件:DBHelper.java   
@SuppressWarnings("WeakerAccess")
public DBHelper(ApplicationManager app) {
    this.app = app;
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure() // configures settings from hibernate.cfg.xml
            .build();
    sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
}
项目:java_pft    文件:DbHelper.java   
public DbHelper() {
  // A SessionFactory is set up once for an application!
  final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
          .configure() // configures settings from hibernate.cfg.xml
          .build();
  sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}