Java 类javax.persistence.PrePersist 实例源码

项目:os    文件:CheckingEntityListener.java   
@PrePersist
@PreUpdate
public void encode(Object target) {
    AnnotationCheckingMetadata metadata = AnnotationCheckingMetadata.getMetadata(target.getClass());
    if (metadata.isCheckable()) {
        StringBuilder sb = new StringBuilder();
        for (Field field : metadata.getCheckedFields()) {
            ReflectionUtils.makeAccessible(field);
            Object value = ReflectionUtils.getField(field, target);
            if (value instanceof Date) {
                throw new RuntimeException("不支持时间类型字段加密!");
            }
            sb.append(value).append(" - ");
        }
        sb.append(MD5_KEY);
        LOGGER.debug("加密数据:" + sb);
        String hex = MD5Utils.encode(sb.toString());
        Field checksumField = metadata.getCheckableField();
        ReflectionUtils.makeAccessible(checksumField);
        ReflectionUtils.setField(checksumField, target, hex);
    }
}
项目:ha-db    文件:CheckingEntityListener.java   
@PrePersist
@PreUpdate
public void encode(Object target) {
    AnnotationCheckingMetadata metadata = AnnotationCheckingMetadata.getMetadata(target.getClass());
    if (metadata.isCheckable()) {
        StringBuilder sb = new StringBuilder();
        for (Field field : metadata.getCheckedFields()) {
            ReflectionUtils.makeAccessible(field);
            Object value = ReflectionUtils.getField(field, target);
            if (value instanceof Date) {
                throw new RuntimeException("不支持时间类型字段加密!");
            }
            sb.append(value).append(" - ");
        }
        sb.append(MD5_KEY);
        LOGGER.debug("加密数据:" + sb);
        String hex = MD5Utils.encode(sb.toString());
        Field checksumField = metadata.getCheckableField();
        ReflectionUtils.makeAccessible(checksumField);
        ReflectionUtils.setField(checksumField, target, hex);
    }
}
项目:myWMS    文件:ItemData.java   
/**
 * Checks, if constraints are kept during the previous operations.
 * 
 * @throws ConstraintViolatedException
 */
@PreUpdate
@PrePersist
public void sanityCheck() throws FacadeException {

    if( number != null ) {
        number = number.trim();
    }

       if( number != null && number.startsWith("* ") ) {
        number = number.substring(2);
       }

    if( number == null || number.length() == 0 ) {
        throw new BusinessException("number must be set");
    }

    if( getAdditionalContent() != null && getAdditionalContent().length() > 255)  {
        setAdditionalContent(getAdditionalContent().substring(0,255));
    }
}
项目:myWMS    文件:ItemDataNumber.java   
/**
 * Checks, if some constraints are kept during the previous operations.
 * 
 * @throws FacadeException
 */
@PreUpdate
@PrePersist
public void sanityCheck() throws FacadeException {

    if( number != null ) {
        number = number.trim();
    }
    if( number != null && number.length()==0 ) {
        number = null;
    }

    if( itemData != null && !itemData.getClient().equals(getClient())) {
        setClient(itemData.getClient());
    }

}
项目:javaee8-jsf-sample    文件:AuditEntityListener.java   
@PrePersist
public void beforePersist(Object entity) {
    if (entity instanceof AbstractAuditableEntity) {
        AbstractAuditableEntity o = (AbstractAuditableEntity) entity;
        final LocalDateTime now = LocalDateTime.now();
        o.setCreatedDate(now);
        o.setLastModifiedDate(now);

        if (o.getCreatedBy() == null) {
            o.setCreatedBy(currentUser());
        }
    }
}
项目:javaee8-jsf-sample    文件:LoginToken.java   
@PrePersist
public void beforeSave() {
    createdDate = LocalDateTime.now();

    if (expiredDate == null) {
        expiredDate = LocalDateTime.now().plusMonths(1L);
    }
}
项目: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!");
    }
}
项目:yum    文件:OrderItem.java   
@PrePersist
private void prePersiste() {
   if (getId() == null) {
       OrderItemId pk = new OrderItemId();
       pk.setDailyOrderId(dailyOrder.getDailyOrderId());
       pk.setFoodId(food.getId());
       setId(pk);
   }
}
项目:oscm    文件:PlatformUser.java   
/**
 * Fill creation date (if not already set)
 */
@PrePersist
public void fillCreationDate() {
    if (getCreationDate() == null) {
        setCreationDate(GregorianCalendar.getInstance().getTime());
    }
}
项目:oscm    文件:OperationRecord.java   
/**
 * Fill creation date (if not already set)
 */
@PrePersist
public void fillCreationDate() {
    if (getExecutiondate() == null) {
        setExecutiondate(GregorianCalendar.getInstance().getTime());
    }
}
项目:spanner-jpa-example    文件:BaseEntity.java   
@PrePersist
protected void onCreate()
{
    created = new Date();
    updated = new Date();
    if (uuid == null)
        uuid = GENERATOR.generate();
    if (id == null)
        id = uuid.getMostSignificantBits() ^ uuid.getLeastSignificantBits();
}
项目:xm-ms-entity    文件:AvatarUrlListener.java   
@PrePersist
@PreUpdate
public void prePersist(XmEntity obj) {
    String avatarUrl = obj.getAvatarUrl();
    if (StringUtils.isNoneBlank(avatarUrl)) {
        if (avatarUrl.matches(PATTERN_FULL)) {
            obj.setAvatarUrl(FilenameUtils.getName(avatarUrl));
        } else {
            obj.setAvatarUrl(null);
        }
    }
}
项目:lams    文件:EntityClass.java   
private void processDefaultJpaCallbacks(String instanceCallbackClassName, List<JpaCallbackClass> jpaCallbackClassList) {
    ClassInfo callbackClassInfo = getLocalBindingContext().getClassInfo( instanceCallbackClassName );

    // Process superclass first if available and not excluded
    if ( JandexHelper.getSingleAnnotation( callbackClassInfo, JPADotNames.EXCLUDE_SUPERCLASS_LISTENERS ) != null ) {
        DotName superName = callbackClassInfo.superName();
        if ( superName != null ) {
            processDefaultJpaCallbacks( instanceCallbackClassName, jpaCallbackClassList );
        }
    }

    String callbackClassName = callbackClassInfo.name().toString();
    Map<Class<?>, String> callbacksByType = new HashMap<Class<?>, String>();
    createDefaultCallback(
            PrePersist.class, PseudoJpaDotNames.DEFAULT_PRE_PERSIST, callbackClassName, callbacksByType
    );
    createDefaultCallback(
            PreRemove.class, PseudoJpaDotNames.DEFAULT_PRE_REMOVE, callbackClassName, callbacksByType
    );
    createDefaultCallback(
            PreUpdate.class, PseudoJpaDotNames.DEFAULT_PRE_UPDATE, callbackClassName, callbacksByType
    );
    createDefaultCallback(
            PostLoad.class, PseudoJpaDotNames.DEFAULT_POST_LOAD, callbackClassName, callbacksByType
    );
    createDefaultCallback(
            PostPersist.class, PseudoJpaDotNames.DEFAULT_POST_PERSIST, callbackClassName, callbacksByType
    );
    createDefaultCallback(
            PostRemove.class, PseudoJpaDotNames.DEFAULT_POST_REMOVE, callbackClassName, callbacksByType
    );
    createDefaultCallback(
            PostUpdate.class, PseudoJpaDotNames.DEFAULT_POST_UPDATE, callbackClassName, callbacksByType
    );
    if ( !callbacksByType.isEmpty() ) {
        jpaCallbackClassList.add( new JpaCallbackClassImpl( instanceCallbackClassName, callbacksByType, true ) );
    }
}
项目:lams    文件:EntityClass.java   
private void processJpaCallbacks(String instanceCallbackClassName, boolean isListener, List<JpaCallbackClass> callbackClassList) {

        ClassInfo callbackClassInfo = getLocalBindingContext().getClassInfo( instanceCallbackClassName );

        // Process superclass first if available and not excluded
        if ( JandexHelper.getSingleAnnotation( callbackClassInfo, JPADotNames.EXCLUDE_SUPERCLASS_LISTENERS ) != null ) {
            DotName superName = callbackClassInfo.superName();
            if ( superName != null ) {
                processJpaCallbacks(
                        instanceCallbackClassName,
                        isListener,
                        callbackClassList
                );
            }
        }

        Map<Class<?>, String> callbacksByType = new HashMap<Class<?>, String>();
        createCallback( PrePersist.class, JPADotNames.PRE_PERSIST, callbacksByType, callbackClassInfo, isListener );
        createCallback( PreRemove.class, JPADotNames.PRE_REMOVE, callbacksByType, callbackClassInfo, isListener );
        createCallback( PreUpdate.class, JPADotNames.PRE_UPDATE, callbacksByType, callbackClassInfo, isListener );
        createCallback( PostLoad.class, JPADotNames.POST_LOAD, callbacksByType, callbackClassInfo, isListener );
        createCallback( PostPersist.class, JPADotNames.POST_PERSIST, callbacksByType, callbackClassInfo, isListener );
        createCallback( PostRemove.class, JPADotNames.POST_REMOVE, callbacksByType, callbackClassInfo, isListener );
        createCallback( PostUpdate.class, JPADotNames.POST_UPDATE, callbacksByType, callbackClassInfo, isListener );
        if ( !callbacksByType.isEmpty() ) {
            callbackClassList.add( new JpaCallbackClassImpl( instanceCallbackClassName, callbacksByType, isListener ) );
        }
    }
项目:api.teiler.io    文件:PersonEntity.java   
/**
 * Sets the update-time and creation-time to {@link Instant#now()}.
 * <br>
 * <i>Note:</i> The creation-time will only be set if it has not been set previously.
 */
@PreUpdate
@PrePersist
public void updateTimeStamps() {
    updateTime = new Timestamp(Instant.now().toEpochMilli());
    if (createTime == null) {
        createTime = updateTime;
    }
}
项目:api.teiler.io    文件:TransactionEntity.java   
/**
 * Sets the update-time and creation-time to {@link Instant#now()}.
 * <br>
 * <i>Note:</i> The creation-time will only be set if it has not been set previously.
 */
@PreUpdate
@PrePersist
public void updateTimeStamps() {
    updateTime = new Timestamp(Instant.now().toEpochMilli());
    if (createTime == null) {
        createTime = updateTime;
    }
}
项目:api.teiler.io    文件:ProfiteerEntity.java   
/**
 * Sets the update-time and creation-time to {@link Instant#now()}.
 * <br>
 * <i>Note:</i> The creation-time will only be set if it has not been set previously.
 */
@PreUpdate
@PrePersist
public void updateTimeStamps() {
    updateTime = new Timestamp(Instant.now().toEpochMilli());
    if (createTime == null) {
        createTime = updateTime;
    }
}
项目:api.teiler.io    文件:GroupEntity.java   
/**
 * Sets the update-time and creation-time to {@link Instant#now()}.
 * <br>
 * <i>Note:</i> The creation-time will only be set if it has not been set previously.
 */
@PreUpdate
@PrePersist
public void updateTimeStamps() {
    updateTime = new Timestamp(Instant.now().toEpochMilli());
    if (createTime == null) {
        createTime = updateTime;
    }
}
项目:springuni-particles    文件:IdentityGeneratorListener.java   
/**
 * Generates a new identity for the given {@link Entity}.
 * @param entity Entity
 */
@PrePersist
public void generate(Entity<Long, ?> entity) {
  if (!entity.isNew()) {
    return;
  }
  long id = IdentityGenerator.generate();
  entity.setId(id);
  LOGGER.debug("Generated ID {} for {}.", id, entity.getClass());
}
项目:tianti    文件:BaseEntity.java   
@PrePersist
  public void prePersist() {
if(this.createDate == null){
    this.setCreateDate(new Date());
}
this.setUpdateDate(new Date());
if(StringUtils.isBlank(this.getDeleteFlag())){
    this.setDeleteFlag(BaseEntity.DELETE_FLAG_NORMAL);  
}
  }
项目:microservices-transactions-tcc    文件:ChangeStateJpaListener.java   
@PrePersist
void onPrePersist(Object o) {
    String txId = (String)ThreadLocalContext.get(CompositeTransactionParticipantService.CURRENT_TRANSACTION_KEY);
    if (null == txId){
        LOG.info("onPrePersist outside any transaction");
    } else {
        LOG.info("onPrePersist inside transaction [{}]", txId);
        enlist(o, EntityCommand.Action.INSERT, txId);
    }
}
项目:apollo-custom    文件:ConsumerAudit.java   
@PrePersist
protected void prePersist() {
  if (this.dataChangeCreatedTime == null) {
    this.dataChangeCreatedTime = new Date();
  }
  if (this.dataChangeLastModifiedTime == null) {
    dataChangeLastModifiedTime = this.dataChangeCreatedTime;
  }
}
项目:javaee8-jaxrs-sample    文件:AuditEntityListener.java   
@PrePersist
public void beforePersist(Object entity) {
    if (entity instanceof AbstractAuditableEntity) {
        AbstractAuditableEntity o = (AbstractAuditableEntity) entity;
        final LocalDateTime now = LocalDateTime.now();
        o.setCreatedDate(now);
        o.setLastModifiedDate(now);

        if (o.getCreatedBy() == null) {
            o.setCreatedBy(currentUser());
        }
    }
}
项目:metacat    文件:BaseEntity.java   
/**
 * Insert.
 */
@PrePersist
public void onInsert() {
    if (createdDate == null) {
        setCreatedDate(Instant.now().toDate());
    }
    if (lastUpdatedDate == null) {
        setLastUpdatedDate(Instant.now().toDate());
    }
}
项目:oma-riista-web    文件:LifecycleEntity.java   
@PrePersist
protected void prePersist() {
    final Date now = now().toDate();
    final Long activeUserId = getActiveUserId();

    getLifecycleFields().setCreationTime(now);
    getLifecycleFields().setModificationTime(now);

    if (activeUserId >= 0 || getAuditFields().getCreatedByUserId() == null) {
        getAuditFields().setCreatedByUserId(activeUserId);
        getAuditFields().setModifiedByUserId(activeUserId);
    }
}
项目:apollo    文件:Instance.java   
@PrePersist
protected void prePersist() {
  if (this.dataChangeCreatedTime == null) {
    dataChangeCreatedTime = new Date();
  }
  if (this.dataChangeLastModifiedTime == null) {
    dataChangeLastModifiedTime = dataChangeCreatedTime;
  }
}
项目:apollo    文件:ConsumerAudit.java   
@PrePersist
protected void prePersist() {
  if (this.dataChangeCreatedTime == null) {
    this.dataChangeCreatedTime = new Date();
  }
  if (this.dataChangeLastModifiedTime == null) {
    dataChangeLastModifiedTime = this.dataChangeCreatedTime;
  }
}
项目:uaa-service    文件:Authority.java   
@SuppressWarnings("squid:UnusedProtectedMethod")
@PrePersist
protected void prePersist() {
    if (this.id == null) {
        this.id = UUID.randomUUID().toString();
    }
}
项目:OSCAR-ConCert    文件:FacilityMessage.java   
@PrePersist
@PreUpdate
protected void jpa_prePersistAndUpdate() {
    if(getProgramId() != null && getProgramId().intValue() == 0) {
        setProgramId(null);
    }
}
项目:springJpaKata    文件:SampleListener.java   
@PreUpdate
@PostPersist
@PrePersist
public void setLastUpdate( Person p ) {
    if("addAction".equals(p.getFirstname())){
    p.setActive(true);}

    log.info("person after set active on true , before save action : {}",p);
}
项目:lemonaid    文件:Mentor.java   
@PrePersist
private void persist() {
    String userName = (String) ODataAuthorization.getThreadLocalData().get().get("UserName");
    this.createdAt = Calendar.getInstance();
    this.updatedAt = Calendar.getInstance();
    if (userName == null) {
        this.createdBy = "SYSTEM";
        this.updatedBy = "SYSTEM";
    } else {
        this.createdBy = userName;
        this.updatedBy = userName;
    }
}
项目:my-paper    文件:Order.java   
/**
 * 持久化前处理
 */
@PrePersist
public void prePersist() {
    if (getArea() != null) {
        setAreaName(getArea().getFullName());
    }
    if (getPaymentMethod() != null) {
        setPaymentMethodName(getPaymentMethod().getName());
    }
    if (getShippingMethod() != null) {
        setShippingMethodName(getShippingMethod().getName());
    }
}
项目:my-paper    文件:Area.java   
/**
 * 持久化前处理
 */
@PrePersist
public void prePersist() {
    Area parent = getParent();
    if (parent != null) {
        setFullName(parent.getFullName() + getName());
        setTreePath(parent.getTreePath() + parent.getId() + TREE_PATH_SEPARATOR);
    } else {
        setFullName(getName());
        setTreePath(TREE_PATH_SEPARATOR);
    }
}
项目:my-paper    文件:Product.java   
/**
 * 持久化前处理
 */
@PrePersist
public void prePersist() {
    if (getStock() == null) {
        setAllocatedStock(0);
    }
    setScore(0F);
}
项目:my-paper    文件:DeliveryCenter.java   
/**
 * 持久化前处理
 */
@PrePersist
public void prePersist() {
    if (getArea() != null) {
        setAreaName(getArea().getFullName());
    }
}
项目:pcm-api    文件:AbstractVersion.java   
@PrePersist
public void prePersist() {
    try {
        modificationTime = getCurrentDate();
        creationTime = getCurrentDate();
    } catch (ParseException e) {
        modificationTime = new Date();
        creationTime = new Date();
    }
}
项目:myWMS    文件:LOSPickingPosition.java   
@PrePersist
@PreUpdate
// For hibernate only. By annotation it is called before saving
private void setRedundantValues() {
    if( pickingOrder == null ) {
        pickingOrderNumber = null;
    }
    else {
        pickingOrderNumber = pickingOrder.getNumber();
    }
}
项目:java-platform    文件:Order.java   
/**
 * 持久化前处理
 */
@PrePersist
public void prePersist() {
    if (getArea() != null) {
        setAreaName(getArea().getFullName());
    }
    if (getPaymentMethod() != null) {
        setPaymentMethodName(getPaymentMethod().getName());
    }
    if (getShippingMethod() != null) {
        setShippingMethodName(getShippingMethod().getName());
    }
}
项目:myWMS    文件:LOSStorageLocation.java   
@PrePersist
@PreUpdate
public void checkValues() {
    if( scanCode == null ) {
        scanCode = name;
    }
}