@Override protected void finalize() throws Throwable { close(); super.finalize(); }
/** * Returns the next element in the iteration. * * @return the next element in the iteration. * @throws java.util.NoSuchElementException if the iteration has no more elements or if it has been closed. */ @Override public E next() throws SQLException { if(moved || result.next()) { moved = false; return transformer.apply(result); } else { close(); throw new NoSuchElementException("no more results"); } }
/** * List all cache entries in the database, regardless of expiry date. * * @return a closeable iteration with KiWiCacheEntries; needs to be released by the caller * @throws SQLException */ public CloseableIteration<KiWiCacheEntry,SQLException> listAll() throws SQLException { PreparedStatement queryExpired = connection.getPreparedStatement("query.entries_all"); final ResultSet result = queryExpired.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiCacheEntry>() { @Override public KiWiCacheEntry apply(ResultSet input) throws SQLException { return constructCacheEntry(result); } }); }
/** * List all cache entries with an expiry date older than the current time. * * @return a closeable iteration with KiWiCacheEntries; needs to be released by the caller * @throws SQLException */ public CloseableIteration<KiWiCacheEntry,SQLException> listExpired() throws SQLException { PreparedStatement queryExpired = connection.getPreparedStatement("query.entries_expired"); final ResultSet result = queryExpired.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiCacheEntry>() { @Override public KiWiCacheEntry apply(ResultSet input) throws SQLException { return constructCacheEntry(result); } }); }
/** * Returns the next element in the iteration. * * @return the next element in the iteration. * @throws java.util.NoSuchElementException if the iteration has no more elements or if it has been closed. */ @Override public E next() throws SQLException { if(moved || result.next()) { moved = false; return transformer.apply(result); } else { close(); throw new NoSuchElementException("no more results"); } }
@Override protected void finalize() throws Throwable { close(); super.finalize(); }
/** * List all cache entries in the database, regardless of expiry date. * * @return a closeable iteration with KiWiCacheEntries; needs to be released by the caller * @throws SQLException */ public CloseableIteration<KiWiCacheEntry,SQLException> listAll() throws SQLException { PreparedStatement queryExpired = connection.getPreparedStatement("query.entries_all"); final ResultSet result = queryExpired.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiCacheEntry>() { @Override public KiWiCacheEntry apply(ResultSet input) throws SQLException { return constructCacheEntry(result); } }); }
/** * Returns <tt>true</tt> if the iteration has more elements. (In other * words, returns <tt>true</tt> if {@link #next} would return an element * rather than throwing a <tt>NoSuchElementException</tt>.) * * @return <tt>true</tt> if the iteration has more elements. * @throws SQLException */ @Override public boolean hasNext() throws SQLException { if(closed) { return false; } else if(moved) { return true; } else if(result.next()) { moved = true; return true; } else { close(); return false; } }
/** * List all cache entries with an expiry date older than the current time. * * @return a closeable iteration with KiWiCacheEntries; needs to be released by the caller * @throws SQLException */ public CloseableIteration<KiWiCacheEntry,SQLException> listExpired() throws SQLException { PreparedStatement queryExpired = connection.getPreparedStatement("query.entries_expired"); final ResultSet result = queryExpired.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiCacheEntry>() { @Override public KiWiCacheEntry apply(ResultSet input) throws SQLException { return constructCacheEntry(result); } }); }
/** * Returns <tt>true</tt> if the iteration has more elements. (In other * words, returns <tt>true</tt> if {@link #next} would return an element * rather than throwing a <tt>NoSuchElementException</tt>.) * * @return <tt>true</tt> if the iteration has more elements. * @throws SQLException */ @Override public boolean hasNext() throws SQLException { if(closed) { return false; } else if(moved) { return true; } else if(result.next()) { moved = true; return true; } else { close(); return false; } }
public CloseableIteration<KiWiNamespace, SQLException> listNamespaces() throws SQLException { requireJDBCConnection(); PreparedStatement queryContexts = getPreparedStatement("query.namespaces"); final ResultSet result = queryContexts.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiNamespace>() { @Override public KiWiNamespace apply(ResultSet input) throws SQLException { return constructNamespaceFromDatabase(result); } }); }
public CloseableIteration<KiWiNamespace, SQLException> listNamespaces() throws SQLException { requireJDBCConnection(); PreparedStatement queryContexts = getPreparedStatement("query.namespaces"); final ResultSet result = queryContexts.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiNamespace>() { @Override public KiWiNamespace apply(ResultSet input) throws SQLException { return constructNamespaceFromDatabase(result); } }); }
/** * List all contexts used in this triple store. See query.contexts . * @return * @throws SQLException */ public CloseableIteration<KiWiUriResource, SQLException> listResources(String prefix) throws SQLException { requireJDBCConnection(); PreparedStatement queryContexts = getPreparedStatement("query.resources_prefix"); queryContexts.setString(1, prefix + "%"); final ResultSet result = queryContexts.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiUriResource>() { @Override public KiWiUriResource apply(ResultSet row) throws SQLException { return (KiWiUriResource)constructNodeFromDatabase(row); } }); }
/** * List all contexts used in this triple store. See query.contexts . * @return * @throws SQLException */ public CloseableIteration<KiWiUriResource, SQLException> listResources(String prefix) throws SQLException { requireJDBCConnection(); PreparedStatement queryContexts = getPreparedStatement("query.resources_prefix"); queryContexts.setString(1, prefix + "%"); final ResultSet result = queryContexts.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiUriResource>() { @Override public KiWiUriResource apply(ResultSet row) throws SQLException { return (KiWiUriResource)constructNodeFromDatabase(row); } }); }
/** * List all contexts used in this triple store. See query.contexts . * @return * @throws SQLException */ public CloseableIteration<KiWiResource, SQLException> listResources() throws SQLException { requireJDBCConnection(); PreparedStatement queryContexts = getPreparedStatement("query.resources"); final ResultSet result = queryContexts.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiResource>() { @Override public KiWiResource apply(ResultSet row) throws SQLException { return (KiWiResource)constructNodeFromDatabase(row); } }); }
/** * List all contexts used in this triple store. See query.contexts . * @return * @throws SQLException */ public CloseableIteration<KiWiResource, SQLException> listResources() throws SQLException { requireJDBCConnection(); PreparedStatement queryContexts = getPreparedStatement("query.resources"); final ResultSet result = queryContexts.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiResource>() { @Override public KiWiResource apply(ResultSet row) throws SQLException { return (KiWiResource)constructNodeFromDatabase(row); } }); }
/** * List all versions in the database; operates directly on the result set, i.e. the iteration is carried out * lazily and needs to be closed when iteration is completed. * * @return * @throws SQLException */ private CloseableIteration<Version, SQLException> listVersionsInternal() throws SQLException { requireJDBCConnection(); PreparedStatement queryVersions = getPreparedStatement("load.versions"); final ResultSet result = queryVersions.executeQuery(); return new ResultSetIteration<Version>(result, new ResultTransformerFunction<Version>() { @Override public Version apply(ResultSet row) throws SQLException { return constructVersionFromDatabase(result); } }); }
/** * List all justifications supporting the given triple. * @param tripleId * @return * @throws SQLException */ public CloseableIteration<Justification,SQLException> listJustificationsForTriple(long tripleId) throws SQLException { requireJDBCConnection(); PreparedStatement listForTriple = getPreparedStatement("justifications.load_by_triple"); synchronized (listForTriple) { listForTriple.setLong(1, tripleId); ResultSet result = listForTriple.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<Justification>() { @Override public Justification apply(ResultSet row) throws SQLException { return constructJustificationFromDatabase(row); } }); } }
/** * List all triples that are not supported by at least one justification. * @return * @throws SQLException */ public CloseableIteration<KiWiTriple, SQLException> listUnsupportedTriples() throws SQLException { requireJDBCConnection(); PreparedStatement listUnsupported = getPreparedStatement("justifications.list_unsupported"); synchronized (listUnsupported) { ResultSet result = listUnsupported.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiTriple>() { @Override public KiWiTriple apply(ResultSet row) throws SQLException { return constructTripleFromDatabase(row); } }); } }
/** * List all triples that are not supported by at least one justification. * @return * @throws SQLException */ public CloseableIteration<KiWiTriple, SQLException> listUnsupportedTriples() throws SQLException { requireJDBCConnection(); PreparedStatement listUnsupported = getPreparedStatement("justifications.list_unsupported"); synchronized (listUnsupported) { ResultSet result = listUnsupported.executeQuery(); return new ResultSetIteration<>(result, new ResultTransformerFunction<KiWiTriple>() { @Override public KiWiTriple apply(ResultSet row) throws SQLException { return constructTripleFromDatabase(row); } }); } }