|
@ -186,6 +186,7 @@ public abstract class DaoServiceImpl<E,ID extends Serializable,R extends DaoRepo |
|
|
if(entity==null){ throw exceptionProvider.getCreateNullObjectException(); } |
|
|
if(entity==null){ throw exceptionProvider.getCreateNullObjectException(); } |
|
|
if(findByUniqueKey(entity)!=null){ throw exceptionProvider.getCreateObjectAlreadyExistsException(entity); } |
|
|
if(findByUniqueKey(entity)!=null){ throw exceptionProvider.getCreateObjectAlreadyExistsException(entity); } |
|
|
standardizeAssociationAttributes(entity); |
|
|
standardizeAssociationAttributes(entity); |
|
|
|
|
|
setCorporation(entity); |
|
|
return repository.save(entity); |
|
|
return repository.save(entity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -257,10 +258,12 @@ public abstract class DaoServiceImpl<E,ID extends Serializable,R extends DaoRepo |
|
|
if(repository.getId(oldObject).equals(id)) { //主键相同,直接更新
|
|
|
if(repository.getId(oldObject).equals(id)) { //主键相同,直接更新
|
|
|
if(oldObject.getClass().equals(entity.getClass())){ |
|
|
if(oldObject.getClass().equals(entity.getClass())){ |
|
|
copyEntityValues(oldObject,entity); |
|
|
copyEntityValues(oldObject,entity); |
|
|
|
|
|
setCorporation(oldObject); |
|
|
return repository.save(oldObject); |
|
|
return repository.save(oldObject); |
|
|
}else{ |
|
|
}else{ |
|
|
repository.delete(oldObject); |
|
|
repository.delete(oldObject); |
|
|
repository.flush();//注意,此处必须通过 flush() 方法使得上面的 delete 生效,但不会进行事务提交
|
|
|
repository.flush();//注意,此处必须通过 flush() 方法使得上面的 delete 生效,但不会进行事务提交
|
|
|
|
|
|
setCorporation(entity); |
|
|
return repository.save(entity); |
|
|
return repository.save(entity); |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
@ -270,10 +273,12 @@ public abstract class DaoServiceImpl<E,ID extends Serializable,R extends DaoRepo |
|
|
oldObject =repository.getReferenceById(id); |
|
|
oldObject =repository.getReferenceById(id); |
|
|
if(oldObject.getClass().equals(entity.getClass())){ |
|
|
if(oldObject.getClass().equals(entity.getClass())){ |
|
|
copyEntityValues(oldObject,entity); |
|
|
copyEntityValues(oldObject,entity); |
|
|
|
|
|
setCorporation(oldObject); |
|
|
return repository.save(oldObject); |
|
|
return repository.save(oldObject); |
|
|
}else{ |
|
|
}else{ |
|
|
repository.delete(oldObject); |
|
|
repository.delete(oldObject); |
|
|
repository.flush();//注意,此处必须通过 flush() 方法使得上面的 delete 生效,但不会进行事务提交
|
|
|
repository.flush();//注意,此处必须通过 flush() 方法使得上面的 delete 生效,但不会进行事务提交
|
|
|
|
|
|
setCorporation(entity); |
|
|
return repository.save(entity); |
|
|
return repository.save(entity); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -472,6 +477,13 @@ public abstract class DaoServiceImpl<E,ID extends Serializable,R extends DaoRepo |
|
|
return specification; |
|
|
return specification; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setCorporation(E entity){ |
|
|
|
|
|
String corporationCode =SecurityUtil.getCorporationCode(); |
|
|
|
|
|
if (Environment.getInstance().isMultiCorportationMode() && !"_PRIMARY_".equals(corporationCode) && CorporationAuditorEntity.class.isAssignableFrom(entity.getClass())) { |
|
|
|
|
|
((CorporationAuditorEntity)entity).setCorporationCode(corporationCode); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 重新 new 一个被删除的实体对象 |
|
|
* 重新 new 一个被删除的实体对象 |
|
|
* 当一个实体被删除后,该实体将从 JPA Session 中脱离,在返回给客户端的 JSON 串时,可能涉及从实体中获取其他关联对象,此时就会出现 Session 状态错误 |
|
|
* 当一个实体被删除后,该实体将从 JPA Session 中脱离,在返回给客户端的 JSON 串时,可能涉及从实体中获取其他关联对象,此时就会出现 Session 状态错误 |
|
|