本文整理了Java中org.hibernate.Query.setCacheRegion
方法的一些代码示例,展示了Query.setCacheRegion
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setCacheRegion
方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setCacheRegion
[英]Set the name of the cache region.
[中]设置缓存区域的名称。
代码示例来源:origin: hibernate/hibernate-orm
t = s.beginTransaction();
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 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString("name", "Simple 1");
t = s.beginTransaction();
q = s.createQuery("from Simple s where s.name=?");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString(0, "Simple 1");
代码示例来源:origin: hibernate/hibernate-orm
t = s.beginTransaction();
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 );
q = s.createQuery("from Simple s where s.name=:name");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString("name", "Simple 1");
t = s.beginTransaction();
q = s.createQuery("from Simple s where s.name=?");
q.setCacheRegion("foo");
q.setCacheable(true);
q.setString(0, "Simple 1");
代码示例来源:origin: spring-projects/spring-framework
/**
* Prepare the given Query object, applying cache settings and/or
* a transaction timeout.
* @param queryObject the Query object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
*/
@SuppressWarnings({"rawtypes", "deprecation"})
protected void prepareQuery(org.hibernate.Query queryObject) {
if (isCacheQueries()) {
queryObject.setCacheable(true);
if (getQueryCacheRegion() != null) {
queryObject.setCacheRegion(getQueryCacheRegion());
}
}
if (getFetchSize() > 0) {
queryObject.setFetchSize(getFetchSize());
}
if (getMaxResults() > 0) {
queryObject.setMaxResults(getMaxResults());
}
ResourceHolderSupport sessionHolder =
(ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) {
queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
代码示例来源:origin: org.springframework/spring-orm
/**
* Prepare the given Query object, applying cache settings and/or
* a transaction timeout.
* @param queryObject the Query object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
*/
@SuppressWarnings({"rawtypes", "deprecation"})
protected void prepareQuery(org.hibernate.Query queryObject) {
if (isCacheQueries()) {
queryObject.setCacheable(true);
if (getQueryCacheRegion() != null) {
queryObject.setCacheRegion(getQueryCacheRegion());
}
}
if (getFetchSize() > 0) {
queryObject.setFetchSize(getFetchSize());
}
if (getMaxResults() > 0) {
queryObject.setMaxResults(getMaxResults());
}
ResourceHolderSupport sessionHolder =
(ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) {
queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate
@Override
public Query setCacheRegion(String s) {
return query.setCacheRegion(s);
}
代码示例来源:origin: riotfamily/riot
public TypedQuery<T> setCacheRegion(String cacheRegion) {
query.setCacheRegion(cacheRegion);
return this;
}
代码示例来源:origin: ezbz/projectx
@Override
public Query setCacheRegion(final String cacheRegion) {
return query.setCacheRegion(cacheRegion);
}
代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb
@Override
protected void applyCacheRegion(String regionName) {
query.setCacheRegion( regionName );
}
代码示例来源:origin: stackoverflow.com
Query qry = session.createQuery("select name from tableName where Id=1");
qry.setCacheRegion("cacheReginName");
代码示例来源:origin: stackoverflow.com
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Employee {
@Column
Integer employeeCode;
}
public Integer getEmployeeCode(String userName) {
Session session = sessionfactory.getCurrentSession();
Query q = session.createQuery("from Employee emp where emp.userName = :username");
q.setString("username", userName);
Employee emp = q.setCacheRegion("Employee").setCacheable(true).uniqueResult();
return emp.getEmployeeCode();
}
代码示例来源: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.infinispan/infinispan-hibernate-cache-commons
public String getBranch(Object holder, boolean useRegion) throws Exception {
return withTxSessionApply(useJta, sessionFactory, session -> {
Query query = session.createQuery(
"select account.branch from Account as account where account.accountHolder = ?");
query.setParameter(0, holder);
if (useRegion) {
query.setCacheRegion("AccountRegion");
}
query.setCacheable(true);
return (String) query.list().get(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.infinispan/infinispan-hibernate-cache-commons
public int getTotalBalance(AccountHolder holder, boolean useRegion) throws Exception {
List results = (List) withTxSessionApply(useJta, sessionFactory, session -> {
Query query = session.createQuery(
"select account.balance from Account as account where account.accountHolder = ?");
query.setParameter(0, holder);
if (useRegion) {
query.setCacheRegion("AccountRegion");
}
query.setCacheable(true);
return query.list();
});
int total = 0;
if (results != null) {
for (Iterator it = results.iterator(); it.hasNext();) {
total += ((Integer) it.next()).intValue();
System.out.println("Total = " + total);
}
}
return total;
}
代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons
public int getCountForBranch(String branch, boolean useRegion) throws Exception {
return withTxSessionApply(useJta, sessionFactory, session -> {
Query query = session.createQuery(
"select account from Account as account where account.branch = :branch");
query.setString("branch", branch);
if (useRegion) {
query.setCacheRegion("AccountRegion");
}
query.setCacheable(true);
return query.list().size();
});
}
代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all
private void initQuery(Query query, NamedQueryDefinition nqd) {
query.setCacheable( nqd.isCacheable() );
query.setCacheRegion( nqd.getCacheRegion() );
if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
query.setReadOnly( nqd.isReadOnly() );
if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
}
代码示例来源:origin: org.hibernate/com.springsource.org.hibernate
private void initQuery(Query query, NamedQueryDefinition nqd) {
query.setCacheable( nqd.isCacheable() );
query.setCacheRegion( nqd.getCacheRegion() );
if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
query.setReadOnly( nqd.isReadOnly() );
if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
}
代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core
private void initQuery(Query query, NamedQueryDefinition nqd) {
query.setCacheable( nqd.isCacheable() );
query.setCacheRegion( nqd.getCacheRegion() );
if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() );
query.setReadOnly( nqd.isReadOnly() );
if ( nqd.getComment() != null ) query.setComment( nqd.getComment() );
}
代码示例来源:origin: org.jboss.seam/jboss-seam
protected org.hibernate.Query createQuery()
{
parseEjbql();
evaluateAllParameters();
org.hibernate.Query query = getSession().createQuery( getRenderedEjbql() );
setParameters( query, getQueryParameterValues(), 0 );
setParameters( query, getRestrictionParameterValues(), getQueryParameterValues().size() );
if ( getFirstResult()!=null) query.setFirstResult( getFirstResult() );
if ( getMaxResults()!=null) query.setMaxResults( getMaxResults()+1 ); //add one, so we can tell if there is another page
if ( getCacheable()!=null ) query.setCacheable( getCacheable() );
if ( getCacheRegion()!=null ) query.setCacheRegion( getCacheRegion() );
if ( getFetchSize()!=null ) query.setFetchSize( getFetchSize() );
return query;
}
代码示例来源:origin: OpenNMS/opennms
private void prepareQuery(Query queryObject) {
if(getHibernateTemplate().isCacheQueries()) {
queryObject.setCacheable(true);
if(getHibernateTemplate().getQueryCacheRegion() != null) {
queryObject.setCacheRegion(getHibernateTemplate().getQueryCacheRegion());
}
}
if(getHibernateTemplate().getFetchSize() > 0) {
queryObject.setFetchSize(getHibernateTemplate().getFetchSize());
}
if(getHibernateTemplate().getMaxResults() > 0) {
queryObject.setMaxResults(getHibernateTemplate().getMaxResults());
}
}
内容来源于网络,如有侵权,请联系作者删除!