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.ArticleCategoryDaoImpl.java

public List<ArticleCategory> findParents(ArticleCategory articleCategory, Integer count) {
    if (articleCategory == null || articleCategory.getParent() == null) {
        return Collections.<ArticleCategory>emptyList();
    }/*from   w  w w . j a  v  a2 s.  co m*/
    String jpql = "select articleCategory from ArticleCategory articleCategory where articleCategory.id in (:ids) order by articleCategory.grade asc";
    TypedQuery<ArticleCategory> query = entityManager.createQuery(jpql, ArticleCategory.class)
            .setFlushMode(FlushModeType.COMMIT).setParameter("ids", articleCategory.getTreePaths());
    if (count != null) {
        query.setMaxResults(count);
    }
    return query.getResultList();
}

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

public MemberRank findDefault() {
    try {// ww w.  j  ava  2s.c o m
        String jpql = "select memberRank from MemberRank memberRank where memberRank.isDefault = true";
        return entityManager.createQuery(jpql, MemberRank.class).setFlushMode(FlushModeType.COMMIT)
                .getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

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

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

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

public CouponCode findByCode(String code) {
    if (code == null) {
        return null;
    }/*from  w  ww .jav  a  2s  . co m*/
    try {
        String jpql = "select couponCode from CouponCode couponCode where lower(couponCode.code) = lower(:code)";
        return entityManager.createQuery(jpql, CouponCode.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("code", code).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

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

public List<ProductCategory> findParents(ProductCategory productCategory, Integer count) {
    if (productCategory == null || productCategory.getParent() == null) {
        return Collections.<ProductCategory>emptyList();
    }/* w  w  w. jav  a 2 s  .  co  m*/
    String jpql = "select productCategory from ProductCategory productCategory where productCategory.id in (:ids) order by productCategory.grade asc";
    TypedQuery<ProductCategory> query = entityManager.createQuery(jpql, ProductCategory.class)
            .setFlushMode(FlushModeType.COMMIT).setParameter("ids", productCategory.getTreePaths());
    if (count != null) {
        query.setMaxResults(count);
    }
    return query.getResultList();
}

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

/**
 * ?//from  w  w  w .  ja v  a2 s  . co  m
 * 
 * @param attribute
 *            
 */
@Override
public void remove(Attribute attribute) {
    if (attribute != null) {
        String propertyName = Product.ATTRIBUTE_VALUE_PROPERTY_NAME_PREFIX + attribute.getPropertyIndex();
        String jpql = "update Product product set product." + propertyName
                + " = null where product.productCategory = :productCategory";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                .setParameter("productCategory", attribute.getProductCategory()).executeUpdate();
        super.remove(attribute);
    }
}

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

/**
 * ???/*from w  ww  . j a  va 2s .  c om*/
 * 
 * @param parameterGroup
 *            ?
 * @return ?
 */
@Override
public ParameterGroup merge(ParameterGroup parameterGroup) {
    Assert.notNull(parameterGroup);

    Set<Parameter> excludes = new HashSet<Parameter>();
    CollectionUtils.select(parameterGroup.getParameters(), new Predicate() {
        public boolean evaluate(Object object) {
            Parameter parameter = (Parameter) object;
            return parameter != null && parameter.getId() != null;
        }
    }, excludes);
    List<Parameter> parameters = parameterDao.findList(parameterGroup, excludes);
    for (int i = 0; i < parameters.size(); i++) {
        Parameter parameter = parameters.get(i);
        String jpql = "select product from Product product join product.parameterValue parameterValue where index(parameterValue) = :parameter";
        List<Product> products = entityManager.createQuery(jpql, Product.class)
                .setFlushMode(FlushModeType.COMMIT).setParameter("parameter", parameter).getResultList();
        for (Product product : products) {
            product.getParameterValue().remove(parameter);
            if (i % 20 == 0) {
                super.flush();
                super.clear();
            }
        }
    }
    return super.merge(parameterGroup);
}

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

/**
 * ?// www .j  a v  a  2 s .  c om
 * 
 * @param deliveryCenter
 *            ?
 * @return ?
 */
@Override
public DeliveryCenter merge(DeliveryCenter deliveryCenter) {
    Assert.notNull(deliveryCenter);
    if (deliveryCenter.getIsDefault()) {
        String jpql = "update DeliveryCenter deliveryCenter set deliveryCenter.isDefault = false where deliveryCenter.isDefault = true and deliveryCenter != :deliveryCenter";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                .setParameter("deliveryCenter", deliveryCenter).executeUpdate();
    }
    return super.merge(deliveryCenter);
}

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

/**
 * // ww  w .j ava2 s.  com
 * 
 * @param goods
 *            ?
 * @return ?
 */
@Override
public Goods merge(Goods goods) {
    Assert.notNull(goods);

    if (goods.getProducts() != null) {
        for (Product product : goods.getProducts()) {
            if (product.getId() != null) {
                if (!product.getIsGift()) {
                    String jpql = "delete from GiftItem giftItem where giftItem.gift = :product";
                    entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                            .setParameter("product", product).executeUpdate();
                }
                if (!product.getIsMarketable() || product.getIsGift()) {
                    String jpql = "delete from CartItem cartItem where cartItem.product = :product";
                    entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                            .setParameter("product", product).executeUpdate();
                }
            }
            setValue(product);
        }
    }
    return super.merge(goods);
}

From source file:com.cimpoint.mes.server.repositories.RoutingRepository.java

@Transactional
public ERouting createRouting(String name, String description, EStep startStep, EStep endStep, Set<EStep> steps,
        CustomAttributes customAttributes, MESTrxInfo trxInfo) throws Exception {
    this.setFlushMode(FlushModeType.COMMIT);

    ERouting routing = new ERouting(name, description, startStep, endStep, steps, customAttributes);

    startStep.setRouting(routing);/* w w  w .  j  a  v  a2 s. c o  m*/
    endStep.setRouting(routing);

    try {
        if (steps != null && !steps.isEmpty()) {
            Set<EStep> mergedSteps = new HashSet<EStep>();
            for (EStep step : steps) {
                if (step != null && step.getId() != null && step.getId() != 0) {
                    step = this.getEntityManager().merge(step);
                    mergedSteps.add(step);
                    step.setRouting(routing);
                }
            }

            routing.setSteps(mergedSteps);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    routing = this.create(routing, trxInfo);

    this.flush();

    return routing;
}