List of usage examples for org.hibernate FlushMode MANUAL
FlushMode MANUAL
To view the source code for org.hibernate FlushMode MANUAL.
Click Source Link
From source file:com.zutubi.pulse.master.xwork.interceptor.ReadOnlyInterceptor.java
License:Apache License
public String intercept(ActionInvocation invocation) throws Exception { Session session = sessionFactory.getCurrentSession(); session.setFlushMode(FlushMode.MANUAL); return invocation.invoke(); }
From source file:de.hotware.hibernate.query.intelligent.searcher.SearcherImpl.java
License:Open Source License
@Override public SearchResult search(U queryBean, FullTextSession fullTextSession, String profile) { fullTextSession.setFlushMode(FlushMode.MANUAL); SearchFactory searchFactory = fullTextSession.getSearchFactory(); QueryBuilder queryBuilder;/*from w w w . j av a2s . c o m*/ { QueryContextBuilder queryContextBuilder = searchFactory.buildQueryBuilder(); EntityContext entityContext = queryContextBuilder.forEntity(this.indexedClass); queryBuilder = entityContext.get(); } @SuppressWarnings("rawtypes") BooleanJunction<BooleanJunction> mainJunction = queryBuilder.bool(); Query hierarchicalQuery = this.hierarchies.get(profile); if (hierarchicalQuery == null) { throw new IllegalArgumentException("profile " + profile + " not available!"); } hierarchicalQuery.constructQuery(mainJunction, queryBuilder, queryBean, cachedInfo, searchFactory); // apply the custom query mainJunction = queryBean.customQuery(mainJunction, queryBuilder); final FullTextQuery query = fullTextSession.createFullTextQuery(mainJunction.createQuery(), this.indexedClass); // apply the filters if (queryBean.getFilters() != null) { for (String filter : queryBean.getFilters()) { FullTextFilter fullTextFilter = query.enableFullTextFilter(filter); Set<QueryBean.FilterParameter> filterParameters = queryBean.getFilterParameters().get(filter); if (filterParameters != null) { for (QueryBean.FilterParameter parameter : filterParameters) { fullTextFilter.setParameter(parameter.key, parameter.value); } } } } // apply the custom sort (if available) if (queryBean.getSort() != null) { query.setSort(queryBean.getSort()); } { DetachedCriteria criteria = queryBean.getCriteriaForFetchModes(); if (criteria != null) { query.setCriteriaQuery(criteria.getExecutableCriteria(fullTextSession)); } } // faceting final Map<String, FacetingRequest> faceting = queryBean.getFaceting(queryBuilder); final Map<String, List<Facet>> facets = new HashMap<>(); if (faceting != null) { FacetManager facetManager = query.getFacetManager(); for (FacetingRequest request : faceting.values()) { facetManager.enableFaceting(request); } for (String name : faceting.keySet()) { facets.put(name, facetManager.getFacets(name)); } } return new SearchResult() { @Override public FullTextQuery getFullTextQuery() { return query; } @Override public Map<String, List<Facet>> getFacets() { return facets; } }; }
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 www. java 2s.c o m //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 w w .jav a 2 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. jav a 2 s . c o 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:de.randi2.utility.webfilter.HibernateWebFilter.java
License:Open Source License
/** * Opens new session using the session factory and configures it. *//*from w ww. ja v a 2 s .c o m*/ private void createHibernateSession() { hibernateSession = sf.openSession(); hibernateSession.setFlushMode(FlushMode.MANUAL); logger.debug("HibernateWebFilter | New HibernateSession has been created | (http session: " + httpSession.getId() + ")"); logger.trace(httpSession.getId() + " >>> New conversation "); }
From source file:de.uniwue.info6.database.map.daos.DaoTools.java
License:Apache License
/** * * * @return/*from w w w.j a va 2 s . co m*/ */ protected synchronized Session getSession() { Session session = HibernateUtil.getSessionFactory().openSession(); if (!session.isOpen()) { session = HibernateUtil.getSessionFactory().openSession(); } session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); return session; }
From source file:edu.duke.cabig.c3pr.grid.registrationservice.service.impl.C3PRRegistrationServiceImpl.java
License:BSD License
public List<PlannedNotification> getPlannedNotifications(String nciInstituteCode) { List<PlannedNotification> result; List<String> nciCodeList = new ArrayList<String>(); nciCodeList.add(nciInstituteCode);//w w w. j a v a 2 s . c om SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); Session session = sessionFactory.openSession(sessionFactory.getCurrentSession().connection()); session.setFlushMode(FlushMode.MANUAL); result = new ArrayList<PlannedNotification>(); try { //Query query = session.createQuery("select p from PlannedNotification p, HealthcareSite o where p.id = o.plannedNotificationsInternal.id and o.nciInstituteCode = ?"); Query query = session.createQuery( "select p from PlannedNotification p, HealthcareSite o where p.id = o.plannedNotificationsInternal.id and o.identifiersAssignedToOrganization.typeInternal='CTEP' and o.identifiersAssignedToOrganization.value in (:nciCodeList)") .setParameterList("nciCodeList", nciCodeList); Query query1 = session.createQuery( "select p from PlannedNotification p, HealthcareSite o where p.id = o.plannedNotificationsInternal.id and o.identifiersAssignedToOrganization.typeInternal='CTEP' and o.identifiersAssignedToOrganization.value=" + "'" + nciInstituteCode + "'"); // Query query = session.createQuery("Select p from PlannedNotification as p, o from HealthcareSite as o where p.id = o.plannedNotificationsInternal.id and" + // "o.nci_institute_code in (:nciCodeList)").setParameterList("nciCodeList",nciCodeList); // query.setEntity(0, nciCodeList); result = query.list(); } catch (DataAccessResourceFailureException e) { logger.error(e.getMessage()); } catch (IllegalStateException e) { e.printStackTrace(); } catch (HibernateException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { session.close(); } return result; //result = organizationDao.getByNciIdentifier(configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE)).get(0).getPlannedNotifications(); //return result; }
From source file:edu.duke.cabig.c3pr.infrastructure.interceptor.NotificationInterceptor.java
License:BSD License
/** * Gets the planned notifications for the list of sites that are passed in. * This method access the db using a new session from the hibernate session factory. * //w ww. j av a 2s . co m * @param hcsList the hcs list * @return the planned notifications */ public List<PlannedNotification> getPlannedNotifications(List<HealthcareSite> hcsList) { List<PlannedNotification> result; List<String> nciCodeList = new ArrayList<String>(); for (HealthcareSite hcs : hcsList) { if (hcs != null) { nciCodeList.add(hcs.getPrimaryIdentifier()); } } SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); Session session = sessionFactory.openSession(sessionFactory.getCurrentSession().connection()); session.setFlushMode(FlushMode.MANUAL); result = new ArrayList<PlannedNotification>(); try { Query query = session.createQuery( "select p from PlannedNotification p, HealthcareSite o, Identifier i where p = any elements(o.plannedNotificationsInternal) and " + "i = any elements(o.identifiersAssignedToOrganization) and i.primaryIndicator = 'true' and " + "i.value in (:nciCodeList)") .setParameterList("nciCodeList", nciCodeList); result = query.list(); } catch (DataAccessResourceFailureException e) { log.error(e.getMessage()); } catch (IllegalStateException e) { e.printStackTrace(); } catch (HibernateException e) { log.error(e.getMessage()); } catch (Exception e) { log.error(e.getMessage()); } finally { session.close(); } return result; }
From source file:edu.duke.cabig.c3pr.infrastructure.interceptor.NotificationInterceptor.java
License:BSD License
/** * Gets the planned notifications for the list of sites that are passed in. * This method access the db using a new session from the hibernate session factory. * /* w w w . ja v a2 s . c om*/ * @param hcsList the hcs list * @return the planned notifications */ public List<PlannedNotification> getPlannedNotificationsForUpdateMasterSubject() { List<PlannedNotification> result; SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); Session session = sessionFactory.openSession(sessionFactory.getCurrentSession().connection()); session.setFlushMode(FlushMode.MANUAL); result = new ArrayList<PlannedNotification>(); try { Query query = session.createQuery("from PlannedNotification p where p.eventName = :var") .setString("var", NotificationEventTypeEnum.MASTER_SUBJECT_UPDATED_EVENT.toString()); result = query.list(); } catch (DataAccessResourceFailureException e) { log.error(e.getMessage()); } catch (IllegalStateException e) { e.printStackTrace(); } catch (HibernateException e) { log.error(e.getMessage()); } catch (Exception e) { log.error(e.getMessage()); } finally { session.close(); } return result; }