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

How to use
CriteriaUpdate
in
javax.persistence.criteria

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

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: 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: 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

Root<T> t = cu.from(this.getClazz());
cu.set(statePath, next.getName());
    );
cu.where(
  cb.and(
    cb.equal(
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.criteriaCriteriaUpdate

Javadoc

The CriteriaUpdate interface defines functionality for performing bulk update operations using the Criteria API.

Criteria API bulk update operations map directly to database update operations, bypassing any optimistic locking checks. Portable applications using bulk update operations must manually update the value of the version column, if desired, and/or manually validate the value of the version column. The persistence context is not synchronized with the result of the bulk update.

A CriteriaUpdate object must have a single root.

Most used methods

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

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • getExternalFilesDir (Context)
  • setScale (BigDecimal)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JComboBox (javax.swing)
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • CodeWhisperer alternatives
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