本文整理汇总了Java中info.aduna.iteration.CloseableIteration类的典型用法代码示例。如果您正苦于以下问题:Java CloseableIteration类的具体用法?Java CloseableIteration怎么用?Java CloseableIteration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloseableIteration类属于info.aduna.iteration包,在下文中一共展示了CloseableIteration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjects
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Override
protected synchronized CloseableIteration<?, ?> getObjects() throws RepositoryException,
QueryEvaluationException {
if (creator == null || factory == null) {
return super.getObjects();
} else if (binding == null) {
ObjectQuery query = factory.createQuery(creator);
if (query == null)
return super.getObjects();
try {
query.setBinding("self", getResource());
return query.evaluate(creator.getPropertyType());
} finally {
factory.returnQuery(creator, query);
}
} else {
CloseableIteratorIteration<BindingSet, QueryEvaluationException> result;
result = new CloseableIteratorIteration<BindingSet, QueryEvaluationException>(
bindings.iterator());
return new ObjectCursor(getObjectConnection(), result, binding);
}
}
示例2: evaluate
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
/**
* Evaluates the statement pattern against the supplied sources with the
* specified set of variable bindings as input.
*
* @param sp
* The Statement Pattern to evaluate
* @param bindings
* The variables bindings to use for evaluating the expression, if
* applicable.
* @return A cursor over the variable binding sets that match the statement
* pattern.
*/
@Override
// public Cursor<BindingSet> evaluate(StatementPattern sp, BindingSet bindings) throws StoreException {
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(StatementPattern sp, BindingSet bindings) throws QueryEvaluationException {
if (sp instanceof MappedStatementPattern) {
// Set<Graph> sources = graphMap.get(sp);
Set<Graph> sources = ((MappedStatementPattern) sp).getSources();
if (LOGGER.isDebugEnabled())
LOGGER.debug("EVAL PATTERN {" + OperatorTreePrinter.print(sp) + "} on sources " + sources);
return sendSparqlQuery(sp, sources , bindings);
}
throw new IllegalArgumentException("pattern has no sources");
}
示例3: evaluateInternal
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Override
protected CloseableIteration<BindingSet, QueryEvaluationException> evaluateInternal(
TupleExpr expr, Dataset dataset, BindingSet bindings, boolean includeInferred)
throws SailException {
triples.flush();
try {
TupleExpr tupleExpr;
EvaluationStrategy strategy;
strategy = factory.createRdbmsEvaluation(dataset);
tupleExpr = optimizer.optimize(expr, dataset, bindings, strategy);
// Mexri edw to GeneralDBSqlDiffDateTime ftanei kanonika
return strategy.evaluate(tupleExpr, EmptyBindingSet.getInstance());
} catch (QueryEvaluationException e) {
throw new SailException(e);
}
}
示例4: toBindingsStream
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
public static Stream<BindingSet> toBindingsStream(
final CloseableIteration<BindingSet, QueryEvaluationException> iteration,
final Iterable<? extends String> variables) {
Preconditions.checkNotNull(iteration);
final List<String> variableList = ImmutableList.copyOf(variables);
final CompactBindingSet.Builder builder = CompactBindingSet.builder(variableList);
return Stream.create(iteration).transform(new Function<BindingSet, BindingSet>() {
@Override
@Nullable
public BindingSet apply(final BindingSet bindings) {
final int variableCount = variableList.size();
for (int i = 0; i < variableCount; ++i) {
final String variable = variableList.get(i);
builder.set(variable, bindings.getValue(variable));
}
return builder.build();
}
}, 0).setProperty(PROPERTY_VARIABLES, variableList);
}
示例5: performQuery
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
private CloseableIteration<Statement, QueryEvaluationException> performQuery(final String type, final Geometry geometry,
final StatementConstraints contraints) {
final List<String> filterParms = new ArrayList<String>();
filterParms.add(type + "(" + GEOMETRY_ATTRIBUTE + ", " + geometry + " )");
if (contraints.hasSubject()) {
filterParms.add("( " + SUBJECT_ATTRIBUTE + "= '" + contraints.getSubject() + "') ");
}
if (contraints.hasContext()) {
filterParms.add("( " + CONTEXT_ATTRIBUTE + "= '" + contraints.getContext() + "') ");
}
if (contraints.hasPredicates()) {
final List<String> predicates = new ArrayList<String>();
for (final URI u : contraints.getPredicates()) {
predicates.add("( " + PREDICATE_ATTRIBUTE + "= '" + u.stringValue() + "') ");
}
filterParms.add("(" + StringUtils.join(predicates, " OR ") + ")");
}
final String filterString = StringUtils.join(filterParms, " AND ");
logger.info("Performing geowave query : " + LogUtils.clean(filterString));
return getIteratorWrapper(filterString);
}
示例6: logClose
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Nullable
private <T, E extends Exception> CloseableIteration<T, E> logClose(
@Nullable final CloseableIteration<T, E> iteration) {
if (iteration == null || !LOGGER.isDebugEnabled()) {
return iteration;
}
final long ts = System.currentTimeMillis();
return new IterationWrapper<T, E>(iteration) {
@Override
protected void handleClose() throws E {
try {
super.handleClose();
} finally {
LOGGER.debug("Virtuoso iteration closed after {} ms",
System.currentTimeMillis() - ts);
}
}
};
}
示例7: get
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Override
public CloseableIteration<? extends Statement, ? extends Exception> get(
@Nullable final Resource subject, @Nullable final URI predicate,
@Nullable final Value object, @Nullable final Resource context)
throws IOException, IllegalStateException {
if (LOGGER.isDebugEnabled()) {
final String name = "statement iteration for <" + format(subject) + ", "
+ format(predicate) + ", " + format(object) + ", " + format(context) + ">";
final long ts = System.currentTimeMillis();
CloseableIteration<? extends Statement, ? extends Exception> result;
result = logClose(super.get(subject, predicate, object, context), name, ts);
LOGGER.debug("{} - {} obtained in {} ms", this, name, System.currentTimeMillis()
- ts);
return result;
} else {
return super.get(subject, predicate, object, context);
}
}
示例8: testMaxResults
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Test
public void testMaxResults() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri1")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri2")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri3")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri4")));
dao.add(new RyaStatement(cpu, loadPerc, new RyaURI(litdupsNS + "uri5")));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf);
long limit = 3l;
queryConf.setLimit(limit);
CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), queryConf);
int count = 0;
while (iter.hasNext()) {
iter.next().getObject();
count++;
}
iter.close();
assertEquals(limit, count);
}
示例9: testLiteralTypes
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Test
public void testLiteralTypes() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaType longLit = new RyaType(XMLSchema.LONG, "3");
dao.add(new RyaStatement(cpu, loadPerc, longLit));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, null, null), conf);
assertTrue(query.hasNext());
RyaStatement next = query.next();
assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
query.close();
RyaType doubleLit = new RyaType(XMLSchema.DOUBLE, "2.0");
dao.add(new RyaStatement(cpu, loadPerc, doubleLit));
query = queryEngine.query(new RyaStatement(cpu, loadPerc, doubleLit), conf);
assertTrue(query.hasNext());
next = query.next();
assertEquals(Double.parseDouble(doubleLit.getData()), Double.parseDouble(next.getObject().getData()), 0.001);
query.close();
}
示例10: testSameLiteralStringTypes
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Test
public void testSameLiteralStringTypes() throws Exception {
RyaURI cpu = new RyaURI(litdupsNS + "cpu");
RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
RyaType longLit = new RyaType(XMLSchema.LONG, "10");
RyaType strLit = new RyaType(XMLSchema.STRING, new String(RyaContext.getInstance().serializeType(longLit)[0]));
RyaStatement expected = new RyaStatement(cpu, loadPerc, longLit);
dao.add(expected);
dao.add(new RyaStatement(cpu, loadPerc, strLit));
AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, loadPerc, longLit), conf);
assertTrue(query.hasNext());
RyaStatement next = query.next();
assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
assertEquals(longLit.getDataType(), next.getObject().getDataType());
assertFalse(query.hasNext());
query.close();
}
示例11: countStatementsInStore
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
private int countStatementsInStore(@Nullable final TripleTransaction transaction)
throws IOException {
final TripleTransaction tx = transaction != null ? transaction : this.store.begin(true);
try {
final CloseableIteration<BindingSet, QueryEvaluationException> cursor = tx.query(
SelectQuery.from("SELECT * WHERE {?s ?p ?o}"), null, null);
int statementsCount = 0;
while (cursor.hasNext()) {
cursor.next();
statementsCount++;
}
return statementsCount;
} catch (final QueryEvaluationException ex) {
throw new IOException(ex);
} finally {
if (transaction == null) {
tx.end(true);
}
}
}
示例12: logClose
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Nullable
private <T, E extends Exception> CloseableIteration<T, E> logClose(
@Nullable final CloseableIteration<T, E> iteration) {
if (iteration == null || !LOGGER.isDebugEnabled()) {
return iteration;
}
final long ts = System.currentTimeMillis();
return new IterationWrapper<T, E>(iteration) {
@Override
protected void handleClose() throws E {
try {
super.handleClose();
} finally {
LOGGER.debug("Repository iteration closed after {} ms",
System.currentTimeMillis() - ts);
}
}
};
}
示例13: readFromBegining_positionStartsNotBegining
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
@Test
public void readFromBegining_positionStartsNotBegining() throws Exception {
final List<QueryChange> expected = write10ChangesToChangeLog();
// set the position to some non-0 position
final TopicPartition partition = new TopicPartition(topic, 0);
consumer.assign(Lists.newArrayList(partition));
consumer.seek(partition, 5L);
final CloseableIteration<ChangeLogEntry<QueryChange>, QueryChangeLogException> iter = changeLog.readFromStart();
final List<QueryChange> actual = new ArrayList<>();
while (iter.hasNext()) {
final ChangeLogEntry<QueryChange> entry = iter.next();
actual.add(entry.getEntry());
}
assertEquals(expected, actual);
}
示例14: testQueryIntervalEquals
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
/**
* Test method for
* {@link org.apache.rya.indexing.Mongo.temporal.MongoTemporalIndexer#queryIntervalEquals(TemporalInterval, StatementConstraints)}
* .
* @throws IOException
* @throws QueryEvaluationException
*
*/
@Test
public void testQueryIntervalEquals() throws IOException, QueryEvaluationException {
try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
tIndexer.setConf(conf);
tIndexer.init();
// tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
tIndexer.storeStatement(convertStatement(spo_B03_E20));
tIndexer.storeStatement(convertStatement(spo_B02_E30));
tIndexer.storeStatement(convertStatement(spo_B02_E40));
tIndexer.storeStatement(convertStatement(spo_B02_E31));
tIndexer.storeStatement(convertStatement(spo_B30_E32));
tIndexer.storeStatement(convertStatement(seriesSpo[4])); // instance at 4 seconds
CloseableIteration<Statement, QueryEvaluationException> iter;
iter = tIndexer.queryIntervalEquals(tvB02_E40, EMPTY_CONSTRAINTS);
// Should be found twice:
assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but actually returned empty results. spo_B02_E40=" + spo_B02_E40, iter.hasNext());
assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but does not match.", spo_B02_E40.equals(iter.next()));
assertFalse("queryIntervalEquals: Find no more than one, but actually has more.", iter.hasNext());
}
}
示例15: queryFirst
import info.aduna.iteration.CloseableIteration; //导入依赖的package包/类
/**
* Handles only the first result of a query. Closes the query iterator when
* done.
* @param subject the subject {@link Resource} to query for.
* @param predicate the predicate {@link URI} to query for.
* @param object the object {@link Value} to query for.
* @param rdfStatementHandler the {@link RDFHandler} to use for handling the
* first statement returned. (not {@code null})
* @param contexts the context {@link Resource}s to query for.
* @throws QueryEvaluationException
*/
public void queryFirst(final Resource subject, final URI predicate, final Value object, final RDFHandler rdfStatementHandler, final Resource... contexts) throws QueryEvaluationException {
checkNotNull(rdfStatementHandler);
final CloseableIteration<Statement, QueryEvaluationException> iter = RyaDAOHelper.query(ryaDao, subject, predicate, object, conf, contexts);
try {
if (iter.hasNext()) {
final Statement statement = iter.next();
try {
rdfStatementHandler.handleStatement(statement);
} catch (final Exception e) {
throw new QueryEvaluationException("Error handling statement.", e);
}
}
} finally {
if (iter != null) {
iter.close();
}
}
}