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


Java CriteriaUpdate.set方法代码示例

本文整理汇总了Java中javax.persistence.criteria.CriteriaUpdate.set方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaUpdate.set方法的具体用法?Java CriteriaUpdate.set怎么用?Java CriteriaUpdate.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.criteria.CriteriaUpdate的用法示例。


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

示例1: softDelete

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void softDelete(T entity, LocalDateTime localDateTime) {
	Assert.notNull(entity, "The entity must not be null!");

	CriteriaBuilder cb = em.getCriteriaBuilder();

	CriteriaUpdate<T> update = cb.createCriteriaUpdate((Class<T>) domainClass);

	Root<T> root = update.from((Class<T>) domainClass);

	update.set(DELETED_FIELD, localDateTime);

	final List<Predicate> predicates = new ArrayList<Predicate>();

	if (entityInformation.hasCompositeId()) {
		for (String s : entityInformation.getIdAttributeNames())
			predicates.add(cb.equal(root.<ID>get(s),
					entityInformation.getCompositeIdAttributeValue(entityInformation.getId(entity), s)));
		update.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
	} else
		update.where(cb.equal(root.<ID>get(entityInformation.getIdAttribute().getName()),
				entityInformation.getId(entity)));

	em.createQuery(update).executeUpdate();
}
 
开发者ID:dzinot,项目名称:spring-boot-jpa-data-rest-soft-delete,代码行数:25,代码来源:SoftDeletesRepositoryImpl.java

示例2: performMove

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void performMove(Sign nodeSign, Long nodeDelta, List nodeIds, Long levelModificator, Class<N> nodeClass) {
    if (!nodeIds.isEmpty()) {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaUpdate<N> update = cb.createCriteriaUpdate(nodeClass);
        Root<N> root = update.from(nodeClass);

        update.set(root.<Long>get(level(nodeClass)), cb.sum(root.<Long>get(level(nodeClass)), levelModificator));
        if (Sign.MINUS.equals(nodeSign)) {
            update.set(root.<Long>get(right(nodeClass)), cb.diff(root.<Long>get(right(nodeClass)), nodeDelta));
            update.set(root.<Long>get(left(nodeClass)), cb.diff(root.<Long>get(left(nodeClass)), nodeDelta));
        } else if (Sign.PLUS.equals(nodeSign)) {
            update.set(root.<Long>get(right(nodeClass)), cb.sum(root.<Long>get(right(nodeClass)), nodeDelta));
            update.set(root.<Long>get(left(nodeClass)), cb.sum(root.<Long>get(left(nodeClass)), nodeDelta));
        }
        update.where(getPredicates(cb, root, root.get(id(nodeClass)).in(nodeIds)));

        em.createQuery(update).executeUpdate();
    }
}
 
开发者ID:eXsio,项目名称:nestedj,代码行数:20,代码来源:NestedNodeMoverImpl.java

示例3: updateFields

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void updateFields(Sign sign, Long delta, Long start, Long stop, Class<N> nodeClass, String field) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaUpdate<N> update = cb.createCriteriaUpdate(nodeClass);
    Root<N> root = update.from(nodeClass);

    if (Sign.MINUS.equals(sign)) {
        update.set(root.<Long>get(field), cb.diff(root.<Long>get(field), delta));
    } else if (Sign.PLUS.equals(sign)) {
        update.set(root.<Long>get(field), cb.sum(root.<Long>get(field), delta));
    }
    update.where(getPredicates(cb, root,
            cb.greaterThan(root.<Long>get(field), start),
            cb.lessThan(root.<Long>get(field), stop)
    ));

    em.createQuery(update).executeUpdate();
}
 
开发者ID:eXsio,项目名称:nestedj,代码行数:18,代码来源:NestedNodeMoverImpl.java

示例4: update

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
/**
 * WARNING, order will not be honoured by this method
 * 
 * @param attribute
 * @param value
 * 
 * @return
 */
public <F> int update(SingularAttribute<E, F> attribute, F value)
{
	Preconditions.checkArgument(orders.size() == 0, "Order is not supported for delete");
	CriteriaUpdate<E> updateCriteria = builder.createCriteriaUpdate(entityClass);
	root = updateCriteria.getRoot();
	if (predicate != null)
	{
		updateCriteria.where(predicate);
		updateCriteria.set(attribute, value);
	}
	Query query = getEntityManager().createQuery(updateCriteria);

	if (limit != null)
	{
		query.setMaxResults(limit);
	}
	if (startPosition != null)
	{
		query.setFirstResult(startPosition);
	}
	int result = query.executeUpdate();
	getEntityManager().getEntityManagerFactory().getCache().evict(entityClass);

	return result;
}
 
开发者ID:rlsutton1,项目名称:VaadinUtils,代码行数:34,代码来源:JpaDslAbstract.java

示例5: shouldExecuteCriteriaUpdate

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
@Test
public void shouldExecuteCriteriaUpdate() throws Exception {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaUpdate<Employee> c =
        builder.createCriteriaUpdate(Employee.class);
    Root<Employee> p = c.from(Employee.class);
    Predicate condition = builder.ge(
        p.get(Employee_.salary), new BigDecimal("50000"));
    c.where(condition);
    TaxCode directorTaxCode = new TaxCode(504, "Director");
    c.set(p.get(Employee_.taxCode), directorTaxCode);

    utx.begin();
    Query query = em.createQuery(c);
    int rowsAffected = query.executeUpdate();
    assertTrue( rowsAffected > 0 );
    utx.commit();
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:19,代码来源:EmployeeCriteriaUpdateTest.java

示例6: updateTask

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
public void updateTask(final ToDoList pToDoList) {
	
       final CriteriaBuilder lCriteriaBuilder = entityManager.getCriteriaBuilder();
       
       //Creation de la requête d'update
       final CriteriaUpdate<ToDoList> lCriteriaUpdate = lCriteriaBuilder.createCriteriaUpdate(ToDoList.class);
       final Root<ToDoList> lRoot = lCriteriaUpdate.from(ToDoList.class);
       final Path<ToDoList> lPath = lRoot.get("id");
       //On utilise la variable pToDoList transmise en parametre de la methode
       final Expression<Boolean> lExpression = lCriteriaBuilder.equal(lPath, pToDoList.getId());
       lCriteriaUpdate.where(lExpression);
       lCriteriaUpdate.set("libelle", pToDoList.getLibelle());
       
       final Query lQuery = entityManager.createQuery(lCriteriaUpdate);
       final int lRowCount = lQuery.executeUpdate();
       
       //Si la requête modifie un nombre d'occurrences différent de 1 > erreur
       //Sinon update fait.
       if (lRowCount != 1) {
           final org.hibernate.Query lHQuery = lQuery.unwrap(org.hibernate.Query.class);
           final String lSql = lHQuery.getQueryString();
           throw new RuntimeException("Nombre d'occurences (" + lRowCount + 
                   ") modifiés différent de 1 pour " + lSql);
       }
	
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:27,代码来源:ToDoListDAO.java

示例7: update

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
@Override
public int update(T entity) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaUpdate<T> criteriaUpdate = builder.createCriteriaUpdate(entityClass);
    Root<T> root = criteriaUpdate.from(entityClass);
    Field[] fields = entityClass.getDeclaredFields();
    Object primaryV = null;
    String primaryKey = this.getPrimaryKey();
    for (Field field : fields) {
        ReflectionUtils.makeAccessible(field);
        Object fieldV = ReflectionUtils.getField(field, entity);
        if (fieldV == null)
            continue;
        if (primaryKey.equals(field.getName())) {// 主键不参与修改
            primaryV = fieldV;
        } else {
            criteriaUpdate.set(root.get(field.getName()), fieldV);
        }
    }
    criteriaUpdate.where(builder.equal(root.get(primaryKey), primaryV));
    Query query = entityManager.createQuery(criteriaUpdate);
    return query.executeUpdate();

}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:25,代码来源:BaseRepositoryImpl.java

示例8: updateBookPrices

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
@Test
public void updateBookPrices() {
	log.info("... updateBookPrices ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	logBookPrices(em);
	
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaUpdate<Book> update = cb.createCriteriaUpdate(Book.class);
	Root<Book> root = update.from(Book.class);
	update.set(Book_.price, cb.prod(root.get(Book_.price), 1.1));
	
	Query query = em.createQuery(update);
	query.executeUpdate();

	logBookPrices(em);
	
	em.getTransaction().commit();
	em.close();
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:23,代码来源:TestCriteriaUpdate.java

示例9: shouldBulkUpdateCriteria

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
@Test
public void shouldBulkUpdateCriteria() {
    CriteriaBuilder cb = em.getCriteriaBuilder(); 
    CriteriaUpdate<Address> update = cb.createCriteriaUpdate(Address.class); //<3>
    Root<Address> i = update.from(Address.class);
    update.set(i.get("disable"), true);
    update.where(cb.greaterThan(i.get("id"), 0l));
    int updatedEntities = em.createQuery(update).executeUpdate(); //<4>
    Assertions.assertThat(updatedEntities).isEqualTo(30);
    Assertions.assertThat(addressRepo.findByDisableTrue()).hasSize(30);
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:12,代码来源:JpaBulkTest.java

示例10: complete

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @param eventName JAVADOC.
 * @param nodeId JAVADOC.
 *
 * @return JAVADOC.
 */
@Override
@Transactional
public boolean complete(String eventName, String nodeId) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Cleaning for event '" + eventName + "' and node '" + nodeId + "'");
    }

    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaUpdate<ClusterControl> cq = cb.createCriteriaUpdate(ClusterControl.class);
    Root<ClusterControl> root = cq.from(ClusterControl.class);
    Predicate ep = cb.equal(root.get("event"), eventName);
    Path<Object> pc = root.get("complete");
    Predicate cp = cb.equal(pc, false);
    Predicate np = cb.equal(root.get("activeNodeId"), nodeId);

    cq.set(pc, true);

    int rows = entityManager.createQuery(cq.where(cb.and(ep, cp, np))).executeUpdate();

    return rows > 0;
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:30,代码来源:ClusterControlRepositoryImpl.java

示例11: updateFields

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void updateFields(Long from, Mode mode, Class<N> nodeClass, String fieldName) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaUpdate<N> update = cb.createCriteriaUpdate(nodeClass);
    Root<N> root = update.from(nodeClass);

    update.set(root.<Long>get(fieldName), cb.sum(root.<Long>get(fieldName), 2L));
    if (applyGte(mode)) {
        update.where(getPredicates(cb, root, cb.greaterThanOrEqualTo(root.<Long>get(fieldName), from)));
    } else {
        update.where(getPredicates(cb, root, cb.greaterThan(root.<Long>get(fieldName), from)));
    }
    em.createQuery(update).executeUpdate();
}
 
开发者ID:eXsio,项目名称:nestedj,代码行数:14,代码来源:NestedNodeInserterImpl.java

示例12: updateMovie

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
public void updateMovie() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaUpdate<Movie> updateCriteria = builder.createCriteriaUpdate(Movie.class);
    Root<Movie> updateRoot = updateCriteria.from(Movie.class);
    updateCriteria.where(builder.equal(updateRoot.get(Movie_.name), "Inception"));
    updateCriteria.set(updateRoot.get(Movie_.name), "INCEPTION");
    Query q = em.createQuery(updateCriteria);
    q.executeUpdate();
    em.flush();
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:11,代码来源:MovieBean.java

示例13: buildUpdate

import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
protected Query buildUpdate(
		Object id,
		T stateful,
		State<T> current,
		State<T> next,
		Field idField,
		Field stateField) throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException {

	CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();

	// update <class>
	//
	CriteriaUpdate<T> cu = cb.createCriteriaUpdate(this.getClazz());
	Root<T> t = cu.from(this.getClazz());

	Path<?> idPath = t.get(this.getIdField().getName());
	Path<String> statePath = t.get(this.getStateField().getName());

	// set state=<next_state>
	//
	cu.set(statePath, next.getName());

	// where id=<id> and state=<current_state>
	//
	Predicate statePredicate = (current.equals(getStartState())) ?
			cb.or(
				cb.equal(
					statePath,
					current.getName()
				),
				cb.equal(
					statePath,
					cb.nullLiteral(String.class)
				)
			) :
			cb.equal(
				statePath,
				current.getName()
			);

	cu.where(
		cb.and(
			cb.equal(
				idPath,
				this.getId(stateful)
			),
			statePredicate
		)
	);

	Query query = entityManager.createQuery(cu);
	if (logger.isDebugEnabled()) {
		logger.debug(query.unwrap(org.hibernate.Query.class).getQueryString());
	}
	return query;
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:57,代码来源:JPAPerister.java


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