CQengine高性能内存数据缓存查找框架
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
}
}
注意:
- sql 查询时,SQLParser必须注册字段registerAttribute
- 注册的字段只能是引用类型(包装类),不然为报错
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。
最新文章
- 微软 Build 2016年开发者大会发布多项功能升级
- 使用Android Annotations开发
- PHP flush sleep 输出缓存控制详解
- IOS 7 Study - Implementing Navigation with UINavigationController
- [每日一题] 11gOCP 1z0-053 :2013-10-11 Flashback Data Archive属性.........................43
- JAVA.IO流学习笔记
- “=”号和“:”的区别,Html.Raw()的使用
- 2:url有规律的多页面爬取
- ar命令提取.a时刻,一个错误 is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
- WebBrowser编程简述
- 【HighCharts系列教程】八、Html标签属性——Labels
- 基于Ubuntu12.04-server版的openstack F版搭建步骤
- QRCode.js生成二维码
- 使用css时的一些技巧及注意事项
- 读懂SAP Leonardo物联网平台
- 基于Bootstrap表单验证
- for /f命令之—Delims和Tokens用法&;总结
- Spring Boot 使用Redis
- 安全关闭MySQL
- PTA——删除重复字符
热门文章
- DBeaver数据表的拷贝过程
- 数据包的抓取[tcpdump]的应用
- [Inno Setup] 安装完成后调用函数
- c语言实现乘法口诀表
- Django入门2:路由系统
- 16.What is pass in Python?
- MySQL使用ProxySQL实现读写分离
- 一只简单的网络爬虫(基于linux C/C++)————线程相关
- 僵尸进程(zombie process)
- python-CSV格式清洗与转换、CSV格式列变换、CSV格式数据清洗【数据读入的三种方法】【strip、replace、split、join函数的使用】