Skip to content

Commit

Permalink
Remove getBinaryFileLevel from the public API (#294)
Browse files Browse the repository at this point in the history
Clean up some ResultSet code
  • Loading branch information
bmeike committed May 23, 2024
1 parent b1c67ed commit 86ff95a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
1 change: 0 additions & 1 deletion common/jni_android.ld
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ CBL {
Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_shareDbCollections;
Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_startHttp;
Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_startTls;
Java_com_couchbase_lite_internal_core_impl_NativeC4Log_getBinaryFileLevel;
Java_com_couchbase_lite_internal_core_impl_NativeC4Log_log;
Java_com_couchbase_lite_internal_core_impl_NativeC4Log_setBinaryFileLevel;
Java_com_couchbase_lite_internal_core_impl_NativeC4Log_setCallbackLevel;
Expand Down
4 changes: 2 additions & 2 deletions common/main/java/com/couchbase/lite/AbstractQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public ResultSet execute() throws CouchbaseLiteException {
}
}

return new ResultSet(this, c4enum, new HashMap<>(colNames));
return new ResultSet(getDatabase(), c4enum, new HashMap<>(colNames));
}
catch (LiteCoreException e) {
throw CouchbaseLiteException.convertException(e);
Expand Down Expand Up @@ -338,7 +338,7 @@ private void onQueryChanged(
@NonNull ChangeListenerToken<QueryChange> token,
@Nullable C4QueryEnumerator results,
@Nullable LiteCoreException err) {
token.postChange(new QueryChange(this, new ResultSet(this, results, columnNames), err));
token.postChange(new QueryChange(this, new ResultSet(getDatabase(), results, columnNames), err));
}

@NonNull
Expand Down
28 changes: 11 additions & 17 deletions common/main/java/com/couchbase/lite/ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public class ResultSet implements Iterable<Result>, AutoCloseable {
@NonNull
private final Object lock = new Object();

@NonNull
private final AbstractQuery query;
@NonNull
private final Map<String, Integer> columnNames;
@NonNull
Expand All @@ -82,12 +80,11 @@ public class ResultSet implements Iterable<Result>, AutoCloseable {

// This object is the sole owner of the c4enum passed as the second argument.
ResultSet(
@NonNull AbstractQuery query,
@Nullable AbstractDatabase database,
@Nullable C4QueryEnumerator c4enum,
@NonNull Map<String, Integer> cols) {
this.query = Preconditions.assertNotNull(query, "query");
this.columnNames = Preconditions.assertNotNull(cols, "columns");
this.context = new ResultContext(query.getDatabase(), this);
this.context = new ResultContext(database, this);
this.c4enum = c4enum;
}

Expand Down Expand Up @@ -142,10 +139,6 @@ public List<Result> allResults() {
return results;
}

//---------------------------------------------
// Iterable implementation
//---------------------------------------------

/**
* Return Iterator of Results.
* <p>Caution: {@link ResultSet#next}, {@link ResultSet#allResults} and {@link ResultSet#iterator}
Expand All @@ -157,6 +150,10 @@ public List<Result> allResults() {
@Override
public Iterator<Result> iterator() { return allResults().iterator(); }

public boolean isClosed() {
synchronized (lock) { return c4enum == null; }
}

@Override
public void close() {
final C4QueryEnumerator qEnum;
Expand All @@ -172,6 +169,10 @@ public void close() {
synchronized (db.getDbLock()) { qEnum.close(); }
}

//---------------------------------------------
// Protected access
//---------------------------------------------

@Override
protected void finalize() throws Throwable {
try {
Expand All @@ -188,12 +189,9 @@ protected void finalize() throws Throwable {
}

//---------------------------------------------
// Package level access
// Package access
//---------------------------------------------

@NonNull
AbstractQuery getQuery() { return query; }

int getColumnCount() { return columnNames.size(); }

@NonNull
Expand All @@ -203,10 +201,6 @@ int getColumnIndex(@NonNull String name) {
final Integer idx = columnNames.get(name);
return (idx == null) ? -1 : idx;
}

boolean isClosed() {
synchronized (lock) { return c4enum == null; }
}
}


0 comments on commit 86ff95a

Please sign in to comment.