List of usage examples for org.hibernate CacheMode NORMAL
CacheMode NORMAL
To view the source code for org.hibernate CacheMode NORMAL.
Click Source Link
From source file:io.dropwizard.sharding.utils.TransactionHandler.java
License:Apache License
private void configureSession() { session.setDefaultReadOnly(readOnly); session.setCacheMode(CacheMode.NORMAL); session.setFlushMode(FlushMode.AUTO); }
From source file:lt.bsprendimai.ddesk.SearchParameters.java
License:Apache License
public List<TicketInfo> getTicketList() { // System.out.println("Getting list at page "+page); try {/*from www .j a va 2 s .co m*/ Criteria crit = SessionHolder.currentSession().getSess().createCriteria(TicketInfo.class); if (getSpe().sortEditDate != null) { if (getSpe().sortEditDate) crit.addOrder(Order.asc("editDate")); else crit.addOrder(Order.desc("editDate")); } else if (getSpe().sortAsignee != null) { if (getSpe().sortAsignee) crit.addOrder(Order.asc("asignee")); else crit.addOrder(Order.desc("asignee")); } else if (getSpe().sortStatus != null) { if (getSpe().sortStatus) crit.addOrder(Order.asc("status")); else crit.addOrder(Order.desc("status")); } else if (getSpe().sortPriority != null) { if (getSpe().sortPriority) crit.addOrder(Order.asc("priority")); else crit.addOrder(Order.desc("priority")); } else if (getSpe().sortCompany != null) { if (getSpe().sortCompany) crit.addOrder(Order.asc("companyName")); else crit.addOrder(Order.desc("companyName")); } else if (getSpe().sortReportDate != null) { if (getSpe().sortReportDate) crit.addOrder(Order.asc("reportDate")); else crit.addOrder(Order.desc("reportDate")); } else if (getSpe().sortName != null) { if (getSpe().sortName) crit.addOrder(Order.asc("name")); else crit.addOrder(Order.desc("name")); } else if (getSpe().sortUniqueId != null) { if (getSpe().sortUniqueId) crit.addOrder(Order.asc("uniqueId")); else crit.addOrder(Order.desc("uniqueId")); } else if (getSpe().sortPlaned != null) { if (getSpe().sortPlaned) crit.addOrder(Order.asc("planedDate")); else crit.addOrder(Order.desc("planedDate")); } else if (getSpe().sortType != null) { if (getSpe().sortType) crit.addOrder(Order.asc("type")); else crit.addOrder(Order.desc("type")); } else if (getSpe().sortVersion != null) { if (getSpe().sortVersion) crit.addOrder(Order.asc("version")); else crit.addOrder(Order.desc("version")); } else { crit.addOrder(Order.desc("id")); } if (spe.status != null)// for verbosity, if != to initial state crit.add(Expression.eq("status", spe.status)); else { if (spe.accepted > 0) {// for verbosity, if != to initial state if (spe.accepted == 1) crit.add(Expression.ge("status", Status.ACCEPTED)); else crit.add(Expression.lt("status", Status.ACCEPTED)); } if (spe.closed > 0) {// for verbosity, if != to initial state if (spe.closed == 1) crit.add(Expression.isNotNull("dateClosed")); else crit.add(Expression.isNull("dateClosed")); } } if (spe.chargeable != 0)// for verbosity, if != to initial state crit.add(Expression.eq("chargeable", spe.chargeable == 1)); if (spe.ticketName != null && !spe.ticketName.trim().equals(""))// for verbosity, if != // to initial state crit.add(Expression.like("name", spe.ticketName, MatchMode.ANYWHERE)); if (spe.uniqueId != null && !spe.uniqueId.trim().equals(""))// for verbosity, if != to // initial state crit.add(Expression.ilike("uniqueId", spe.uniqueId, MatchMode.START)); if (spe.person != null)// for verbosity, if != to initial state crit.add(Expression.eq("person", spe.person)); if (spe.company != null)// for verbosity, if != to initial state crit.add(Expression.eq("company", spe.company)); if (spe.priority != null)// for verbosity, if != to initial state crit.add(Expression.eq("priority", spe.priority)); if (spe.assigned != null) {// for verbosity, if != to initial state if (spe.assigned >= 0) crit.add(Expression.eq("assignedTo", spe.assigned)); else { if (spe.assigned == -2) crit.add(Expression.isNotNull("assignedTo")); else crit.add(Expression.isNull("assignedTo")); } } if (spe.project != null)// for verbosity, if != to initial state crit.add(Expression.eq("project", spe.project)); if (spe.module != null)// for verbosity, if != to initial state crit.add(Expression.eq("module", spe.module)); if (spe.version != null)// for verbosity, if != to initial state crit.add(Expression.eq("version", spe.version)); if (spe.type != null)// for verbosity, if != to initial state crit.add(Expression.eq("type", spe.type)); if (ti.getUserHandler().isPartner()) { Disjunction dis = Expression.disjunction(); dis.add(Expression.eq("projectsCompany", ti.getUserHandler().getUser().getCompany())); dis.add(Expression.eq("assignedTo", ti.getUserHandler().getUser().getId())); dis.add(Expression.eq("reportBy", ti.getUserHandler().getUser().getId())); crit.add(dis); } if (spe.forDate != null) { Calendar c = Calendar.getInstance(); c.setTime(spe.forDate); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); long time1 = c.getTimeInMillis(); c.set(Calendar.HOUR, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); long time2 = c.getTimeInMillis(); crit.add(Expression.between("planedDate", new Date(time1), new Date(time2))); } crit.setCacheMode(CacheMode.NORMAL); crit.setMaxResults(PAGE_STEP); crit.setFirstResult(page * PAGE_STEP); List<TicketInfo> l = (List<TicketInfo>) crit.list(); this.lastEmpty = l.size() == 0 || l.size() < PAGE_STEP; return l; } catch (Exception ex) { SessionHolder.endSession(); UIMessenger.addFatalKeyMessage("error.transaction.abort", ti.getUserHandler().getUserLocale()); ex.printStackTrace(); return TicketAccessor.getEMPTYInfoList(); } }
From source file:org.azrul.langkuik.dao.HibernateGenericDAO.java
public static void massIndexDatabaseForSearch(EntityManagerFactory emf) { try {//from w w w. ja va2s . c o m EntityManager em = emf.createEntityManager(); List<Class> classes = new ArrayList<>(); for (EntityType e : emf.getMetamodel().getEntities()) { Class c = e.getJavaType(); if (c.isAnnotationPresent(Index.class)) { classes.add(c); } } FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search .getFullTextEntityManager(em); fullTextEntityManager.createIndexer(classes.toArray(new Class[] {})).batchSizeToLoadObjects(30) .optimizeAfterPurge(true).optimizeOnFinish(true).threadsToLoadObjects(4) .cacheMode(CacheMode.NORMAL) // defaults to CacheMode.IGNORE .startAndWait(); } catch (InterruptedException ex) { Logger.getLogger(HibernateGenericDAO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.faster.orm.service.hibernate.with.option.HibernateGetWithOptionService.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w ww . j a v a2 s .c o m*/ public PO get(ID id, QueryOption queryOption) { StopWatch sw = null; if (log.isDebugEnabled()) { log.debug("Getting {}#{} with cache {}...", new Object[] { persistClassName, id, getCacheDisplay(queryOption.isCacheEnabled()) }); sw = new StopWatch(); sw.start(); } PO ret = null; if (id != null) { CacheMode origCacheMode = getSession().getCacheMode(); getSession().setCacheMode(queryOption.isCacheEnabled() ? CacheMode.NORMAL : CacheMode.IGNORE); ret = (PO) getSession().get(persistClass, id); getSession().setCacheMode(origCacheMode); if (ret != null) { postLoad(ret); } } if (log.isDebugEnabled()) { log.debug("{}#{}{} found. ({} ms)", new Object[] { persistClassName, id, ret == null ? " not" : "", sw.getTime() }); } return ret; }
From source file:org.mzd.shap.spring.cli.Index.java
License:Open Source License
public static void main(String[] args) { if (args.length != 0) { System.out.println(USAGE_MSG); System.exit(1);//www . j ava2s . c o m } try { ApplicationContext ctx = new ClassPathXmlApplicationContext("datasource-context.xml", "orm-massindex-context.xml"); SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory"); Session session = sessionFactory.openSession(); System.out.println(BEGIN_MSG); LOGGER.info(BEGIN_MSG); // Index single-threaded. Appear to have problems with collections. Search.getFullTextSession(session).createIndexer().batchSizeToLoadObjects(30) .threadsForSubsequentFetching(4).threadsToLoadObjects(2).cacheMode(CacheMode.NORMAL) .optimizeOnFinish(true).startAndWait(); //LOGGER.debug(Reporting.reportQueryCacheStatistics(sessionFactory)); //LOGGER.debug(Reporting.reportSecondLevleCacheStatistics(sessionFactory)); System.out.println(FINISH_MSG); LOGGER.info(FINISH_MSG); System.exit(0); } catch (Exception ex) { System.err.println(ERROR_MSG + " [" + ex.getMessage() + "]"); LOGGER.debug(ERROR_MSG, ex); } }
From source file:org.pentaho.platform.repository.datasource.DatasourceMgmtService.java
License:Open Source License
public void createDatasource(IDatasource newDatasource) throws DuplicateDatasourceException, DatasourceMgmtServiceException { Session session = HibernateUtil.getSession(); if (newDatasource != null) { if (getDatasource(newDatasource.getName()) == null) { try { session.setCacheMode(CacheMode.REFRESH); IPasswordService passwordService = PentahoSystem.getObjectFactory().get(IPasswordService.class, null);//from ww w. j ava 2s . co m newDatasource.setPassword(passwordService.encrypt(newDatasource.getPassword())); session.save(newDatasource); } catch (ObjectFactoryException objface) { throw new DatasourceMgmtServiceException(Messages .getErrorString("DatasourceMgmtService.ERROR_0009_UNABLE_TO_INIT_PASSWORD_SERVICE")); //$NON-NLS-1$ } catch (PasswordServiceException pse) { session.evict(newDatasource); throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), //$NON-NLS-1$ pse); } catch (HibernateException ex) { session.evict(newDatasource); throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", //$NON-NLS-1$ newDatasource.getName()), ex); } finally { session.setCacheMode(CacheMode.NORMAL); } } else { throw new DuplicateDatasourceException(Messages.getErrorString( "DatasourceMgmtService.ERROR_0005_DATASOURCE_ALREADY_EXIST", newDatasource.getName()));//$NON-NLS-1$ } } else { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0010_NULL_DATASOURCE_OBJECT"));//$NON-NLS-1$ } session.setCacheMode(CacheMode.NORMAL); HibernateUtil.flushSession(); }
From source file:org.pentaho.platform.repository.datasource.DatasourceMgmtService.java
License:Open Source License
public void deleteDatasource(IDatasource datasource) throws NonExistingDatasourceException, DatasourceMgmtServiceException { Session session = HibernateUtil.getSession(); if (datasource != null) { try {// ww w . j a v a 2 s.com session.setCacheMode(CacheMode.REFRESH); session.delete(session.merge(datasource)); } catch (HibernateException ex) { throw new DatasourceMgmtServiceException(ex.getMessage(), ex); } finally { session.setCacheMode(CacheMode.NORMAL); } } else { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0010_NULL_DATASOURCE_OBJECT"));//$NON-NLS-1$ } HibernateUtil.flushSession(); }
From source file:org.pentaho.platform.repository.datasource.DatasourceMgmtService.java
License:Open Source License
public IDatasource getDatasource(String jndiName) throws DatasourceMgmtServiceException { Session session = HibernateUtil.getSession(); IDatasource datasource = null;//from w w w.j ava 2 s .c om try { session.setCacheMode(CacheMode.REFRESH); IDatasource pentahoDatasource = (IDatasource) session.get(Datasource.class, jndiName); if (pentahoDatasource != null) { datasource = clone(pentahoDatasource); IPasswordService passwordService = PentahoSystem.getObjectFactory().get(IPasswordService.class, null); datasource.setPassword(passwordService.decrypt(datasource.getPassword())); } return datasource; } catch (ObjectFactoryException objface) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0009_UNABLE_TO_INIT_PASSWORD_SERVICE"), //$NON-NLS-1$ objface); } catch (PasswordServiceException pse) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse);//$NON-NLS-1$ } catch (HibernateException ex) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE"), ex);//$NON-NLS-1$ } finally { session.setCacheMode(CacheMode.NORMAL); } }
From source file:org.pentaho.platform.repository.datasource.DatasourceMgmtService.java
License:Open Source License
public List<IDatasource> getDatasources() throws DatasourceMgmtServiceException { Session session = HibernateUtil.getSession(); try {/*from www .j av a 2 s.com*/ session.setCacheMode(CacheMode.REFRESH); String nameQuery = "org.pentaho.platform.repository.datasource.Datasource.findAllDatasources"; //$NON-NLS-1$ Query qry = session.getNamedQuery(nameQuery).setCacheable(true); List<IDatasource> pentahoDatasourceList = qry.list(); List<IDatasource> datasourceList = new ArrayList<IDatasource>(); for (IDatasource pentahoDatasource : pentahoDatasourceList) { IDatasource datasource = clone(pentahoDatasource); IPasswordService passwordService = PentahoSystem.getObjectFactory().get(IPasswordService.class, null); datasource.setPassword(passwordService.decrypt(datasource.getPassword())); datasourceList.add(datasource); } return datasourceList; } catch (PasswordServiceException pse) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse);//$NON-NLS-1$ } catch (ObjectFactoryException objface) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0009_UNABLE_TO_INIT_PASSWORD_SERVICE"), //$NON-NLS-1$ objface); } catch (HibernateException ex) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", ""), //$NON-NLS-1$//$NON-NLS-2$ ex); } finally { session.setCacheMode(CacheMode.NORMAL); } }
From source file:org.pentaho.platform.repository.datasource.DatasourceMgmtService.java
License:Open Source License
public void updateDatasource(IDatasource datasource) throws NonExistingDatasourceException, DatasourceMgmtServiceException { Session session = HibernateUtil.getSession(); if (datasource != null) { IDatasource tmpDatasource = getDatasource(datasource.getName()); if (tmpDatasource != null) { try { session.setCacheMode(CacheMode.REFRESH); IPasswordService passwordService = PentahoSystem.getObjectFactory().get(IPasswordService.class, null);//from ww w .j ava 2 s . c o m // Store the new encrypted password in the datasource object datasource.setPassword(passwordService.encrypt(datasource.getPassword())); // BISERVER-5677 - clear the old datasource from the datasource service cache so updates will be available // without having to restart the server IDatasourceService datasourceService = PentahoSystem.getObjectFactory() .get(IDatasourceService.class, null); datasourceService.clearDataSource(datasource.getName()); session.update(session.merge(datasource)); } catch (ObjectFactoryException objface) { throw new DatasourceMgmtServiceException(Messages.getErrorString( "DatasourceMgmtService.ERROR_0009_UNABLE_TO_INIT_PASSWORD_SERVICE"), objface);//$NON-NLS-1$ } catch (PasswordServiceException pse) { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), //$NON-NLS-1$ pse); } catch (HibernateException ex) { throw new DatasourceMgmtServiceException(Messages.getErrorString( "DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", datasource.getName()), //$NON-NLS-1$ ex); } finally { session.setCacheMode(CacheMode.NORMAL); } } else { throw new NonExistingDatasourceException(Messages.getErrorString( "DatasourceMgmtService.ERROR_0006_DATASOURCE_DOES_NOT_EXIST", datasource.getName()));//$NON-NLS-1$ } } else { throw new DatasourceMgmtServiceException( Messages.getErrorString("DatasourceMgmtService.ERROR_0010_NULL_DATASOURCE_OBJECT"));//$NON-NLS-1$ } }