Tabnine Logo
CriteriaUpdate.set
Code IndexAdd Tabnine to your IDE (free)

How to use
set
method
in
javax.persistence.criteria.CriteriaUpdate

Best Java code snippets using javax.persistence.criteria.CriteriaUpdate.set (Showing top 7 results out of 315)

origin: JoleneOL/market-manage

@Override
public void updateOrderTime(LocalDateTime time) {
  CriteriaUpdate<MainOrder> criteriaUpdate = entityManager.getCriteriaBuilder().createCriteriaUpdate(MainOrder.class);
  Root<MainOrder> root = criteriaUpdate.from(MainOrder.class);
  criteriaUpdate = criteriaUpdate.set(root.get("orderTime"), time);
  entityManager.createQuery(criteriaUpdate).executeUpdate();
}
origin: io.github.toquery/clever-framework-dao

/**
 * 使用动态更新的方法更新数据库简单映射字段的内容
 *
 * @param entity           要修改的对象
 * @param updateFieldsName 将要修改对象的字段
 */
public E updateSimpleField(E entity, Collection<String> updateFieldsName) {
  Assert.notEmpty(updateFieldsName, entity.getClass() + "更新字段不能为空。");
  Assert.isTrue(!entityInformation.hasCompositeId(), "不支持组合ID更新。");
  CriteriaUpdate<E> criteriaUpdate = new CriteriaUpdateImpl<E>((CriteriaBuilderImpl) entityManager.getCriteriaBuilder());
  //更新的实体对象
  Root<E> root = criteriaUpdate.from(getDomainClass());
  for (String fieldName : updateFieldsName) {
    try {
      //通过反射读取属性的值
      criteriaUpdate.set(fieldName, PropertyUtils.getProperty(entity, fieldName));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  //构造更新过滤条件
  String idField = entityInformation.getIdAttributeNames().iterator().next();
  Predicate predicate = entityManager.getCriteriaBuilder().equal(root.get(idField), entityInformation.getId(entity));
  criteriaUpdate.where(predicate);
  //执行更新
  entityManager.createQuery(criteriaUpdate).executeUpdate();
  return entity;
}
origin: dzinot/spring-boot-jpa-data-rest-soft-delete

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();
}
origin: vladmihalcea/high-performance-java-persistence

public <T extends PostModerate> int flagSpam(EntityManager entityManager, Class<T> postModerateClass) {
  CriteriaBuilder builder = entityManager.getCriteriaBuilder();
  CriteriaUpdate<T> update = builder.createCriteriaUpdate(postModerateClass);
  Root<T> root = update.from(postModerateClass);
  Expression<Boolean> filterPredicate =
    builder.like(builder.lower(root.get("message")), "%spam%");
  if(Post.class.isAssignableFrom(postModerateClass)) {
    filterPredicate = builder.or(
      filterPredicate,
      builder.like(builder.lower(root.get("title")), "%spam%")
    );
  }
  update
  .set(root.get("status"), PostStatus.SPAM)
  .set(root.get("updatedOn"), new Date())
  .where(filterPredicate);
  return entityManager.createQuery(update).executeUpdate();
}
origin: statefulj/statefulj

cu.set(statePath, next.getName());
origin: vladmihalcea/high-performance-java-persistence

@Test
public void testCriteriaAPI() {
  doInJPA(entityManager -> {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaUpdate<Event> update = builder.createCriteriaUpdate(Event.class);
    Root<Event> root = update.from(Event.class);
    update
    .set(root.get("eventValue"), "100")
    .where(
      builder.equal(root.get("id"), 1L)
    );
    entityManager.createQuery(update).executeUpdate();
  });
  doInJPA(entityManager -> {
    Event event = entityManager.find(Event.class, 1L);
    assertEquals("100", event.getEventValue());
  });
}
origin: vladmihalcea/high-performance-java-persistence

@Test
public void testCriteriaAPI() {
  try {
    doInJPA(entityManager -> {
      CriteriaBuilder builder = entityManager.getCriteriaBuilder();
      CriteriaUpdate<Event> update = builder.createCriteriaUpdate(Event.class);
      Root<Event> root = update.from(Event.class);
      update
      .set(root.get("eventValue"), "100")
      .where(
        builder.equal(root.get("id"), 1L)
      );
      entityManager.createQuery(update).executeUpdate();
    });
    fail("Should have thrown exception");
  } catch (Exception e) {
    HibernateException cause = (HibernateException) e.getCause();
    assertEquals(
      "The query: [" +
      "update Event as generatedAlias0 " +
      "set generatedAlias0.eventValue = :param0 " +
      "where generatedAlias0.id=1L" +
      "] attempts to update an immutable entity: [Event]",
      cause.getMessage()
    );
  }
}
javax.persistence.criteriaCriteriaUpdateset

Javadoc

Update the value of the specified attribute.

Popular methods of CriteriaUpdate

  • from
    Create and add a query root corresponding to the entity that is the target of the update. A Criteria
  • where
    Modify the update query to restrict the target of the update according to the conjunction of the spe

Popular in Java

  • Parsing JSON documents to java classes using gson
  • startActivity (Activity)
  • compareTo (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JButton (javax.swing)
  • JComboBox (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now