List of usage examples for org.hibernate Query setFlushMode
@Override Query<R> setFlushMode(FlushModeType flushMode);
From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java
License:Open Source License
@SuppressWarnings({ "unchecked", "cast" }) private void cacheVariablesNoBatch(Session session, List<Long> contextInstanceIds, Map<Long, TokenVariableMap> variablesCache) { Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheInstanceVariables"); query.setParameterList("ids", contextInstanceIds); query.setCacheMode(CacheMode.PUT);/* w ww . j a v a 2 s. c o m*/ query.setFlushMode(FlushMode.MANUAL); query.setCacheable(true); List<TokenVariableMap> results = (List<TokenVariableMap>) query.list(); for (TokenVariableMap tokenVariableMap : results) { variablesCache.put(tokenVariableMap.getContextInstance().getId(), tokenVariableMap); } }
From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java
License:Open Source License
@SuppressWarnings({ "unchecked", "cast" }) private void cacheTasksNoBatch(Session session, List<Long> taskInstanceIds, Map<Long, TaskInstance> returnMap) { Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheTaskInstanceProperties"); query.setParameterList("ids", taskInstanceIds); query.setCacheMode(CacheMode.PUT);/* w w w. j av a2 s . co m*/ query.setFlushMode(FlushMode.MANUAL); query.setCacheable(true); List<TaskInstance> results = (List<TaskInstance>) query.list(); for (TaskInstance taskInstance : results) { returnMap.put(taskInstance.getId(), taskInstance); } }
From source file:com.mg.framework.support.orm.OrmTemplateHibernateImpl.java
License:Open Source License
@Override protected void prepareQuery(Query queryObject) { if (isCacheQueries()) { queryObject.setCacheable(true);//w ww. j a v a2 s . com if (getQueryCacheRegion() != null) { queryObject.setCacheRegion(getQueryCacheRegion()); } } if (getFetchSize() > 0) { queryObject.setFetchSize(getFetchSize()); } if (getMaxResults() > 0) { queryObject.setMaxResults(getMaxResults()); } if (getFlushMode() != null) { queryObject.setFlushMode(CriteriaHibernateImpl.convertFlushModeToHibernate(getFlushMode())); } //SessionFactoryUtils.applyTransactionTimeout(queryObject, getSessionFactory()); }
From source file:com.mysema.query.jpa.hibernate.AbstractHibernateQuery.java
License:Apache License
private Query createQuery(String queryString, @Nullable QueryModifiers modifiers, boolean forCount) { Query query = session.createQuery(queryString); HibernateUtil.setConstants(query, getConstants(), getMetadata().getParams()); if (fetchSize > 0) { query.setFetchSize(fetchSize);//from ww w.ja v a2 s . c o m } if (timeout > 0) { query.setTimeout(timeout); } if (cacheable != null) { query.setCacheable(cacheable); } if (cacheRegion != null) { query.setCacheRegion(cacheRegion); } if (comment != null) { query.setComment(comment); } if (readOnly != null) { query.setReadOnly(readOnly); } for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()) { query.setLockMode(entry.getKey().toString(), entry.getValue()); } if (flushMode != null) { query.setFlushMode(flushMode); } if (modifiers != null && modifiers.isRestricting()) { if (modifiers.getLimit() != null) { query.setMaxResults(modifiers.getLimit().intValue()); } if (modifiers.getOffset() != null) { query.setFirstResult(modifiers.getOffset().intValue()); } } // set transformer, if necessary List<? extends Expression<?>> projection = getMetadata().getProjection(); if (projection.size() == 1 && !forCount) { Expression<?> expr = projection.get(0); if (expr instanceof FactoryExpression<?>) { query.setResultTransformer( new FactoryExpressionTransformer((FactoryExpression<?>) projection.get(0))); } } else if (!forCount) { FactoryExpression<?> proj = FactoryExpressionUtils.wrap(projection); if (proj != null) { query.setResultTransformer(new FactoryExpressionTransformer(proj)); } } return query; }
From source file:com.querydsl.jpa.hibernate.AbstractHibernateQuery.java
License:Apache License
private Query createQuery(@Nullable QueryModifiers modifiers, boolean forCount) { JPQLSerializer serializer = serialize(forCount); String queryString = serializer.toString(); logQuery(queryString, serializer.getConstantToLabel()); Query query = session.createQuery(queryString); HibernateUtil.setConstants(query, serializer.getConstantToLabel(), getMetadata().getParams()); if (fetchSize > 0) { query.setFetchSize(fetchSize);/*from www.j a v a 2s .c o m*/ } if (timeout > 0) { query.setTimeout(timeout); } if (cacheable != null) { query.setCacheable(cacheable); } if (cacheRegion != null) { query.setCacheRegion(cacheRegion); } if (comment != null) { query.setComment(comment); } if (readOnly != null) { query.setReadOnly(readOnly); } for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()) { query.setLockMode(entry.getKey().toString(), entry.getValue()); } if (flushMode != null) { query.setFlushMode(flushMode); } if (modifiers != null && modifiers.isRestricting()) { Integer limit = modifiers.getLimitAsInteger(); Integer offset = modifiers.getOffsetAsInteger(); if (limit != null) { query.setMaxResults(limit); } if (offset != null) { query.setFirstResult(offset); } } // set transformer, if necessary Expression<?> projection = getMetadata().getProjection(); if (!forCount && projection instanceof FactoryExpression) { query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection)); } return query; }
From source file:org.alfresco.repo.workflow.jbpm.JBPMEngine.java
License:Open Source License
@SuppressWarnings({ "unchecked", "cast" }) private void cacheVariablesNoBatch(Session session, List<Long> contextInstanceIds, Map<Long, TokenVariableMap> variablesCache) { Query query = session.getNamedQuery("org.alfresco.repo.workflow.cacheInstanceVariables"); query.setParameterList("ids", contextInstanceIds); query.setCacheMode(CacheMode.PUT);//from w ww . ja v a2s . co m query.setFlushMode(FlushMode.MANUAL); query.setCacheable(true); List<TokenVariableMap> results = (List<TokenVariableMap>) query.list(); for (TokenVariableMap tokenVariableMap : results) { variablesCache.put(tokenVariableMap.getToken().getId(), tokenVariableMap); } }
From source file:org.cgiar.ccafs.marlo.data.dao.mysql.AbstractMarloDAO.java
License:Open Source License
/** * This method make a query that returns a not mapped object result from the model. * //from w w w. jav a2 s . com * @param sqlQuery is a string representing an SQL query. */ public List<Map<String, Object>> excuteStoreProcedure(String storeProcedure, String sqlQuery) { this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure).executeUpdate(); Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); query.setFlushMode(FlushMode.COMMIT); List<Map<String, Object>> result = query.list(); return result; }
From source file:org.cgiar.ccafs.marlo.data.dao.mysql.AbstractMarloDAO.java
License:Open Source License
/** * Pass String based hibernate query.//from ww w .jav a 2 s . co m * * @param sqlQuery */ public void executeUpdateQuery(String sqlQuery) { Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setFlushMode(FlushMode.COMMIT); query.executeUpdate(); }
From source file:org.cgiar.ccafs.marlo.data.dao.mysql.AbstractMarloDAO.java
License:Open Source License
protected List<T> findAll(Query hibernateQuery) { hibernateQuery.setFlushMode(FlushMode.COMMIT); @SuppressWarnings("unchecked") List<T> list = hibernateQuery.list(); return list;/*from w w w.j av a 2 s . c o m*/ }
From source file:org.cgiar.ccafs.marlo.data.dao.mysql.AbstractMarloDAO.java
License:Open Source License
/** * This method make a query that returns a list of objects from the model. * This method was implemented in a generic way, so, the list of objects to be returned will depend on how the method * is being called./*from w w w .ja v a 2 s.co m*/ * e.g: * List<SomeObject> list = this.findAll("some hibernate query"); * or * this.<SomeObject>findAll("some hibernate query"); * * @param hibernateQuery is a string representing an HQL query. * @return a list of <T> objects. */ protected List<T> findAll(String hibernateQuery) { Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); query.setFlushMode(FlushMode.COMMIT); return this.findAll(query); }