本文整理了Java中org.hibernate.Query.uniqueResult
方法的一些代码示例,展示了Query.uniqueResult
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.uniqueResult
方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:uniqueResult
[英]Convenience method to return a single instance that matches the query, or null if the query returns no results.
[中]
代码示例来源:origin: citerus/dddsample-core
public Cargo find(TrackingId tid) {
return (Cargo) getSession().
createQuery("from Cargo where trackingId = :tid").
setParameter("tid", tid).
uniqueResult();
}
代码示例来源:origin: gocd/gocd
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();
});
}
}
代码示例来源:origin: gocd/gocd
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;
}
代码示例来源: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: org.ow2.bonita/bonita-core
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;
}
代码示例来源:origin: gocd/gocd
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;
}
代码示例来源:origin: sakaiproject/sakai
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();
}
代码示例来源: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-demos
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;
}
代码示例来源:origin: org.sakaiproject.common/sakai-common-composite-component
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();
}
};
代码示例来源:origin: kaaproject/kaa
@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;
}
代码示例来源:origin: jtalks-org/jcommune
/**
* {@inheritDoc}
*/
@Override
public UserContact getContactById(long id) {
return (UserContact) session()
.createQuery("from UserContact u where u.id = ?")
.setCacheable(true)
.setLong(0, id)
.uniqueResult();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected Object getResults(Session s, boolean isSingleResult) {
Query query = getQuery( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() );
return ( isSingleResult ? query.uniqueResult() : query.list() );
}
}
代码示例来源:origin: hibernate/hibernate-orm
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 );
代码示例来源:origin: sakaiproject/sakai
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();
}
代码示例来源:origin: netgloo/spring-boot-samples
public User getByEmail(String email) {
return (User) getSession().createQuery(
"from User where email = :email")
.setParameter("email", email)
.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: org.ow2.bonita/bonita-core
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();
}
代码示例来源:origin: sakaiproject/sakai
/**
*/
public CourseGrade getCourseGrade(final Long gradebookId) {
return (CourseGrade) getSessionFactory().getCurrentSession().createQuery(
"from CourseGrade as cg where cg.gradebook.id = :gradebookid")
.setLong("gradebookid", gradebookId)
.uniqueResult();
}
代码示例来源:origin: sakaiproject/sakai
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();
}
内容来源于网络,如有侵权,请联系作者删除!