當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。