CQengine高性能內存數據緩存查找框架

CQengine可實現高性能內存數據緩存查找html

 

CQEngine 須要設置字段對應的屬性以方便訪問與查詢

主要有屬性連接

  • SimpleAttribute(不能爲空)sql

  • SimpleNullableAttribute(能夠爲空)緩存

  • MultiValueAttribute(集合類型字段,不爲空)app

  • MultiValueNullableAttribute(集合類型的字段,能夠爲空)less

另外SimpleAttribute下有幾個重要的子類性能

OrderControlAttribute : 排序相關spa

ReflectiveAttribute : 動態反射建立Attribute ,性能沒有直接在類中定義好code

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

自動生成實體類的 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; }
};htm

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。

相關文章
相關標籤/搜索