mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 06:16:01 +00:00
perf[storage]: orm和storage的注解的语法校验,避免犯小错误
This commit is contained in:
1 parent
3cdf9b6131
commit
9ae201abf6
4 files changed
+49
-20
No files matched your search
@@ -28,9 +28,9 @@ public class IdDef {
|
||||
private Field field;
|
||||
|
||||
public static IdDef valueOf(Class<?> clazz) {
|
||||
Field[] fields = ReflectionUtils.getFieldsByAnnoInPOJOClass(clazz, Id.class);
|
||||
var fields = ReflectionUtils.getFieldsByAnnoInPOJOClass(clazz, Id.class);
|
||||
if (fields.length <= 0) {
|
||||
throw new RunException("class[{}]没有主键Id注解", clazz.getName());
|
||||
throw new RunException("class[{}]没有被Id注解标识的主键(如果确实已经被Id注解标注,注意不要使用ORM的Id注解)", clazz.getName());
|
||||
}
|
||||
if (fields.length > 1) {
|
||||
throw new RunException("类[{}]的主键Id注解重复", clazz.getName());
|
||||
@@ -38,9 +38,9 @@ public class IdDef {
|
||||
if (fields[0] == null) {
|
||||
throw new RunException("不合法的Id资源映射对象:" + clazz.getName());
|
||||
}
|
||||
Field idField = fields[0];
|
||||
var idField = fields[0];
|
||||
ReflectionUtils.makeAccessible(idField);
|
||||
IdDef idDef = new IdDef();
|
||||
var idDef = new IdDef();
|
||||
idDef.setField(idField);
|
||||
return idDef;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
package com.zfoo.storage.model.vo;
|
||||
|
||||
import com.zfoo.protocol.collection.ArrayUtils;
|
||||
import com.zfoo.protocol.exception.RunException;
|
||||
import com.zfoo.protocol.util.ReflectionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import com.zfoo.storage.model.anno.Index;
|
||||
@@ -44,6 +46,10 @@ public class IndexDef {
|
||||
var fields = ReflectionUtils.getFieldsByAnnoInPOJOClass(clazz, Index.class);
|
||||
var indexes = new ArrayList<IndexDef>(fields.length);
|
||||
|
||||
var ormIndexes = ReflectionUtils.getFieldsByAnnoNameInPOJOClass(clazz, "com.zfoo.orm.model.anno.Index");
|
||||
if (ArrayUtils.isNotEmpty(ormIndexes)) {
|
||||
throw new RunException("在Storage中只能使用Storage的Index注解,不能使用Orm的Index注解,为了避免不必要的误解和增强项目的健壮性,禁止这样使用");
|
||||
}
|
||||
|
||||
for (var field : fields) {
|
||||
IndexDef indexDef = new IndexDef(field);
|
||||
|
||||
Reference in new issue
Block a user