Example usage for javax.persistence FlushModeType COMMIT

List of usage examples for javax.persistence FlushModeType COMMIT

Introduction

In this page you can find the example usage for javax.persistence FlushModeType COMMIT.

Prototype

FlushModeType COMMIT

To view the source code for javax.persistence FlushModeType COMMIT.

Click Source Link

Document

Flushing to occur at transaction commit.

Usage

From source file:net.groupbuy.dao.impl.NavigationDaoImpl.java

public List<Navigation> findList(Position position) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Navigation> criteriaQuery = criteriaBuilder.createQuery(Navigation.class);
    Root<Navigation> root = criteriaQuery.from(Navigation.class);
    criteriaQuery.select(root);//from w w w  . j  ava  2s.c  om
    if (position != null) {
        criteriaQuery.where(criteriaBuilder.equal(root.get("position"), position));
    }
    criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order")));
    return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList();
}

From source file:net.groupbuy.dao.impl.PluginConfigDaoImpl.java

public PluginConfig findByPluginId(String pluginId) {
    if (pluginId == null) {
        return null;
    }//from  w  w w.  j a va 2 s .  c om
    try {
        String jpql = "select pluginConfig from PluginConfig pluginConfig where pluginConfig.pluginId = :pluginId";
        return entityManager.createQuery(jpql, PluginConfig.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("pluginId", pluginId).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:net.groupbuy.dao.impl.MemberDaoImpl.java

public boolean usernameExists(String username) {
    if (username == null) {
        return false;
    }/*from w w w . ja  v  a 2  s  . c o  m*/
    String jpql = "select count(*) from Member members where lower(members.username) = lower(:username)";
    Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT)
            .setParameter("username", username).getSingleResult();
    return count > 0;
}

From source file:net.groupbuy.dao.impl.CouponCodeDaoImpl.java

public boolean codeExists(String code) {
    if (code == null) {
        return false;
    }//from ww w.  ja v a2  s  .  co  m
    String jpql = "select count(*) from CouponCode couponCode where lower(couponCode.code) = lower(:code)";
    Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT)
            .setParameter("code", code).getSingleResult();
    return count > 0;
}

From source file:net.groupbuy.dao.impl.MemberRankDaoImpl.java

public boolean amountExists(BigDecimal amount) {
    if (amount == null) {
        return false;
    }/*from   ww w.j  av  a2  s.  co  m*/
    String jpql = "select count(*) from MemberRank memberRank where memberRank.amount = :amount";
    Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT)
            .setParameter("amount", amount).getSingleResult();
    return count > 0;
}

From source file:net.groupbuy.dao.impl.MemberAttributeDaoImpl.java

public List<MemberAttribute> findList() {
    String jpql = "select memberAttribute from MemberAttribute memberAttribute where memberAttribute.isEnabled = true order by memberAttribute.order asc";
    return entityManager.createQuery(jpql, MemberAttribute.class).setFlushMode(FlushModeType.COMMIT)
            .getResultList();//  w  w w  .  ja  v  a 2  s  . com
}

From source file:net.groupbuy.dao.impl.DeliveryCenterDaoImpl.java

/**
 * ??/*from ww  w. j  ava 2  s.c om*/
 * 
 * @param deliveryCenter
 *            ?
 */
@Override
public void persist(DeliveryCenter deliveryCenter) {
    Assert.notNull(deliveryCenter);
    if (deliveryCenter.getIsDefault()) {
        String jpql = "update DeliveryCenter deliveryCenter set deliveryCenter.isDefault = false where deliveryCenter.isDefault = true";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT).executeUpdate();
    }
    super.persist(deliveryCenter);
}

From source file:net.groupbuy.dao.impl.DeliveryTemplateDaoImpl.java

/**
 * ??/*from   ww w . jav  a 2  s  . com*/
 * 
 * @param deliveryTemplate
 *            ??
 */
@Override
public void persist(DeliveryTemplate deliveryTemplate) {
    Assert.notNull(deliveryTemplate);
    if (deliveryTemplate.getIsDefault()) {
        String jpql = "update DeliveryTemplate deliveryTemplate set deliveryTemplate.isDefault = false where deliveryTemplate.isDefault = true";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT).executeUpdate();
    }
    super.persist(deliveryTemplate);
}

From source file:net.groupbuy.dao.impl.OrderDaoImpl.java

public Order findBySn(String sn) {
    if (sn == null) {
        return null;
    }/*from   w w  w . java2 s.  c o  m*/
    String jpql = "select orders from Order orders where lower(orders.sn) = lower(:sn)";
    try {
        return entityManager.createQuery(jpql, Order.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("sn", sn).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:net.groupbuy.dao.impl.ParameterDaoImpl.java

public List<Parameter> findList(ParameterGroup parameterGroup, Set<Parameter> excludes) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Parameter> criteriaQuery = criteriaBuilder.createQuery(Parameter.class);
    Root<Parameter> root = criteriaQuery.from(Parameter.class);
    criteriaQuery.select(root);/*www  .j  ava 2s.  c o  m*/
    Predicate restrictions = criteriaBuilder.conjunction();
    if (parameterGroup != null) {
        restrictions = criteriaBuilder.and(restrictions,
                criteriaBuilder.equal(root.get("parameterGroup"), parameterGroup));
    }
    if (excludes != null && !excludes.isEmpty()) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.not(root.in(excludes)));
    }
    criteriaQuery.where(restrictions);
    return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList();
}