public Cargo find(TrackingId tid) { return (Cargo) getSession(). createQuery("from Cargo where trackingId = :tid"). setParameter("tid", tid). uniqueResult(); }
private Agent fetchAgentByUuid(final String uuid) { return (Agent) getHibernateTemplate().execute(session -> { Query query = session.createQuery("from Agent where uuid = :uuid"); query.setString("uuid", uuid); return query.uniqueResult(); }); } }
Modification findModificationWithRevision(Session session, long materialId, String revision) { Modification modification; String key = cacheKeyForModificationWithRevision(materialId, revision); modification = (Modification) goCache.get(key); if (modification == null) { synchronized (key) { modification = (Modification) goCache.get(key); if (modification == null) { Query query = session.createQuery("FROM Modification WHERE materialId = ? and revision = ? ORDER BY id DESC"); query.setLong(0, materialId); query.setString(1, revision); modification = (Modification) query.uniqueResult(); goCache.put(key, modification); } } } return modification; }
/** * @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 ProcessVersion getLastProcessVersion(String processId, String packageId) { Query query = getSession().getNamedQuery("getLastProcessVersion"); query.setCacheable(true); query.setString("processId", processId); query.setString("packageId", packageId); query.setMaxResults(1); ProcessVersion pv = (ProcessVersion) query.uniqueResult(); return pv; }
public Long getTotalModificationsFor(final MaterialInstance materialInstance) { String key = materialModificationCountKey(materialInstance); Long totalCount = (Long) goCache.get(key); if (totalCount == null || totalCount == 0) { synchronized (key) { totalCount = (Long) goCache.get(key); if (totalCount == null || totalCount == 0) { totalCount = (Long) getHibernateTemplate().execute((HibernateCallback) session -> { Query q = session.createQuery("select count(*) FROM Modification WHERE materialId = ?"); q.setLong(0, materialInstance.getId()); return q.uniqueResult(); }); goCache.put(key, totalCount); } } } return totalCount; }
public Integer getCountItemFacades(final Long questionPoolId) { final HibernateCallback<Number> hcb = session -> { Query q = session.createQuery("select count(ab) from ItemData ab, QuestionPoolItemData qpi where ab.itemId = qpi.itemId and qpi.questionPoolId = :id"); q.setLong("id", questionPoolId); q.setCacheable(true); return (Number) q.uniqueResult(); }; return getHibernateTemplate().execute(hcb).intValue(); }
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; } }
public Project getProject(long id) { final Session s = openSession(); s.getTransaction().begin(); final Query q = s.createQuery( "FROM Project WHERE id = :id" ); q.setParameter( "id", id ); q.setCacheable( true ); final Project project = (Project) q.uniqueResult(); s.getTransaction().commit(); return project; }
public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = session.getNamedQuery(FINDTYPEBYTUPLE); q.setString(AUTHORITY, authority); q.setString(DOMAIN, domain); q.setString(KEYWORD, keyword); q.setCacheable(cacheFindTypeByTuple); q.setCacheRegion(Type.class.getCanonicalName()); return q.uniqueResult(); } };
@Override public EventClassFamily findByEcfvId(String ecfvId) { LOG.debug("Searching event class family by ecfv id [{}]", ecfvId); Query query = getSession().createSQLQuery( "select ecf.*" + " from " + EVENT_CLASS_FAMILY_TABLE_NAME + " as ecf" + " join " + EVENT_CLASS_FAMILY_VERSION_TABLE_NAME + " as ecfv" + " on ecf.id = ecfv." + EVENT_CLASS_FAMILY_ID + " where ecfv.id = :id").addEntity(getEntityClass()); query.setLong("id", Long.valueOf(ecfvId)); EventClassFamily eventClassFamily = (EventClassFamily) query.uniqueResult(); LOG.debug("[{}] Search result: {}.", ecfvId, eventClassFamily); return eventClassFamily; }
/** * {@inheritDoc} */ @Override public UserContact getContactById(long id) { return (UserContact) session() .createQuery("from UserContact u where u.id = ?") .setCacheable(true) .setLong(0, id) .uniqueResult(); } }
@Override protected Object getResults(Session s, boolean isSingleResult) { Query query = getQuery( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() ); return ( isSingleResult ? query.uniqueResult() : query.list() ); } }
s.save( bar2 ); List list = s.createQuery( "from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar %'" ).list(); assertTrue( row instanceof Object[] && ( (Object[]) row ).length==3 ); Query q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar%'"); list = q.list(); if ( !(getDialect() instanceof SAPDBDialect) ) assertTrue( list.size()==2 ); q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where ( bar.name in (:nameList) or bar.name in (:nameList) ) and bar.string = :stringVal"); HashSet nameList = new HashSet(); nameList.add( "bar" ); q = s.createQuery("select bar, b from Bar bar inner join bar.baz baz inner join baz.cascadingBars b where bar.name like 'Bar%'"); Object result = q.uniqueResult(); assertTrue( result != null ); q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like :name and b.name like :name"); q.setString( "name", "Bar%" ); list = q.list(); assertTrue( list.size()==1 );
protected GradebookAssignment getAssignmentWithoutStats(final String gradebookUid, final Long assignmentId) throws HibernateException { return (GradebookAssignment) getSessionFactory().getCurrentSession() .createQuery("from GradebookAssignment as asn where asn.id = :assignmentid and asn.gradebook.uid = :gradebookuid and asn.removed is false") .setLong("assignmentid", assignmentId) .setString("gradebookuid", gradebookUid) .uniqueResult(); }
public User getByEmail(String email) { return (User) getSession().createQuery( "from User where email = :email") .setParameter("email", email) .uniqueResult(); }
public OnmsNode doInHibernate(Session session) throws HibernateException, SQLException { Integer nodeId = (Integer)session.createQuery(query2).setMaxResults(1).uniqueResult(); return getNode(nodeId, session); } });
public PackageFullDefinition getPackage(String packageId, String version) { final Query query = getSession().getNamedQuery("getPackageFromIdAndVersion"); query.setCacheable(true); query.setString("packageId", packageId); query.setString("version", version); query.setMaxResults(1); return (PackageFullDefinition) query.uniqueResult(); }
/** */ public CourseGrade getCourseGrade(final Long gradebookId) { return (CourseGrade) getSessionFactory().getCurrentSession().createQuery( "from CourseGrade as cg where cg.gradebook.id = :gradebookid") .setLong("gradebookid", gradebookId) .uniqueResult(); }
public long getSubPoolSize(final Long poolId) { final HibernateCallback<Number> hcb = session -> { Query q = session.createQuery("select count(qpp) from QuestionPoolData qpp where qpp.parentPoolId = :id"); q.setCacheable(true); q.setLong("id", poolId); return (Number) q.uniqueResult(); }; return getHibernateTemplate().execute(hcb).longValue(); }