當前位置: 首頁>>代碼示例>>Java>>正文


Java ScrollableResults.close方法代碼示例

本文整理匯總了Java中org.hibernate.ScrollableResults.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ScrollableResults.close方法的具體用法?Java ScrollableResults.close怎麽用?Java ScrollableResults.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.ScrollableResults的用法示例。


在下文中一共展示了ScrollableResults.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializeLines

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void initializeLines(CostAdjustment costAdjustment) {
  // initialize is related transaction adjusted flag to false
  OBCriteria<CostAdjustmentLine> critLines = OBDal.getInstance().createCriteria(
      CostAdjustmentLine.class);
  critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_COSTADJUSTMENT, costAdjustment));
  critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_ISRELATEDTRANSACTIONADJUSTED, true));
  ScrollableResults lines = critLines.scroll(ScrollMode.FORWARD_ONLY);
  long count = 1L;
  try {
    while (lines.next()) {
      CostAdjustmentLine line = (CostAdjustmentLine) lines.get(0);
      line.setRelatedTransactionAdjusted(false);
      OBDal.getInstance().save(line);

      if (count % 1000 == 0) {
        OBDal.getInstance().flush();
        OBDal.getInstance().getSession().clear();
      }
      count++;
    }
    OBDal.getInstance().flush();
    OBDal.getInstance().getSession().clear();
  } finally {
    lines.close();
  }
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:27,代碼來源:CostAdjustmentProcess.java

示例2: updateInitInventoriesTrxDate

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void updateInitInventoriesTrxDate(Date startingDate, String ruleId) {
  StringBuffer where = new StringBuffer();
  where.append(" as trx");
  where.append("   join trx." + MaterialTransaction.PROPERTY_PHYSICALINVENTORYLINE + " as il");
  where.append(" where il." + InventoryCountLine.PROPERTY_PHYSINVENTORY + ".id IN (");
  where.append("    select cri." + CostingRuleInit.PROPERTY_INITINVENTORY + ".id");
  where.append("    from " + CostingRuleInit.ENTITY_NAME + " as cri");
  where.append("    where cri." + CostingRuleInit.PROPERTY_COSTINGRULE + ".id = :cr");
  where.append("    )");
  OBQuery<MaterialTransaction> trxQry = OBDal.getInstance().createQuery(
      MaterialTransaction.class, where.toString());
  trxQry.setNamedParameter("cr", ruleId);
  trxQry.setFetchSize(1000);
  ScrollableResults trxs = trxQry.scroll(ScrollMode.FORWARD_ONLY);
  int i = 0;
  while (trxs.next()) {
    MaterialTransaction trx = (MaterialTransaction) trxs.get(0);
    trx.setTransactionProcessDate(startingDate);
    OBDal.getInstance().save(trx);
    if ((i % 100) == 0) {
      OBDal.getInstance().flush();
      OBDal.getInstance().getSession().clear();
    }
  }
  trxs.close();
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:27,代碼來源:CostingRuleProcess.java

示例3: testScrollCriteria

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public void testScrollCriteria() {
	Session session = openSession();
	Transaction t = session.beginTransaction();

	Course course = new Course();
	course.setCourseCode("HIB");
	course.setDescription("Hibernate Training");
	session.persist(course);
	session.flush();
	session.clear();
	ScrollableResults sr = session.createCriteria(Course.class).scroll();
	assertTrue( sr.next() );
	course = (Course) sr.get(0);
	assertNotNull(course);
	sr.close();
	session.delete(course);
	
	t.commit();
	session.close();
	
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:22,代碼來源:CriteriaQueryTest.java

示例4: cacheExistingStringClassIdentities

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void cacheExistingStringClassIdentities() throws Exception {

    Logger.getLogger(getClass()).info("Loading String Class Identities");

    final Session session =
        getService().getEntityManager().unwrap(Session.class);
    final org.hibernate.Query hQuery = session
        .createSQLQuery("select id, name, language from string_class_identity");
    hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false);
    final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY);
    while (results.next()) {

      final Long id = ((BigInteger) results.get()[0]).longValue();
      final String name = (String) results.get()[1];
      final String language = (String) results.get()[2];
      final String identityCode = name + language;
      stringClassIdentityCache.put(identityCode, id);
    }
    results.close();
  }
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:21,代碼來源:UmlsIdentifierAssignmentHandler.java

示例5: cacheExistingLexicalClassIdentities

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void cacheExistingLexicalClassIdentities() throws Exception {

    Logger.getLogger(getClass()).info("Loading Lexical Class Identities");

    final Session session =
        getService().getEntityManager().unwrap(Session.class);
    final org.hibernate.Query hQuery = session.createSQLQuery(
        "select id, language, normalizedName from lexical_class_identity");
    hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false);
    final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY);
    while (results.next()) {

      final Long id = ((BigInteger) results.get()[0]).longValue();
      final String language = (String) results.get()[1];
      final String normalizedName = (String) results.get()[2];
      final String identityCode = language + normalizedName;
      lexicalClassIdentityCache.put(identityCode, id);
    }
    results.close();
  }
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:21,代碼來源:UmlsIdentifierAssignmentHandler.java

示例6: doGetAll

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected <T extends OriannaObject<?>> List<T> doGetAll(final Class<T> type) {
    final Class<? extends OriannaDto> clazz = getDtoClass(type);

    final ScrollableResults result = hibernateGetAll(clazz);
    if(result == null) {
        return Collections.emptyList();
    }

    try {
        final List<T> response = new ArrayList<>();
        while(result.next()) {
            response.add((T)type.getDeclaredConstructors()[0].newInstance(result.get(0)));
        }
        result.close();
        return response;
    }
    catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
        throw new OriannaException("Couldn't load data from DB");
    }
}
 
開發者ID:meraki-analytics,項目名稱:orianna-hibernate,代碼行數:23,代碼來源:HibernateDB.java

示例7: getGroupedCount

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
protected int getGroupedCount(Query countQuery) {
  int nRows = -1;
  ScrollableResults scrollableResults = countQuery.scroll();
  if (scrollableResults.last()) {
    nRows = scrollableResults.getRowNumber();
  }
  scrollableResults.close();
  return nRows + 1;
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:10,代碼來源:HQLDataSourceService.java

示例8: updateElementValues

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void updateElementValues(Element _element, AcctSchema acctSchema, boolean assetPositive,
    boolean liabilityPositive, boolean ownersEquityPositive, boolean expensePositive,
    boolean revenuePositive) {
  StringBuffer where = new StringBuffer();
  final String ACCOUNTSIGN_CREDIT = "C";
  final String ACCOUNTSIGN_DEBIT = "D";
  final String ACCOUNTTYPE_MEMO = "M";
  Element element = OBDal.getInstance().get(Element.class, _element.getId());
  where.append(ElementValue.PROPERTY_ACCOUNTINGELEMENT + ".id = :element");
  OBQuery<ElementValue> elementValueQry = OBDal.getInstance().createQuery(ElementValue.class,
      where.toString());
  elementValueQry.setFilterOnActive(false);
  elementValueQry.setFilterOnReadableClients(false);
  elementValueQry.setFilterOnReadableOrganization(false);
  elementValueQry.setNamedParameter("element", element.getId());
  elementValueQry.setFetchSize(1000);

  ScrollableResults elementvalues = elementValueQry.scroll(ScrollMode.FORWARD_ONLY);
  try {
    // TODO: Review with Martin to see if flush is permitted in handlers
    // int i = 0;
    while (elementvalues.next()) {
      ElementValue elementValue = (ElementValue) elementvalues.get(0);
      boolean isCredit = getAccountSign(elementValue.getAccountType(), assetPositive,
          liabilityPositive, ownersEquityPositive, expensePositive, revenuePositive);
      if (!ACCOUNTTYPE_MEMO.equals(elementValue.getAccountType())) {
        elementValue.setAccountSign(isCredit ? ACCOUNTSIGN_CREDIT : ACCOUNTSIGN_DEBIT);
      }
      // if ((i % 100) == 0) {
      // OBDal.getInstance().flush();
      // OBDal.getInstance().getSession().clear();
      // element = OBDal.getInstance().get(Element.class, element.getId());
      // }
      // i++;
    }
  } finally {
    elementvalues.close();
  }
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:40,代碼來源:AcctSchemaEventHandler.java

示例9: fixLegacyCostingCurrency

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void fixLegacyCostingCurrency() {
  StringBuffer where = new StringBuffer();
  where.append(" as c");
  where.append("   join c." + Costing.PROPERTY_CLIENT + " as cl");
  where.append(" where c." + Costing.PROPERTY_CURRENCY + " <> cl." + Client.PROPERTY_CURRENCY);
  final OBQuery<Costing> costQry = OBDal.getInstance().createQuery(Costing.class,
      where.toString());
  costQry.setFilterOnActive(false);
  costQry.setFilterOnReadableClients(false);
  costQry.setFilterOnReadableOrganization(false);
  costQry.setFetchSize(1000);

  final ScrollableResults costs = costQry.scroll(ScrollMode.FORWARD_ONLY);
  int i = 0;
  try {
    while (costs.next()) {
      Costing cost = (Costing) costs.get(0);
      cost.setCurrency(cost.getClient().getCurrency());
      OBDal.getInstance().save(cost);
      if ((i % 100) == 0) {
        OBDal.getInstance().flush();
        OBDal.getInstance().getSession().clear();
      }
      i++;
    }
  } finally {
    costs.close();
  }
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:30,代碼來源:CostingMigrationProcess.java

示例10: testSerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public void testSerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources() throws Throwable {
	prepare();
	Session s = getSessionUnderTest();

	Silly silly = new Silly( "silly" );
	s.save( silly );

	// this should cause the CM to obtain a connection, and then release it
	s.flush();

	// both scroll() and iterate() cause the batcher to hold on
	// to resources, which should make aggresive-release not release
	// the connection (and thus cause serialization to fail)
	ScrollableResults sr = s.createQuery( "from Silly" ).scroll();

	try {
		SerializationHelper.serialize( s );
		fail( "Serialization allowed on connected session; or aggressive release released connection with open resources" );
	}
	catch( IllegalStateException e ) {
		// expected behavior
	}

	// Closing the ScrollableResults does currently force the batcher to
	// aggressively release the connection
	sr.close();
	SerializationHelper.serialize( s );

	s.delete( silly );
	s.flush();

	release( s );
	done();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:35,代碼來源:AggressiveReleaseTest.java

示例11: testQueryScrolling

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public void testQueryScrolling() throws Throwable {
	prepare();
	Session s = getSessionUnderTest();
	Silly silly = new Silly( "silly" );
	s.save( silly );
	s.flush();

	ScrollableResults sr = s.createQuery( "from Silly" ).scroll();
	assertTrue( sr.next() );
	Silly silly2 = ( Silly ) sr.get( 0 );
	assertEquals( silly, silly2 );
	sr.close();

	sr = s.createQuery( "from Silly" ).scroll();
	ScrollableResults sr2 = s.createQuery( "from Silly where name = 'silly'" ).scroll();

	assertTrue( sr.next() );
	assertEquals( silly, sr.get( 0 ) );
	assertTrue( sr2.next() );
	assertEquals( silly, sr2.get( 0 ) );

	sr.close();
	sr2.close();

	s.delete( silly );
	s.flush();

	release( s );
	done();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:31,代碼來源:AggressiveReleaseTest.java

示例12: cacheExistingAttributeIdentities

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void cacheExistingAttributeIdentities(String terminology, String name)
  throws Exception {

  Logger.getLogger(getClass())
      .info("Loading Attribute Identities for terminology = " + terminology
          + ", name = " + name);

  final Session session =
      getService().getEntityManager().unwrap(Session.class);
  final org.hibernate.Query hQuery = session.createSQLQuery(
      "select id, componentId, componentTerminology, hashCode, terminologyId from attribute_identity "
          + "where terminology = :terminology and name = :name");
  hQuery.setParameter("terminology", terminology);
  hQuery.setParameter("name", name);
  hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false);
  final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY);
  while (results.next()) {

    final Long id = ((BigInteger) results.get()[0]).longValue();
    final String componentId = (String) results.get()[1];
    final String componentTerminology = (String) results.get()[2];
    final String hashcode = (String) results.get()[3];
    final String terminologyId = (String) results.get()[4];
    final String identityCode = componentId + componentTerminology + hashcode
        + name + terminology + terminologyId;
    attributeIdentityCache.put(identityCode, id);
  }
  results.close();

  // Add this terminology and name to the cached set.
  attributeIdentityCachedTerms.add(terminology + name);
}
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:33,代碼來源:UmlsIdentifierAssignmentHandler.java

示例13: cacheExistingAtomIdentities

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void cacheExistingAtomIdentities(String terminology)
  throws Exception {

  Logger.getLogger(getClass())
      .info("Loading Atom Identities for terminology = " + terminology);

  final Session session =
      getService().getEntityManager().unwrap(Session.class);
  final org.hibernate.Query hQuery = session.createSQLQuery(
      "select id, stringClassId, terminologyId, termType, codeId, conceptId, descriptorId from atom_identity "
          + "where terminology = :terminology");
  hQuery.setParameter("terminology", terminology);
  hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false);
  final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY);
  while (results.next()) {

    final Long id = ((BigInteger) results.get()[0]).longValue();
    final String stringClassId = (String) results.get()[1];
    final String terminologyId = (String) results.get()[2];
    final String termType = (String) results.get()[3];
    final String codeId = (String) results.get()[4];
    final String conceptId = (String) results.get()[5];
    final String descriptorId = (String) results.get()[6];
    final String identityCode = stringClassId + terminology + terminologyId
        + termType + codeId + conceptId + descriptorId;
    atomIdentityCache.put(identityCode, id);
  }
  results.close();

  // Add this terminology to the cached set.
  atomIdentityCachedTerms.add(terminology);
}
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:33,代碼來源:UmlsIdentifierAssignmentHandler.java

示例14: cacheExistingRelationshipIdentities

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
private void cacheExistingRelationshipIdentities(String terminology)
  throws Exception {

  Logger.getLogger(getClass()).info(
      "Loading Relationship Identities for terminology = " + terminology);

  final Session session =
      getService().getEntityManager().unwrap(Session.class);
  final org.hibernate.Query hQuery = session.createSQLQuery(
      "select id, additionalRelationshipType, fromId, fromTerminology, fromType, "
          + "relationshipType, terminologyId, toId, toTerminology, "
          + "toType from relationship_identity "
          + "where terminology = :terminology");
  hQuery.setParameter("terminology", terminology);
  hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false);
  final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY);
  while (results.next()) {

    final Long id = ((BigInteger) results.get()[0]).longValue();
    final String additionalRelationshipType = (String) results.get()[1];
    final String fromId = (String) results.get()[2];
    final String fromTerminology = (String) results.get()[3];
    final String fromType = (String) results.get()[4];
    final String relationshipType = (String) results.get()[5];
    final String terminologyId = (String) results.get()[6];
    final String toId = (String) results.get()[7];
    final String toTerminology = (String) results.get()[8];
    final String toType = (String) results.get()[9];
    final String identityCode = additionalRelationshipType + fromId
        + fromTerminology + fromType + relationshipType + terminology
        + terminologyId + toId + toTerminology + toType;
    relationshipIdentityCache.put(identityCode, id);
  }
  results.close();

  // Add this terminology to the cached set.
  relationshipIdentityCachedTerms.add(terminology);
}
 
開發者ID:WestCoastInformatics,項目名稱:UMLS-Terminology-Server,代碼行數:39,代碼來源:UmlsIdentifierAssignmentHandler.java

示例15: getRowCountOfDCRst

import org.hibernate.ScrollableResults; //導入方法依賴的package包/類
public Integer getRowCountOfDCRst(DetachedCriteria dc) {
	Session session = (Session) this.em.getDelegate();
	boolean needClose = false;
	if (!session.isOpen()) {
		session = session.getSessionFactory().openSession();
		needClose = true;
	}

	ScrollableResults sc = null;
	try {
		Criteria c = dc.getExecutableCriteria(session);
		sc = c.scroll(ScrollMode.FORWARD_ONLY);
		sc.last();
		int count = sc.getRowNumber() + 1;

		return count;
	} finally {
		if (sc != null) {
			sc.close();
			sc = null;
		}

		if (needClose) {
			session.close();
			session = null;
		}

	}
}
 
開發者ID:dynamo2,項目名稱:tianma,代碼行數:30,代碼來源:AbstractBaseDAO.java


注:本文中的org.hibernate.ScrollableResults.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。