本文整理汇总了Java中org.hibernate.Query.setCacheable方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setCacheable方法的具体用法?Java Query.setCacheable怎么用?Java Query.setCacheable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Query
的用法示例。
在下文中一共展示了Query.setCacheable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findLastNChanges
import org.hibernate.Query; //导入方法依赖的package包/类
public static List findLastNChanges(Long sessionId, Long managerId, Long subjAreaId, Long departmentId, int n) {
try {
org.hibernate.Session hibSession = new ChangeLogDAO().getSession();
Query q = hibSession.createQuery(
"select ch from ChangeLog ch where " +
"ch.session.uniqueId=:sessionId " +
(managerId==null?"":"and ch.manager.uniqueId=:managerId ") +
(subjAreaId==null?"":"and ch.subjectArea.uniqueId=:subjAreaId ") +
(departmentId==null?"":"and ch.department.uniqueId=:departmentId ") +
"order by ch.timeStamp desc");
q.setLong("sessionId", sessionId.longValue());
if (managerId!=null) q.setLong("managerId",managerId.longValue());
if (subjAreaId!=null) q.setLong("subjAreaId",subjAreaId.longValue());
if (departmentId!=null) q.setLong("departmentId",departmentId.longValue());
q.setMaxResults(n);
q.setCacheable(true);
return q.list();
} catch (Exception e) {
Debug.error(e);
}
return null;
}
示例2: prepareQuery
import org.hibernate.Query; //导入方法依赖的package包/类
/**
* Prepare the given Query object, applying cache settings and/or
* a transaction timeout.
* @param queryObject the Query object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
*/
protected void prepareQuery(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());
}
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) {
queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
}
}
示例3: prepareQuery
import org.hibernate.Query; //导入方法依赖的package包/类
/**
* Prepare the given Query object, applying cache settings and/or
* a transaction timeout.
* @param queryObject the Query object to prepare
* @see #setCacheQueries
* @see #setQueryCacheRegion
* @see SessionFactoryUtils#applyTransactionTimeout
*/
protected void prepareQuery(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());
}
SessionFactoryUtils.applyTransactionTimeout(queryObject, getSessionFactory());
}
示例4: findAll
import org.hibernate.Query; //导入方法依赖的package包/类
public static List<TimePattern> findAll(Long sessionId, Boolean visible) {
String query = "from TimePattern tp " +
"where tp.session.uniqueId=:sessionId";
if (visible!=null)
query += " and visible=:visible";
org.hibernate.Session hibSession = new TimePatternDAO().getSession();
Query q = hibSession.createQuery(query);
q.setCacheable(true);
q.setLong("sessionId", sessionId.longValue());
if (visible!=null)
q.setBoolean("visible", visible.booleanValue());
List<TimePattern> v = q.list();
Collections.sort(v);
return v;
}
示例5: findLastChange
import org.hibernate.Query; //导入方法依赖的package包/类
public static ChangeLog findLastChange(String objectType, Number objectUniqueId, Source source) {
try {
org.hibernate.Session hibSession = new ChangeLogDAO().getSession();
Query q = hibSession.createQuery(
"select ch from ChangeLog ch " +
"where ch.objectUniqueId=:objectUniqueId and ch.objectType=:objectType "+
(source==null?"":"and ch.sourceString=:source ") +
"and ch.operationString != :note " +
"order by ch.timeStamp desc");
q.setLong("objectUniqueId", objectUniqueId.longValue());
q.setString("objectType",objectType);
q.setString("note", Operation.NOTE.toString());
if (source!=null)
q.setString("source",source.name());
q.setMaxResults(1);
q.setCacheable(true);
List logs = q.list();
return (logs.isEmpty()?null:(ChangeLog)logs.get(0));
} catch (Exception e) {
Debug.error(e);
}
return null;
}
示例6: createModel
import org.hibernate.Query; //导入方法依赖的package包/类
public static TimetableGridModel createModel(String solutionIdsStr, Department department, org.hibernate.Session hibSession, TimetableGridContext context) {
TimetableGridModel model = new TimetableGridModel(ResourceType.DEPARTMENT.ordinal(), department.getUniqueId());
model.setName(department.getShortLabel());
model.setFirstDay(context.getFirstDay());
model.setFirstSessionDay(context.getFirstSessionDay());
model.setFirstDate(context.getFirstDate());
Query q = hibSession.createQuery("select distinct a from Assignment as a inner join a.clazz.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings as o inner join o.subjectArea.department as d where " +
"a.solution.uniqueId in ("+solutionIdsStr+") and d.uniqueId=:resourceId and " +
"o.isControl=true");
q.setCacheable(true);
q.setLong("resourceId", department.getUniqueId());
List assignments = q.list();
createCells(model, assignments, hibSession, context, false);
model.setSize(assignments.size());
model.setUtilization(countUtilization(assignments, context));
return model;
}
示例7: initQuery
import org.hibernate.Query; //导入方法依赖的package包/类
private void initQuery(Query query, NamedQueryDefinition nqd) {
// todo : cacheable and readonly should be Boolean rather than boolean...
query.setCacheable( nqd.isCacheable() );
query.setCacheRegion( nqd.getCacheRegion() );
query.setReadOnly( nqd.isReadOnly() );
if ( nqd.getTimeout() != null ) {
query.setTimeout( nqd.getTimeout() );
}
if ( nqd.getFetchSize() != null ) {
query.setFetchSize( nqd.getFetchSize() );
}
if ( nqd.getCacheMode() != null ) {
query.setCacheMode( nqd.getCacheMode() );
}
if ( nqd.getComment() != null ) {
query.setComment( nqd.getComment() );
}
if ( nqd.getFirstResult() != null ) {
query.setFirstResult( nqd.getFirstResult() );
}
if ( nqd.getMaxResults() != null ) {
query.setMaxResults( nqd.getMaxResults() );
}
if ( nqd.getFlushMode() != null ) {
query.setFlushMode( nqd.getFlushMode() );
}
}
示例8: SolutionGridModel
import org.hibernate.Query; //导入方法依赖的package包/类
public SolutionGridModel(String solutionIdsStr, Department dept, org.hibernate.Session hibSession, TimetableGridContext context) {
super(sResourceTypeDepartment, dept.getUniqueId().longValue());
setName(dept.getShortLabel());
setFirstDay(context.getFirstDay());
Query q = hibSession.createQuery("select distinct a from Assignment as a inner join a.clazz.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings as o inner join o.subjectArea.department as d where " +
"a.solution.uniqueId in ("+solutionIdsStr+") and d.uniqueId=:resourceId and " +
"o.isControl=true");
q.setCacheable(true);
q.setLong("resourceId", dept.getUniqueId().longValue());
List a = q.list();
setSize(a.size());
init(a,hibSession,context);
}
示例9: getStaffByDept
import org.hibernate.Query; //导入方法依赖的package包/类
/**
*
* @param deptCode
* @return
*/
public static List getStaffByDept(String deptCode, Long acadSessionId) throws Exception {
if (deptCode == null){
return(null);
}
Query q = StaffDAO.getInstance().getSession().createQuery(
"select distinct s from Staff s where s.dept=:deptCode and " +
"(select di.externalUniqueId from DepartmentalInstructor di " +
"where di.department.deptCode=:deptCode and di.department.session.uniqueId=:sessionId and di.externalUniqueId = s.externalUniqueId ) is null");
q.setString("deptCode", deptCode);
q.setLong("sessionId", acadSessionId);
q.setCacheable(true);
return (q.list());
}
示例10: getInstructors
import org.hibernate.Query; //导入方法依赖的package包/类
/**
* Executes the query to retrieve instructors
* @param request
* @param clause
* @throws Exception
*/
private static void getInstructors(HttpServletRequest request, SessionContext context, StringBuffer clause) throws Exception {
String instructorNameFormat = UserProperty.NameFormat.get(context.getUser());
Long acadSessionId = context.getUser().getCurrentAcademicSessionId();
StringBuffer query = new StringBuffer();
query.append("select distinct i from DepartmentalInstructor i ");
query.append(" where i.department.session.uniqueId = :acadSessionId ");
query.append(clause);
query.append(" order by upper(i.lastName), upper(i.firstName) ");
DepartmentalInstructorDAO idao = new DepartmentalInstructorDAO();
org.hibernate.Session hibSession = idao.getSession();
Query q = hibSession.createQuery(query.toString());
q.setFetchSize(5000);
q.setCacheable(true);
q.setLong("acadSessionId", acadSessionId);
List result = q.list();
Vector v = new Vector(result.size());
Vector h = new Vector(result.size());
for (Iterator i=result.iterator();i.hasNext();) {
DepartmentalInstructor di = (DepartmentalInstructor)i.next();
String name = di.getName(instructorNameFormat);
v.addElement(new ComboBoxLookup(name, di.getUniqueId().toString()));
if (di.hasPreferences())
h.add(di.getUniqueId());
}
request.setAttribute(DepartmentalInstructor.INSTR_LIST_ATTR_NAME, v);
request.setAttribute(DepartmentalInstructor.INSTR_HAS_PREF_ATTR_NAME, h);
}