当前位置: 首页 > 工具软件 > HyperGraphDB > 使用案例 >

HyperGraphDB查询中的变量

史默
2023-12-01
Introduction

A feature that has been requested on a few occasions is the ability to parametarize HyperGraphDB queries with variables, sort of like the JDBC PreparedStatement allows. That feature has now been implemented with the introduction of named variables. Named variables can be used in place of a regular condition parameters and can contain arbitrary values, whatever is expected by the condition.

The benefits are twofold: increase performance by avoiding to recompile queries where only a few condition parameters change and a cleaner code with less query duplication. The performance increase of precompiled queries is quite tangible and shouldn't be neglected.

Nearly all predefined query conditions support variables, except for the TypePlusCondition which is expanded into a type disjunction during query compilation and therefore cannot be easily precompiled into a parametarized form. It must also be noted that some optimizations made during the compilation phase, in particular related to index usage, can't be performed when a condition is parametarized.

A simple example of this limitation is a parameterized TypeCondition - indices are defined per type, so if the type is not known during query analysis, no index will be used.

The API

The API is designed to fit the existing query condition expressions. A variable is created by calling the hg.var method and the result of that method passed as a condition parameter. For example:

CODE:

1.HGQuery q = hg.make(HGHandle.class, graph).compile(
2.hg.and(hg.type(typeHandle),hg.incident(hg.var("targetOfInterest"))));

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/301743/viewspace-751709/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/301743/viewspace-751709/

 类似资料: