CQengine高性能内存数据缓存查找框架

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

CQengine高性能内存数据缓存查找框架

itank   2020-05-20 我要评论

CQengine可实现高性能内存数据缓存查找

 

CQEngine 需要设置字段对应的属性以方便访问与查询

主要有属性链接

  • SimpleAttribute(不能为空)

  • SimpleNullableAttribute(可以为空)

  • MultiValueAttribute(集合类型字段,不为空)

  • MultiValueNullableAttribute(集合类型的字段,可以为空)

另外SimpleAttribute下有几个重要的子类

OrderControlAttribute : 排序相关

ReflectiveAttribute : 动态反射创建Attribute ,性能没有直接在类中定义好

SelfAttribute:集合里中查找元素, 如["a","b","c"] 中查找b

自动生成实体类的 Attribute

cqengine 查询对象,根据字段查询,生成索引都需要用到SimpleAttribute,为每个实体的字段建 SimpleAttribute比较费力,所以cqengine 默认提供了自动生成属性代码
String code = AttributeSourceGenerator.generateAttributesForPastingIntoTargetClass(clazz);//传入实体类的CLASS,生成实体类下的所有属性对应的SimpleAttribute
如下:
public static final SimpleAttribute<Car, String> MODEL = new SimpleAttribute<Car, String>("model") {
public String getValue(Car car, QueryOptions queryOptions) { return car.model; }
};

AttributeSourceGenerator 生成源代码
AttributeBytecodeGenerator 运行时通过反射读取字段并反映创建Attribute对象添加到CLASS中

 

 

支持sql和cqn查询

示例链接

SQL

public static void main(String[] args) {
    SQLParser<Car> parser = SQLParser.forPojoWithAttributes(Car.class, createAttributes(Car.class));
    IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
    cars.addAll(CarFactory.createCollectionOfCars(10));
 
    ResultSet<Car> results = parser.retrieve(cars, "SELECT * FROM cars WHERE (" +
                                    "(manufacturer = 'Ford' OR manufacturer = 'Honda') " +
                                    "AND price <= 5000.0 " +
                                    "AND color NOT IN ('GREEN', 'WHITE')) " +
                                    "ORDER BY manufacturer DESC, price ASC");
    for (Car car : results) {
        System.out.println(car); // Prints: Honda Accord, Ford Fusion, Ford Focus
    }
}

注意:

  1. sql 查询时,SQLParser必须注册字段registerAttribute
  2. 注册的字段只能是引用类型(包装类),不然为报错

CQN


public static void main(String[] args) {
    CQNParser<Car> parser = CQNParser.forPojoWithAttributes(Car.class, createAttributes(Car.class));
    IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
    cars.addAll(CarFactory.createCollectionOfCars(10));
 
    ResultSet<Car> results = parser.retrieve(cars,
                                    "and(" +
                                        "or(equal(\"manufacturer\", \"Ford\"), equal(\"manufacturer\", \"Honda\")), " +
                                        "lessThanOrEqualTo(\"price\", 5000.0), " +
                                        "not(in(\"color\", GREEN, WHITE))" +
                                    ")");
    for (Car car : results) {
        System.out.println(car); // Prints: Ford Focus, Ford Fusion, Honda Accord
    }
}

支持索引

支持的索引类型有:
HashIndex,NavigableIndex,RadixTreeIndex,ReversedRadixTreeIndex,InvertedRadixTreeIndex,SuffixTreeIndex

HashIndex:
索引依赖ConcurrentHashMap ,适用于Equal 来比较。一般适用于字段为字符串,枚举。

NavigableIndex:
依赖ConcurrentSkipListMap,适用于Equal,LessThan,GreaterThan,Between;一般适用于字段为数字类型。

RadixTreeIndex:
依赖ConcurrentRadixTree,适用于Equal,StringStartsWith ;一般适用于字段为字符串需要StartsWith模糊匹配。

ReversedRadixTreeIndex:
依赖ConcurrentReversedRadixTree,适用于Equal,StringEndsWith;一般适用于字段为符串需要EndsWith模糊匹配。

InvertedRadixTreeIndex:
依赖ConcurrentInvertedRadixTree,适用于Equal,StringIsContainedIn;一般适用于字段为字符串是否包含XX字符char

SuffixTreeIndex:
依赖ConcurrentSuffixTree,适用于Equal,StringEndsWith,StringContains ; 一般适用于字段为需要 in(a,b,c....),容器是否包含字符串string。

 

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们