当前位置: 首页>>代码示例>>Java>>正文


Java FlushModeType类代码示例

本文整理汇总了Java中javax.persistence.FlushModeType的典型用法代码示例。如果您正苦于以下问题:Java FlushModeType类的具体用法?Java FlushModeType怎么用?Java FlushModeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FlushModeType类属于javax.persistence包,在下文中一共展示了FlushModeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findSalesList

import javax.persistence.FlushModeType; //导入依赖的package包/类
public List<Object[]> findSalesList(Date beginDate, Date endDate, Integer count) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);
	Root<Product> product = criteriaQuery.from(Product.class);
	Join<Product, OrderItem> orderItems = product.join("orderItems");
	Join<Product, com.easyshopping.entity.Order> order = orderItems.join("order");
	criteriaQuery.multiselect(product.get("id"), product.get("sn"), product.get("name"), product.get("fullName"), product.get("price"), criteriaBuilder.sum(orderItems.<Integer> get("quantity")), criteriaBuilder.sum(criteriaBuilder.prod(orderItems.<Integer> get("quantity"), orderItems.<BigDecimal> get("price"))));
	Predicate restrictions = criteriaBuilder.conjunction();
	if (beginDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(order.<Date> get("createDate"), beginDate));
	}
	if (endDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(order.<Date> get("createDate"), endDate));
	}
	restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(order.get("orderStatus"), OrderStatus.completed), criteriaBuilder.equal(order.get("paymentStatus"), PaymentStatus.paid));
	criteriaQuery.where(restrictions);
	criteriaQuery.groupBy(product.get("id"), product.get("sn"), product.get("name"), product.get("fullName"), product.get("price"));
	criteriaQuery.orderBy(criteriaBuilder.desc(criteriaBuilder.sum(criteriaBuilder.prod(orderItems.<Integer> get("quantity"), orderItems.<BigDecimal> get("price")))));
	TypedQuery<Object[]> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT);
	if (count != null && count >= 0) {
		query.setMaxResults(count);
	}
	return query.getResultList();
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:25,代码来源:ProductDaoImpl.java

示例2: withoutFlush

import javax.persistence.FlushModeType; //导入依赖的package包/类
private static <T> T withoutFlush(EntityManager entityManager, boolean flushAtEnd,
    Function<EntityManager, T> task) {
    FlushModeType fm = entityManager.getFlushMode();
    entityManager.setFlushMode(FlushModeType.COMMIT);
    try {
        T result = task.apply(entityManager);
        entityManager.setFlushMode(fm);
        if (flushAtEnd) {
            entityManager.flush();
        }
        return result;
    } catch (RuntimeException e) {
        entityManager.setFlushMode(fm);
        throw e;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:17,代码来源:MCRCategoryDAOImpl.java

示例3: findList

import javax.persistence.FlushModeType; //导入依赖的package包/类
protected List<T> findList(CriteriaQuery<T> criteriaQuery, Integer first, Integer count, List<Filter> filters, List<Order> orders) {
	Assert.notNull(criteriaQuery);
	Assert.notNull(criteriaQuery.getSelection());
	Assert.notEmpty(criteriaQuery.getRoots());

	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	Root<T> root = getRoot(criteriaQuery);
	addRestrictions(criteriaQuery, filters);
	addOrders(criteriaQuery, orders);
	if (criteriaQuery.getOrderList().isEmpty()) {
		if (OrderEntity.class.isAssignableFrom(entityClass)) {
			criteriaQuery.orderBy(criteriaBuilder.asc(root.get(OrderEntity.ORDER_PROPERTY_NAME)));
		} else {
			criteriaQuery.orderBy(criteriaBuilder.desc(root.get(OrderEntity.CREATE_DATE_PROPERTY_NAME)));
		}
	}
	TypedQuery<T> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT);
	if (first != null) {
		query.setFirstResult(first);
	}
	if (count != null) {
		query.setMaxResults(count);
	}
	return query.getResultList();
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:26,代码来源:BaseDaoImpl.java

示例4: getSalesAmount

import javax.persistence.FlushModeType; //导入依赖的package包/类
public BigDecimal getSalesAmount(Date beginDate, Date endDate) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<BigDecimal> criteriaQuery = criteriaBuilder.createQuery(BigDecimal.class);
	Root<Order> root = criteriaQuery.from(Order.class);
	criteriaQuery.select(criteriaBuilder.sum(root.<BigDecimal> get("amountPaid")));
	Predicate restrictions = criteriaBuilder.conjunction();
	restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("orderStatus"), OrderStatus.completed));
	if (beginDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date> get("createDate"), beginDate));
	}
	if (endDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date> get("createDate"), endDate));
	}
	criteriaQuery.where(restrictions);
	return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getSingleResult();
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:17,代码来源:OrderDaoImpl.java

示例5: getSalesVolume

import javax.persistence.FlushModeType; //导入依赖的package包/类
public Integer getSalesVolume(Date beginDate, Date endDate) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Integer> criteriaQuery = criteriaBuilder.createQuery(Integer.class);
	Root<Order> root = criteriaQuery.from(Order.class);
	criteriaQuery.select(criteriaBuilder.sum(root.join("orderItems").<Integer> get("shippedQuantity")));
	Predicate restrictions = criteriaBuilder.conjunction();
	restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("orderStatus"), OrderStatus.completed));
	if (beginDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date> get("createDate"), beginDate));
	}
	if (endDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date> get("createDate"), endDate));
	}
	criteriaQuery.where(restrictions);
	return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getSingleResult();
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:17,代码来源:OrderDaoImpl.java

示例6: remove

import javax.persistence.FlushModeType; //导入依赖的package包/类
/**
 * 清除商品属性值并删除
 * 
 * @param productCategory
 *            商品分类
 */
@Override
public void remove(ProductCategory productCategory) {
	if (productCategory != null) {
		StringBuffer jpql = new StringBuffer("update Product product set ");
		for (int i = 0; i < Product.ATTRIBUTE_VALUE_PROPERTY_COUNT; i++) {
			String propertyName = Product.ATTRIBUTE_VALUE_PROPERTY_NAME_PREFIX + i;
			if (i == 0) {
				jpql.append("product." + propertyName + " = null");
			} else {
				jpql.append(", product." + propertyName + " = null");
			}
		}
		jpql.append(" where product.productCategory = :productCategory");
		entityManager.createQuery(jpql.toString()).setFlushMode(FlushModeType.COMMIT).setParameter("productCategory", productCategory).executeUpdate();
		super.remove(productCategory);
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:24,代码来源:ProductCategoryDaoImpl.java

示例7: remove

import javax.persistence.FlushModeType; //导入依赖的package包/类
/**
 * 处理商品参数并删除
 * 
 * @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));
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:26,代码来源:ParameterGroupDaoImpl.java

示例8: remove

import javax.persistence.FlushModeType; //导入依赖的package包/类
/**
 * 忽略默认、清除会员价并删除
 * 
 * @param memberRank
 *            会员等级
 */
@Override
public void remove(MemberRank memberRank) {
	if (memberRank != null && !memberRank.getIsDefault()) {
		String jpql = "select product from Product product join product.memberPrice memberPrice where index(memberPrice) = :memberRank";
		List<Product> products = entityManager.createQuery(jpql, Product.class).setFlushMode(FlushModeType.COMMIT).setParameter("memberRank", memberRank).getResultList();
		for (int i = 0; i < products.size(); i++) {
			Product product = products.get(i);
			product.getMemberPrice().remove(memberRank);
			if (i % 20 == 0) {
				super.flush();
				super.clear();
			}
		}
		super.remove(super.merge(memberRank));
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:23,代码来源:MemberRankDaoImpl.java

示例9: findPurchaseList

import javax.persistence.FlushModeType; //导入依赖的package包/类
public List<Object[]> findPurchaseList(Date beginDate, Date endDate, Integer count) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);
	Root<Member> member = criteriaQuery.from(Member.class);
	Join<Product, Order> orders = member.join("orders");
	criteriaQuery.multiselect(member.get("id"), member.get("username"), member.get("email"), member.get("point"), member.get("amount"), member.get("balance"), criteriaBuilder.sum(orders.<BigDecimal> get("amountPaid")));
	Predicate restrictions = criteriaBuilder.conjunction();
	if (beginDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(orders.<Date> get("createDate"), beginDate));
	}
	if (endDate != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(orders.<Date> get("createDate"), endDate));
	}
	restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(orders.get("orderStatus"), OrderStatus.completed), criteriaBuilder.equal(orders.get("paymentStatus"), PaymentStatus.paid));
	criteriaQuery.where(restrictions);
	criteriaQuery.groupBy(member.get("id"), member.get("username"), member.get("email"), member.get("point"), member.get("amount"), member.get("balance"));
	criteriaQuery.orderBy(criteriaBuilder.desc(criteriaBuilder.sum(orders.<BigDecimal> get("amountPaid"))));
	TypedQuery<Object[]> query = entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT);
	if (count != null && count >= 0) {
		query.setMaxResults(count);
	}
	return query.getResultList();
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:24,代码来源:MemberDaoImpl.java

示例10: aliasRules

import javax.persistence.FlushModeType; //导入依赖的package包/类
@Test
@Ignore("TODO replace persistence provider")
public void aliasRules() {
    TestSecurityContext.authenticate(USER);
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("alias");

    EntityManager entityManager = factory.createEntityManager();
    EntityManager mock = (EntityManager)entityManager.getDelegate();
    reset(mock);
    String originalQuery = "SELECT c.text, SUM(c.id) AS cSum FROM Contact AS c "
                         + "WHERE c.owner.name = :name GROUP BY c.text ORDER BY cSum";
    // TODO check why the rule is applied twice
    String filteredQuery = " SELECT c.text,  SUM(c.id)  AS cSum FROM Contact c "
                         + "WHERE (c.owner.name = :name) AND (c.owner.name = 'user') "
                         + "GROUP BY c.text  ORDER BY cSum";

    when(mock.isOpen()).thenReturn(true);
    when(mock.getFlushMode()).thenReturn(FlushModeType.AUTO);
    when(mock.createQuery(filteredQuery)).thenReturn(mock(Query.class));

    entityManager.createQuery(originalQuery);

    verify(mock).createQuery(filteredQuery);
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:25,代码来源:AccessCheckTest.java

示例11: findByGoodsWithExcludes

import javax.persistence.FlushModeType; //导入依赖的package包/类
@Override
public List<Product> findByGoodsWithExcludes(Goods goods, Set<Product> excludes) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Product> criteriaQuery = criteriaBuilder.createQuery(Product.class);
	Root<Product> root = criteriaQuery.from(Product.class);
	criteriaQuery.select(root);
	Predicate restrictions = criteriaBuilder.conjunction();
	if (goods != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("goods"), goods));
	}
	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();
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:17,代码来源:ProductRepositoryImpl.java

示例12: setUpClass

import javax.persistence.FlushModeType; //导入依赖的package包/类
@BeforeClass
public void setUpClass() throws Exception {
  entityManagerFactory = Persistence
      .createEntityManagerFactory("postgres_test");
  entityManager = entityManagerFactory.createEntityManager();
  entityManager.setFlushMode(FlushModeType.COMMIT);
  entityManager.clear();
  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);
}
 
开发者ID:FlavioF,项目名称:hazelcast-mapstore-postgres-cassandra,代码行数:18,代码来源:HCPostgresWorkerTest.java

示例13: updateAllFormElementsWithDescriptionChanged

import javax.persistence.FlushModeType; //导入依赖的package包/类
/**
 * If the description list of a source element was changed,
 * this ensures that the description(s) of its associated LinkElements is up-to-date.
 */
public void updateAllFormElementsWithDescriptionChanged(FormElement formElement) {
	Iterator<Description> newDescriptionIterator = formElement.getDescriptionList().iterator();
	
	while ( newDescriptionIterator.hasNext() )
	{
		Description newDescription = newDescriptionIterator.next();
		
		if ( ! newDescription.isNew() )
		{			
			Query query = em.createNativeQuery("update form_element set description = :desc from description d where form_element.link_id=:uuid and form_element.description = d.source_description_text and d.id = :id");
							
			query.setParameter("desc", newDescription.getDescription() );
			
			query.setParameter("uuid", formElement.isLink() && !formElement.isExternalQuestion() ? (( LinkElement )formElement).getSourceId() : formElement.getUuid() );
			
			query.setParameter("id", newDescription.getId() );
			
			query.setFlushMode(FlushModeType.COMMIT);
			
			query.executeUpdate();
		}
	}
}
 
开发者ID:NCIP,项目名称:edct-formbuilder,代码行数:28,代码来源:FormElementDao.java

示例14: shouldNotSaveEntityWithCommitFlush

import javax.persistence.FlushModeType; //导入依赖的package包/类
@Test
public void shouldNotSaveEntityWithCommitFlush() {
	Plane boeing = new Plane(6L, "boeing");

	doInTransaction(() -> {
		em.persist(boeing);
		em.setFlushMode(FlushModeType.COMMIT);
		em.createQuery("select p from Plane p").getResultList();
		em.clear();
	});
	doInTransaction(() -> assertThat(em.find(Plane.class, 6L)).isNull());
}
 
开发者ID:jkubrynski,项目名称:jpa-caches,代码行数:13,代码来源:PersistenceContextTest.java

示例15: testQueryNoPersonsShared

import javax.persistence.FlushModeType; //导入依赖的package包/类
@SuppressWarnings({ "unused", "unchecked" })
public void testQueryNoPersonsShared() {
	EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
	Query q = em.createQuery("select p from Person as p");
	q.setFlushMode(FlushModeType.AUTO);
	List<Person> people = q.getResultList();
	try {
		assertNull(q.getSingleResult());
		fail("Should have thrown NoResultException");
	}
	catch (NoResultException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:AbstractContainerEntityManagerFactoryIntegrationTests.java


注:本文中的javax.persistence.FlushModeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。