mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-22 22:26:06 +00:00
test[orm]: map type test
This commit is contained in:
@@ -61,12 +61,29 @@ public class MapTest {
|
||||
entity.setBaseMap(map);
|
||||
|
||||
var longStringHashMap = new HashMap<Long, String>();
|
||||
longStringHashMap.put(100L,"hello map1");
|
||||
longStringHashMap.put(101L,"hello map2");
|
||||
longStringHashMap.put(100L, "hello map1");
|
||||
longStringHashMap.put(101L, "hello map2");
|
||||
entity.setLongStringMap(longStringHashMap);
|
||||
|
||||
OrmContext.getAccessor().insert(entity);
|
||||
var intStringHashMap = new HashMap<Integer, String>();
|
||||
intStringHashMap.put(100, "hello map1");
|
||||
intStringHashMap.put(102, "hello map2");
|
||||
intStringHashMap.put(103, "hello map2");
|
||||
entity.setIntStringMap(intStringHashMap);
|
||||
|
||||
var intBagMap = new HashMap<Integer, BagItem>();
|
||||
entity.setIntBagMap(intBagMap);
|
||||
intBagMap.put(1, bagItem1);
|
||||
intBagMap.put(2, bagItem2);
|
||||
intBagMap.put(3, bagItem3);
|
||||
|
||||
var intBaseMap = new HashMap<Integer, Map<Integer, String>>();
|
||||
intBaseMap.put(1, Map.of(1, "1"));
|
||||
intBaseMap.put(2, Map.of(2, "2"));
|
||||
intBaseMap.put(3, Map.of(3, "3"));
|
||||
entity.setIntBaseMap(intBaseMap);
|
||||
|
||||
OrmContext.getAccessor().insert(entity);
|
||||
var myEntity = OrmContext.getAccessor().load(1, MapEntity.class);
|
||||
Assert.assertEquals(entity, myEntity);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ public class MapEntity implements IEntity<Long> {
|
||||
private Map<String, Map<String, String>> baseMap = new HashMap<>();
|
||||
|
||||
private Map<Long, String> longStringMap = new HashMap<>();
|
||||
private Map<Integer, String> intStringMap = new HashMap<>();
|
||||
private Map<Integer, BagItem> intBagMap = new HashMap<>();
|
||||
private Map<Integer, Map<Integer, String>> intBaseMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Long id() {
|
||||
@@ -62,6 +65,14 @@ public class MapEntity implements IEntity<Long> {
|
||||
this.baseMap = baseMap;
|
||||
}
|
||||
|
||||
public Map<Integer, String> getIntStringMap() {
|
||||
return intStringMap;
|
||||
}
|
||||
|
||||
public void setIntStringMap(Map<Integer, String> intStringMap) {
|
||||
this.intStringMap = intStringMap;
|
||||
}
|
||||
|
||||
public Map<Long, String> getLongStringMap() {
|
||||
return longStringMap;
|
||||
}
|
||||
@@ -70,16 +81,32 @@ public class MapEntity implements IEntity<Long> {
|
||||
this.longStringMap = longStringMap;
|
||||
}
|
||||
|
||||
public Map<Integer, BagItem> getIntBagMap() {
|
||||
return intBagMap;
|
||||
}
|
||||
|
||||
public void setIntBagMap(Map<Integer, BagItem> intBagMap) {
|
||||
this.intBagMap = intBagMap;
|
||||
}
|
||||
|
||||
public Map<Integer, Map<Integer, String>> getIntBaseMap() {
|
||||
return intBaseMap;
|
||||
}
|
||||
|
||||
public void setIntBaseMap(Map<Integer, Map<Integer, String>> intBaseMap) {
|
||||
this.intBaseMap = intBaseMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MapEntity mapEntity = (MapEntity) o;
|
||||
return id == mapEntity.id && Objects.equals(bagMap, mapEntity.bagMap);
|
||||
return id == mapEntity.id && Objects.equals(bagMap, mapEntity.bagMap) && Objects.equals(baseMap, mapEntity.baseMap) && Objects.equals(longStringMap, mapEntity.longStringMap) && Objects.equals(intStringMap, mapEntity.intStringMap) && Objects.equals(intBagMap, mapEntity.intBagMap) && Objects.equals(intBaseMap, mapEntity.intBaseMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, bagMap);
|
||||
return Objects.hash(id, bagMap, baseMap, longStringMap, intStringMap, intBagMap, intBaseMap);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user