本文整理了Java中org.hibernate.Query.setCacheable
方法的一些代码示例,展示了Query.setCacheable
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setCacheable
方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setCacheable
[英]Enable caching of this query result set.
[中]启用此查询结果集的缓存。
代码示例来源:origin: gocd/gocd
@Override
public List<Plugin> getAllPlugins() {
return (List<Plugin>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM " + Plugin.class.getSimpleName());
query.setCacheable(true);
return query.list();
});
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Call setEntity() on a cacheable query - see FORGE-265
*/
public List listEventsOfOrganizer(Person organizer) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("from Event ev where ev.organizer = :organizer");
query.setCacheable(true);
query.setEntity("organizer", organizer);
List result = query.list();
session.getTransaction().commit();
return result;
}
代码示例来源: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
Query q = s.createQuery("from Simple s where s.name=?");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheable(true);
q.setString("name", "Simple 1");
assertTrue( q.list().size()==1 );
simple = (Simple) q.list().get(0);
q.setString("name", "Simple 2");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
q = s.createQuery("from Simple s where s.name=:name");
q.setString("name", "Simple 2");
q.setCacheable(true);
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
t = s.beginTransaction();
q = s.createQuery("from Simple s where s.name=?");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==0 );
代码示例来源: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: org.ow2.bonita/bonita-core
@SuppressWarnings("unchecked")
public Set<ActivityFullInstance<TaskInstance>> getUserTasks(String userId, TaskState taskState) {
Query query = getSession().getNamedQuery("getUserTasksWithState");
query.setCacheable(true);
query.setString("userId", userId);
query.setParameter("state", taskState, taskStateUserType);
Set<ActivityFullInstance<TaskInstance>> result = new HashSet<ActivityFullInstance<TaskInstance>>();
result.addAll(query.list());
return result;
}
代码示例来源: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: org.openmobster.core/security
device = (Device)session.createQuery(query).setString(0, identifier).setCacheable(true).uniqueResult();
代码示例来源:origin: at.chrl/chrl-orm
/**
* Create query
*
* @param stmt
* the statement
*/
public Query createQuery(String stmt) {
return session.createQuery(stmt).setCacheable(true);
}
代码示例来源: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: 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: org.ow2.bonita/bonita-core
public Set<ProcessFullDefinition> getProcesses(String processId, String version) {
final Query query = getSession().getNamedQuery("getProcessFromIdAndVersion");
query.setCacheable(true);
query.setString("processId", processId);
query.setString("version", version);
return getProcessSet(query);
}
代码示例来源:origin: hibernate/hibernate-orm
Query q = s.createQuery("from Simple s where s.name=?");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString("name", "Simple 1");
assertTrue( q.list().size()==1 );
simple = (Simple) q.list().get(0);
q.setString("name", "Simple 2");
assertTrue( q.list().size()==0 );
assertTrue( q.list().size()==0 );
q = s.createQuery("from Simple s where s.name=?");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString(0, "Simple 1");
assertTrue( q.list().size()==0 );
代码示例来源:origin: hibernate/hibernate-orm
/**
* Call setEntity() on a cacheable query - see FORGE-265
*/
public List listEventsOfOrganizer(Person organizer) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("from Event ev where ev.organizer = :organizer");
query.setCacheable(true);
query.setEntity("organizer", organizer);
List result = query.list();
session.getTransaction().commit();
return result;
}
代码示例来源:origin: org.sakaiproject.common/sakai-common-composite-component
public Object doInHibernate(Session session) throws HibernateException, SQLException
{
Query q = session.getNamedQuery(FINDTYPEBYUUID);
q.setString(UUID, uuid);
q.setCacheable(cacheFindTypeByUuid);
q.setCacheRegion(Type.class.getCanonicalName());
return q.uniqueResult();
}
};
代码示例来源:origin: org.ow2.bonita/bonita-core
@SuppressWarnings("unchecked")
public Set<PackageDependency> getPackageDependencies(String className) {
final Query query = getSession().getNamedQuery("getPackageDependencies");
query.setCacheable(true);
query.setString("className", className);
final List<PackageDependency> results = query.list();
if (results != null) {
return new HashSet<PackageDependency>(results);
}
return null;
}
代码示例来源: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();
}
代码示例来源:origin: org.openmobster.core/security
identity = (Identity)session.createQuery(query).setString(0, principal).setCacheable(true).uniqueResult();
代码示例来源:origin: gocd/gocd
public Users allUsers() {
return new Users((List<User>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM User");
query.setCacheable(true);
return query.list();
}));
}
代码示例来源:origin: jpos/jPOS-EE
private void addRules
(Map<String,Object> ruleMap, Journal journal, List acctHierarchy, int offset)
throws HibernateException
{
Query q = session.createQuery (
"from org.jpos.gl.RuleInfo where journal=:journal and account in (:accts) order by id"
);
q.setParameter ("journal", journal);
q.setParameterList ("accts", acctHierarchy, new LongType());
q.setCacheable (true);
q.setCacheRegion ("rules");
Iterator iter = q.iterate();
while (iter.hasNext()) {
RuleInfo ri = (RuleInfo) iter.next();
RuleEntry k = new RuleEntry (ri, ri.getAccount());
RuleEntry re = (RuleEntry) ruleMap.get (k.getKey());
if (re == null)
ruleMap.put (k.getKey(), re = k);
re.addOffset (offset);
}
}
private void applyRules (GLTransaction txn, Collection rules)
内容来源于网络,如有侵权,请联系作者删除!