Skip to content

Commit e601422

Browse files
committed
feat(bookmarks): delete deprecated multi value support in Bookmark
BREAKING CHANGE: the `org.neo4j.driver.Bookmark` no longer supports having multiple bookmark values, multiple values are supportted by simply having multiple instances of `Bookmark`
1 parent 9721aed commit e601422

22 files changed

+211
-562
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,34 @@
682682
<differenceType>8001</differenceType>
683683
</difference>
684684

685+
<difference>
686+
<className>org/neo4j/driver/Bookmark</className>
687+
<differenceType>7002</differenceType>
688+
<method>org.neo4j.driver.Bookmark from(java.util.Set)</method>
689+
</difference>
690+
691+
<difference>
692+
<className>org/neo4j/driver/Bookmark</className>
693+
<differenceType>7002</differenceType>
694+
<method>boolean isEmpty()</method>
695+
</difference>
696+
697+
<difference>
698+
<className>org/neo4j/driver/Bookmark</className>
699+
<differenceType>7002</differenceType>
700+
<method>java.util.Set values()</method>
701+
</difference>
702+
703+
<difference>
704+
<className>org/neo4j/driver/Session</className>
705+
<differenceType>7002</differenceType>
706+
<method>org.neo4j.driver.Bookmark lastBookmark()</method>
707+
</difference>
708+
709+
<difference>
710+
<className>org/neo4j/driver/async/AsyncSession</className>
711+
<differenceType>7002</differenceType>
712+
<method>org.neo4j.driver.Bookmark lastBookmark()</method>
713+
</difference>
714+
685715
</differences>

driver/src/main/java/org/neo4j/driver/Bookmark.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.neo4j.driver;
1818

19-
import java.util.Collections;
20-
import java.util.Set;
2119
import org.neo4j.driver.internal.InternalBookmark;
2220

2321
/**
@@ -39,39 +37,13 @@ public interface Bookmark {
3937
*/
4038
String value();
4139

42-
/**
43-
* Returns a read-only set of bookmark strings that this bookmark instance identifies.
44-
*
45-
* @return a read-only set of bookmark strings that this bookmark instance identifies.
46-
*/
47-
@Deprecated
48-
Set<String> values();
49-
5040
/**
5141
* Reconstruct bookmark from bookmark string value.
5242
*
5343
* @param value value obtained from a previous bookmark.
5444
* @return A bookmark.
5545
*/
5646
static Bookmark from(String value) {
57-
return InternalBookmark.parse(Collections.singleton(value));
47+
return new InternalBookmark(value);
5848
}
59-
60-
/**
61-
* Reconstruct bookmark from bookmarks string values.
62-
*
63-
* @param values values obtained from a previous bookmark.
64-
* @return A bookmark.
65-
*/
66-
@Deprecated
67-
static Bookmark from(Set<String> values) {
68-
return InternalBookmark.parse(values);
69-
}
70-
71-
/**
72-
* Return true if the bookmark is empty.
73-
* @return true if the bookmark is empty.
74-
*/
75-
@Deprecated
76-
boolean isEmpty();
7749
}

driver/src/main/java/org/neo4j/driver/Session.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,6 @@ default void executeWriteWithoutResult(Consumer<TransactionContext> contextConsu
308308
*/
309309
Result run(Query query, TransactionConfig config);
310310

311-
/**
312-
* Return the last bookmark of this session.
313-
* <p>
314-
* When no new bookmark is received, the initial bookmarks are returned as a composite {@link Bookmark} containing all initial bookmarks. This may happen
315-
* when no work has been done using the session. If no initial bookmarks have been provided, an empty {@link Bookmark} is returned.
316-
*
317-
* @return the last bookmark.
318-
*/
319-
@Deprecated
320-
Bookmark lastBookmark();
321-
322311
/**
323312
* Return a set of last bookmarks.
324313
* <p>

driver/src/main/java/org/neo4j/driver/async/AsyncSession.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,6 @@ <T> CompletionStage<T> executeWriteAsync(
381381
*/
382382
CompletionStage<ResultCursor> runAsync(Query query, TransactionConfig config);
383383

384-
/**
385-
* Return the last bookmark of this session.
386-
* <p>
387-
* When no new bookmark is received, the initial bookmarks are returned as a composite {@link Bookmark} containing all initial bookmarks. This may happen
388-
* when no work has been done using the session. If no initial bookmarks have been provided, an empty {@link Bookmark} is returned.
389-
*
390-
* @return the last bookmark.
391-
*/
392-
@Deprecated
393-
Bookmark lastBookmark();
394-
395384
/**
396385
* Return a set of last bookmarks.
397386
* <p>

driver/src/main/java/org/neo4j/driver/internal/InternalBookmark.java

Lines changed: 5 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -18,120 +18,14 @@
1818

1919
import static java.util.Objects.requireNonNull;
2020

21-
import java.io.Serial;
2221
import java.io.Serializable;
23-
import java.util.Collections;
24-
import java.util.HashSet;
25-
import java.util.Objects;
26-
import java.util.Set;
2722
import org.neo4j.driver.Bookmark;
28-
import org.neo4j.driver.internal.util.Iterables;
2923

30-
public final class InternalBookmark implements Bookmark, Serializable {
31-
@Serial
32-
private static final long serialVersionUID = 8196096018245038950L;
33-
34-
private static final InternalBookmark EMPTY = new InternalBookmark(Collections.emptySet());
35-
36-
@SuppressWarnings("serial")
37-
private final Set<String> values;
38-
39-
private InternalBookmark(Set<String> values) {
40-
requireNonNull(values);
41-
this.values = values;
42-
}
43-
44-
public static Bookmark empty() {
45-
return EMPTY;
46-
}
47-
48-
@SuppressWarnings("deprecation")
49-
public static Bookmark from(Iterable<Bookmark> bookmarks) {
50-
if (bookmarks == null) {
51-
return empty();
52-
}
53-
54-
var size = Iterables.count(bookmarks);
55-
if (size == 0) {
56-
return empty();
57-
} else if (size == 1) {
58-
return from(bookmarks.iterator().next());
59-
}
60-
61-
Set<String> newValues = new HashSet<>();
62-
for (var value : bookmarks) {
63-
if (value == null) {
64-
continue; // skip any null bookmark value
65-
}
66-
newValues.addAll(value.values());
67-
}
68-
return new InternalBookmark(newValues);
69-
}
70-
71-
private static Bookmark from(Bookmark bookmark) {
72-
if (bookmark == null) {
73-
return empty();
74-
}
75-
// it is safe to return the given bookmark as bookmarks values can not be modified once it is created.
76-
return bookmark;
77-
}
78-
79-
/**
80-
* Used to extract bookmark from metadata from server.
81-
*/
82-
public static Bookmark parse(String value) {
83-
if (value == null) {
84-
return empty();
24+
public record InternalBookmark(String value) implements Bookmark, Serializable {
25+
public InternalBookmark {
26+
requireNonNull(value);
27+
if (value.isEmpty()) {
28+
throw new IllegalArgumentException("The value must not be empty");
8529
}
86-
return new InternalBookmark(Collections.singleton(value));
87-
}
88-
89-
/**
90-
* Used to reconstruct bookmark from values.
91-
*/
92-
public static Bookmark parse(Set<String> values) {
93-
if (values == null) {
94-
return empty();
95-
}
96-
return new InternalBookmark(values);
97-
}
98-
99-
@Override
100-
@Deprecated
101-
public boolean isEmpty() {
102-
return values.isEmpty();
103-
}
104-
105-
@Override
106-
public String value() {
107-
return values.isEmpty() ? null : values.iterator().next();
108-
}
109-
110-
@Override
111-
@Deprecated
112-
public Set<String> values() {
113-
return Collections.unmodifiableSet(values);
114-
}
115-
116-
@Override
117-
public boolean equals(Object o) {
118-
if (this == o) {
119-
return true;
120-
}
121-
if (o == null || getClass() != o.getClass()) {
122-
return false;
123-
}
124-
var bookmark = (InternalBookmark) o;
125-
return Objects.equals(values, bookmark.values);
126-
}
127-
128-
@Override
129-
public int hashCode() {
130-
return Objects.hash(values);
131-
}
132-
133-
@Override
134-
public String toString() {
135-
return "Bookmark{values=" + values + "}";
13630
}
13731
}

driver/src/main/java/org/neo4j/driver/internal/InternalSession.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ public <T> T executeWrite(TransactionCallback<T> callback, TransactionConfig con
132132
return execute(AccessMode.WRITE, callback, config, TelemetryApi.MANAGED_TRANSACTION, true);
133133
}
134134

135-
@Override
136-
@Deprecated
137-
public Bookmark lastBookmark() {
138-
return InternalBookmark.from(session.lastBookmarks());
139-
}
140-
141135
@Override
142136
public Set<Bookmark> lastBookmarks() {
143137
return session.lastBookmarks();

driver/src/main/java/org/neo4j/driver/internal/SessionFactoryImpl.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,8 @@ private Set<Bookmark> toDistinctSet(Iterable<Bookmark> bookmarks) {
101101
if (bookmarks != null) {
102102
for (var bookmark : bookmarks) {
103103
if (bookmark != null) {
104-
@SuppressWarnings("deprecation")
105-
var values = bookmark.values();
106-
var size = values.size();
107-
if (size == 1) {
108-
set.add(bookmark);
109-
} else if (size > 1) {
110-
for (var value : values) {
111-
set.add(Bookmark.from(value));
112-
}
113-
}
104+
var values = bookmark.value();
105+
set.add(bookmark);
114106
}
115107
}
116108
}

driver/src/main/java/org/neo4j/driver/internal/async/InternalAsyncSession.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.neo4j.driver.async.ResultCursor;
3737
import org.neo4j.driver.exceptions.ClientException;
3838
import org.neo4j.driver.internal.GqlStatusError;
39-
import org.neo4j.driver.internal.InternalBookmark;
4039
import org.neo4j.driver.internal.telemetry.ApiTelemetryWork;
4140
import org.neo4j.driver.internal.util.Futures;
4241

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

125-
@Override
126-
@Deprecated
127-
public Bookmark lastBookmark() {
128-
return InternalBookmark.from(session.lastBookmarks());
129-
}
130-
131124
@Override
132125
public Set<Bookmark> lastBookmarks() {
133126
return new HashSet<>(session.lastBookmarks());

0 commit comments

Comments
 (0)