-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial BookmarkManager implementation
- Loading branch information
1 parent
7a0515f
commit 96c9f27
Showing
53 changed files
with
878 additions
and
455 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
driver/src/main/java/org/neo4j/driver/BookmarkManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.driver; | ||
|
||
import java.io.Serializable; | ||
import java.util.Set; | ||
|
||
/** | ||
* Keeps track of database bookmarks and is used by the driver to ensure causal consistency between sessions and query executions. | ||
* <p> | ||
* Please note that implementations of this interface MUST NOT block for extended periods of time. | ||
* | ||
* @see org.neo4j.driver.Config.ConfigBuilder#withBookmarkManager(BookmarkManager) | ||
*/ | ||
public interface BookmarkManager extends Serializable { | ||
/** | ||
* Fallback database name used by the driver when session has no database name configured and database discovery is unavailable. | ||
*/ | ||
String FALLBACK_DATABASE_NAME = ""; | ||
|
||
/** | ||
* Updates database bookmarks by deleting the given previous bookmarks and adding the new bookmarks. | ||
* | ||
* @param database the database name | ||
* @param previousBookmarks the previous bookmarks | ||
* @param newBookmarks the new bookmarks | ||
*/ | ||
void updateBookmarks(String database, Set<Bookmark> previousBookmarks, Set<Bookmark> newBookmarks); | ||
|
||
/** | ||
* Gets an immutable set of bookmarks for a given database. | ||
* | ||
* @param database the database name | ||
* @return the set of bookmarks or an empty set if the database name is unknown to the bookmark manager | ||
*/ | ||
Set<Bookmark> getBookmarks(String database); | ||
|
||
/** | ||
* Gets an immutable set of bookmarks for all databases. | ||
* <p> | ||
* The additional set of database names provided to this method allows bookmark manager implementations to supply | ||
* bookmarks for databases that are not directly managed by them. For instance, a bookmark manager implementation | ||
* may use an external supplier of bookmarks for databases. | ||
* | ||
* @param additionalDatabases the set of additional database names | ||
* @return the set of bookmarks | ||
*/ | ||
Set<Bookmark> getAllBookmarks(Set<String> additionalDatabases); | ||
|
||
/** | ||
* Deletes bookmarks for the given databases. | ||
* | ||
* @param databases the set of database names | ||
*/ | ||
void forget(Set<String> databases); | ||
} |
81 changes: 81 additions & 0 deletions
81
driver/src/main/java/org/neo4j/driver/BookmarkManagerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.driver; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
|
||
public final class BookmarkManagerConfig { | ||
private final Map<String, Set<Bookmark>> initialBookmarks; | ||
private final BiConsumer<String, Set<Bookmark>> updateListener; | ||
private final Function<String, Set<Bookmark>> extraBookmarksProvider; | ||
|
||
private BookmarkManagerConfig(BookmarkManagerConfigBuilder builder) { | ||
this.initialBookmarks = builder.initialBookmarks; | ||
this.updateListener = builder.updateListener; | ||
this.extraBookmarksProvider = builder.extraBookmarksProvider; | ||
} | ||
|
||
public Map<String, Set<Bookmark>> initialBookmarks() { | ||
return initialBookmarks; | ||
} | ||
|
||
public BiConsumer<String, Set<Bookmark>> updateListener() { | ||
return updateListener; | ||
} | ||
|
||
public Function<String, Set<Bookmark>> extraBookmarksProvider() { | ||
return extraBookmarksProvider; | ||
} | ||
|
||
public static BookmarkManagerConfigBuilder builder() { | ||
return new BookmarkManagerConfigBuilder(); | ||
} | ||
|
||
public static class BookmarkManagerConfigBuilder { | ||
private Map<String, Set<Bookmark>> initialBookmarks = Collections.emptyMap(); | ||
private BiConsumer<String, Set<Bookmark>> updateListener; | ||
private Function<String, Set<Bookmark>> extraBookmarksProvider; | ||
|
||
private BookmarkManagerConfigBuilder() {} | ||
|
||
public BookmarkManagerConfigBuilder withInitialBookmarks(Map<String, Set<Bookmark>> initialBookmarks) { | ||
this.initialBookmarks = initialBookmarks; | ||
return this; | ||
} | ||
|
||
public BookmarkManagerConfigBuilder withUpdateListener(BiConsumer<String, Set<Bookmark>> updateListener) { | ||
this.updateListener = updateListener; | ||
return this; | ||
} | ||
|
||
public BookmarkManagerConfigBuilder withExtraBookmarksProvider( | ||
Function<String, Set<Bookmark>> extraBookmarksProvider) { | ||
this.extraBookmarksProvider = extraBookmarksProvider; | ||
return this; | ||
} | ||
|
||
public BookmarkManagerConfig build() { | ||
return new BookmarkManagerConfig(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.