@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);
}
}
java类javax.persistence.PreUpdate的实例源码
CheckingEntityListener.java 文件源码
项目:os
阅读 40
收藏 0
点赞 0
评论 0
CheckingEntityListener.java 文件源码
项目:ha-db
阅读 39
收藏 0
点赞 0
评论 0
@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);
}
}
ItemData.java 文件源码
项目:myWMS
阅读 36
收藏 0
点赞 0
评论 0
/**
* 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));
}
}
ItemDataNumber.java 文件源码
项目:myWMS
阅读 40
收藏 0
点赞 0
评论 0
/**
* 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());
}
}
ResourceParameter.java 文件源码
项目:cibet
阅读 43
收藏 0
点赞 0
评论 0
@PrePersist
@PreUpdate
public void prePersist() {
if (encodedValue == null && unencodedValue != null) {
try {
encodedValue = CibetUtil.encode(unencodedValue);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (parameterId == null) {
parameterId = UUID.randomUUID().toString();
log.debug("PREPERSIST: " + parameterId);
}
}
AuditEntityListener.java 文件源码
项目:javaee8-jsf-sample
阅读 42
收藏 0
点赞 0
评论 0
@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());
}
}
}
User.java 文件源码
项目:spring-data-examples
阅读 36
收藏 0
点赞 0
评论 0
/**
* 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!");
}
}
AvatarUrlListener.java 文件源码
项目:xm-ms-entity
阅读 34
收藏 0
点赞 0
评论 0
@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);
}
}
}
EntityClass.java 文件源码
项目:lams
阅读 44
收藏 0
点赞 0
评论 0
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 ) );
}
}
EntityClass.java 文件源码
项目:lams
阅读 35
收藏 0
点赞 0
评论 0
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 ) );
}
}
PersonEntity.java 文件源码
项目:api.teiler.io
阅读 38
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
TransactionEntity.java 文件源码
项目:api.teiler.io
阅读 36
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
ProfiteerEntity.java 文件源码
项目:api.teiler.io
阅读 33
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
GroupEntity.java 文件源码
项目:api.teiler.io
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
ChangeStateJpaListener.java 文件源码
项目:microservices-transactions-tcc
阅读 36
收藏 0
点赞 0
评论 0
@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);
}
}
AuditEntityListener.java 文件源码
项目:javaee8-jaxrs-sample
阅读 42
收藏 0
点赞 0
评论 0
@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());
}
}
}
LifecycleEntity.java 文件源码
项目:oma-riista-web
阅读 27
收藏 0
点赞 0
评论 0
@PreUpdate
void preUpdate() {
setModificationTimeToCurrentTime();
final Long activeUserId = getActiveUserId();
if (activeUserId >= 0 || getAuditFields().getModifiedByUserId() == null) {
getAuditFields().setModifiedByUserId(activeUserId);
}
}
FacilityMessage.java 文件源码
项目:OSCAR-ConCert
阅读 38
收藏 0
点赞 0
评论 0
@PrePersist
@PreUpdate
protected void jpa_prePersistAndUpdate() {
if(getProgramId() != null && getProgramId().intValue() == 0) {
setProgramId(null);
}
}
BaseEntity.java 文件源码
项目:coordinated-entry
阅读 30
收藏 0
点赞 0
评论 0
@PreUpdate
protected void onUpdate(){
dateUpdated = LocalDateTime.now();
if(SecurityContextUtil.getUserAccount()!=null) {
userId = SecurityContextUtil.getUserAccount().getAccountId();
}
}
Order.java 文件源码
项目:my-paper
阅读 35
收藏 0
点赞 0
评论 0
/**
* 更新前处理
*/
@PreUpdate
public void preUpdate() {
if (getArea() != null) {
setAreaName(getArea().getFullName());
}
if (getPaymentMethod() != null) {
setPaymentMethodName(getPaymentMethod().getName());
}
if (getShippingMethod() != null) {
setShippingMethodName(getShippingMethod().getName());
}
}
Area.java 文件源码
项目:my-paper
阅读 36
收藏 0
点赞 0
评论 0
/**
* 更新前处理
*/
@PreUpdate
public void preUpdate() {
Area parent = getParent();
if (parent != null) {
setFullName(parent.getFullName() + getName());
} else {
setFullName(getName());
}
}
Receiver.java 文件源码
项目:my-paper
阅读 30
收藏 0
点赞 0
评论 0
/**
* 更新前处理
*/
@PreUpdate
public void preUpdate() {
if (getArea() != null) {
setAreaName(getArea().getFullName());
}
}
Product.java 文件源码
项目:my-paper
阅读 58
收藏 0
点赞 0
评论 0
/**
* 更新前处理
*/
@PreUpdate
public void preUpdate() {
if (getStock() == null) {
setAllocatedStock(0);
}
if (getTotalScore() != null && getScoreCount() != null && getScoreCount() != 0) {
setScore((float) getTotalScore() / getScoreCount());
} else {
setScore(0F);
}
}
HousingInventoryBaseEntity.java 文件源码
项目:coordinated-entry
阅读 33
收藏 0
点赞 0
评论 0
@PreUpdate
protected void onUpdate(){
dateUpdated = LocalDateTime.now();
if(SecurityContextUtil.getUserAccount()!=null) {
userId = SecurityContextUtil.getUserAccount().getAccountId();
}
if(SecurityContextUtil.getUserProjectGroup()!=null){
projectGroupCode=SecurityContextUtil.getUserProjectGroup();
}
}
AbstractVersion.java 文件源码
项目:pcm-api
阅读 29
收藏 0
点赞 0
评论 0
@PreUpdate
public void preUpdate() {
try {
modificationTime = getCurrentDate();
} catch (ParseException e) {
modificationTime = new Date();
}
}
Post.java 文件源码
项目:ee8-sandbox
阅读 38
收藏 0
点赞 0
评论 0
@PreUpdate
public void beforeUpdate() {
setUpdatedAt(LocalDateTime.now());
if (PUBLISHED == this.status) {
setPublishedAt(LocalDateTime.now());
}
}
Post.java 文件源码
项目:ee8-sandbox
阅读 37
收藏 0
点赞 0
评论 0
@PreUpdate
public void beforeUpdate() {
setUpdatedAt(LocalDateTime.now());
if (PUBLISHED == this.status) {
setPublishedAt(LocalDateTime.now());
}
}
Post.java 文件源码
项目:ee8-sandbox
阅读 40
收藏 0
点赞 0
评论 0
@PreUpdate
public void beforeUpdate() {
setUpdatedAt(LocalDateTime.now());
if (PUBLISHED == this.status) {
setPublishedAt(LocalDateTime.now());
}
}
BaseEntityListener.java 文件源码
项目:sit-ad-archetype-javaee7-web
阅读 36
收藏 0
点赞 0
评论 0
@PreUpdate
public void preUpdate(BaseEntity entity) {
if (principal == null) {
entity.setUpdatedBy("system");
} else {
entity.setUpdatedBy(principal.getName());
}
}
LOSPickingPosition.java 文件源码
项目:myWMS
阅读 29
收藏 0
点赞 0
评论 0
@PrePersist
@PreUpdate
// For hibernate only. By annotation it is called before saving
private void setRedundantValues() {
if( pickingOrder == null ) {
pickingOrderNumber = null;
}
else {
pickingOrderNumber = pickingOrder.getNumber();
}
}