Skip to content

Commit 090a891

Browse files
committed
Update bookmarks API
`Bookmark` objects should represent singular bookmark values. Multiple bookmarks will be represented as a set of bookmarks (`Set<Bookmark>`). The main API updates are highlighted below. `Bookmark` updates: - `value()` - new method - `values()` - deprecated - `isEmpty()` - deprecated `Session` and `AsyncSession` updates: - `Set<Bookmark> lastBookmarks()` - new method - `Bookmark lastBookmark()` - deprecated `ReactiveSession` updates: - `Set<Bookmark> lastBookmarks()` - new method - `Bookmark lastBookmark()` - deprecated (has not been released)
1 parent b1bf3fa commit 090a891

File tree

92 files changed

+1097
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1097
-858
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,28 @@
304304
<method>org.neo4j.driver.Value parameters(java.util.Map)</method>
305305
</difference>
306306

307+
<difference>
308+
<className>org/neo4j/driver/Bookmark</className>
309+
<differenceType>7012</differenceType>
310+
<method>org.neo4j.driver.Bookmark from(java.lang.String)</method>
311+
</difference>
312+
313+
<difference>
314+
<className>org/neo4j/driver/Bookmark</className>
315+
<differenceType>7012</differenceType>
316+
<method>java.lang.String value()</method>
317+
</difference>
318+
319+
<difference>
320+
<className>org/neo4j/driver/Session</className>
321+
<differenceType>7012</differenceType>
322+
<method>java.util.Set lastBookmarks()</method>
323+
</difference>
324+
325+
<difference>
326+
<className>org/neo4j/driver/async/AsyncSession</className>
327+
<differenceType>7012</differenceType>
328+
<method>java.util.Set lastBookmarks()</method>
329+
</difference>
330+
307331
</differences>

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.neo4j.driver;
2020

21+
import java.util.Collections;
2122
import java.util.Set;
2223

2324
import org.neo4j.driver.internal.InternalBookmark;
@@ -35,17 +36,39 @@
3536
*/
3637
public interface Bookmark
3738
{
39+
/**
40+
* Returns a string that this bookmark instance identifies.
41+
*
42+
* @return a string that this bookmark instance identifies.
43+
*/
44+
String value();
45+
3846
/**
3947
* Returns a read-only set of bookmark strings that this bookmark instance identifies.
48+
*
4049
* @return a read-only set of bookmark strings that this bookmark instance identifies.
4150
*/
51+
@Deprecated
4252
Set<String> values();
4353

4454
/**
45-
* Reconstruct bookmark from \bookmarks string values.
55+
* Reconstruct bookmark from bookmark string value.
56+
*
57+
* @param value value obtained from a previous bookmark.
58+
* @return A bookmark.
59+
*/
60+
static Bookmark from( String value )
61+
{
62+
return InternalBookmark.parse( Collections.singleton( value ) );
63+
}
64+
65+
/**
66+
* Reconstruct bookmark from bookmarks string values.
67+
*
4668
* @param values values obtained from a previous bookmark.
4769
* @return A bookmark.
4870
*/
71+
@Deprecated
4972
static Bookmark from( Set<String> values )
5073
{
5174
return InternalBookmark.parse( values );
@@ -55,5 +78,6 @@ static Bookmark from( Set<String> values )
5578
* Return true if the bookmark is empty.
5679
* @return true if the bookmark is empty.
5780
*/
81+
@Deprecated
5882
boolean isEmpty();
5983
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.neo4j.driver;
2020

2121
import java.util.Map;
22+
import java.util.Set;
2223
import java.util.function.Consumer;
2324

2425
import org.neo4j.driver.async.AsyncSession;
@@ -317,18 +318,23 @@ default void executeWriteWithoutResult( Consumer<TransactionContext> contextCons
317318
Result run(Query query, TransactionConfig config );
318319

319320
/**
320-
* Return the bookmark received following the last completed
321-
* {@linkplain Transaction transaction}. If no bookmark was received
322-
* or if this transaction was rolled back, the bookmark value will
323-
* be null.
321+
* Return the bookmark received following the last completed {@linkplain Transaction transaction}. If no bookmark was received or if this transaction was
322+
* rolled back, the bookmark value will be null.
324323
*
325324
* @return a reference to a previous transaction
326325
*/
326+
@Deprecated
327327
Bookmark lastBookmark();
328328

329329
/**
330-
* Signal that you are done using this session. In the default driver usage, closing and accessing sessions is
331-
* very low cost.
330+
* Return an immutable set of bookmarks known by this session.
331+
*
332+
* @return the set of bookmarks.
333+
*/
334+
Set<Bookmark> lastBookmarks();
335+
336+
/**
337+
* Signal that you are done using this session. In the default driver usage, closing and accessing sessions is very low cost.
332338
*/
333339
@Override
334340
void close();

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Optional;
2727

2828
import org.neo4j.driver.async.AsyncSession;
29+
import org.neo4j.driver.reactive.ReactiveSession;
2930
import org.neo4j.driver.reactive.RxSession;
3031

3132
import static java.util.Objects.requireNonNull;
@@ -186,14 +187,12 @@ private Builder()
186187
/**
187188
* Set the initial bookmarks to be used in a session.
188189
* <p>
189-
* First transaction in a session will ensure that server hosting is at least as up-to-date as the
190-
* latest transaction referenced by the supplied bookmarks.
191-
* The bookmarks can be obtained via {@link Session#lastBookmark()}, {@link AsyncSession#lastBookmark()},
192-
* and/or {@link RxSession#lastBookmark()}.
190+
* First transaction in a session will ensure that server hosting is at least as up-to-date as the latest transaction referenced by the supplied
191+
* bookmarks. The bookmarks can be obtained via {@link Session#lastBookmarks()}, {@link AsyncSession#lastBookmarks()}, and/or {@link
192+
* ReactiveSession#lastBookmarks()}.
193193
*
194-
* @param bookmarks a series of initial bookmarks.
195-
* Both {@code null} value and empty array
196-
* are permitted, and indicate that the bookmarks do not exist or are unknown.
194+
* @param bookmarks a series of initial bookmarks. Both {@code null} value and empty array are permitted, and indicate that the bookmarks do not exist
195+
* or are unknown.
197196
* @return this builder.
198197
*/
199198
public Builder withBookmarks( Bookmark... bookmarks )
@@ -210,14 +209,22 @@ public Builder withBookmarks( Bookmark... bookmarks )
210209
}
211210

212211
/**
213-
* Set the initial bookmarks to be used in a session.
214-
* First transaction in a session will ensure that server hosting is at least as up-to-date as the
215-
* latest transaction referenced by the supplied bookmarks.
216-
* The bookmarks can be obtained via {@link Session#lastBookmark()}, {@link AsyncSession#lastBookmark()},
217-
* and/or {@link RxSession#lastBookmark()}.
212+
* Set the initial bookmarks to be used in a session. First transaction in a session will ensure that server hosting is at least as up-to-date as the
213+
* latest transaction referenced by the supplied bookmarks. The bookmarks can be obtained via {@link Session#lastBookmarks()}, {@link
214+
* AsyncSession#lastBookmarks()}, and/or {@link ReactiveSession#lastBookmarks()}.
215+
* <p>
216+
* Multiple immutable sets of bookmarks may be joined in the following way:
217+
* <pre>
218+
* {@code
219+
* Set<Bookmark> bookmarks = new HashSet<>();
220+
* bookmarks.addAll( session1.lastBookmarks() );
221+
* bookmarks.addAll( session2.lastBookmarks() );
222+
* bookmarks.addAll( session3.lastBookmarks() );
223+
* }
224+
* </pre>
218225
*
219-
* @param bookmarks initial references to some previous transactions. Both {@code null} value and empty iterable
220-
* are permitted, and indicate that the bookmarks do not exist or are unknown.
226+
* @param bookmarks initial references to some previous transactions. Both {@code null} value and empty iterable are permitted, and indicate that the
227+
* bookmarks do not exist or are unknown.
221228
* @return this builder
222229
*/
223230
public Builder withBookmarks( Iterable<Bookmark> bookmarks )

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.neo4j.driver.async;
2020

2121
import java.util.Map;
22+
import java.util.Set;
2223
import java.util.concurrent.CompletableFuture;
2324
import java.util.concurrent.CompletionStage;
2425
import java.util.concurrent.Executor;
@@ -389,8 +390,16 @@ default <T> CompletionStage<T> executeWriteAsync( AsyncTransactionCallback<Compl
389390
*
390391
* @return a reference to a previous transaction
391392
*/
393+
@Deprecated
392394
Bookmark lastBookmark();
393395

396+
/**
397+
* Return an immutable set of bookmarks known by this session.
398+
*
399+
* @return the set of bookmarks.
400+
*/
401+
Set<Bookmark> lastBookmarks();
402+
394403
/**
395404
* Signal that you are done using this session. In the default driver usage, closing and accessing sessions is
396405
* very low cost.

driver/src/main/java/org/neo4j/driver/internal/BookmarkHolder.java renamed to driver/src/main/java/org/neo4j/driver/internal/BookmarksHolder.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21+
import java.util.Collections;
22+
import java.util.Set;
23+
2124
import org.neo4j.driver.Bookmark;
2225

23-
public interface BookmarkHolder
26+
public interface BookmarksHolder
2427
{
25-
Bookmark getBookmark();
28+
Set<Bookmark> getBookmarks();
2629

2730
void setBookmark( Bookmark bookmark );
2831

29-
BookmarkHolder NO_OP = new BookmarkHolder()
32+
BookmarksHolder NO_OP = new BookmarksHolder()
3033
{
3134
@Override
32-
public Bookmark getBookmark()
35+
public Set<Bookmark> getBookmarks()
3336
{
34-
return InternalBookmark.empty();
37+
return Collections.emptySet();
3538
}
3639

3740
@Override

driver/src/main/java/org/neo4j/driver/internal/DefaultBookmarkHolder.java renamed to driver/src/main/java/org/neo4j/driver/internal/DefaultBookmarksHolder.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,41 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21+
import java.util.Collections;
22+
import java.util.Set;
23+
2124
import org.neo4j.driver.Bookmark;
2225

2326
/**
2427
* @since 2.0
2528
*/
26-
public class DefaultBookmarkHolder implements BookmarkHolder
29+
public class DefaultBookmarksHolder implements BookmarksHolder
2730
{
28-
private volatile Bookmark bookmark;
31+
private volatile Set<Bookmark> bookmarks;
2932

30-
public DefaultBookmarkHolder()
33+
// for testing only
34+
public DefaultBookmarksHolder()
3135
{
32-
this( InternalBookmark.empty() );
36+
this( Collections.emptySet() );
3337
}
3438

35-
public DefaultBookmarkHolder( Bookmark bookmark )
39+
public DefaultBookmarksHolder( Set<Bookmark> bookmarks )
3640
{
37-
this.bookmark = bookmark;
41+
this.bookmarks = bookmarks;
3842
}
3943

4044
@Override
41-
public Bookmark getBookmark()
45+
public Set<Bookmark> getBookmarks()
4246
{
43-
return bookmark;
47+
return bookmarks;
4448
}
4549

4650
@Override
4751
public void setBookmark( Bookmark bookmark )
4852
{
4953
if ( bookmark != null && !bookmark.isEmpty() )
5054
{
51-
this.bookmark = bookmark;
55+
bookmarks = Collections.singleton( bookmark );
5256
}
5357
}
5458
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public boolean isEmpty()
117117
return values.isEmpty();
118118
}
119119

120+
@Override
121+
public String value()
122+
{
123+
return values.isEmpty() ? null : values.iterator().next();
124+
}
125+
120126
@Override
121127
public Set<String> values()
122128
{

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.neo4j.driver.internal;
2020

2121
import java.util.Map;
22+
import java.util.Set;
2223

2324
import org.neo4j.driver.AccessMode;
2425
import org.neo4j.driver.Bookmark;
@@ -140,7 +141,13 @@ public <T> T executeWrite( TransactionCallback<T> callback, TransactionConfig co
140141
@Override
141142
public Bookmark lastBookmark()
142143
{
143-
return session.lastBookmark();
144+
return InternalBookmark.from( session.lastBookmarks() );
145+
}
146+
147+
@Override
148+
public Set<Bookmark> lastBookmarks()
149+
{
150+
return session.lastBookmarks();
144151
}
145152

146153
private <T> T transaction( AccessMode mode, TransactionWork<T> work, TransactionConfig config )
@@ -149,19 +156,21 @@ private <T> T transaction( AccessMode mode, TransactionWork<T> work, Transaction
149156
// caller thread will also be the one who sleeps between retries;
150157
// it is unsafe to execute retries in the event loop threads because this can cause a deadlock
151158
// event loop thread will bock and wait for itself to read some data
152-
return session.retryLogic().retry( () -> {
153-
try ( Transaction tx = beginTransaction( mode, config ) )
154-
{
155-
156-
T result = work.execute( tx );
157-
if ( tx.isOpen() )
159+
return session.retryLogic().retry(
160+
() ->
158161
{
159-
// commit tx if a user has not explicitly committed or rolled back the transaction
160-
tx.commit();
161-
}
162-
return result;
163-
}
164-
} );
162+
try ( Transaction tx = beginTransaction( mode, config ) )
163+
{
164+
165+
T result = work.execute( tx );
166+
if ( tx.isOpen() )
167+
{
168+
// commit tx if a user has not explicitly committed or rolled back the transaction
169+
tx.commit();
170+
}
171+
return result;
172+
}
173+
} );
165174
}
166175

167176
private Transaction beginTransaction( AccessMode mode, TransactionConfig config )

driver/src/main/java/org/neo4j/driver/internal/ReadOnlyBookmarkHolder.java renamed to driver/src/main/java/org/neo4j/driver/internal/ReadOnlyBookmarksHolder.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,26 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21+
import java.util.Set;
22+
2123
import org.neo4j.driver.Bookmark;
2224

2325
/**
2426
* @since 2.0
2527
*/
26-
public class ReadOnlyBookmarkHolder implements BookmarkHolder
28+
public class ReadOnlyBookmarksHolder implements BookmarksHolder
2729
{
28-
private final Bookmark bookmark;
30+
private final Set<Bookmark> bookmarks;
2931

30-
public ReadOnlyBookmarkHolder( Bookmark bookmark )
32+
public ReadOnlyBookmarksHolder( Set<Bookmark> bookmarks )
3133
{
32-
this.bookmark = bookmark;
34+
this.bookmarks = bookmarks;
3335
}
3436

3537
@Override
36-
public Bookmark getBookmark()
38+
public Set<Bookmark> getBookmarks()
3739
{
38-
return bookmark;
40+
return bookmarks;
3941
}
4042

4143
@Override

0 commit comments

Comments
 (0)