Skip to content

Commit f609279

Browse files
authored
Merge pull request #619 from zhenlineo/2.0-sys-bookmark
System database bookmarks.
2 parents e0d8985 + 1880b9f commit f609279

File tree

111 files changed

+2249
-2171
lines changed

Some content is hidden

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

111 files changed

+2249
-2171
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Map;
2222

2323
import org.neo4j.driver.async.AsyncSession;
24+
import org.neo4j.driver.internal.Bookmark;
2425
import org.neo4j.driver.util.Resource;
2526

2627
/**
@@ -212,7 +213,7 @@ public interface Session extends Resource, StatementRunner
212213
*
213214
* @return a reference to a previous transaction
214215
*/
215-
String lastBookmark();
216+
Bookmark lastBookmark();
216217

217218
/**
218219
* Reset the current session. This sends an immediate RESET signal to the server which both interrupts

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

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

2121
import java.util.Arrays;
22-
import java.util.List;
2322
import java.util.Objects;
2423
import java.util.Optional;
2524

2625
import org.neo4j.driver.async.AsyncSession;
26+
import org.neo4j.driver.internal.Bookmark;
2727
import org.neo4j.driver.reactive.RxSession;
2828

2929
import static java.util.Objects.requireNonNull;
@@ -36,7 +36,7 @@ public class SessionConfig
3636
{
3737
private static final SessionConfig EMPTY = builder().build();
3838

39-
private final List<String> bookmarks;
39+
private final Iterable<Bookmark> bookmarks;
4040
private final AccessMode defaultAccessMode;
4141
private final String database;
4242

@@ -85,7 +85,7 @@ public static SessionConfig forDatabase( String database )
8585
*
8686
* @return the initial bookmarks.
8787
*/
88-
public List<String> bookmarks()
88+
public Iterable<Bookmark> bookmarks()
8989
{
9090
return bookmarks;
9191
}
@@ -143,7 +143,7 @@ public String toString()
143143
*/
144144
public static class Builder
145145
{
146-
private List<String> bookmarks = null;
146+
private Iterable<Bookmark> bookmarks = null;
147147
private AccessMode defaultAccessMode = AccessMode.WRITE;
148148
private String database = null;
149149

@@ -164,11 +164,10 @@ private Builder()
164164
* are permitted, and indicate that the bookmarks do not exist or are unknown.
165165
* @return this builder.
166166
*/
167-
public Builder withBookmarks( String... bookmarks )
167+
public Builder withBookmarks( Bookmark... bookmarks )
168168
{
169169
if ( bookmarks == null )
170170
{
171-
// TODO bookmarks should not be null
172171
this.bookmarks = null;
173172
}
174173
else
@@ -189,7 +188,7 @@ public Builder withBookmarks( String... bookmarks )
189188
* are permitted, and indicate that the bookmarks do not exist or are unknown.
190189
* @return this builder
191190
*/
192-
public Builder withBookmarks( List<String> bookmarks )
191+
public Builder withBookmarks( Iterable<Bookmark> bookmarks )
193192
{
194193
this.bookmarks = bookmarks;
195194
return this;
@@ -229,7 +228,11 @@ public Builder withDatabase( String database )
229228
// Disallow users to use bolt internal value directly. To users, this is totally an illegal database name.
230229
throw new IllegalArgumentException( String.format( "Illegal database name '%s'.", database ) );
231230
}
232-
this.database = database;
231+
// The database name is normalized to lowercase on the server side.
232+
// The client in theory shall not perform any normalization at all.
233+
// However as this name is also used in routing table registry as the map's key to find the routing table for the given database,
234+
// to avoid multiple routing tables for the same database, we perform a client side normalization.
235+
this.database = database.toLowerCase();
233236
return this;
234237
}
235238

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.neo4j.driver.Transaction;
3030
import org.neo4j.driver.TransactionConfig;
3131
import org.neo4j.driver.Values;
32+
import org.neo4j.driver.internal.Bookmark;
3233

3334
/**
3435
* Provides a context of work for database interactions.
@@ -301,7 +302,7 @@ public interface AsyncSession extends AsyncStatementRunner
301302
*
302303
* @return a reference to a previous transaction
303304
*/
304-
String lastBookmark();
305+
Bookmark lastBookmark();
305306

306307
/**
307308
* Signal that you are done using this session. In the default driver usage, closing and accessing sessions is
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2002-2019 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.internal;
20+
21+
import java.io.Serializable;
22+
23+
/**
24+
* Causal chaining is carried out by passing bookmarks between transactions.
25+
*
26+
* When starting a session with initial bookmarks, the first transaction will be ensured to run at least after
27+
* the database is as up-to-date as the latest transaction referenced by the supplied bookmarks.
28+
*
29+
* Within a session, bookmark propagation is carried out automatically.
30+
* Thus all transactions in a session including explicit and implicit transactions are ensured to be carried out one after another.
31+
*
32+
* To opt out of this mechanism for unrelated units of work, applications can use multiple sessions.
33+
*/
34+
public interface Bookmark extends Serializable
35+
{
36+
}

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

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

21-
public interface BookmarksHolder
21+
public interface BookmarkHolder
2222
{
23-
Bookmarks getBookmarks();
23+
InternalBookmark getBookmark();
2424

25-
void setBookmarks( Bookmarks bookmarks );
25+
void setBookmark( InternalBookmark bookmark );
2626

27-
String lastBookmark();
28-
29-
BookmarksHolder NO_OP = new BookmarksHolder()
27+
BookmarkHolder NO_OP = new BookmarkHolder()
3028
{
3129
@Override
32-
public Bookmarks getBookmarks()
33-
{
34-
return Bookmarks.empty();
35-
}
36-
37-
@Override
38-
public void setBookmarks( Bookmarks bookmarks )
30+
public InternalBookmark getBookmark()
3931
{
32+
return InternalBookmark.empty();
4033
}
4134

4235
@Override
43-
public String lastBookmark()
36+
public void setBookmark( InternalBookmark bookmark )
4437
{
45-
return null;
4638
}
4739
};
4840
}

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

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)