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.MemberAttributeDaoImpl.java
public Integer findUnusedPropertyIndex() { for (int i = 0; i < Member.ATTRIBUTE_VALUE_PROPERTY_COUNT; i++) { String jpql = "select count(*) from MemberAttribute memberAttribute where memberAttribute.propertyIndex = :propertyIndex"; Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT) .setParameter("propertyIndex", i).getSingleResult(); if (count == 0) { return i; }// w w w. ja v a 2 s . c om } return null; }
From source file:net.groupbuy.dao.impl.MemberRankDaoImpl.java
public boolean nameExists(String name) { if (name == null) { return false; }/*from w ww . java 2s . c om*/ String jpql = "select count(*) from MemberRank memberRank where lower(memberRank.name) = lower(:name)"; Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT) .setParameter("name", name).getSingleResult(); return count > 0; }
From source file:net.groupbuy.dao.impl.AttributeDaoImpl.java
/** * propertyIndex?//from w w w .jav a 2 s .c om * * @param attribute * */ @Override public void persist(Attribute attribute) { Assert.notNull(attribute); String jpql = "select attribute.propertyIndex from Attribute attribute where attribute.productCategory = :productCategory"; List<Integer> propertyIndexs = entityManager.createQuery(jpql, Integer.class) .setFlushMode(FlushModeType.COMMIT).setParameter("productCategory", attribute.getProductCategory()) .getResultList(); for (int i = 0; i < Product.ATTRIBUTE_VALUE_PROPERTY_COUNT; i++) { if (!propertyIndexs.contains(i)) { attribute.setPropertyIndex(i); super.persist(attribute); break; } } }
From source file:net.groupbuy.dao.impl.ArticleCategoryDaoImpl.java
public List<ArticleCategory> findRoots(Integer count) { String jpql = "select articleCategory from ArticleCategory articleCategory where articleCategory.parent is null order by articleCategory.order asc"; TypedQuery<ArticleCategory> query = entityManager.createQuery(jpql, ArticleCategory.class) .setFlushMode(FlushModeType.COMMIT); if (count != null) { query.setMaxResults(count);// w ww . j a v a2 s .c o m } return query.getResultList(); }
From source file:net.groupbuy.dao.impl.ProductCategoryDaoImpl.java
public List<ProductCategory> findRoots(Integer count) { String jpql = "select productCategory from ProductCategory productCategory where productCategory.parent is null order by productCategory.order asc"; TypedQuery<ProductCategory> query = entityManager.createQuery(jpql, ProductCategory.class) .setFlushMode(FlushModeType.COMMIT); if (count != null) { query.setMaxResults(count);//from www .ja va 2 s. com } return query.getResultList(); }
From source file:net.groupbuy.dao.impl.ReceiverDaoImpl.java
public Receiver findDefault(Member member) { if (member == null) { return null; }/*from w w w . j av a 2s.co m*/ try { String jpql = "select receiver from Receiver receiver where receiver.member = :member and receiver.isDefault = true"; return entityManager.createQuery(jpql, Receiver.class).setFlushMode(FlushModeType.COMMIT) .setParameter("member", member).getSingleResult(); } catch (NoResultException e) { try { String jpql = "select receiver from Receiver receiver where receiver.member = :member order by receiver.modifyDate desc"; return entityManager.createQuery(jpql, Receiver.class).setFlushMode(FlushModeType.COMMIT) .setParameter("member", member).setMaxResults(1).getSingleResult(); } catch (NoResultException e1) { return null; } } }
From source file:net.groupbuy.dao.impl.TagDaoImpl.java
public List<Tag> findList(Type type) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tag> criteriaQuery = criteriaBuilder.createQuery(Tag.class); Root<Tag> root = criteriaQuery.from(Tag.class); criteriaQuery.select(root);//from ww w . j a v a2s.co m if (type != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type)); } criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:net.groupbuy.dao.impl.ProductNotifyDaoImpl.java
public boolean exists(Product product, String email) { String jpql = "select count(*) from ProductNotify productNotify where productNotify.product = :product and lower(productNotify.email) = lower(:email) and productNotify.hasSent = false"; Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT) .setParameter("product", product).setParameter("email", email).getSingleResult(); return count > 0; }
From source file:net.groupbuy.dao.impl.AdminDaoImpl.java
public Admin findByUsername(String username) { if (username == null) { return null; }// ww w . ja va2s. com try { String jpql = "select admin from Admin admin where lower(admin.username) = lower(:username)"; return entityManager.createQuery(jpql, Admin.class).setFlushMode(FlushModeType.COMMIT) .setParameter("username", username).getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:net.groupbuy.dao.impl.FriendLinkDaoImpl.java
public List<FriendLink> findList(Type type) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<FriendLink> criteriaQuery = criteriaBuilder.createQuery(FriendLink.class); Root<FriendLink> root = criteriaQuery.from(FriendLink.class); criteriaQuery.select(root);//from ww w.ja v a2s . c o m if (type != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type)); } criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }