@Test public void testSize() throws Exception { ValueFactory vf = SimpleValueFactory.getInstance(); Configuration cfg = HBaseServerTestInstance.getInstanceConfig(); HBaseSail sail = new HBaseSail(cfg, "whatevertablesize", true, 0, true, 180, null, null); sail.initialize(); assertEquals(0, sail.size()); assertEquals(0, sail.size(HALYARD.STATS_ROOT_NODE)); IRI iri = vf.createIRI("http: sail.addStatement(iri, iri, iri); sail.commit(); assertEquals(1, sail.size()); sail.addStatement(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, vf.createLiteral(567), HALYARD.STATS_GRAPH_CONTEXT); sail.commit(); assertEquals(567, sail.size()); assertEquals(567, sail.size(HALYARD.STATS_ROOT_NODE)); sail.addStatement(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, vf.createLiteral(568), HALYARD.STATS_GRAPH_CONTEXT); sail.commit(); try { sail.size(); fail("Expected SailException"); } catch (SailException se) {} try { sail.size(HALYARD.STATS_ROOT_NODE); fail("Expected SailException"); } catch (SailException se) {} }
@Override public synchronized long size(Resource... contexts) throws SailException { long size = 0; if (contexts != null && contexts.length > 0 && contexts[0] != null) { for (Resource ctx : contexts) { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(ctx, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics for context: "+ctx.stringValue()+". Considering removing and recomputing statistics"); } } } } else { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics. Considering removing and recomputing statistics"); } } } if (size == 0 && evaluationTimeout > 0) try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(null, null, null, true, contexts)) { while (scanner.hasNext()) { scanner.next(); size++; } } return size; }
HBaseSail implements Sail, SailConnection, FederatedServiceResolver, FederatedService { @Override public synchronized long size(Resource... contexts) throws SailException { long size = 0; if (contexts != null && contexts.length > 0 && contexts[0] != null) { for (Resource ctx : contexts) { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(ctx, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics for context: "+ctx.stringValue()+". Considering removing and recomputing statistics"); } } } } else { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics. Considering removing and recomputing statistics"); } } } if (size == 0 && evaluationTimeout > 0) try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(null, null, null, true, contexts)) { while (scanner.hasNext()) { scanner.next(); size++; } } return size; } }
HBaseSail implements Sail, SailConnection, FederatedServiceResolver, FederatedService { @Override public synchronized long size(Resource... contexts) throws SailException { long size = 0; if (contexts != null && contexts.length > 0 && contexts[0] != null) { for (Resource ctx : contexts) { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(ctx, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics for context: "+ctx.stringValue()+". Considering removing and recomputing statistics"); } } } } else { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics. Considering removing and recomputing statistics"); } } } if (size == 0 && evaluationTimeout > 0) try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(null, null, null, true, contexts)) { while (scanner.hasNext()) { scanner.next(); size++; } } return size; } HBaseSail(Configuration config, String tableName, boolean create, int splitBits, boolean pushStrategy, int evaluationTimeout, String elasticIndexURL, Ticker ticker); }
HBaseSail implements Sail, SailConnection, FederatedServiceResolver, FederatedService { @Override public synchronized long size(Resource... contexts) throws SailException { long size = 0; if (contexts != null && contexts.length > 0 && contexts[0] != null) { for (Resource ctx : contexts) { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(ctx, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics for context: "+ctx.stringValue()+". Considering removing and recomputing statistics"); } } } } else { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics. Considering removing and recomputing statistics"); } } } if (size == 0 && evaluationTimeout > 0) try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(null, null, null, true, contexts)) { while (scanner.hasNext()) { scanner.next(); size++; } } return size; } HBaseSail(Configuration config, String tableName, boolean create, int splitBits, boolean pushStrategy, int evaluationTimeout, String elasticIndexURL, Ticker ticker); @Override void setDataDir(File dataDir); @Override File getDataDir(); @Override void initialize(); @Override FederatedService getService(String serviceUrl); @Override boolean ask(Service service, BindingSet bindings, String baseUri); @Override CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri); @Override CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Service service, CloseableIteration<BindingSet, QueryEvaluationException> bindings, String baseUri); @Override boolean isInitialized(); @Override void shutdown(); @Override void shutDown(); @Override boolean isWritable(); @Override SailConnection getConnection(); @Override ValueFactory getValueFactory(); @Override List<IsolationLevel> getSupportedIsolationLevels(); @Override IsolationLevel getDefaultIsolationLevel(); @Override boolean isOpen(); @Override void close(); @Override CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings, final boolean includeInferred); @Override CloseableIteration<? extends Resource, SailException> getContextIDs(); @Override CloseableIteration<? extends Statement, SailException> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override synchronized long size(Resource... contexts); @Override void begin(); @Override void begin(IsolationLevel level); @Override void flush(); @Override void prepare(); @Override void commit(); @Override void rollback(); @Override boolean isActive(); @Override void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, Resource... contexts); @Override void addStatement(Resource subj, IRI pred, Value obj, Resource... contexts); @Override void removeStatement(UpdateContext op, Resource subj, IRI pred, Value obj, Resource... contexts); @Override void removeStatements(Resource subj, IRI pred, Value obj, Resource... contexts); @Override boolean pendingRemovals(); @Override void startUpdate(UpdateContext op); @Override void endUpdate(UpdateContext op); @Override void clear(Resource... contexts); @Override String getNamespace(String prefix); @Override CloseableIteration<? extends Namespace, SailException> getNamespaces(); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); }
HBaseSail implements Sail, SailConnection, FederatedServiceResolver, FederatedService { @Override public synchronized long size(Resource... contexts) throws SailException { long size = 0; if (contexts != null && contexts.length > 0 && contexts[0] != null) { for (Resource ctx : contexts) { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(ctx, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics for context: "+ctx.stringValue()+". Considering removing and recomputing statistics"); } } } } else { try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(HALYARD.STATS_ROOT_NODE, VOID.TRIPLES, null, true, HALYARD.STATS_GRAPH_CONTEXT)) { if (scanner.hasNext()) { size += ((Literal)scanner.next().getObject()).longValue(); } if (scanner.hasNext()) { throw new SailException("Multiple different values exist in VOID statistics. Considering removing and recomputing statistics"); } } } if (size == 0 && evaluationTimeout > 0) try (CloseableIteration<? extends Statement, SailException> scanner = getStatements(null, null, null, true, contexts)) { while (scanner.hasNext()) { scanner.next(); size++; } } return size; } HBaseSail(Configuration config, String tableName, boolean create, int splitBits, boolean pushStrategy, int evaluationTimeout, String elasticIndexURL, Ticker ticker); @Override void setDataDir(File dataDir); @Override File getDataDir(); @Override void initialize(); @Override FederatedService getService(String serviceUrl); @Override boolean ask(Service service, BindingSet bindings, String baseUri); @Override CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri); @Override CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Service service, CloseableIteration<BindingSet, QueryEvaluationException> bindings, String baseUri); @Override boolean isInitialized(); @Override void shutdown(); @Override void shutDown(); @Override boolean isWritable(); @Override SailConnection getConnection(); @Override ValueFactory getValueFactory(); @Override List<IsolationLevel> getSupportedIsolationLevels(); @Override IsolationLevel getDefaultIsolationLevel(); @Override boolean isOpen(); @Override void close(); @Override CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings, final boolean includeInferred); @Override CloseableIteration<? extends Resource, SailException> getContextIDs(); @Override CloseableIteration<? extends Statement, SailException> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override synchronized long size(Resource... contexts); @Override void begin(); @Override void begin(IsolationLevel level); @Override void flush(); @Override void prepare(); @Override void commit(); @Override void rollback(); @Override boolean isActive(); @Override void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, Resource... contexts); @Override void addStatement(Resource subj, IRI pred, Value obj, Resource... contexts); @Override void removeStatement(UpdateContext op, Resource subj, IRI pred, Value obj, Resource... contexts); @Override void removeStatements(Resource subj, IRI pred, Value obj, Resource... contexts); @Override boolean pendingRemovals(); @Override void startUpdate(UpdateContext op); @Override void endUpdate(UpdateContext op); @Override void clear(Resource... contexts); @Override String getNamespace(String prefix); @Override CloseableIteration<? extends Namespace, SailException> getNamespaces(); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces();  }