类javax.persistence.PreUpdate源码实例Demo

下面列出了怎么用javax.persistence.PreUpdate的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: cloud-espm-v2   文件: Stock.java
@PrePersist
@PreUpdate
private void persist() {
	EntityManagerFactory emf = Utility.getEntityManagerFactory();
	EntityManager em = emf.createEntityManager();
	try {
		em.getTransaction().begin();
		if (this.quantity.compareTo(this.minStock) < 0) {
			this.quantityLessMin = true;
		} else {
			this.quantityLessMin = false;
		}

		em.getTransaction().commit();
	} finally {
		em.close();
	}
}
 
源代码2 项目: javaee8-jsf-sample   文件: AuditEntityListener.java
@PreUpdate
public void beforeUpdate(Object entity) {
    if (entity instanceof AbstractAuditableEntity) {
        AbstractAuditableEntity o = (AbstractAuditableEntity) entity;
        o.setLastModifiedDate(LocalDateTime.now());

        if (o.getLastModifiedBy()== null) {
            o.setLastModifiedBy(currentUser());
        }
    }
}
 
源代码3 项目: griffin   文件: AbstractJob.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (configMap != null) {
        this.predicateConfig = JsonUtil.toJson(configMap);
    }
}
 
源代码4 项目: griffin   文件: SegmentPredicate.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (configMap != null) {
        this.config = JsonUtil.toJson(configMap);
    }
}
 
源代码5 项目: griffin   文件: DataSource.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (checkpointMap != null) {
        this.checkpoint = JsonUtil.toJson(checkpointMap);
    }
}
 
源代码6 项目: griffin   文件: Measure.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (sinksList != null) {
        this.sinks = JsonUtil.toJson(sinksList);
    }
}
 
源代码7 项目: griffin   文件: StreamingPreProcess.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (detailsMap != null) {
        this.details = JsonUtil.toJson(detailsMap);
    }
}
 
源代码8 项目: griffin   文件: Rule.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (detailsMap != null) {
        this.details = JsonUtil.toJson(detailsMap);
    }
    if (outList != null) {
        this.out = JsonUtil.toJson(outList);
    }
}
 
源代码9 项目: rice   文件: EntityExternalIdentifierBo.java
@Override
@PreUpdate
protected void preUpdate() {
    super.preUpdate();
    if (!this.decryptionNeeded) {
        encryptExternalId();
    }
}
 
源代码10 项目: griffin   文件: GriffinMeasure.java
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    super.save();
    if (ruleDescriptionMap != null) {
        this.ruleDescription = JsonUtil.toJson(ruleDescriptionMap);
    }
}
 
@PreUpdate
void onPreUpdate(Object o) {
	String txId = (String)ThreadLocalContext.get(CompositeTransactionParticipantService.CURRENT_TRANSACTION_KEY);
	if (null == txId){
		LOG.info("onPreUpdate outside any transaction");
	} else {
		LOG.info("onPreUpdate inside transaction [{}]", txId);
		enlist(o, EntityCommand.Action.UPDATE, txId);
	}
}
 
源代码12 项目: javaee8-jaxrs-sample   文件: AuditEntityListener.java
@PreUpdate
public void beforeUpdate(Object entity) {
    if (entity instanceof AbstractAuditableEntity) {
        AbstractAuditableEntity o = (AbstractAuditableEntity) entity;
        o.setLastModifiedDate(LocalDateTime.now());

        if (o.getLastModifiedBy() == null) {
            o.setLastModifiedBy(currentUser());
        }
    }
}
 
源代码13 项目: lemonaid   文件: Mentor.java
@PreUpdate
private void update() {
	String userName = null;
	try {
		userName = (String) ODataAuthorization.getThreadLocalData().get().get("UserName");
	} catch (RuntimeException e) {};
	if (userName != null) {
		this.updatedAt = Calendar.getInstance();
		this.updatedBy = userName;
	}
}
 
源代码14 项目: ee8-sandbox   文件: Post.java
@PreUpdate
public void beforeUpdate() {
    setUpdatedAt(LocalDateTime.now());
    if (PUBLISHED == this.status) {
        setPublishedAt(LocalDateTime.now());
    }
}
 
源代码15 项目: ee8-sandbox   文件: Post.java
@PreUpdate
public void beforeUpdate() {
    setUpdatedAt(LocalDateTime.now());
    if (PUBLISHED == this.status) {
        setPublishedAt(LocalDateTime.now());
    }
}
 
源代码16 项目: ee8-sandbox   文件: Post.java
@PreUpdate
public void beforeUpdate() {
    setUpdatedAt(LocalDateTime.now());
    if (PUBLISHED == this.status) {
        setPublishedAt(LocalDateTime.now());
    }
}
 
源代码17 项目: celerio-angular-quickstart   文件: User.java
@PreUpdate
protected void preUpdate() {
    if (AuditContextHolder.audit()) {
        setLastModificationAuthor(AuditContextHolder.username());
        setLastModificationDate(Instant.now());
    }
}
 
源代码18 项目: java-platform   文件: Product.java
/**
 * 更新前处理
 */
@PreUpdate
public void preUpdate() {
	if (getStock() == null) {
		setAllocatedStock(0);
	}
	if (getTotalScore() != null && getScoreCount() != null && getScoreCount() != 0) {
		setScore((float) getTotalScore() / getScoreCount());
	} else {
		setScore(0F);
	}
}
 
源代码19 项目: java-platform   文件: Order.java
/**
 * 更新前处理
 */
@PreUpdate
public void preUpdate() {
	if (getArea() != null) {
		setAreaName(getArea().getFullName());
	}
	if (getPaymentMethod() != null) {
		setPaymentMethodName(getPaymentMethod().getName());
	}
	if (getShippingMethod() != null) {
		setShippingMethodName(getShippingMethod().getName());
	}
}
 
源代码20 项目: java-platform   文件: TreeEntityListener.java
/**
 * 
 * @param entity
 */
@PreUpdate
public <U, I extends Serializable, T> void preUpdate(TreeEntity<U, I, T> entity) {
	@SuppressWarnings("unchecked")
	TreeEntity<U, I, T> parent = (TreeEntity<U, I, T>) entity.getParent();
	if (parent != null) {
		entity.setTreePath(parent.getTreePath() + parent.getId() + TREE_PATH_SEPARATOR);
	} else {
		entity.setTreePath(TREE_PATH_SEPARATOR);
	}
}
 
源代码21 项目: rice   文件: EntityDefaultInfoCacheBo.java
@PreUpdate
protected void preUpdate() {
    if (StringUtils.isEmpty(getObjectId())) {
        setObjectId(UUID.randomUUID().toString());
    }

    lastUpdateTimestamp = new Timestamp(System.currentTimeMillis());
}
 
/**
 * A listener method which is invoked on instances of TransactionalEntity
 * (or their subclasses) prior to being updated. Sets the
 * <code>updated</code> audit values for the entity. Attempts to obtain this
 * thread's instance of username from the RequestContext. If none exists,
 * throws an IllegalArgumentException. The username is used to set the
 * <code>updatedBy</code> value. The <code>updatedAt</code> value is set to
 * the current timestamp.
 */
@PreUpdate
public void beforeUpdate() {
    String username = RequestContext.getUsername();
    if (username == null) {
        throw new IllegalArgumentException(
                "Cannot update a TransactionalEntity without a username "
                        + "in the RequestContext for this thread.");
    }
    setUpdatedBy(username);

    setUpdatedAt(new DateTime());
}
 
/**
 * A listener method which is invoked on instances of TransactionalEntity (or their subclasses) prior to being
 * updated. Sets the <code>updated</code> audit values for the entity. Attempts to obtain this thread's instance of
 * username from the RequestContext. If none exists, throws an IllegalArgumentException. The username is used to set
 * the <code>updatedBy</code> value. The <code>updatedAt</code> value is set to the current timestamp.
 */
@PreUpdate
public void beforeUpdate() {
    final String username = RequestContext.getUsername();
    if (username == null) {
        throw new IllegalArgumentException("Cannot update a TransactionalEntity without a username "
                + "in the RequestContext for this thread.");
    }
    setUpdatedBy(username);

    setUpdatedAt(Instant.now());
}
 
源代码24 项目: che   文件: AbstractPermissions.java
@PreUpdate
@PrePersist
private void prePersist() {
  if ("*".equals(userIdHolder)) {
    userId = null;
  } else {
    userId = userIdHolder;
  }
}
 
源代码25 项目: che   文件: SourceStorageImpl.java
@PrePersist
@PreUpdate
public void validate() {
  if (parameters != null) {
    for (Map.Entry<String, String> e : parameters.entrySet()) {
      if (e.getValue() == null) {
        throw new IllegalStateException(
            format(
                "Parameter '%s' of the source %s is null. This is illegal.", e.getKey(), this));
      }
    }
  }
}
 
@PrePersist
@PreUpdate
private void setCurrentTimestamp(Object entity) {
    if(entity instanceof Updatable) {
        Updatable updatable = (Updatable) entity;
        updatable.setTimestamp(new Date());
    }
}
 
源代码27 项目: cloud-weatherapp   文件: BaseObject.java
/**
 * Life-cycle event callback, which automatically sets the last modification date.  
 */
@PreUpdate
protected void updateAuditInformation() 
{
    lastModifiedAt = new Date();
    
    // TODO - obtain currently logged-on user
}
 
源代码28 项目: syncope   文件: EntityValidationListener.java
@PrePersist
@PreUpdate
public void validate(final Object object) {
    final Validator validator = ApplicationContextProvider.getBeanFactory().getBean(Validator.class);
    Set<ConstraintViolation<Object>> violations = validator.validate(object);
    if (!violations.isEmpty()) {
        LOG.warn("Bean validation errors found: {}", violations);

        Class<?> entityInt = null;
        for (Class<?> interf : ClassUtils.getAllInterfaces(object.getClass())) {
            if (!Entity.class.equals(interf)
                    && !ProvidedKeyEntity.class.equals(interf)
                    && !Schema.class.equals(interf)
                    && !Task.class.equals(interf)
                    && !Policy.class.equals(interf)
                    && !GroupableRelatable.class.equals(interf)
                    && !Any.class.equals(interf)
                    && !DynMembership.class.equals(interf)
                    && Entity.class.isAssignableFrom(interf)) {

                entityInt = interf;
            }
        }

        throw new InvalidEntityException(entityInt == null
                ? "Entity" : entityInt.getSimpleName(), violations);
    }
}
 
源代码29 项目: spring-data-examples   文件: User.java
/**
 * Makes sure only {@link User}s with encrypted {@link Password} can be persisted.
 */
@PrePersist
@PreUpdate
void assertEncrypted() {

	if (!password.isEncrypted()) {
		throw new IllegalStateException("Tried to persist/load a user with a non-encrypted password!");
	}
}
 
源代码30 项目: init-spring   文件: User.java
@PrePersist
@PreUpdate
public void preUpdate() {
    if (this.passwordHash != null && !this.passwordHash.equals(this.storedPassword))
        this.expirationDate = DateUtils.addDays(new Date(), 90);
}
 
 类所在包
 同包方法