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

项目:lambda-rds-mysql    文件:HibernateUtil.java   
public static SessionFactory getSessionFactory() {
    if (null != sessionFactory)
        return sessionFactory;

    Configuration configuration = new Configuration();

    String jdbcUrl = "jdbc:mysql://"
            + System.getenv("RDS_HOSTNAME")
            + "/"
            + System.getenv("RDS_DB_NAME");

    configuration.setProperty("hibernate.connection.url", jdbcUrl);
    configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
    configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));

    configuration.configure();
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (HibernateException e) {
        System.err.println("Initial SessionFactory creation failed." + e);
        throw new ExceptionInInitializerError(e);
    }
    return sessionFactory;
}
项目:java-jdbc    文件:HibernateTest.java   
private SessionFactory createSessionFactory(boolean traceWithActiveSpanOnly) {
  Configuration configuration = new Configuration();
  configuration.addAnnotatedClass(Employee.class);
  configuration.setProperty("hibernate.connection.driver_class",
      "io.opentracing.contrib.jdbc.TracingDriver");
  configuration.setProperty("hibernate.connection.url",
      "jdbc:tracing:h2:mem:hibernate?traceWithActiveSpanOnly=" + traceWithActiveSpanOnly);
  configuration.setProperty("hibernate.connection.username", "sa");
  configuration.setProperty("hibernate.connection.password", "");
  configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
  configuration.setProperty("hibernate.hbm2ddl.auto", "create-drop");
  configuration.setProperty("hibernate.show_sql", "true");
  configuration.setProperty("hibernate.connection.pool_size", "10");

  StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
      .applySettings(configuration.getProperties());
  return configuration.buildSessionFactory(builder.build());
}
项目:java-p6spy    文件:HibernateTest.java   
private SessionFactory createSessionFactory(String options) {
  Configuration configuration = new Configuration();
  configuration.addAnnotatedClass(Employee.class);
  configuration.setProperty("hibernate.connection.url", "jdbc:p6spy:hsqldb:mem:hibernate" + options);
  configuration.setProperty("hibernate.connection.username", "sa");
  configuration.setProperty("hibernate.connection.password", "");
  configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
  configuration.setProperty("hibernate.hbm2ddl.auto", "create-drop");
  configuration.setProperty("hibernate.show_sql", "true");
  configuration.setProperty("hibernate.connection.pool_size", "10");

  StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
      .applySettings(configuration.getProperties());
  SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
  return sessionFactory;
}
项目: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;
}
项目:userinterface    文件:HibernateUtil.java   
public static SessionFactory getSessionFactory() {
        if (sessionFactory == null || sessionFactory.isClosed()) {
            try {
                Configuration configuration = new Configuration().configure();
                StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
                serviceRegistryBuilder.applySettings(configuration.getProperties());
                ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
                sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//            sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (HibernateException ex) {
                ex.printStackTrace();
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
        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;
}
项目:interview-preparation    文件:ContextualSessionExample.java   
public static SessionFactory getSessionFactory() {

        final Configuration configuration = new Configuration().configure();
        configuration.addPackage("com.tvajjala.domain");
        configuration.addAnnotatedClass(com.tvajjala.domain.User.class);
        configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
        configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/test");
        configuration.setProperty("hibernate.connection.username", "root");
        configuration.setProperty("hibernate.connection.password", "admin");
        System.out.println("Using dialect " + org.hibernate.dialect.MySQL5InnoDBDialect.class.getName());
        configuration.setProperty("hibernate.dialect", org.hibernate.dialect.MySQL5InnoDBDialect.class.getName());
        configuration.setProperty("hibernate.hbm2ddl.auto", "update");
        // session_context_class is jta then transaction manager lookup class need to set
        // configuration.setProperty("hibernate.transaction.manager_lookup_class", TransactionManagerLookup.);

        // This below property used to create session per context// jta, thread, managed
        configuration.setProperty("hibernate.current_session_context_class", "thread");
        configuration.setProperty("hibernate.show_sql", "true");
        configuration.setProperty(" hibernate.connection.pool_size", "10");

        final StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());

        return configuration.buildSessionFactory(builder.build());

    }
项目:SearchEnhancer    文件:HibernateUtil.java   
public static SessionFactory buildSessionFactory() {
    try {

        Configuration configuration = new Configuration();

        // Create properties file
        Properties properties = new Properties();

        properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("Hibernate.properties"));

        configuration.setProperties(properties);

        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        configuration.addAnnotatedClass(Wordlist.class);

        sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    } catch (Throwable ex) {
        ex.printStackTrace();
    }
    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 );
  }
}
项目:Nomad    文件:DB.java   
private static SessionFactory buildSessionFactory() {
    try {
        Configuration configuration = new Configuration();

        Properties props = new Properties();
        props.put("hibernate.current_session_context_class", "thread");
        configuration.setProperties(props);

        for (Class<?> clazz : entityClasses) {
            configuration.addAnnotatedClass(clazz);
        }

        PluginHandler.get().getPlugin().addAnnotatedClass(configuration);

        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties())
                .addService(ConnectionProvider.class, new NomadConnectionProvider()).build();

        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

        return sessionFactory;
    } catch (Throwable ex) {
        logger.error("Failed to build session factory.", ex);
        throw new ExceptionInInitializerError(ex);
    }
}
项目: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);
}
项目:HibernateTips    文件:TestHibernateBootstrapping.java   
@Test
public void bootstrapping() {
    log.info("... bootstrapping ...");

    ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().build();

    SessionFactory sessionFactory = new MetadataSources(standardRegistry)
        .addAnnotatedClass(Author.class).buildMetadata()
        .buildSessionFactory();
        Session session = sessionFactory.openSession();
    session.beginTransaction();

    Author a = new Author();
    a.setFirstName("Thorben");
    a.setLastName("Janssen");
    session.persist(a);

    session.getTransaction().commit();
    session.close();
}
项目:miner    文件:RegexDAOImpl.java   
public boolean addRegex(Regex regex) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Regex.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.save(regex);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:RegexDAOImpl.java   
public boolean updateRegex(Regex regex) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Regex.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.update(regex);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:DataDAOImpl.java   
public boolean addData(Data data) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Data.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.save(data);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:DataDAOImpl.java   
public boolean updateData(Data data) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Data.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.update(data);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:TaskDAOImpl.java   
public boolean addTask(Task task) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Task.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.save(task);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:TaskDAOImpl.java   
public boolean updateTask(Task task) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Task.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.update(task);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:WorkspaceDAOImpl.java   
public boolean addWorkspace(Workspace wspace) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Workspace.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.save(wspace);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:WorkspaceDAOImpl.java   
public boolean updateWorkspace(Workspace wspace) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Workspace.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.update(wspace);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:ClusterDAOImpl.java   
public boolean updateTask(Task task) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Task.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.update(task);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:ProjectDAOImpl.java   
public boolean addProject(Project p) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Project.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.save(p);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目:miner    文件:ProjectDAOImpl.java   
public boolean updateProject(Project p) {
    Transaction tx = null;
    Configuration config = new Configuration().configure();

    config.addClass(Project.class);

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
            .build();
    SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    Session session        = sessionFactory.getCurrentSession();
    try{
        tx = session.beginTransaction();
        session.update(p);
        tx.commit();
        return true;
    }catch (Exception ex){
        ex.printStackTrace();
        tx.commit();
        return false;
    }finally {
        if(tx != null){
            tx = null;
        }
        sessionFactory.close();
    }
}
项目: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 );
    }
}
项目:springJpaKata    文件:HibernateServiceUtils.java   
public static SessionFactory getSessionFactory() {
    log.info("+++ getSessionFactory");
    if (sf == null) {
        Configuration cfg = new Configuration();
        cfg.configure("hibernate.cfg.xml");
        // @formatter:off
        cfg.addPackage("pl.java.scalatech.domain")
          .addAnnotatedClass(Item.class)
          .addAnnotatedClass(GeneratorOne.class)
          .addAnnotatedClass(Note.class)
          .addAnnotatedClass(HiloEntity.class)
          .addAnnotatedClass(TableGeneratorEntity.class)
          ;
        // @formatter:on
        cfg.setProperty("hibernate.generate_statistics","true");
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
        sf = cfg.buildSessionFactory(serviceRegistry);
    }

    return sf;

}
项目:springJpaKata    文件:HibernateServiceUtils.java   
public static SessionFactory getSessionFactory(Class[] clazz) {
    log.info("+++ getConcreteEntitySessionFactory");
    if (sf == null) {
        Configuration cfg = new Configuration();
        cfg.configure("hibernate.cfg.xml");
        // @formatter:off
        for (Class cl : clazz) {
            log.info("+++     mapped entity => {}",cl);
            cfg.addPackage("pl.java.scalatech.domain").addAnnotatedClass(cl);
        }
        // @formatter:on
        cfg.setProperty("hibernate.generate_statistics","true");
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
        sf = cfg.buildSessionFactory(serviceRegistry);
    }

    return sf;

}