private Stream<Record> filter(final Stream<Record> stream, @Nullable final XPath xpath) { if (xpath == null) { return stream; } return stream.filter(xpath.asPredicate(), 0); }
@Override public Stream<Record> retrieve(URI type, @Nullable XPath condition, @Nullable Set<? extends URI> properties) throws IOException, IllegalArgumentException, IllegalStateException { String tableName = getTableName(type); List<Record> returns = new ArrayList<>(); logger.debug("Retrieving all lines"); String query = selectAllQuery.replace("$tableName", tableName); try { Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(query); while (resultSet.next()) { Record r = unserializeRecord(resultSet.getBytes("value")); if (condition != null && !condition.evalBoolean(r)) { continue; } if (properties != null) { r.retain(Iterables.toArray(properties, URI.class)); } returns.add(r); } } catch (SQLException e) { throw new IOException(e); } return Stream.create(returns); }
private static Object convertSingle(final Object object, final Class<?> type) { if (type == XPath.class) { return object instanceof XPath || object == null ? (XPath) object : // XPath.parse((String) convertSingle(object, String.class)); } else { return Data.convert(object, type); } }
&& !props.containsAll(condition.getProperties())) { props = Sets.union(properties, condition.getProperties()); stream = stream.filter(condition.asPredicate(), 0);
@Override public long count(final URI type, @Nullable final XPath condition) throws IOException, IllegalArgumentException, IllegalStateException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("{} - counting {}{}", this, Data.toString(type, Data.getNamespaceMap()), // condition == null ? "" : ", " + condition.toString()); final long ts = System.currentTimeMillis(); final long result = super.count(type, condition); LOGGER.debug("{} - count result {} obtained in {} ms", this, result, System.currentTimeMillis() - ts); return result; } else { return super.count(type, condition); } }
@Override protected long doCount(@Nullable final Long timeout, final URI type, @Nullable final XPath condition, @Nullable final Set<URI> ids) throws Throwable { // Try to transform a retrieve with condition to a faster lookup, if possible final Set<URI> actualIDs = ids != null ? ids : retrieveToLookup(type, condition); // If IDs have been supplied, we prefer to retrieve the records and apply the optional // condition locally (more efficient if few IDs are used) if (actualIDs != null) { return doRetrieve(timeout, type, condition, actualIDs, condition == null ? null : condition.getProperties(), null, null).count(); } // Otherwise, we resort to the count operation within a read-only datastore TX final DataTransaction tx = Server.this.dataStore.begin(true); try { return tx.count(type, condition); } finally { tx.end(true); // commit or rollback irrelevant } }
condition.decompose(restrictions);
@Override public Stream<Record> retrieve(final URI type, @Nullable final XPath condition, @Nullable final Set<? extends URI> properties) throws IOException, IllegalArgumentException, IllegalStateException { if (LOGGER.isDebugEnabled()) { final String name = "retrieve() result stream for " + Data.toString(type, Data.getNamespaceMap()) + (condition == null ? "" : ", " + condition.toString()) + (properties == null ? "" : ", " + properties.size() + " properties"); final long ts = System.currentTimeMillis(); final Stream<Record> result = super.retrieve(type, condition, properties); LOGGER.debug("{} - {} obtained in {} ms", this, name, System.currentTimeMillis() - ts); return logClose(result, name, ts); } else { return super.retrieve(type, condition, properties); } }
@Override public Stream<Record> retrieve(URI type, @Nullable XPath condition, @Nullable Set<? extends URI> properties) throws IOException, IllegalArgumentException, IllegalStateException { optimize(type); List<Record> returns = new ArrayList<>(); for (int i = 0; i < readers.get(type).numDocs(); i++) { Document doc = readers.get(type).document(i); Record r = unserializeRecord(doc.getBinaryValue(VALUE_NAME), serializer); if (condition != null && !condition.evalBoolean(r)) { continue; } if (properties != null) { r.retain(Iterables.toArray(properties, URI.class)); } returns.add(r); } return Stream.create(returns); }
recordStream = recordStream.filter(condition.asPredicate(), 1);
&& (condition == null || condition.evalBoolean(oldRecord))) { final URI oldInvocationID = getInvocationID(); setInvocationID(factory.createURI(oldInvocationID + "#"