Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,34 @@
<differenceType>8001</differenceType>
</difference>

<difference>
<className>org/neo4j/driver/Bookmark</className>
<differenceType>7002</differenceType>
<method>org.neo4j.driver.Bookmark from(java.util.Set)</method>
</difference>

<difference>
<className>org/neo4j/driver/Bookmark</className>
<differenceType>7002</differenceType>
<method>boolean isEmpty()</method>
</difference>

<difference>
<className>org/neo4j/driver/Bookmark</className>
<differenceType>7002</differenceType>
<method>java.util.Set values()</method>
</difference>

<difference>
<className>org/neo4j/driver/Session</className>
<differenceType>7002</differenceType>
<method>org.neo4j.driver.Bookmark lastBookmark()</method>
</difference>

<difference>
<className>org/neo4j/driver/async/AsyncSession</className>
<differenceType>7002</differenceType>
<method>org.neo4j.driver.Bookmark lastBookmark()</method>
</difference>

</differences>
30 changes: 1 addition & 29 deletions driver/src/main/java/org/neo4j/driver/Bookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.neo4j.driver;

import java.util.Collections;
import java.util.Set;
import org.neo4j.driver.internal.InternalBookmark;

/**
Expand All @@ -39,39 +37,13 @@ public interface Bookmark {
*/
String value();

/**
* Returns a read-only set of bookmark strings that this bookmark instance identifies.
*
* @return a read-only set of bookmark strings that this bookmark instance identifies.
*/
@Deprecated
Set<String> values();

/**
* Reconstruct bookmark from bookmark string value.
*
* @param value value obtained from a previous bookmark.
* @return A bookmark.
*/
static Bookmark from(String value) {
return InternalBookmark.parse(Collections.singleton(value));
return new InternalBookmark(value);
}

/**
* Reconstruct bookmark from bookmarks string values.
*
* @param values values obtained from a previous bookmark.
* @return A bookmark.
*/
@Deprecated
static Bookmark from(Set<String> values) {
return InternalBookmark.parse(values);
}

/**
* Return true if the bookmark is empty.
* @return true if the bookmark is empty.
*/
@Deprecated
boolean isEmpty();
}
11 changes: 0 additions & 11 deletions driver/src/main/java/org/neo4j/driver/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,6 @@ default void executeWriteWithoutResult(Consumer<TransactionContext> contextConsu
*/
Result run(Query query, TransactionConfig config);

/**
* Return the last bookmark of this session.
* <p>
* When no new bookmark is received, the initial bookmarks are returned as a composite {@link Bookmark} containing all initial bookmarks. This may happen
* when no work has been done using the session. If no initial bookmarks have been provided, an empty {@link Bookmark} is returned.
*
* @return the last bookmark.
*/
@Deprecated
Bookmark lastBookmark();

/**
* Return a set of last bookmarks.
* <p>
Expand Down
11 changes: 0 additions & 11 deletions driver/src/main/java/org/neo4j/driver/async/AsyncSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,6 @@ <T> CompletionStage<T> executeWriteAsync(
*/
CompletionStage<ResultCursor> runAsync(Query query, TransactionConfig config);

/**
* Return the last bookmark of this session.
* <p>
* When no new bookmark is received, the initial bookmarks are returned as a composite {@link Bookmark} containing all initial bookmarks. This may happen
* when no work has been done using the session. If no initial bookmarks have been provided, an empty {@link Bookmark} is returned.
*
* @return the last bookmark.
*/
@Deprecated
Bookmark lastBookmark();

/**
* Return a set of last bookmarks.
* <p>
Expand Down
116 changes: 5 additions & 111 deletions driver/src/main/java/org/neo4j/driver/internal/InternalBookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,120 +18,14 @@

import static java.util.Objects.requireNonNull;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.neo4j.driver.Bookmark;
import org.neo4j.driver.internal.util.Iterables;

public final class InternalBookmark implements Bookmark, Serializable {
@Serial
private static final long serialVersionUID = 8196096018245038950L;

private static final InternalBookmark EMPTY = new InternalBookmark(Collections.emptySet());

@SuppressWarnings("serial")
private final Set<String> values;

private InternalBookmark(Set<String> values) {
requireNonNull(values);
this.values = values;
}

public static Bookmark empty() {
return EMPTY;
}

@SuppressWarnings("deprecation")
public static Bookmark from(Iterable<Bookmark> bookmarks) {
if (bookmarks == null) {
return empty();
}

var size = Iterables.count(bookmarks);
if (size == 0) {
return empty();
} else if (size == 1) {
return from(bookmarks.iterator().next());
}

Set<String> newValues = new HashSet<>();
for (var value : bookmarks) {
if (value == null) {
continue; // skip any null bookmark value
}
newValues.addAll(value.values());
}
return new InternalBookmark(newValues);
}

private static Bookmark from(Bookmark bookmark) {
if (bookmark == null) {
return empty();
}
// it is safe to return the given bookmark as bookmarks values can not be modified once it is created.
return bookmark;
}

/**
* Used to extract bookmark from metadata from server.
*/
public static Bookmark parse(String value) {
if (value == null) {
return empty();
public record InternalBookmark(String value) implements Bookmark, Serializable {
public InternalBookmark {
requireNonNull(value);
if (value.isEmpty()) {
throw new IllegalArgumentException("The value must not be empty");
}
return new InternalBookmark(Collections.singleton(value));
}

/**
* Used to reconstruct bookmark from values.
*/
public static Bookmark parse(Set<String> values) {
if (values == null) {
return empty();
}
return new InternalBookmark(values);
}

@Override
@Deprecated
public boolean isEmpty() {
return values.isEmpty();
}

@Override
public String value() {
return values.isEmpty() ? null : values.iterator().next();
}

@Override
@Deprecated
public Set<String> values() {
return Collections.unmodifiableSet(values);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var bookmark = (InternalBookmark) o;
return Objects.equals(values, bookmark.values);
}

@Override
public int hashCode() {
return Objects.hash(values);
}

@Override
public String toString() {
return "Bookmark{values=" + values + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ public <T> T executeWrite(TransactionCallback<T> callback, TransactionConfig con
return execute(AccessMode.WRITE, callback, config, TelemetryApi.MANAGED_TRANSACTION, true);
}

@Override
@Deprecated
public Bookmark lastBookmark() {
return InternalBookmark.from(session.lastBookmarks());
}

@Override
public Set<Bookmark> lastBookmarks() {
return session.lastBookmarks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,8 @@ private Set<Bookmark> toDistinctSet(Iterable<Bookmark> bookmarks) {
if (bookmarks != null) {
for (var bookmark : bookmarks) {
if (bookmark != null) {
@SuppressWarnings("deprecation")
var values = bookmark.values();
var size = values.size();
if (size == 1) {
set.add(bookmark);
} else if (size > 1) {
for (var value : values) {
set.add(Bookmark.from(value));
}
}
var values = bookmark.value();
set.add(bookmark);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.neo4j.driver.async.ResultCursor;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.InternalBookmark;
import org.neo4j.driver.internal.telemetry.ApiTelemetryWork;
import org.neo4j.driver.internal.util.Futures;

Expand Down Expand Up @@ -122,12 +121,6 @@ public <T> CompletionStage<T> executeWriteAsync(
return writeTransactionAsync(tx -> callback.execute(new DelegatingAsyncTransactionContext(tx)), config);
}

@Override
@Deprecated
public Bookmark lastBookmark() {
return InternalBookmark.from(session.lastBookmarks());
}

@Override
public Set<Bookmark> lastBookmarks() {
return new HashSet<>(session.lastBookmarks());
Expand Down
Loading