当前位置: 首页>>代码示例>>Java>>正文


Java StatelessSession.close方法代码示例

本文整理汇总了Java中org.hibernate.StatelessSession.close方法的典型用法代码示例。如果您正苦于以下问题:Java StatelessSession.close方法的具体用法?Java StatelessSession.close怎么用?Java StatelessSession.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.StatelessSession的用法示例。


在下文中一共展示了StatelessSession.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runStatelessHql

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private static void runStatelessHql() throws Exception {
  Stopwatch watch = Stopwatch.createStarted();
  StatelessSession statelessSession = sessionFactory.openStatelessSession();
  try {
    statelessSession.getTransaction().begin();
    Query query = statelessSession
        .createQuery(
            " SELECT d.id, d.firstName, d.lastName, c.id, c.make " + " FROM Driver d "
                + " LEFT JOIN d.cars c WHERE index(c) LIKE 'Good'").setFetchSize(0).setReadOnly(true);

    ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);
    while (scroll.next()) {
      LOG.info("Entry " + scroll.get(0));
    }
    statelessSession.getTransaction().commit();
  } catch (Exception ex) {
    statelessSession.getTransaction().rollback();
    throw ex;
  } finally {
    statelessSession.close();
  }
  LOG.info("StatelessHql:=" + watch.toString());
}
 
开发者ID:AndreasKl,项目名称:java-classic-playground,代码行数:24,代码来源:Program.java

示例2: removeLocalization

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void removeLocalization(EntityPersister persister, Object entity) {
    if (entity instanceof DomainObject<?>) {
        DomainObject<?> obj = (DomainObject<?>) entity;
        List<LocalizedObjectTypes> objType = obj.getLocalizedObjectTypes();
        if (objType.size() > 0) {
            long key = obj.getKey();
            final StatelessSession session = persister.getFactory()
                    .openStatelessSession();
            Transaction tx = session.beginTransaction();
            org.hibernate.Query query = session.createQuery(
                    "DELETE FROM LocalizedResource WHERE objectKey = :objectKey AND objectType IN (:objectType)");
            query.setParameter("objectKey", key);
            query.setParameterList("objectType", objType);
            query.executeUpdate();
            tx.commit();
            session.close();
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:HibernateEventListener.java

示例3: createHistory

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void createHistory(EntityPersister persister, Object entity,
        ModificationType type) {
    if (entity instanceof DomainObject<?>) {
        DomainObject<?> obj = (DomainObject<?>) entity;
        if (obj.hasHistory()) {
            final DomainHistoryObject<?> hist = HistoryObjectFactory.create(
                    obj, type, DataServiceBean.getCurrentHistoryUser());

            final StatelessSession session = persister.getFactory()
                    .openStatelessSession();
            Transaction tx = session.beginTransaction();
            session.insert(hist);
            tx.commit();
            session.close();

            if (logger.isDebugLoggingEnabled()) {
                logger.logDebug(String.format("%s %s[%s, v=%s]", type,
                        obj.getClass().getSimpleName(), obj.getKey(),
                        hist.getObjVersion()));
            }
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:HibernateEventListener.java

示例4: removeLocalization

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void removeLocalization(EntityPersister persister, Object entity) {
    if (entity instanceof DomainObject<?>) {
        DomainObject<?> obj = (DomainObject<?>) entity;
        List<LocalizedObjectTypes> objType = obj.getLocalizedObjectTypes();
        if (objType.size() > 0) {
            long key = obj.getKey();
            final StatelessSession session = persister.getFactory()
                    .openStatelessSession();
            Transaction tx = session.beginTransaction();
            org.hibernate.Query query = session
                    .createQuery("DELETE FROM LocalizedResource WHERE objectKey = :objectKey AND objectType IN (:objectType)");
            query.setParameter("objectKey", Long.valueOf(key));
            query.setParameterList("objectType", objType);
            query.executeUpdate();
            tx.commit();
            session.close();
        }
    }
}
 
开发者ID:servicecatalog,项目名称:development,代码行数:20,代码来源:HibernateEventListener.java

示例5: createHistory

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void createHistory(EntityPersister persister, Object entity,
        ModificationType type) {
    if (entity instanceof DomainObject<?>) {
        DomainObject<?> obj = (DomainObject<?>) entity;
        if (obj.hasHistory()) {
            final DomainHistoryObject<?> hist = HistoryObjectFactory
                    .create(obj, type,
                            DataServiceBean.getCurrentHistoryUser());

            final StatelessSession session = persister.getFactory()
                    .openStatelessSession();
            Transaction tx = session.beginTransaction();
            session.insert(hist);
            tx.commit();
            session.close();

            if (logger.isDebugLoggingEnabled()) {
                logger.logDebug(String.format("%s %s[%s, v=%s]", type, obj
                        .getClass().getSimpleName(), Long.valueOf(obj
                        .getKey()), Long.valueOf(hist.getObjVersion())));
            }
        }
    }
}
 
开发者ID:servicecatalog,项目名称:development,代码行数:25,代码来源:HibernateEventListener.java

示例6: testRefresh

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testRefresh() {
	StatelessSession ss = getSessions().openStatelessSession();
	Transaction tx = ss.beginTransaction();
	Paper paper = new Paper();
	paper.setColor( "whtie" );
	ss.insert( paper );
	tx.commit();
	ss.close();

	ss = getSessions().openStatelessSession();
	tx = ss.beginTransaction();
	Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() );
	p2.setColor( "White" );
	ss.update( p2 );
	tx.commit();
	ss.close();

	ss = getSessions().openStatelessSession();
	tx = ss.beginTransaction();
	assertEquals( "whtie", paper.getColor() );
	ss.refresh( paper );
	assertEquals( "White", paper.getColor() );
	ss.delete( paper );
	tx.commit();
	ss.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:StatelessSessionTest.java

示例7: usingStatelessSession

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
static boolean usingStatelessSession(Consumer<StatelessSession> action) {
    if (sessionFactory != null) {
        StatelessSession session = sessionFactory.openStatelessSession();
        try {
            Transaction transaction = session.beginTransaction();
            action.accept(session);
            transaction.commit();
            return true;
        } catch (Throwable e) {
            return false;
        } finally {
            session.close();
        }
    }
    return false;
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:17,代码来源:DataSource.java

示例8: executeTransactional

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
/**
 * 지정한 session으로부터 StatelessSession을 생성한 후 작업을 수행하고, 닫습니다.  @param session the session
 *
 * @param action the action
 */
public static void executeTransactional(Session session, Action1<StatelessSession> action) {
    if (log.isDebugEnabled())
        log.debug("StatelessSession을 이용하여 Transaction 하에서 특정 작업을 수행합니다.");

    StatelessSession stateless = openStatelessSession(session);
    Transaction tx = null;

    try {
        tx = stateless.beginTransaction();
        action.perform(stateless);
        tx.commit();
    } catch (Exception e) {
        log.error("StatelessSession을 이용한 작업에 실패했습니다. rollback 합니다.", e);
        if (tx != null)
            tx.rollback();
        throw new RuntimeException(e);
    } finally {
        stateless.close();
    }
}
 
开发者ID:debop,项目名称:debop4j,代码行数:26,代码来源:StatelessTool.java

示例9: execute

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
/**
 * Execute the actions.
 *
 * @param session the session
 * @param actions the actions
 */
public static void execute(Session session, Iterable<Action1<StatelessSession>> actions) {
    if (log.isDebugEnabled())
        log.debug("StatelessSession을 이용하여 특정 작업을 수행합니다.");

    StatelessSession stateless = openStatelessSession(session);
    try {
        for (Action1<StatelessSession> action : actions)
            action.perform(stateless);
    } catch (Exception e) {
        log.error("StatelessSession에서 작업이 실패했습니다.", e);
        throw new RuntimeException(e);
    } finally {
        stateless.close();
    }
}
 
开发者ID:debop,项目名称:debop4j,代码行数:22,代码来源:StatelessTool.java

示例10: testHqlBulk

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testHqlBulk() {
	StatelessSession ss = getSessions().openStatelessSession();
	Transaction tx = ss.beginTransaction();
	Document doc = new Document("blah blah blah", "Blahs");
	ss.insert(doc);
	Paper paper = new Paper();
	paper.setColor( "White" );
	ss.insert(paper);
	tx.commit();

	tx = ss.beginTransaction();
	int count = ss.createQuery( "update Document set name = :newName where name = :oldName" )
			.setString( "newName", "Foos" )
			.setString( "oldName", "Blahs" )
			.executeUpdate();
	assertEquals( "hql-update on stateless session", 1, count );
	count = ss.createQuery( "update Paper set color = :newColor" )
			.setString( "newColor", "Goldenrod" )
			.executeUpdate();
	assertEquals( "hql-update on stateless session", 1, count );
	tx.commit();

	tx = ss.beginTransaction();
	count = ss.createQuery( "delete Document" ).executeUpdate();
	assertEquals( "hql-delete on stateless session", 1, count );
	count = ss.createQuery( "delete Paper" ).executeUpdate();
	assertEquals( "hql-delete on stateless session", 1, count );
	tx.commit();
	ss.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:31,代码来源:StatelessSessionTest.java

示例11: testInitId

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testInitId() {
	StatelessSession ss = getSessions().openStatelessSession();
	Transaction tx = ss.beginTransaction();
	Paper paper = new Paper();
	paper.setColor( "White" );
	ss.insert(paper);
	assertNotNull( paper.getId() );
	tx.commit();

	tx = ss.beginTransaction();
	ss.delete( ss.get( Paper.class, paper.getId() ) );
	tx.commit();
	ss.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:15,代码来源:StatelessSessionTest.java

示例12: exists

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
@Override
public String exists(final String tenantId,
                     final String name) {
  logger.trace(ORM_LOG_MARKER, "exists(...) entering...");

  StatelessSession session = null;
  try {
    session = sessionFactory.openStatelessSession();

    List<?> ids = session
        .createCriteria(AlarmDefinitionDb.class)
        .add(Restrictions.eq("tenantId", tenantId))
        .add(Restrictions.eq("name", name))
        .add(Restrictions.isNull("deletedAt"))
        .setProjection(Projections.property("id"))
        .setMaxResults(1)
        .list();

    final String existingId = CollectionUtils.isEmpty(ids) ? null : (String) ids.get(0);

    if (null == existingId) {
      logger.debug(ORM_LOG_MARKER, "No AlarmDefinition matched tenantId={} and name={}", tenantId, name);
    }

    return existingId;
  } finally {
    if (session != null) {
      session.close();
    }
  }
}
 
开发者ID:openstack,项目名称:monasca-api,代码行数:32,代码来源:AlarmDefinitionSqlRepoImpl.java

示例13: findAlarmIds

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public List<String> findAlarmIds(String tenantId, Map<String, String> dimensions) {
  logger.trace(BaseSqlRepo.ORM_LOG_MARKER, "findAlarmIds(...) entering");
  List<String> alarmIdList = null;

  StatelessSession session = null;
  try {
    session = sessionFactory.openStatelessSession();

    final String sql = this.findAlarmQueryString(dimensions);
    final Query query = session
        .createSQLQuery(sql)
        .setString("tenantId", tenantId);

    this.bindDimensionsToQuery(query, dimensions);

    @SuppressWarnings("unchecked") List<Object[]> rows = query.list();
    alarmIdList = Lists.newArrayListWithCapacity(rows.size());
    for (Object[] row : rows) {
      String id = (String) row[0];
      alarmIdList.add(id);
    }

  } finally {
    if (session != null) {
      session.close();
    }
  }

  // no need to check if alarmIdList != null, because in case of exception method
  // will leave immediately, otherwise list wont be null.
  return alarmIdList;
}
 
开发者ID:openstack,项目名称:monasca-api,代码行数:33,代码来源:AlarmHibernateUtils.java

示例14: saveInventory

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void saveInventory() throws HibernateException, IOException{
	File inventoryFile = new File("ghcnm.inv");
	BufferedReader br = new BufferedReader(new FileReader(inventoryFile));
	String line;

	org.hibernate.Session session = 
			(org.hibernate.Session)GeoInventory.em().getDelegate(); 
	StatelessSession stateless = session.getSessionFactory().openStatelessSession();
	try {
		stateless.connection().setAutoCommit(false);
	} catch (SQLException e) {
		e.printStackTrace();
	}
	org.hibernate.Transaction tx = stateless.beginTransaction();

	int counter=0;
	while ((line = br.readLine()) != null) {
		counter++;
		GeoInventory inv = new GeoInventory(line);
		stateless.insert(inv);
		if(counter%1000==0){
			tx.commit();
			tx = stateless.beginTransaction();
			Logger.info("Data Saved: %s", counter);
		}
	}
	tx.commit();
	br.close();
	stateless.close();
	session.clear();
	Logger.info("Geoloc Inventory save complete!");
}
 
开发者ID:dreampowder,项目名称:ghcnm-play,代码行数:33,代码来源:Bootstrap.java

示例15: closeSession

import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void closeSession(StatelessSession session) {
    session.close();
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:4,代码来源:StatelessHibernateExternalDataSource.java


注:本文中的org.hibernate.StatelessSession.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。