當前位置: 首頁>>代碼示例>>Java>>正文


Java PreUpdate類代碼示例

本文整理匯總了Java中javax.persistence.PreUpdate的典型用法代碼示例。如果您正苦於以下問題:Java PreUpdate類的具體用法?Java PreUpdate怎麽用?Java PreUpdate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PreUpdate類屬於javax.persistence包,在下文中一共展示了PreUpdate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import javax.persistence.PreUpdate; //導入依賴的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: testUpdateProperties

import javax.persistence.PreUpdate; //導入依賴的package包/類
@Test
public void testUpdateProperties() throws Exception {
	User user = new User();
	user.name = "Michael";
	user.email = "[email protected]";
	warpdb.save(user);
	Thread.sleep(100);
	user.name = "Changed";
	user.version = 99;
	warpdb.updateProperties(user, "name", "version", "updatedAt");
	assertTrue(user.callbacks.contains(PreUpdate.class));
	assertTrue(user.callbacks.contains(PostUpdate.class));
	assertNotEquals(user.createdAt, user.updatedAt);
	assertEquals(System.currentTimeMillis(), user.updatedAt, 500);
	// fetch:
	User bak = warpdb.fetch(User.class, user.id);
	assertNotNull(bak);
	assertEquals(user.id, bak.id);
	assertEquals("Changed", bak.name);
	assertEquals("Changed", bak.name);
	assertEquals(99, bak.version);
}
 
開發者ID:michaelliao,項目名稱:warpdb,代碼行數:23,代碼來源:WarpDbCRUDAndCallbackTest.java

示例3: testUpdate

import javax.persistence.PreUpdate; //導入依賴的package包/類
@Test
public void testUpdate() throws Exception {
	User user = new User();
	user.name = "Michael";
	user.email = "[email protected]";
	warpdb.save(user);
	Thread.sleep(100);
	user.name = "Changed";
	user.email = "[email protected]";
	warpdb.update(user);
	assertTrue(user.callbacks.contains(PreUpdate.class));
	assertTrue(user.callbacks.contains(PostUpdate.class));
	assertNotEquals(user.createdAt, user.updatedAt);
	assertEquals(System.currentTimeMillis(), user.updatedAt, 500);
	// fetch:
	User bak = warpdb.fetch(User.class, user.id);
	assertNotNull(bak);
	assertEquals(user.id, bak.id);
	assertEquals("Changed", bak.name);
	// email is set updatable=false:
	assertEquals("[email protected]", bak.email);
	assertEquals(user.createdAt, bak.createdAt);
	assertEquals(user.updatedAt, bak.updatedAt);
	assertEquals(user.version, bak.version);
}
 
開發者ID:michaelliao,項目名稱:warpdb,代碼行數:26,代碼來源:WarpDbCRUDAndCallbackTest.java

示例4: sanityCheck

import javax.persistence.PreUpdate; //導入依賴的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

示例5: sanityCheck

import javax.persistence.PreUpdate; //導入依賴的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

示例6: prePersist

import javax.persistence.PreUpdate; //導入依賴的package包/類
@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);
   }
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:17,代碼來源:ResourceParameter.java

示例7: beforeUpdate

import javax.persistence.PreUpdate; //導入依賴的package包/類
@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());
        }
    }
}
 
開發者ID:hantsy,項目名稱:javaee8-jsf-sample,代碼行數:12,代碼來源:AuditEntityListener.java

示例8: assertEncrypted

import javax.persistence.PreUpdate; //導入依賴的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

示例9: prePersist

import javax.persistence.PreUpdate; //導入依賴的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

示例10: processDefaultJpaCallbacks

import javax.persistence.PreUpdate; //導入依賴的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

示例11: processJpaCallbacks

import javax.persistence.PreUpdate; //導入依賴的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

示例12: updateTimeStamps

import javax.persistence.PreUpdate; //導入依賴的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

示例13: onPreUpdate

import javax.persistence.PreUpdate; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:jotorren,項目名稱:microservices-transactions-tcc,代碼行數:11,代碼來源:ChangeStateJpaListener.java

示例14: beforeUpdate

import javax.persistence.PreUpdate; //導入依賴的package包/類
@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());
        }
    }
}
 
開發者ID:hantsy,項目名稱:javaee8-jaxrs-sample,代碼行數:12,代碼來源:AuditEntityListener.java

示例15: preUpdate

import javax.persistence.PreUpdate; //導入依賴的package包/類
@PreUpdate
void preUpdate() {
    setModificationTimeToCurrentTime();

    final Long activeUserId = getActiveUserId();

    if (activeUserId >= 0 || getAuditFields().getModifiedByUserId() == null) {
        getAuditFields().setModifiedByUserId(activeUserId);
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:11,代碼來源:LifecycleEntity.java


注:本文中的javax.persistence.PreUpdate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。