mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-12 14:15:22 +00:00
feat[orm]: support record class in orm
This commit is contained in:
1 parent
596b483dc5
commit
242cfb9c9a
4 files changed
+24
-52
No files matched your search
@@ -500,7 +500,9 @@ public class OrmManager implements IOrmManager {
|
||||
// 不能是泛型类
|
||||
AssertionUtils.isTrue(ArrayUtils.isEmpty(clazz.getTypeParameters()), "[class:{}] can't be a generic class", clazz.getCanonicalName());
|
||||
// 必须要有一个空的构造器
|
||||
ReflectionUtils.publicEmptyConstructor(clazz);
|
||||
if (!clazz.isRecord()) {
|
||||
ReflectionUtils.publicEmptyConstructor(clazz);
|
||||
}
|
||||
|
||||
// 不能使用Storage的Index注解
|
||||
var storageIndexes = ReflectionUtils.getFieldsByAnnoNameInPOJOClass(clazz, "com.zfoo.storage.anno.Index");
|
||||
@@ -517,7 +519,9 @@ public class OrmManager implements IOrmManager {
|
||||
|
||||
// entity必须包含属性的get和set方法
|
||||
FieldUtils.fieldToGetMethod(clazz, field);
|
||||
FieldUtils.fieldToSetMethod(clazz, field);
|
||||
if (!clazz.isRecord()) {
|
||||
FieldUtils.fieldToSetMethod(clazz, field);
|
||||
}
|
||||
|
||||
// 是一个基本类型变量
|
||||
var fieldType = field.getType();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
package com.zfoo.orm.accessor;
|
||||
|
||||
import com.zfoo.orm.OrmContext;
|
||||
import com.zfoo.orm.entity.UserEntity;
|
||||
import com.zfoo.orm.entity.bag.BagItem;
|
||||
import com.zfoo.orm.entity.bag.Item;
|
||||
import com.zfoo.orm.entity.bag.MapEntity;
|
||||
@@ -52,7 +53,8 @@ public class MapTest {
|
||||
var entity = new MapEntity();
|
||||
entity.setId(id);
|
||||
|
||||
entity.setList(List.of(1, 2, 3));
|
||||
entity.setItem(new Item(1, "item1"));
|
||||
entity.setList(List.of(new Item(1, "item1"), new Item(2, "item2"), new Item(3, "item3")));
|
||||
|
||||
CopyOnWriteArrayList<Integer> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
|
||||
copyOnWriteArrayList.add(1);
|
||||
|
||||
@@ -13,48 +13,5 @@
|
||||
|
||||
package com.zfoo.orm.entity.bag;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Item {
|
||||
|
||||
private int a;
|
||||
private String b;
|
||||
|
||||
public Item() {
|
||||
}
|
||||
|
||||
public Item(int a, String b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public String getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(String b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Item item = (Item) o;
|
||||
return a == item.a && Objects.equals(b, item.b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(a, b);
|
||||
}
|
||||
public record Item(int a, String b) {
|
||||
}
|
||||
@@ -25,7 +25,8 @@ public class MapEntity implements IEntity<Long> {
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private List<Integer> list = new ArrayList<>();
|
||||
private Item item;
|
||||
private List<Item> list = new ArrayList<>();
|
||||
|
||||
private CopyOnWriteArrayList<Integer> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -61,11 +62,19 @@ public class MapEntity implements IEntity<Long> {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Integer> getList() {
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public List<Item> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<Integer> list) {
|
||||
public void setList(List<Item> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@@ -202,11 +211,11 @@ public class MapEntity implements IEntity<Long> {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MapEntity mapEntity = (MapEntity) o;
|
||||
return id == mapEntity.id && Objects.equals(list, mapEntity.list) && Objects.equals(bagMap, mapEntity.bagMap) && Objects.equals(baseMap, mapEntity.baseMap) && Objects.equals(longStringMap, mapEntity.longStringMap) && Objects.equals(intStringMap, mapEntity.intStringMap) && Objects.equals(intBaseMap, mapEntity.intBaseMap) && Objects.equals(charBagMap, mapEntity.charBagMap) && Objects.equals(boolBagMap, mapEntity.boolBagMap) && Objects.equals(byteBagMap, mapEntity.byteBagMap) && Objects.equals(shortBagMap, mapEntity.shortBagMap) && Objects.equals(intBagMap, mapEntity.intBagMap) && Objects.equals(longBagMap, mapEntity.longBagMap) && Objects.equals(floatBagMap, mapEntity.floatBagMap) && Objects.equals(doubleBagMap, mapEntity.doubleBagMap);
|
||||
return id == mapEntity.id && Objects.equals(item, mapEntity.item) && Objects.equals(list, mapEntity.list) && Objects.equals(copyOnWriteArrayList, mapEntity.copyOnWriteArrayList) && Objects.equals(concurrentHashMap, mapEntity.concurrentHashMap) && Objects.equals(copyOnWriteHashMap, mapEntity.copyOnWriteHashMap) && Objects.equals(bagMap, mapEntity.bagMap) && Objects.equals(baseMap, mapEntity.baseMap) && Objects.equals(longStringMap, mapEntity.longStringMap) && Objects.equals(intStringMap, mapEntity.intStringMap) && Objects.equals(intBaseMap, mapEntity.intBaseMap) && Objects.equals(charBagMap, mapEntity.charBagMap) && Objects.equals(boolBagMap, mapEntity.boolBagMap) && Objects.equals(byteBagMap, mapEntity.byteBagMap) && Objects.equals(shortBagMap, mapEntity.shortBagMap) && Objects.equals(intBagMap, mapEntity.intBagMap) && Objects.equals(longBagMap, mapEntity.longBagMap) && Objects.equals(floatBagMap, mapEntity.floatBagMap) && Objects.equals(doubleBagMap, mapEntity.doubleBagMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, list, bagMap, baseMap, longStringMap, intStringMap, intBaseMap, charBagMap, boolBagMap, byteBagMap, shortBagMap, intBagMap, longBagMap, floatBagMap, doubleBagMap);
|
||||
return Objects.hash(id, item, list, copyOnWriteArrayList, concurrentHashMap, copyOnWriteHashMap, bagMap, baseMap, longStringMap, intStringMap, intBaseMap, charBagMap, boolBagMap, byteBagMap, shortBagMap, intBagMap, longBagMap, floatBagMap, doubleBagMap);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user