@Override public boolean exists(final ObjectId id) { checkNotNull(id, "argument id is null"); checkState(isOpen(), "Database is closed"); config.checkRepositoryExists(); if (sharedCache.contains(id)) { return true; } final String sql = format( "SELECT TRUE WHERE EXISTS ( SELECT 1 FROM %s WHERE ((id).h1) = ? AND id = CAST(ROW(?,?,?) AS OBJECTID) )", objectsTable()); final PGId pgid = PGId.valueOf(id); try (Connection cx = PGStorage.newConnection(dataSource)) { try (PreparedStatement ps = cx.prepareStatement(log(sql, LOG, id))) { ps.setInt(1, pgid.hash1()); pgid.setArgs(ps, 2); try (ResultSet rs = ps.executeQuery()) { boolean exists = rs.next(); return exists; } } } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public boolean exists(final ObjectId id) { checkNotNull(id, "argument id is null"); checkState(isOpen(), "Database is closed"); config.checkRepositoryExists(); if (sharedCache.contains(id)) { return true; } final String sql = format( "SELECT TRUE WHERE EXISTS ( SELECT 1 FROM %s WHERE ((id).h1) = ? AND id = CAST(ROW(?,?,?) AS OBJECTID) )", objectsTable()); final PGId pgid = PGId.valueOf(id); try (Connection cx = PGStorage.newConnection(dataSource)) { try (PreparedStatement ps = cx.prepareStatement(log(sql, LOG, id))) { ps.setInt(1, pgid.hash1()); pgid.setArgs(ps, 2); try (ResultSet rs = ps.executeQuery()) { boolean exists = rs.next(); return exists; } } } catch (SQLException e) { throw propagate(e); } }