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

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

From source file:org.grails.datastore.mapping.validation.ValidatingEventListener.java

private boolean doValidate(PersistentEntity entity, Object o) {
    Validator v = datastore.getMappingContext().getEntityValidator(entity);
    if (v == null) {
        return true;
    }//  w  w w.j  a  va 2s. c o  m

    if (datastore.skipValidation(o)) {
        return true;
    }

    Session currentSession = datastore.getCurrentSession();
    FlushModeType flushMode = currentSession.getFlushMode();
    try {
        currentSession.setFlushMode(FlushModeType.COMMIT);

        Errors result = new ValidationErrors(o);
        v.validate(o, result);
        if (result.hasErrors()) {
            onErrors(o, result);
            return false;
        }

        return true;
    } finally {
        currentSession.setFlushMode(flushMode);
    }
}

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

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

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

/**
 * ???/*from  ww  w.ja  v a  2s .  co m*/
 * 
 * @param parameterGroup
 *            ?
 * @return ?
 */
@Override
public void remove(ParameterGroup parameterGroup) {
    if (parameterGroup != null) {
        for (int i = 0; i < parameterGroup.getParameters().size(); i++) {
            Parameter parameter = parameterGroup.getParameters().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();
                }
            }
        }
        super.remove(super.merge(parameterGroup));
    }
}

From source file:org.grails.datastore.gorm.support.DatastorePersistenceContextInterceptor.java

public void setReadOnly() {
    getSession().setFlushMode(FlushModeType.COMMIT);
}

From source file:com.expressui.sample.dao.PermissionDao.java

public List<Permission> findByRoleEntityTypeAndField(AbstractRole role, String entityType, String field) {
    Query query = getEntityManager().createQuery("SELECT p FROM Permission p WHERE p.role = :role"
            + " AND p.entityType = :entityType AND p.field = :field");
    query.setParameter("role", role);
    query.setParameter("entityType", entityType);
    query.setParameter("field", field);

    query.setFlushMode(FlushModeType.COMMIT);

    return query.getResultList();
}

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

/**
 * ?/*from w ww  .  j  a  va  2 s  .  co m*/
 * 
 * @param memberRank
 *            
 * @return 
 */
@Override
public MemberRank merge(MemberRank memberRank) {
    Assert.notNull(memberRank);
    if (memberRank.getIsDefault()) {
        String jpql = "update MemberRank memberRank set memberRank.isDefault = false where memberRank.isDefault = true and memberRank != :memberRank";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                .setParameter("memberRank", memberRank).executeUpdate();
    }
    return super.merge(memberRank);
}

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

/**
 * ?/*w ww.  ja  v a  2 s.  co  m*/
 * 
 * @param receiver
 *            ?
 * @return ?
 */
@Override
public Receiver merge(Receiver receiver) {
    Assert.notNull(receiver);
    Assert.notNull(receiver.getMember());
    if (receiver.getIsDefault()) {
        String jpql = "update Receiver receiver set receiver.isDefault = false where receiver.member = :member and receiver.isDefault = true and receiver != :receiver";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                .setParameter("member", receiver.getMember()).setParameter("receiver", receiver)
                .executeUpdate();
    }
    return super.merge(receiver);
}

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

public Product findBySn(String sn) {
    if (sn == null) {
        return null;
    }//w  w w  . ja v a 2s . co  m
    String jpql = "select product from Product product where lower(product.sn) = lower(:sn)";
    try {
        return entityManager.createQuery(jpql, Product.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("sn", sn).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

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

private long getLastValue(Type type) {
    String jpql = "select sn from Sn sn where sn.type = :type";
    Sn sn = entityManager.createQuery(jpql, Sn.class).setFlushMode(FlushModeType.COMMIT)
            .setLockMode(LockModeType.PESSIMISTIC_WRITE).setParameter("type", type).getSingleResult();
    long lastValue = sn.getLastValue();
    sn.setLastValue(lastValue + 1);/*from w w  w  . j ava  2 s. c o m*/
    entityManager.merge(sn);
    return lastValue;
}