-
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.
Introduce new Reactive Streams session (#1325)
This update introduces support for reactive session with Reactive Streams types. While it is similar to the deprecated `RxSession`, it includes the improvements introduced with the `ReactiveSession` that uses Flow API types. Sample session creation: ``` var session = driver.reactiveSession(org.neo4j.driver.reactivestreams.ReactiveSession.class); ```
- Loading branch information
1 parent
93c7b95
commit 1fc6a41
Showing
65 changed files
with
1,719 additions
and
39 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
driver/src/main/java/org/neo4j/driver/BaseReactiveSession.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,24 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* A base interface for reactive sessions, used by {@link Driver#reactiveSession(Class)} and {@link Driver#reactiveSession(Class, SessionConfig)}. | ||
*/ | ||
public interface BaseReactiveSession {} |
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
74 changes: 74 additions & 0 deletions
74
driver/src/main/java/org/neo4j/driver/internal/reactivestreams/BaseReactiveQueryRunner.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,74 @@ | ||
/* | ||
* 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.internal.reactivestreams; | ||
|
||
import java.util.Map; | ||
import org.neo4j.driver.Query; | ||
import org.neo4j.driver.Record; | ||
import org.neo4j.driver.Value; | ||
import org.neo4j.driver.Values; | ||
import org.neo4j.driver.internal.util.Extract; | ||
import org.neo4j.driver.internal.value.MapValue; | ||
import org.neo4j.driver.reactivestreams.ReactiveQueryRunner; | ||
import org.neo4j.driver.reactivestreams.ReactiveResult; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Mono; | ||
|
||
interface BaseReactiveQueryRunner extends ReactiveQueryRunner { | ||
@Override | ||
default Publisher<ReactiveResult> run(String queryStr, Value parameters) { | ||
try { | ||
Query query = new Query(queryStr, parameters); | ||
return run(query); | ||
} catch (Throwable t) { | ||
return Mono.error(t); | ||
} | ||
} | ||
|
||
@Override | ||
default Publisher<ReactiveResult> run(String query, Map<String, Object> parameters) { | ||
return run(query, parameters(parameters)); | ||
} | ||
|
||
@Override | ||
default Publisher<ReactiveResult> run(String query, Record parameters) { | ||
return run(query, parameters(parameters)); | ||
} | ||
|
||
@Override | ||
default Publisher<ReactiveResult> run(String queryStr) { | ||
try { | ||
Query query = new Query(queryStr); | ||
return run(query); | ||
} catch (Throwable t) { | ||
return Mono.error(t); | ||
} | ||
} | ||
|
||
static Value parameters(Record record) { | ||
return record == null ? Values.EmptyMap : parameters(record.asMap()); | ||
} | ||
|
||
static Value parameters(Map<String, Object> map) { | ||
if (map == null || map.isEmpty()) { | ||
return Values.EmptyMap; | ||
} | ||
return new MapValue(Extract.mapOfValues(map)); | ||
} | ||
} |
Oops, something went wrong.