一.实体类
@Data
public class CategoryT {
private Integer id;
private String oneCategory;
private String twoCategory;
private String createTime;
private String updateTime;
public String uniKey() {
return oneCategory + "/" + twoCategory;
}
}
二.集合
@SuppressWarnings("unchecked")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CategoryDb {
private static final IndexedCollection<CategoryT> CACHE;
static {
CACHE = new TransactionalIndexedCollection<>(CategoryT.class);
CACHE.addIndex(UniqueIndex.onAttribute(Index.ID));
CACHE.addIndex(HashIndex.onAttribute(Index.ONE_CATEGORY));
CACHE.addIndex(HashIndex.onAttribute(Index.TWO_CATEGORY));
CACHE.addIndex(CompoundIndex.onAttributes(Index.ONE_CATEGORY, Index.TWO_CATEGORY));
CACHE.addIndex(UniqueIndex.onAttribute(Index.UNI_KEY));
}
private static final class Index {
private static final Attribute<CategoryT, Integer> ID = QueryFactory.attribute("ID", CategoryT::getId);
private static final Attribute<CategoryT, String> ONE_CATEGORY = QueryFactory.attribute("ONE_CATEGORY", CategoryT::getOneCategory);
private static final Attribute<CategoryT, String> TWO_CATEGORY = QueryFactory.attribute("TWO_CATEGORY", CategoryT::getTwoCategory);
private static final Attribute<CategoryT, String> UNI_KEY = QueryFactory.attribute("UNI_KEY", CategoryT::uniKey);
private static final Attribute<CategoryT, String> CREATE_TIME = QueryFactory.attribute("CREATE_TIME", CategoryT::getCreateTime);
private static final Attribute<CategoryT, String> UPDATE_TIME = QueryFactory.attribute("UPDATE_TIME", CategoryT::getUpdateTime);
}
}