List of usage examples for org.hibernate Session setCacheMode
void setCacheMode(CacheMode cacheMode);
From source file:de.fhdo.gui.admin.modules.terminology.Codesystems.java
License:Apache License
private void initListVersion() { logger.debug("initListVersion()"); logger.debug("selectedItem: " + selectedItem); Include incVersions = (Include) getFellow("incListVersions"); West title = (West) getFellow("titleVersion"); if (selectedItem == null) { logger.debug("show empty message"); if (mode == Mode.VALUESET) title.setTitle(Labels.getLabel("valuesetVersion")); else/* w ww .j a va 2 s. c o m*/ title.setTitle(Labels.getLabel("codesystemVersion")); incVersions.setSrc(null); incVersions.setSrc("/gui/templates/MessageInclude.zul?msg=" + Labels.getLabel("noSelection")); } else { logger.debug("show version list"); int selectedIndex = -1; incVersions.setSrc(null); incVersions.setSrc("/gui/templates/GenericList.zul"); try { // header information for list view List<GenericListHeaderType> header = new LinkedList<GenericListHeaderType>(); header.add(new GenericListHeaderType("ID", 60, "", true, "String", true, true, false, false)); header.add(new GenericListHeaderType(Labels.getLabel("name"), 0, "", true, "String", true, true, false, false)); header.add(new GenericListHeaderType(Labels.getLabel("status"), 80, "", true, "String", true, true, false, false)); // load data from db Session hb_session = HibernateUtil.getSessionFactory().openSession(); hb_session.setCacheMode(org.hibernate.CacheMode.IGNORE); hb_session.clear(); List<GenericListRowType> dataList = new LinkedList<GenericListRowType>(); try { if (mode == Mode.VALUESET) { // fill version list with value set versions ValueSet selectedVS = (ValueSet) selectedItem; ValueSetVersion selectedVSV = (ValueSetVersion) selectedItemVersion; String hql = "from ValueSetVersion where valueSetId=:vs_id order by name"; Query q = hb_session.createQuery(hql); q.setParameter("vs_id", selectedVS.getId()); q.setCacheable(false); q.setCacheMode(CacheMode.IGNORE); hb_session.setCacheMode(CacheMode.IGNORE); hb_session.clear(); hb_session.flush(); List<ValueSetVersion> vsList = q.list(); for (int i = 0; i < vsList.size(); ++i) { ValueSetVersion vsv = vsList.get(i); GenericListRowType row = createRowFromValueSetVersion(vsv); dataList.add(row); if (selectedVSV != null) { if (vsv.getVersionId().longValue() == selectedVSV.getVersionId()) selectedIndex = i; } } // set title title.setTitle(Labels.getLabel("valuesetVersion") + " - " + selectedVS.getName()); } else { // fill version list with code system versions CodeSystem selectedCS = (CodeSystem) selectedItem; CodeSystemVersion selectedCSV = (CodeSystemVersion) selectedItemVersion; String hql = "from CodeSystemVersion where codeSystemId=:cs_id order by name"; Query q = hb_session.createQuery(hql); q.setParameter("cs_id", selectedCS.getId()); q.setCacheable(false); q.setCacheMode(CacheMode.IGNORE); hb_session.setCacheMode(CacheMode.IGNORE); hb_session.clear(); hb_session.flush(); List<CodeSystemVersion> csList = q.list(); for (int i = 0; i < csList.size(); ++i) { CodeSystemVersion csv = csList.get(i); GenericListRowType row = createRowFromCodesystemVersion(csv); dataList.add(row); if (selectedCSV != null) { if (csv.getVersionId().longValue() == selectedCSV.getVersionId()) selectedIndex = i; } } // set title title.setTitle(Labels.getLabel("codesystemVersion") + " - " + selectedCS.getName()); } } catch (Exception e) { LoggingOutput.outputException(e, this); } finally { hb_session.close(); } // initialize list Window winGenericList = (Window) incVersions.getFellow("winGenericList"); genericListVersion = (GenericList) winGenericList; genericListVersion.setListId("listVersion"); genericListVersion.setListActions(this); genericListVersion.setButton_new(true); genericListVersion.setButton_edit(false); genericListVersion.setButton_delete(true); genericListVersion.setListHeader(header); genericListVersion.setDataList(dataList); if (selectedIndex >= 0) genericListVersion.setSelectedIndex(selectedIndex); Button button = new Button(Labels.getLabel("changeStatus") + "..."); button.addEventListener(Events.ON_CLICK, new EventListener<Event>() { public void onEvent(Event t) throws Exception { changeStatus(); } }); genericListVersion.removeCustomButtons(); genericListVersion.addCustomButton(button); } catch (Exception ex) { LoggingOutput.outputException(ex, this); } } initDetails(); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticeam.IteraplanMetamodelAndModelLoader.java
License:Open Source License
@Override public MetamodelAndModelContainer call() throws ElasticeamException { MetamodelAndModelContainer result = null; try {/*from w ww . j ava 2 s. c om*/ //Create a temporary user context to avoid errors createTempUserContext(); //Open a new session Session session = SessionFactoryUtils.getSession(hibernateAccessor.getSessionFactory(), hibernateAccessor.getEntityInterceptor(), hibernateAccessor.getJdbcExceptionTranslator()); session.setFlushMode(FlushMode.MANUAL); session.setCacheMode(CacheMode.GET); SessionHolder sessionHolder = null; try { hibernateAccessor.applyFlushMode(session, false); sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(hibernateAccessor.getSessionFactory(), sessionHolder); Transaction t = hibernateAccessor.getSessionFactory().getCurrentSession().beginTransaction(); try { //Once the session has been opened, trigger the actual model and data loading in the superclass result = super.call(); //After model and data have been loaded, close the session. t.commit(); } catch (HibernateException e) { t.rollback(); throw new ElasticeamException(ElasticeamException.GENERAL_ERROR, "IteraQl model and data could not be loaded in iteraplan due to an exception in hibernate: \n " + e); } } finally { SessionFactoryUtils.closeSession(sessionHolder.getSession()); TransactionSynchronizationManager.unbindResource(hibernateAccessor.getSessionFactory()); } //Remove the temporary user context UserContext.detachCurrentUserContext(); } catch (Exception ex) { LOGGER.error("IteraQl model and data loading failed", ex); throw new ElasticeamException(ElasticeamException.GENERAL_ERROR, "IteraQl model and data loading failed: \n" + ex, ex); } return result; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticmi.IteraplanMiLoadTask.java
License:Open Source License
@Override public SimpleM3C call() { SimpleM3C result = null;/*from w ww .j a v a2 s . c o m*/ if (UserContext.getCurrentUserContext() != null) { try { result = super.call(); } catch (Exception ex) { LOGGER.error("IteraQl model and data loading failed", ex); throw new ElasticMiException(ElasticMiException.GENERAL_ERROR, "IteraQl model and data loading failed: \n" + ex, ex); } } else { try { //Create a temporary user context to avoid errors createTempUserContext(); //Open a new session Session session = SessionFactoryUtils.getSession(hibernateAccessor.getSessionFactory(), hibernateAccessor.getEntityInterceptor(), hibernateAccessor.getJdbcExceptionTranslator()); session.setFlushMode(FlushMode.MANUAL); session.setCacheMode(CacheMode.GET); SessionHolder sessionHolder = null; try { hibernateAccessor.applyFlushMode(session, false); sessionHolder = new SessionHolder(session); TransactionSynchronizationManager.bindResource(hibernateAccessor.getSessionFactory(), sessionHolder); Transaction t = hibernateAccessor.getSessionFactory().getCurrentSession().beginTransaction(); try { //Once the session has been opened, trigger the actual model and data loading in the superclass result = super.call(); //After model and data have been loaded, close the session. t.commit(); } catch (HibernateException e) { t.rollback(); throw new ElasticMiException(ElasticMiException.GENERAL_ERROR, "IteraQl model and data could not be loaded in iteraplan due to an exception in hibernate: \n " + e); } } finally { SessionFactoryUtils.closeSession(sessionHolder.getSession()); TransactionSynchronizationManager.unbindResource(hibernateAccessor.getSessionFactory()); } } catch (Exception ex) { LOGGER.error("IteraQl model and data loading failed", ex); throw new ElasticMiException(ElasticMiException.GENERAL_ERROR, "IteraQl model and data loading failed: \n" + ex, ex); } finally { //Remove the temporary user context UserContext.detachCurrentUserContext(); } } return result; }
From source file:de.iteratec.iteraplan.persistence.dao.SearchDAOImpl.java
License:Open Source License
/** {@inheritDoc} */ public void createIndexes(Set<Class<?>> classList) { Session session = this.getSession(); FullTextSession fullTextSession = getFullTextSession(); session.setFlushMode(FlushMode.MANUAL); // Disable flush operations session.setCacheMode(CacheMode.IGNORE); // Disable second-level cache operations int batchSize = 100; // data is read from the database for (Class<?> bbClass : classList) { ScrollableResults results = session.createCriteria(bbClass).setFetchSize(batchSize) .scroll(ScrollMode.SCROLL_INSENSITIVE); LOGGER.info("Indexing " + bbClass.getSimpleName()); int index = 0; while (results.next()) { index++;/*from ww w .j a v a 2 s. co m*/ // entities are indexed fullTextSession.index(results.get(0)); if (index % batchSize == 0) { fullTextSession.flushToIndexes(); fullTextSession.clear(); } } results.close(); LOGGER.info("Index for " + bbClass.getSimpleName() + " was created!"); } }
From source file:es.logongas.ix3.dao.impl.GenericDAOImplHibernate.java
License:Apache License
@Override final public EntityType readOriginalByNaturalKey(DataSession dataSession, Object naturalKey) throws BusinessException { Session session = (Session) dataSession.getDataBaseSessionAlternativeImpl(); try {/* w ww . ja v a 2 s .c o m*/ session.setCacheMode(CacheMode.IGNORE); EntityType entity = (EntityType) session.bySimpleNaturalId(getEntityMetaData().getType()) .load(naturalKey); if (entity != null) { session.evict(entity); } return entity; } catch (javax.validation.ConstraintViolationException cve) { throw new BusinessException(exceptionTranslator.getBusinessMessages(cve)); } catch (org.hibernate.exception.ConstraintViolationException cve) { throw new BusinessException(exceptionTranslator.getBusinessMessages(cve)); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:es.logongas.ix3.dao.impl.GenericDAOImplHibernate.java
License:Apache License
@Override final public EntityType readOriginal(DataSession dataSession, PrimaryKeyType id) throws BusinessException { Session session = (Session) dataSession.getDataBaseSessionAlternativeImpl(); try {// ww w .j a v a2 s .c o m session.setCacheMode(CacheMode.IGNORE); EntityType entity = (EntityType) session.get(getEntityMetaData().getType(), id); if (entity != null) { session.evict(entity); } return entity; } catch (javax.validation.ConstraintViolationException cve) { throw new BusinessException(exceptionTranslator.getBusinessMessages(cve)); } catch (org.hibernate.exception.ConstraintViolationException cve) { throw new BusinessException(exceptionTranslator.getBusinessMessages(cve)); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:info.jtrac.hibernate.HibernateJtracDao.java
License:Apache License
public long loadNextSequenceNum(final long spaceSequenceId) { return (Long) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { session.flush();/*from w w w.j a v a2 s. c om*/ session.setCacheMode(CacheMode.IGNORE); SpaceSequence ss = (SpaceSequence) session.get(SpaceSequence.class, spaceSequenceId); long next = ss.getAndIncrement(); session.update(ss); session.flush(); return next; } }); }
From source file:info.jtrac.repository.HibernateJtracDao.java
License:Apache License
@Override @Transactional(propagation = Propagation.REQUIRED) public long loadNextSequenceNum(final long spaceSequenceId) { entityManager.flush();// www . j a v a2 s .com Session session = getSession(); session.setCacheMode(CacheMode.IGNORE); SpaceSequence ss = (SpaceSequence) session.get(SpaceSequence.class, spaceSequenceId); long next = ss.getAndIncrement(); session.update(ss); session.flush(); return next; }
From source file:org.alfresco.repo.workflow.jbpm.JBPMEngine.java
License:Open Source License
@SuppressWarnings("unchecked") public List<WorkflowInstance> cancelWorkflows(final List<String> workflowIds) { return (List<WorkflowInstance>) jbpmTemplate.execute(new JbpmCallback() { public Object doInJbpm(JbpmContext context) { // Bypass the cache making sure not to flush it Session session = context.getSession(); CacheMode cacheMode = session.getCacheMode(); FlushMode flushMode = session.getFlushMode(); session.setCacheMode(CacheMode.GET); session.setFlushMode(FlushMode.MANUAL); try { List<WorkflowInstance> workflowInstances = new ArrayList<WorkflowInstance>(workflowIds.size()); Map<String, ProcessInstance> processInstances = new HashMap<String, ProcessInstance>( workflowIds.size() * 2); GraphSession graphSession = context.getGraphSession(); // retrieve and cancel process instances for (String workflowId : workflowIds) { try { ProcessInstance processInstance = getProcessInstance(graphSession, workflowId); processInstance.getContextInstance().setVariable("cancelled", true); processInstance.end(); processInstances.put(workflowId, processInstance); } catch (JbpmException e) { String msg = messageService.getMessage(ERR_CANCEL_WORKFLOW, workflowId); throw new WorkflowException(msg, JbpmAccessor.convertJbpmException(e)); }/*from w w w . j a va 2 s . co m*/ } // Flush at the end of the batch session.flush(); for (String workflowId : workflowIds) { try { // retrieve process instance ProcessInstance processInstance = processInstances.get(workflowId); // TODO: Determine if this is the most appropriate way to cancel workflow... // It might be useful to record point at which it was cancelled etc try { workflowInstances.add(createWorkflowInstance(processInstance)); } catch (Exception ex) { logger.warn("Unable to load workflow instance: '" + processInstance + "' due to exception.", ex); } // delete the process instance graphSession.deleteProcessInstance(processInstance, true, true); } catch (JbpmException e) { String msg = messageService.getMessage(ERR_CANCEL_WORKFLOW, workflowId); throw new WorkflowException(msg, JbpmAccessor.convertJbpmException(e)); } } // Flush at the end of the batch session.flush(); return workflowInstances; } finally { session.setCacheMode(cacheMode); session.setFlushMode(flushMode); } } }); }
From source file:org.alfresco.repo.workflow.jbpm.JBPMEngine.java
License:Open Source License
@SuppressWarnings("unchecked") public List<WorkflowTask> queryTasks(final WorkflowTaskQuery query, final boolean sameSession) { try {//w w w .j a v a2 s. com return (List<WorkflowTask>) jbpmTemplate.execute(new JbpmCallback() { public List<WorkflowTask> doInJbpm(JbpmContext context) { // Bypass the cache making sure not to flush it Session session = context.getSession(); CacheMode cacheMode = session.getCacheMode(); try { session.setCacheMode(CacheMode.GET); Criteria criteria = createTaskQueryCriteria(session, query); List<TaskInstance> tasks = criteria.list(); return getWorkflowTasks(tasks, sameSession); } finally { session.setCacheMode(cacheMode); } } }); } catch (JbpmException e) { String msg = messageService.getMessage(ERR_QUERY_TASKS, query); throw new WorkflowException(msg, e); } }