Changeset 101:7268c3ca025b in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r98 r101 62 62 public class AnnotationStore { 63 63 64 protected static Logger logger = Logger.getLogger( "de.mpiwg.itgroup.annotations.neo4j.AnnotationStore");64 protected static Logger logger = Logger.getLogger(AnnotationStore.class.getCanonicalName()); 65 65 66 66 protected GraphDatabaseService graphDb; … … 257 257 258 258 /** 259 * Returns the total number of Annotations. 260 * 261 * @return number of annotations 262 */ 263 public int getAnnotationCount() { 264 int num = -1; 265 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); 266 try (Transaction tx = graphDb.beginTx()) { 267 IndexHits<Node> annotNodes = idx.query("id", "*"); 268 num = annotNodes.size(); 269 tx.success(); 270 } 271 return num; 272 } 273 274 /** 259 275 * Returns List of Annotations. Key has to be indexed. 260 276 * 261 277 * @param key 262 278 * @param query 263 * @return 264 */ 265 public List<Annotation> getAnnotations(String key, String query) { 279 * @param limit 280 * @param offset 281 * @return 282 */ 283 public List<Annotation> getAnnotations(String key, String query, int limit, int offset) { 284 long ts = System.currentTimeMillis(); 266 285 ArrayList<Annotation> annotations = new ArrayList<Annotation>(); 267 286 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); … … 272 291 try (Transaction tx = graphDb.beginTx()) { 273 292 IndexHits<Node> annotNodes = idx.query(key, query); 293 int cnt = 0; 294 int max = offset + limit; 274 295 for (Node annotNode : annotNodes) { 296 cnt += 1; 297 if (cnt < offset) continue; 275 298 Annotation annotation = createAnnotationFromNode(annotNode); 276 299 annotations.add(annotation); 277 } 278 tx.success(); 279 } 300 if (limit > 0 && cnt >= max) { 301 annotNodes.close(); 302 break; 303 } 304 } 305 tx.success(); 306 } 307 logger.finer("got "+annotations.size()+" annotations in "+(System.currentTimeMillis()-ts)+"ms"); 280 308 return annotations; 281 309 }
Note: See TracChangeset
for help on using the changeset viewer.