Package com.github.dactiv.orm.annotation

Examples of com.github.dactiv.orm.annotation.SecurityCode


   */
  @Override
  public boolean onSave(E entity, JpaSupportRepository<E, ID> persistentContext,Serializable id) {
   
    Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
    SecurityCode securityCode = ReflectionUtils.getAnnotation(entityClass,SecurityCode.class);
   
    if (persistentContext.getEntityInformation().isNew(entity)) {
      String code = generateSecurityCode(entity,securityCode);
      ReflectionUtils.invokeSetterMethod(entity, securityCode.value(), code);
    } else {
      E e = persistentContext.findOne((ID) id);
      String originalCode = ReflectionUtils.invokeGetterMethod(e, securityCode.value());
      String currentCode = generateSecurityCode(e, securityCode);
     
      if (!StringUtils.equals(originalCode, currentCode)) {
        throw new SecurityCodeNotEqualException("安全码不正确,原始码为:" + originalCode + "当前对象的安全码为:" + currentCode);
      }
     
      ReflectionUtils.invokeSetterMethod(entity, securityCode.value(), currentCode);
    }
   
    return Boolean.TRUE;
  }
View Full Code Here


   */
  @Override
  public boolean onSave(E entity, BasicHibernateDao<E, ID> persistentContext,Serializable id) {
   
    Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
    SecurityCode securityCode = ReflectionUtils.getAnnotation(entityClass,SecurityCode.class);
   
    if (securityCode != null) {
      if (id == null || id.toString().equals("")) {
        String code = generateSecurityCode(entity,securityCode);
        ReflectionUtils.invokeSetterMethod(entity, securityCode.value(), code);
      } else {
        E e = persistentContext.get((ID) id);
        String originalCode = ReflectionUtils.invokeGetterMethod(e, securityCode.value());
        String currentCode = generateSecurityCode(e, securityCode);
       
        if (!StringUtils.equals(originalCode, currentCode)) {
          throw new SecurityCodeNotEqualException("安全码不正确,原始码为:" + originalCode + "当前对象的安全码为:" + currentCode);
        }
       
        ReflectionUtils.invokeSetterMethod(entity, securityCode.value(), currentCode);
      }
    }
   
   
    return Boolean.TRUE;
View Full Code Here

TOP

Related Classes of com.github.dactiv.orm.annotation.SecurityCode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.