本文整理了Java中org.hibernate.Query.setMaxResults
方法的一些代码示例,展示了Query.setMaxResults
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setMaxResults
方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setMaxResults
[英]Set the maximum number of rows to retrieve. If not set, there is no limit to the number of rows retrieved.
[中]设置要检索的最大行数。如果未设置,则检索的行数没有限制。
代码示例来源:origin: gocd/gocd
Modification findLatestModification(final MaterialInstance expandedInstance) {
Modifications modifications = cachedModifications(expandedInstance);
if (modifications != null && !modifications.isEmpty()) {
return modifications.get(0);
}
String cacheKey = latestMaterialModificationsKey(expandedInstance);
synchronized (cacheKey) {
Modification modification = (Modification) getHibernateTemplate().execute((HibernateCallback) session -> {
Query query = session.createQuery("FROM Modification WHERE materialId = ? ORDER BY id DESC");
query.setMaxResults(1);
query.setLong(0, expandedInstance.getId());
return query.uniqueResult();
});
goCache.put(cacheKey, new Modifications(modification));
return modification;
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testPSCache() throws Exception {
Session s = openSession();
Transaction txn = s.beginTransaction();
for ( int i=0; i<10; i++ ) s.save( new Foo() );
Query q = s.createQuery("from Foo");
q.setMaxResults(2);
q.setFirstResult(5);
assertTrue( q.list().size()==2 );
q = s.createQuery("from Foo");
assertTrue( q.list().size()==10 );
assertTrue( q.list().size()==10 );
q.setMaxResults(3);
q.setFirstResult(3);
assertTrue( q.list().size()==3 );
q = s.createQuery("from Foo");
assertTrue( q.list().size()==10 );
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
q = s.createQuery("from Foo");
assertTrue( q.list().size()==10 );
q.setMaxResults(5);
assertTrue( q.list().size()==5 );
doDelete( s, "from Foo" );
txn.commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
s.save(simple );
s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'" ).list();
Query q = s.createQuery("from Simple s");
q.setMaxResults( 10 );
assertTrue( q.list().size()==3 );
q = s.createQuery("from Simple s");
q.setMaxResults( 1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s");
assertTrue( q.list().size() == 3 );
q = s.createQuery("from Simple s where s.name = ?");
q.setString( 0, "Simple 1" );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name = ? and upper(s.name) = ?");
q.setString(1, "SIMPLE 1");
q.setString( 0, "Simple 1" );
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );
q = s.createQuery("select s.id from Simple s");
q.setFirstResult(1);
q.setMaxResults( 2 );
iter = q.iterate();
int i=0;
代码示例来源:origin: org.ow2.bonita/bonita-pvm
public ClientExecution findExecutionById(String executionId) {
// query definition can be found at the bottom of resource
// org/ow2/bonita/pvm/hibernate.execution.hbm.xml
Query query = session.getNamedQuery("findExecutionById");
query.setString("id", executionId);
query.setMaxResults(1);
return (ClientExecution) query.uniqueResult();
}
代码示例来源:origin: org.ow2.bonita/bonita-server
@Override
@SuppressWarnings("unchecked")
public List<InternalProcessInstance> getParentProcessInstancesWithInvolvedUser(final String userId,
final int fromIndex, final int pageSize) {
final Query query = getSession().getNamedQuery("getParentProcessInstancesWithInvolvedUser");
query.setFirstResult(fromIndex);
query.setMaxResults(pageSize);
query.setString("userId", userId);
return formatList(query.list());
}
代码示例来源:origin: denimgroup/threadfix
@Override
public Calendar getMostRecentQueueScanTime(Integer channelId) {
return (Calendar) sessionFactory
.getCurrentSession()
.createQuery("select scanDate from JobStatus status " +
"where applicationChannel = :channelId and hasStartedProcessing is false " +
"order by scanDate desc")
.setInteger("channelId", channelId).setMaxResults(1).uniqueResult();
}
代码示例来源:origin: openmrs/openmrs-core
/**
* @see org.openmrs.hl7.db.HL7DAO#getNextHL7InQueue()
*/
@Override
public HL7InQueue getNextHL7InQueue() throws DAOException {
Query query = sessionFactory.getCurrentSession().createQuery(
"from HL7InQueue as hiq where hiq.messageState = ? order by HL7InQueueId").setParameter(0,
HL7Constants.HL7_STATUS_PENDING, StandardBasicTypes.INTEGER).setMaxResults(1);
if (query == null) {
return null;
}
return (HL7InQueue) query.uniqueResult();
}
代码示例来源:origin: gocd/gocd
public Modifications getModificationsFor(final MaterialInstance materialInstance, final Pagination pagination) {
String key = materialModificationsWithPaginationKey(materialInstance);
String subKey = materialModificationsWithPaginationSubKey(pagination);
Modifications modifications = (Modifications) goCache.get(key, subKey);
if (modifications == null) {
synchronized (key) {
modifications = (Modifications) goCache.get(key, subKey);
if (modifications == null) {
List<Modification> modificationsList = (List<Modification>) getHibernateTemplate().execute((HibernateCallback) session -> {
Query q = session.createQuery("FROM Modification WHERE materialId = ? ORDER BY id DESC");
q.setFirstResult(pagination.getOffset());
q.setMaxResults(pagination.getPageSize());
q.setLong(0, materialInstance.getId());
return q.list();
});
if (!modificationsList.isEmpty()) {
modifications = new Modifications(modificationsList);
goCache.put(key, subKey, modifications);
}
}
}
}
return modifications;
}
代码示例来源:origin: org.jbpm/pvm
public ClientExecution findExecutionById(String executionId) {
// query definition can be found at the bottom of resource org/jbpm/pvm/hibernate.execution.hbm.xml
Query query = session.getNamedQuery("findExecutionById");
query.setString("id", executionId);
query.setMaxResults(1);
return (ClientExecution) query.uniqueResult();
}
代码示例来源:origin: hibernate/hibernate-orm
s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat( lower(s.name), 3 + (1-1) / 2) = 'foofoofoo'" ).list();
Query q = s.createQuery("from Simple s");
q.setMaxResults(10);
assertTrue( q.list().size()==3 );
q = s.createQuery("from Simple s");
q.setMaxResults(1);
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s");
assertTrue( q.list().size()==3 );
q = s.createQuery("from Simple s where s.name = ?");
q.setString(0, "Simple 1");
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name = ? and upper(s.name) = ?");
q.setString(1, "SIMPLE 1");
q.setString(0, "Simple 1");
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );
q = s.createQuery("select s.id from Simple s");
q.setFirstResult(1);
q.setMaxResults(2);
iter = q.iterate();
int i=0;
代码示例来源:origin: org.ow2.bonita/bonita-server
@SuppressWarnings("unchecked")
@Override
public List<Document> getDocuments(final ProcessInstanceUUID instanceUUID, final int fromResult, final int maxResults) {
final Query query = getSession().getNamedQuery("getDocumentsOfProcessInstance");
query.setString("processInstanceUUID", instanceUUID.getValue());
query.setFirstResult(fromResult);
query.setMaxResults(maxResults);
return query.list();
}
代码示例来源:origin: denimgroup/threadfix
@Override
public WafRule retrieveByVulnerabilityAndWafAndDirective(
Vulnerability vuln, Waf waf, WafRuleDirective directive) {
return (WafRule) sessionFactory
.getCurrentSession()
.createQuery( "from WafRule wafRule where wafRule.vulnerability = :vulnId " +
"and wafRule.waf = :wafId and wafRule.wafRuleDirective = :directiveId")
.setInteger("vulnId", vuln.getId())
.setInteger("wafId", waf.getId())
.setInteger("directiveId", directive.getId())
.setMaxResults(1).uniqueResult();
}
代码示例来源:origin: OpenNMS/opennms
public OnmsNode doInHibernate(Session session) throws HibernateException, SQLException {
Integer nodeId = (Integer)session.createQuery(query2).setMaxResults(1).uniqueResult();
return getNode(nodeId, session);
}
});
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testHql() {
Session session = openSession();
session.beginTransaction();
Query qry = session.createQuery( "from Door" );
qry.getLockOptions().setLockMode( LockMode.PESSIMISTIC_WRITE );
qry.setFirstResult( 2 );
qry.setMaxResults( 2 );
@SuppressWarnings("unchecked") List<Door> results = qry.list();
assertEquals( 2, results.size() );
for ( Door door : results ) {
assertEquals( LockMode.PESSIMISTIC_WRITE, session.getCurrentLockMode( door ) );
}
session.getTransaction().commit();
session.close();
}
代码示例来源:origin: org.jbpm/pvm
public ClientProcessDefinition findLatestProcessDefinitionByName(String name) {
// query definition can be found at the bottom of resource org/jbpm/pvm/hibernate.definition.hbm.xml
Query query = session.getNamedQuery("findProcessDefinitionsByName");
query.setString("name", name);
query.setMaxResults(1);
ClientProcessDefinition processDefinition = (ClientProcessDefinition) query.uniqueResult();
return processDefinition;
}
代码示例来源:origin: OpenClinica/OpenClinica
public LogUsageStatsBean findLatestUsageStatParamValue(String param_key) {
// logger.debug("UsageStatsServiceDAO -> findLatestUsageStatParamValue");
String query =
"from " + getDomainClassName() + " usageStatParams where param_key = :param_key order by update_timestamp desc";
List<LogUsageStatsBean> logUsageStatsBeanLst = new ArrayList<LogUsageStatsBean>();
LogUsageStatsBean logUsageStatsBeanRet = new LogUsageStatsBean();
org.hibernate.Query q = getCurrentSession().createQuery(query);
q.setString("param_key", param_key);
q.setMaxResults(1);
logUsageStatsBeanLst = q.list();
if ((null != logUsageStatsBeanLst) && (logUsageStatsBeanLst.size() != 0)) {
logUsageStatsBeanRet = logUsageStatsBeanLst.get(0);
}
return logUsageStatsBeanRet;
}
代码示例来源:origin: org.ow2.bonita/bonita-server
@SuppressWarnings("unchecked")
@Override
public List<DocumentDescriptor> getDocumentDescriptors(final ProcessDefinitionUUID processDefinitionUUID,
final int fromIndex, final int maxResults) {
final Query query = getSession().getNamedQuery("getDocumentDescriptorsOfProcessDefinition");
query.setString("processDefinitionUUID", processDefinitionUUID.getValue());
query.setFirstResult(fromIndex);
query.setMaxResults(maxResults);
return query.list();
}
代码示例来源:origin: riotfamily/riot
private boolean isSetupRequired(Session session) {
if (condition == null) {
return true;
}
Query query = session.createQuery(condition).setMaxResults(1);
Object test = query.uniqueResult();
if (test instanceof Number) {
return ((Number) test).intValue() == 0;
}
if (test instanceof Boolean) {
return ((Boolean) test).booleanValue();
}
return test == null;
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testMaxResults() {
doInHibernate(
this::sessionFactory,
session -> {
Query query = session.createQuery( "from Employee" );
// not initialized yet
assertNull( query.getHibernateMaxResults() );
// values <= 0 are considered uninitialized;
assertNull( query.setHibernateMaxResults( -1 ).getHibernateMaxResults() );
assertNull( query.setHibernateMaxResults( 0 ).getHibernateMaxResults() );
assertEquals( Integer.valueOf( 1 ), query.setHibernateMaxResults( 1 ).getHibernateMaxResults() );
assertEquals( Integer.valueOf( 0 ), query.setMaxResults( 0 ).getHibernateMaxResults() );
assertEquals( Integer.valueOf( 2 ), query.setMaxResults( 2 ).getHibernateMaxResults() );
}
);
}
代码示例来源:origin: org.jbpm/pvm
public ClientProcessDefinition findProcessDefinitionById(String processDefinitionId) {
// query definition can be found at the bottom of resource org/jbpm/pvm/hibernate.definition.hbm.xml
Query query = session.getNamedQuery("findProcessDefinitionsById");
query.setString("id", processDefinitionId);
query.setMaxResults(1);
ClientProcessDefinition processDefinition = (ClientProcessDefinition) query.uniqueResult();
return processDefinition;
}
内容来源于网络,如有侵权,请联系作者删除!