Refine search
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; } }
@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(); }
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;
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(); }
@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()); }
@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(); }
/** * @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(); }
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; }
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(); }
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;
@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(); }
@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(); }
public OnmsNode doInHibernate(Session session) throws HibernateException, SQLException { Integer nodeId = (Integer)session.createQuery(query2).setMaxResults(1).uniqueResult(); return getNode(nodeId, session); } });
@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(); }
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; }
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; }
@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(); }
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; }
@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() ); } ); }
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; }