本文整理汇总了Java中javax.persistence.criteria.CriteriaUpdate.where方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaUpdate.where方法的具体用法?Java CriteriaUpdate.where怎么用?Java CriteriaUpdate.where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.CriteriaUpdate
的用法示例。
在下文中一共展示了CriteriaUpdate.where方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
示例8: 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);
}
示例9: updateDeletedNodeChildren
import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void updateDeletedNodeChildren(NestedNodeInfo<N> node, Class<N> nodeClass) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<N> update = cb.createCriteriaUpdate(nodeClass);
Root<N> root = update.from(nodeClass);
update.set(root.<Long>get(right(nodeClass)), cb.diff(root.<Long>get(right(nodeClass)), 1L))
.set(root.<Long>get(left(nodeClass)), cb.diff(root.<Long>get(left(nodeClass)), 1L))
.set(root.<Long>get(level(nodeClass)), cb.diff(root.<Long>get(level(nodeClass)), 1L));
update.where(getPredicates(cb, root,
cb.lessThan(root.<Long>get(right(nodeClass)), node.getRight()),
cb.greaterThan(root.<Long>get(left(nodeClass)), node.getLeft()))
);
em.createQuery(update).executeUpdate();
}
示例10: 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();
}
示例11: 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();
}
示例12: 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;
}