org.hibernate.Query.setReadOnly()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中org.hibernate.Query.setReadOnly方法的一些代码示例,展示了Query.setReadOnly的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setReadOnly方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setReadOnly

Query.setReadOnly介绍

[英]Set the read-only/modifiable mode for entities and proxies loaded by this Query. This setting overrides the default setting for the persistence context.
[中]为此查询加载的实体和代理设置只读/可修改模式。此设置覆盖持久性上下文的默认设置。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

List list = s.createFilter( c.getLazyDataPoints(), "" )
    .setMaxResults(1)
    .setReadOnly( true )
    .list();
assertEquals( 1, list.size() );
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
    .setMaxResults(1)
    .setReadOnly( true )
    .list();
assertEquals( 1, list.size() );
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
    .setMaxResults(1)
    .setReadOnly( true )
    .list();
assertEquals( 1, list.size() );

代码示例来源:origin: hibernate/hibernate-orm

List list = s.createFilter( c.getLazyDataPoints(), "" )
    .setMaxResults(1)
    .setReadOnly( false )
    .list();
assertEquals( 1, list.size() );
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
    .setMaxResults(1)
    .setReadOnly( false )
    .list();
assertEquals( 1, list.size() );
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
    .setMaxResults(1)
    .setReadOnly( false )
    .list();
assertEquals( 1, list.size() );

代码示例来源:origin: hibernate/hibernate-orm

s.setDefaultReadOnly( false );
assertFalse( query.isReadOnly() );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( true );
s.setDefaultReadOnly( false );
assertTrue( query.isReadOnly() );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( true );
assertFalse( query.isReadOnly() );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( false );
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );
assertFalse( s.isReadOnly( dpLast ) );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
int nExpectedChanges = 0;

代码示例来源:origin: hibernate/hibernate-orm

s.setDefaultReadOnly( true );
assertTrue( query.isReadOnly() );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( false );
s.setDefaultReadOnly( true );
assertFalse( query.isReadOnly() );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( false );
assertTrue( query.isReadOnly() );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( true );
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );
assertTrue( s.isReadOnly( dpLast ) );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
int nExpectedChanges = 0;

代码示例来源:origin: hibernate/hibernate-orm

s.setDefaultReadOnly( true );
assertTrue( query.isReadOnly() );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( false );
s.setDefaultReadOnly( true );
assertFalse( query.isReadOnly() );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( false );
assertTrue( query.isReadOnly() );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( true );
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );
assertTrue( s.isReadOnly( dpLast ) );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
int nExpectedChanges = 0;

代码示例来源:origin: hibernate/hibernate-orm

s.setDefaultReadOnly( false );
assertFalse( query.isReadOnly() );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( true );
s.setDefaultReadOnly( false );
assertTrue( query.isReadOnly() );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( true );
assertFalse( query.isReadOnly() );
query.setReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( false );
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );		
assertFalse( s.isReadOnly( dpLast ) );
query.setReadOnly( false );
assertFalse( query.isReadOnly() );
int nExpectedChanges = 0;

代码示例来源:origin: stackoverflow.com

Query query = session.createQuery(query);
query.setReadOnly(true);
// MIN_VALUE gives hint to JDBC driver to stream results
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
// iterate over results
while (results.next()) {
  Object row = results.get();
  // process row then release reference
  // you may need to evict() as well
}
results.close();

代码示例来源:origin: ezbz/projectx

@Override
public Query setReadOnly(final boolean readOnly) {
 return query.setReadOnly(readOnly);
}

代码示例来源:origin: org.sakaiproject.samigo/samigo-services

private int countItems(Map<String, String> hqlQueries, Session session) {
  @SuppressWarnings("unchecked")
  final List<Integer> totalItemsResult = session
      .createQuery(hqlQueries.get(TOTAL_ITEM_COUNT_HQL))
      .setReadOnly(true).list();
  return totalItemsResult.get(0);
}

代码示例来源:origin: sakaiproject/sakai

private int countItems(Map<String, String> hqlQueries, Session session) {
  @SuppressWarnings("unchecked")
  final List<Integer> totalItemsResult = session
      .createQuery(hqlQueries.get(TOTAL_ITEM_COUNT_HQL))
      .setReadOnly(true).list();
  return totalItemsResult.get(0);
}

代码示例来源:origin: sakaiproject/sakai

private int countItemsNeedingHashBackfill(Map<String, String> hqlQueries, Session session) {
  @SuppressWarnings("unchecked")
  final List<Integer> totalItemsNeedingBackfillResult = session
      .createQuery(hqlQueries.get(TOTAL_HASH_BACKFILLABLE_ITEM_COUNT_HQL))
      .setReadOnly(true).list();
  return totalItemsNeedingBackfillResult.get(0);
}

代码示例来源:origin: org.sakaiproject.samigo/samigo-services

private int countItemsNeedingHashBackfill(Map<String, String> hqlQueries, Session session) {
  @SuppressWarnings("unchecked")
  final List<Integer> totalItemsNeedingBackfillResult = session
      .createQuery(hqlQueries.get(TOTAL_HASH_BACKFILLABLE_ITEM_COUNT_HQL))
      .setReadOnly(true).list();
  return totalItemsNeedingBackfillResult.get(0);
}

代码示例来源:origin: at.chrl/chrl-orm

/**
 * Creates {@link Stream} with given query Result
 * 
 * @param q
 *            - given Query q. q is marked as ReadOnly with
 *            {@link Query#setReadOnly(true)}
 * @return new {@link Stream} with given ResultSet
 */
public <T> Stream<T> streamReadOnly(Query q) {
  return stream(q.setReadOnly(true));
}

代码示例来源:origin: org.ow2.bonita/bonita-server

@Override
public int getCasesNumber(final String ownerName, final String labelName) {
 final Query query = getSession().getNamedQuery("getCasesNumber");
 query.setString("ownerName", ownerName);
 query.setString("label", labelName);
 query.setReadOnly(true);
 return ((Long) query.uniqueResult()).intValue();
}

代码示例来源:origin: org.wso2.bpel/ode-dao-hibernate

public boolean checkRoute(CorrelationKeySet correlationKeySet) {
  entering("CorrelatorDaoImpl.checkRoute");
  Query q = getSession().getNamedQuery(HCorrelatorSelector.SELECT_MESSAGE_ROUTE);
  q.setEntity("corr",_hobj);
  q.setString("ckey", correlationKeySet.toCanonicalString());
  q.setReadOnly(true);
  return q.list().isEmpty();
}

代码示例来源:origin: stackoverflow.com

Query query = session.createQuery(query);
query.setReadOnly(true);
setFetchSize(Integer.MIN_VALUE); //MUST use Integer.MIN_VALUE, other value=fetch all
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
// iterate over results
while (results.next()) {
  Object row = results.get();
}
results.close();

代码示例来源:origin: org.ow2.bonita/bonita-server

@Override
public int getCasesNumberWithTwoLabels(final String ownerName, final String label1Name, final String label2Name) {
 final Query query = getSession().getNamedQuery("getCasesNumberWithTwoLabels");
 query.setString("label1", CaseImpl.buildLabel(ownerName, label1Name));
 query.setString("label2", CaseImpl.buildLabel(ownerName, label2Name));
 query.setReadOnly(true);
 return ((Long) query.uniqueResult()).intValue();
}

代码示例来源:origin: stackoverflow.com

Query query = session.createQuery(query);
query.setReadOnly(true);
// MIN_VALUE gives hint to JDBC driver to stream results
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
// iterate over results
while (results.next()) {
  Object row = results.get();
  // process row then release reference
  // you may need to evict() as well
}
results.close();

代码示例来源:origin: stackoverflow.com

Query query = session.createQuery(query);
query.setReadOnly(true);
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
// iterate over results
while (results.next()) {
  Object row = results.get();
  // process row then release reference
  // you may need to evict() as well
}
results.close();

代码示例来源:origin: stackoverflow.com

Query query = session.createQuery(query);
query.setReadOnly(true);
// MIN_VALUE gives hint to JDBC driver to stream results
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
// iterate over results
while (results.next()) {
  Object row = results.get();
  // process row then release reference
  // you may need to flush() as well
}
results.close();

相关文章