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

/**
 * /*ww  w .  j  a v a  2s  .co m*/
 * 
 * @param memberAttribute
 *            
 */
@Override
public void remove(MemberAttribute memberAttribute) {
    if (memberAttribute != null && (memberAttribute.getType() == Type.text
            || memberAttribute.getType() == Type.select || memberAttribute.getType() == Type.checkbox)) {
        String propertyName = Member.ATTRIBUTE_VALUE_PROPERTY_NAME_PREFIX + memberAttribute.getPropertyIndex();
        String jpql = "update Member members set members." + propertyName + " = null";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT).executeUpdate();
        super.remove(memberAttribute);
    }
}

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

/**
 * ?// w  ww . ja v  a2s.  c o  m
 * 
 * @param deliveryTemplate
 *            ??
 * @return ??
 */
@Override
public DeliveryTemplate merge(DeliveryTemplate deliveryTemplate) {
    Assert.notNull(deliveryTemplate);
    if (deliveryTemplate.getIsDefault()) {
        String jpql = "update DeliveryTemplate deliveryTemplate set deliveryTemplate.isDefault = false where deliveryTemplate.isDefault = true and deliveryTemplate != :deliveryTemplate";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                .setParameter("deliveryTemplate", deliveryTemplate).executeUpdate();
    }
    return super.merge(deliveryTemplate);
}

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

public Member findByUsername(String username) {
    if (username == null) {
        return null;
    }/*from www.jav a 2s . com*/
    try {
        String jpql = "select members from Member members where lower(members.username) = lower(:username)";
        return entityManager.createQuery(jpql, Member.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("username", username).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

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

public MemberRank findByAmount(BigDecimal amount) {
    if (amount == null) {
        return null;
    }/*from   ww  w. j  av  a2  s  . com*/
    String jpql = "select memberRank from MemberRank memberRank where memberRank.isSpecial = false and memberRank.amount <= :amount order by memberRank.amount desc";
    return entityManager.createQuery(jpql, MemberRank.class).setFlushMode(FlushModeType.COMMIT)
            .setParameter("amount", amount).setMaxResults(1).getSingleResult();
}

From source file:org.grails.datastore.gorm.jpa.support.JpaPersistenceContextInterceptor.java

@Override
public void setReadOnly() {
    entityManager.setFlushMode(FlushModeType.COMMIT);
}

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

public List<ArticleCategory> findChildren(ArticleCategory articleCategory, Integer count) {
    TypedQuery<ArticleCategory> query;
    if (articleCategory != null) {
        String jpql = "select articleCategory from ArticleCategory articleCategory where articleCategory.treePath like :treePath order by articleCategory.order asc";
        query = entityManager.createQuery(jpql, ArticleCategory.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("treePath", "%" + ArticleCategory.TREE_PATH_SEPARATOR + articleCategory.getId()
                        + ArticleCategory.TREE_PATH_SEPARATOR + "%");
    } else {//from  w ww . j a v a2 s.  c  om
        String jpql = "select articleCategory from ArticleCategory articleCategory order by articleCategory.order asc";
        query = entityManager.createQuery(jpql, ArticleCategory.class).setFlushMode(FlushModeType.COMMIT);
    }
    if (count != null) {
        query.setMaxResults(count);
    }
    return sort(query.getResultList(), articleCategory);
}

From source file:com.fferreira.example.hazelcast.mapstore.postgres.HCPostgresWorkerTest.java

@BeforeClass
public void setUpClass() throws Exception {
    entityManagerFactory = Persistence.createEntityManagerFactory("postgres_test");
    entityManager = entityManagerFactory.createEntityManager();
    entityManager.setFlushMode(FlushModeType.COMMIT);
    entityManager.clear();//from  w  ww  .j  a  v  a2s  . co m
    tx = entityManager.getTransaction();

    // provision daos
    dao = new EntryEntityDao();
    dao.setEntityManager(entityManager);

    mapStore = new HazelcastMapStore(String.class, User.class, dao);
    store = new MyHazelcastInstance(mapStore, Constants.POSTGRES_MAP_STORE);
    worker = new HazelcastWorker(Constants.POSTGRES_MAP_STORE);
}

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

public List<ProductCategory> findChildren(ProductCategory productCategory, Integer count) {
    TypedQuery<ProductCategory> query;
    if (productCategory != null) {
        String jpql = "select productCategory from ProductCategory productCategory where productCategory.treePath like :treePath order by productCategory.order asc";
        query = entityManager.createQuery(jpql, ProductCategory.class).setFlushMode(FlushModeType.COMMIT)
                .setParameter("treePath", "%" + ProductCategory.TREE_PATH_SEPARATOR + productCategory.getId()
                        + ProductCategory.TREE_PATH_SEPARATOR + "%");
    } else {/*from  ww w  .  j a  v a 2  s  .c  o  m*/
        String jpql = "select productCategory from ProductCategory productCategory order by productCategory.order asc";
        query = entityManager.createQuery(jpql, ProductCategory.class).setFlushMode(FlushModeType.COMMIT);
    }
    if (count != null) {
        query.setMaxResults(count);
    }
    return sort(query.getResultList(), productCategory);
}

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

public List<Member> findListByEmail(String email) {
    if (email == null) {
        return Collections.<Member>emptyList();
    }//  w  w  w  . j  a  va 2  s.  c o  m
    String jpql = "select members from Member members where lower(members.email) = lower(:email)";
    return entityManager.createQuery(jpql, Member.class).setFlushMode(FlushModeType.COMMIT)
            .setParameter("email", email).getResultList();
}

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

/**
 * ??/*from w w w.j a  va 2 s.com*/
 * 
 * @param receiver
 *            ?
 */
@Override
public void persist(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";
        entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
                .setParameter("member", receiver.getMember()).executeUpdate();
    }
    super.persist(receiver);
}