Mercurial > hg > AnnotationManagerN4J
diff src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 101:7268c3ca025b
make admin ui view of all annotations scale better.
author | casties |
---|---|
date | Fri, 13 Feb 2015 18:10:11 +0100 |
parents | 5a764c625290 |
children |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Wed Feb 11 20:02:56 2015 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java Fri Feb 13 18:10:11 2015 +0100 @@ -61,7 +61,7 @@ */ public class AnnotationStore { - protected static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.neo4j.AnnotationStore"); + protected static Logger logger = Logger.getLogger(AnnotationStore.class.getCanonicalName()); protected GraphDatabaseService graphDb; @@ -256,13 +256,32 @@ } /** + * Returns the total number of Annotations. + * + * @return number of annotations + */ + public int getAnnotationCount() { + int num = -1; + Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); + try (Transaction tx = graphDb.beginTx()) { + IndexHits<Node> annotNodes = idx.query("id", "*"); + num = annotNodes.size(); + tx.success(); + } + return num; + } + + /** * Returns List of Annotations. Key has to be indexed. * * @param key * @param query + * @param limit + * @param offset * @return */ - public List<Annotation> getAnnotations(String key, String query) { + public List<Annotation> getAnnotations(String key, String query, int limit, int offset) { + long ts = System.currentTimeMillis(); ArrayList<Annotation> annotations = new ArrayList<Annotation>(); Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); if (key == null) { @@ -271,12 +290,21 @@ } try (Transaction tx = graphDb.beginTx()) { IndexHits<Node> annotNodes = idx.query(key, query); + int cnt = 0; + int max = offset + limit; for (Node annotNode : annotNodes) { + cnt += 1; + if (cnt < offset) continue; Annotation annotation = createAnnotationFromNode(annotNode); annotations.add(annotation); + if (limit > 0 && cnt >= max) { + annotNodes.close(); + break; + } } tx.success(); } + logger.finer("got "+annotations.size()+" annotations in "+(System.currentTimeMillis()-ts)+"ms"); return annotations; }