本文整理汇总了Java中javax.persistence.criteria.CriteriaUpdate.from方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaUpdate.from方法的具体用法?Java CriteriaUpdate.from怎么用?Java CriteriaUpdate.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.CriteriaUpdate
的用法示例。
在下文中一共展示了CriteriaUpdate.from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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包/类
public void update() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<Post> q = cb.createCriteriaUpdate(Post.class);
Root<Post> root = q.from(Post.class);
q.set(root.get("approved"), true)
.where(root.get("id").in(getCheckedList()));
int result = em.createQuery(q).executeUpdate();
log.info("update @" + result);
load();
}
示例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: updateByCriteria
import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T extends BaseEntity> int updateByCriteria(UpdateCriteria<T> criteria) {
EntityManager em = null;
EntityTransaction txn = null;
try {
em = this.emf.createEntityManager();
txn = JpaUtil.getTransaction(em);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<T> cu = cb.createCriteriaUpdate(criteria.getEntity());
criteria.getUpdateAttributes().forEach(cu::set);
Root<T> root = cu.from(criteria.getEntity());
int rowsUpdated = em
.createQuery(cu.where(cb.and(JpaUtil.getPredicates(criteria.getCriteriaAttributes(), cb, root))))
.executeUpdate();
txn.commit();
LOGGER.debug("No. of rows updated: {}", rowsUpdated);
return rowsUpdated;
} catch (RuntimeException ex) {
JpaUtil.setRollbackOnly(txn);
LOGGER.error(ex.getMessage(), ex);
throw new PersistenceException(ex.getMessage(), ex);
} finally {
JpaUtil.rollbackTransaction(txn);
JpaUtil.closeEntityManager(em);
}
}
示例9: 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();
}
示例10: 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);
}
示例11: 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;
}
示例12: updateParentField
import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void updateParentField(Optional<N> newParent, 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.get(parent(nodeClass)), newParent.isPresent() ? newParent.get() : null)
.where(getPredicates(cb, root, cb.equal(root.get(id(nodeClass)), node.getId())));
em.createQuery(update).executeUpdate();
}
示例13: 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();
}
示例14: updateFieldsBeforeSingleNodeRemoval
import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void updateFieldsBeforeSingleNodeRemoval(Long from, Class<N> nodeClass, String field) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<N> update = cb.createCriteriaUpdate(nodeClass);
Root<N> root = update.from(nodeClass);
update.set(root.<Long>get(field), cb.diff(root.<Long>get(field), 2L))
.where(getPredicates(cb, root, cb.greaterThan(root.<Long>get(field), from)));
em.createQuery(update).executeUpdate();
}
示例15: updateNodesParent
import javax.persistence.criteria.CriteriaUpdate; //导入方法依赖的package包/类
private void updateNodesParent(NestedNodeInfo<N> node, Optional<N> parent, Class<N> nodeClass) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<N> update = cb.createCriteriaUpdate(nodeClass);
Root<N> root = update.from(nodeClass);
N newParent = parent.isPresent() ? parent.get() : null;
update.set(root.get(parent(nodeClass)), newParent)
.where(getPredicates(cb, root,
cb.greaterThanOrEqualTo(root.<Long>get(left(nodeClass)), node.getLeft()),
cb.lessThanOrEqualTo(root.<Long>get(right(nodeClass)), node.getRight()),
cb.equal(root.<Long>get(level(nodeClass)), node.getLevel() + 1)
));
em.createQuery(update).executeUpdate();
}