javax.persistence.PreUpdate Java Examples

The following examples show how to use javax.persistence.PreUpdate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Stock.java    From cloud-espm-v2 with Apache License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example #2
Source File: Post.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
@PreUpdate
public void beforeUpdate() {
    setUpdatedAt(LocalDateTime.now());
    if (PUBLISHED == this.status) {
        setPublishedAt(LocalDateTime.now());
    }
}
 
Example #3
Source File: AuditEntityListener.java    From javaee8-jsf-sample with GNU General Public License v3.0 5 votes vote down vote up
@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());
        }
    }
}
 
Example #4
Source File: AbstractJob.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (configMap != null) {
        this.predicateConfig = JsonUtil.toJson(configMap);
    }
}
 
Example #5
Source File: SegmentPredicate.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (configMap != null) {
        this.config = JsonUtil.toJson(configMap);
    }
}
 
Example #6
Source File: StreamingPreProcess.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (detailsMap != null) {
        this.details = JsonUtil.toJson(detailsMap);
    }
}
 
Example #7
Source File: DataSource.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (checkpointMap != null) {
        this.checkpoint = JsonUtil.toJson(checkpointMap);
    }
}
 
Example #8
Source File: SourceStorageImpl.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@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));
      }
    }
  }
}
 
Example #9
Source File: UpdatableListener.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
private void setCurrentTimestamp(Object entity) {
    if(entity instanceof Updatable) {
        Updatable updatable = (Updatable) entity;
        updatable.setTimestamp(new Date());
    }
}
 
Example #10
Source File: BaseObject.java    From cloud-weatherapp with Apache License 2.0 5 votes vote down vote up
/**
 * Life-cycle event callback, which automatically sets the last modification date.  
 */
@PreUpdate
protected void updateAuditInformation() 
{
    lastModifiedAt = new Date();
    
    // TODO - obtain currently logged-on user
}
 
Example #11
Source File: TreeEntityListener.java    From java-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @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);
	}
}
 
Example #12
Source File: EntityValidationListener.java    From syncope with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #13
Source File: User.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
/**
 * 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!");
	}
}
 
Example #14
Source File: EntityDefaultInfoCacheBo.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@PreUpdate
protected void preUpdate() {
    if (StringUtils.isEmpty(getObjectId())) {
        setObjectId(UUID.randomUUID().toString());
    }

    lastUpdateTimestamp = new Timestamp(System.currentTimeMillis());
}
 
Example #15
Source File: Measure.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (sinksList != null) {
        this.sinks = JsonUtil.toJson(sinksList);
    }
}
 
Example #16
Source File: Rule.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    if (detailsMap != null) {
        this.details = JsonUtil.toJson(detailsMap);
    }
    if (outList != null) {
        this.out = JsonUtil.toJson(outList);
    }
}
 
Example #17
Source File: GriffinMeasure.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PrePersist
@PreUpdate
public void save() throws JsonProcessingException {
    super.save();
    if (ruleDescriptionMap != null) {
        this.ruleDescription = JsonUtil.toJson(ruleDescriptionMap);
    }
}
 
Example #18
Source File: AbstractPermissions.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@PreUpdate
@PrePersist
private void prePersist() {
  if ("*".equals(userIdHolder)) {
    userId = null;
  } else {
    userId = userIdHolder;
  }
}
 
Example #19
Source File: Order.java    From java-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 更新前处理
 */
@PreUpdate
public void preUpdate() {
	if (getArea() != null) {
		setAreaName(getArea().getFullName());
	}
	if (getPaymentMethod() != null) {
		setPaymentMethodName(getPaymentMethod().getName());
	}
	if (getShippingMethod() != null) {
		setShippingMethodName(getShippingMethod().getName());
	}
}
 
Example #20
Source File: Product.java    From java-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 更新前处理
 */
@PreUpdate
public void preUpdate() {
	if (getStock() == null) {
		setAllocatedStock(0);
	}
	if (getTotalScore() != null && getScoreCount() != null && getScoreCount() != 0) {
		setScore((float) getTotalScore() / getScoreCount());
	} else {
		setScore(0F);
	}
}
 
Example #21
Source File: TransactionalEntity.java    From skeleton-ws-spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #22
Source File: User.java    From celerio-angular-quickstart with Apache License 2.0 5 votes vote down vote up
@PreUpdate
protected void preUpdate() {
    if (AuditContextHolder.audit()) {
        setLastModificationAuthor(AuditContextHolder.username());
        setLastModificationDate(Instant.now());
    }
}
 
Example #23
Source File: ChangeStateJpaListener.java    From microservices-transactions-tcc with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #24
Source File: AuditEntityListener.java    From javaee8-jaxrs-sample with GNU General Public License v3.0 5 votes vote down vote up
@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());
        }
    }
}
 
Example #25
Source File: Post.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
@PreUpdate
public void beforeUpdate() {
    setUpdatedAt(LocalDateTime.now());
    if (PUBLISHED == this.status) {
        setPublishedAt(LocalDateTime.now());
    }
}
 
Example #26
Source File: TransactionalEntity.java    From spring-data-fundamentals with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #27
Source File: Mentor.java    From lemonaid with MIT License 5 votes vote down vote up
@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;
	}
}
 
Example #28
Source File: Post.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
@PreUpdate
public void beforeUpdate() {
    setUpdatedAt(LocalDateTime.now());
    if (PUBLISHED == this.status) {
        setPublishedAt(LocalDateTime.now());
    }
}
 
Example #29
Source File: EntityExternalIdentifierBo.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
@PreUpdate
protected void preUpdate() {
    super.preUpdate();
    if (!this.decryptionNeeded) {
        encryptExternalId();
    }
}
 
Example #30
Source File: PdfConversion.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
@PreUpdate
private void onUpdate() {
	this.setUpdatedDate(new DateTime());
}