当前位置: 首页>>代码示例>>Java>>正文


Java PrePersist类代码示例

本文整理汇总了Java中javax.persistence.PrePersist的典型用法代码示例。如果您正苦于以下问题:Java PrePersist类的具体用法?Java PrePersist怎么用?Java PrePersist使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PrePersist类属于javax.persistence包,在下文中一共展示了PrePersist类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import javax.persistence.PrePersist; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:onsoul,项目名称:os,代码行数:23,代码来源:CheckingEntityListener.java

示例2: sanityCheck

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * 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));
	}
}
 
开发者ID:salimvanak,项目名称:myWMS,代码行数:26,代码来源:ItemData.java

示例3: sanityCheck

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * 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());
	}

}
 
开发者ID:salimvanak,项目名称:myWMS,代码行数:22,代码来源:ItemDataNumber.java

示例4: beforePersist

import javax.persistence.PrePersist; //导入依赖的package包/类
@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());
        }
    }
}
 
开发者ID:hantsy,项目名称:javaee8-jsf-sample,代码行数:14,代码来源:AuditEntityListener.java

示例5: beforeSave

import javax.persistence.PrePersist; //导入依赖的package包/类
@PrePersist
public void beforeSave() {
    createdDate = LocalDateTime.now();

    if (expiredDate == null) {
        expiredDate = LocalDateTime.now().plusMonths(1L);
    }
}
 
开发者ID:hantsy,项目名称:javaee8-jsf-sample,代码行数:9,代码来源:LoginToken.java

示例6: assertEncrypted

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * 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!");
	}
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:12,代码来源:User.java

示例7: prePersiste

import javax.persistence.PrePersist; //导入依赖的package包/类
@PrePersist
private void prePersiste() {
   if (getId() == null) {
       OrderItemId pk = new OrderItemId();
       pk.setDailyOrderId(dailyOrder.getDailyOrderId());
       pk.setFoodId(food.getId());
       setId(pk);
   }
}
 
开发者ID:jrtechnologies,项目名称:yum,代码行数:10,代码来源:OrderItem.java

示例8: fillCreationDate

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * Fill creation date (if not already set)
 */
@PrePersist
public void fillCreationDate() {
    if (getCreationDate() == null) {
        setCreationDate(GregorianCalendar.getInstance().getTime());
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:PlatformUser.java

示例9: fillCreationDate

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * Fill creation date (if not already set)
 */
@PrePersist
public void fillCreationDate() {
    if (getExecutiondate() == null) {
        setExecutiondate(GregorianCalendar.getInstance().getTime());
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:OperationRecord.java

示例10: onCreate

import javax.persistence.PrePersist; //导入依赖的package包/类
@PrePersist
protected void onCreate()
{
	created = new Date();
	updated = new Date();
	if (uuid == null)
		uuid = GENERATOR.generate();
	if (id == null)
		id = uuid.getMostSignificantBits() ^ uuid.getLeastSignificantBits();
}
 
开发者ID:olavloite,项目名称:spanner-jpa-example,代码行数:11,代码来源:BaseEntity.java

示例11: prePersist

import javax.persistence.PrePersist; //导入依赖的package包/类
@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);
        }
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:13,代码来源:AvatarUrlListener.java

示例12: processDefaultJpaCallbacks

import javax.persistence.PrePersist; //导入依赖的package包/类
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 ) );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:EntityClass.java

示例13: processJpaCallbacks

import javax.persistence.PrePersist; //导入依赖的package包/类
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 ) );
		}
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:EntityClass.java

示例14: updateTimeStamps

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:teiler,项目名称:api.teiler.io,代码行数:14,代码来源:PersonEntity.java

示例15: generate

import javax.persistence.PrePersist; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:springuni,项目名称:springuni-particles,代码行数:14,代码来源:IdentityGeneratorListener.java


注:本文中的javax.persistence.PrePersist类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。