List of usage examples for javax.persistence FlushModeType COMMIT
FlushModeType COMMIT
To view the source code for javax.persistence FlushModeType COMMIT.
Click Source Link
From source file:net.groupbuy.dao.impl.BaseDaoImpl.java
protected List<T> findList(CriteriaQuery<T> criteriaQuery, Integer first, Integer count, List<Filter> filters, List<Order> orders) { Assert.notNull(criteriaQuery);/*from w w w. j a v a 2 s. com*/ Assert.notNull(criteriaQuery.getSelection()); Assert.notEmpty(criteriaQuery.getRoots()); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Root<T> root = getRoot(criteriaQuery); addRestrictions(criteriaQuery, filters); addOrders(criteriaQuery, orders); if (criteriaQuery.getOrderList().isEmpty()) { if (OrderEntity.class.isAssignableFrom(entityClass)) { criteriaQuery.orderBy(criteriaBuilder.asc(root.get(OrderEntity.ORDER_PROPERTY_NAME))); } else { criteriaQuery.orderBy(criteriaBuilder.desc(root.get(OrderEntity.CREATE_DATE_PROPERTY_NAME))); } } TypedQuery<T> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT); if (first != null) { query.setFirstResult(first); } if (count != null) { query.setMaxResults(count); } return query.getResultList(); }
From source file:net.groupbuy.dao.impl.ReviewDaoImpl.java
public long calculateTotalScore(Product product) { if (product == null) { return 0L; }/*from ww w . j a v a 2 s . co m*/ String jpql = "select sum(review.score) from Review review where review.product = :product and review.isShow = :isShow"; Long totalScore = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT) .setParameter("product", product).setParameter("isShow", true).getSingleResult(); return totalScore != null ? totalScore : 0L; }
From source file:net.groupbuy.dao.impl.ReviewDaoImpl.java
public long calculateScoreCount(Product product) { if (product == null) { return 0L; }//from ww w . j av a 2 s . c o m String jpql = "select count(*) from Review review where review.product = :product and review.isShow = :isShow"; return entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT) .setParameter("product", product).setParameter("isShow", true).getSingleResult(); }
From source file:com.zero.dao.impl.BaseDaoImpl.java
protected Page<T> findPage(CriteriaQuery<T> criteriaQuery, Pageable pageable) { Assert.notNull(criteriaQuery);//from w w w .j a va2 s. c o m Assert.notNull(criteriaQuery.getSelection()); Assert.notEmpty(criteriaQuery.getRoots()); if (pageable == null) { pageable = new Pageable(); } // CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); // Root<T> root = getRoot(criteriaQuery); addRestrictions(criteriaQuery, pageable); // addOrders(criteriaQuery, pageable); // if (criteriaQuery.getOrderList().isEmpty()) { // if (OrderEntity.class.isAssignableFrom(entityClass)) { // criteriaQuery.orderBy(criteriaBuilder.asc(root // .get(OrderEntity.ORDER_PROPERTY_NAME))); // } else { // criteriaQuery.orderBy(criteriaBuilder.desc(root // .get(OrderEntity.CREATE_DATE_PROPERTY_NAME))); // } // } long total = count(criteriaQuery, null); int totalPages = (int) Math.ceil(total / (double) pageable.getPageSize()); if (totalPages < pageable.getPageNumber()) { pageable.setPageNumber(totalPages); } TypedQuery<T> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT); query.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize()); query.setMaxResults(pageable.getPageSize()); return new Page<T>(query.getResultList(), total, pageable); }
From source file:net.groupbuy.dao.impl.BaseDaoImpl.java
protected Page<T> findPage(CriteriaQuery<T> criteriaQuery, Pageable pageable) { Assert.notNull(criteriaQuery);/* ww w .jav a 2 s.com*/ Assert.notNull(criteriaQuery.getSelection()); Assert.notEmpty(criteriaQuery.getRoots()); if (pageable == null) { pageable = new Pageable(); } CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Root<T> root = getRoot(criteriaQuery); addRestrictions(criteriaQuery, pageable); addOrders(criteriaQuery, pageable); if (criteriaQuery.getOrderList().isEmpty()) { if (OrderEntity.class.isAssignableFrom(entityClass)) { criteriaQuery.orderBy(criteriaBuilder.asc(root.get(OrderEntity.ORDER_PROPERTY_NAME))); } else { criteriaQuery.orderBy(criteriaBuilder.desc(root.get(OrderEntity.CREATE_DATE_PROPERTY_NAME))); } } long total = count(criteriaQuery, null); int totalPages = (int) Math.ceil((double) total / (double) pageable.getPageSize()); if (totalPages < pageable.getPageNumber()) { pageable.setPageNumber(totalPages); } TypedQuery<T> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT); query.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize()); query.setMaxResults(pageable.getPageSize()); return new Page<T>(query.getResultList(), total, pageable); }
From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java
/** * Get named query with FlushModeType.COMMIT * @param queryName the name of the query * @throws SocialSiteException on any error *//*from ww w.j a v a2 s. c om*/ public Query getNamedQuery(String queryName) throws SocialSiteException { EntityManager em = getEntityManager(false); Query q = em.createNamedQuery(queryName); // Never flush for queries. SocialSite code assumes this behavior q.setFlushMode(FlushModeType.COMMIT); return q; }
From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java
/** * Create query from queryString with FlushModeType.COMMIT * @param queryString the quuery//from w w w .java 2s . com * @throws SocialSiteException on any error */ public Query getDynamicQuery(String queryString) throws SocialSiteException { EntityManager em = getEntityManager(false); Query q = em.createQuery(queryString); // Never flush for queries. SocialSite code assumes this behavior q.setFlushMode(FlushModeType.COMMIT); return q; }
From source file:com.zero.dao.impl.BaseDaoImpl.java
protected Long count(CriteriaQuery<T> criteriaQuery, List<Filter> filters) { Assert.notNull(criteriaQuery);/* w ww. j a v a2 s. c om*/ Assert.notNull(criteriaQuery.getSelection()); Assert.notEmpty(criteriaQuery.getRoots()); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); addRestrictions(criteriaQuery, filters); CriteriaQuery<Long> countCriteriaQuery = criteriaBuilder.createQuery(Long.class); for (Root<?> root : criteriaQuery.getRoots()) { Root<?> dest = countCriteriaQuery.from(root.getJavaType()); dest.alias(getAlias(root)); copyJoins(root, dest); } Root<?> countRoot = getRoot(countCriteriaQuery, criteriaQuery.getResultType()); countCriteriaQuery.select(criteriaBuilder.count(countRoot.get("id").<String>get("stcd"))); if (criteriaQuery.getGroupList() != null) { countCriteriaQuery.groupBy(criteriaQuery.getGroupList()); } if (criteriaQuery.getGroupRestriction() != null) { countCriteriaQuery.having(criteriaQuery.getGroupRestriction()); } if (criteriaQuery.getRestriction() != null) { countCriteriaQuery.where(criteriaQuery.getRestriction()); } return entityManager.createQuery(countCriteriaQuery).setFlushMode(FlushModeType.COMMIT).getSingleResult(); }
From source file:org.jrecruiter.dao.jpa.JobDaoJpa.java
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public void reindexSearch() { final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); fullTextEntityManager.setFlushMode(FlushModeType.COMMIT); final List<Job> jobs = entityManager.createQuery("select job from Job as job").getResultList(); for (final Job job : jobs) { fullTextEntityManager.index(job); }//from ww w . j a v a 2s.c om final List<Region> regions = entityManager.createQuery("select region from Region as region") .getResultList(); for (final Region region : regions) { fullTextEntityManager.index(region); } final List<Industry> industries = entityManager.createQuery("select industry from Industry as industry") .getResultList(); for (final Industry industry : industries) { fullTextEntityManager.index(industry); } }
From source file:org.grails.orm.hibernate.HibernateSession.java
public void setFlushMode(FlushModeType flushMode) { if (flushMode == FlushModeType.AUTO) { hibernateTemplate.setFlushMode(GrailsHibernateTemplate.FLUSH_AUTO); } else if (flushMode == FlushModeType.COMMIT) { hibernateTemplate.setFlushMode(GrailsHibernateTemplate.FLUSH_COMMIT); }/* w w w . j a v a 2 s . c o m*/ }