Skip to content

Commit b1bd259

Browse files
committed
Introduce new managed transaction methods and deprecate existing methods
This update introduces new methods for managed transactions, also known as transaction functions. Furthermore, it deprecates the existing methods. The new methods are: - `executeRead` - `executeReadWithoutResult` - `executeWrite` - `executeWriteWithoutResult` There are overloaded options that take transaction configuration. The new methods are available in all supported API styles (synchronous, asynchronous and reactive). The new methods do not permit explicit management (commit, rollback, close) of managed transaction. The driver will attempt committing the transaction as long as the provided unit of work completes successfully.
1 parent 350435c commit b1bd259

22 files changed

+1235
-177
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,150 @@
122122
<method>org.reactivestreams.Publisher isOpen()</method>
123123
</difference>
124124

125+
<difference>
126+
<className>org/neo4j/driver/Session</className>
127+
<differenceType>7012</differenceType>
128+
<method>java.lang.Object executeRead(org.neo4j.driver.TransactionCallback)</method>
129+
</difference>
130+
131+
<difference>
132+
<className>org/neo4j/driver/Session</className>
133+
<differenceType>7012</differenceType>
134+
<method>java.lang.Object executeRead(org.neo4j.driver.TransactionCallback, org.neo4j.driver.TransactionConfig)</method>
135+
</difference>
136+
137+
<difference>
138+
<className>org/neo4j/driver/Session</className>
139+
<differenceType>7012</differenceType>
140+
<method>void executeReadWithoutResult(java.util.function.Consumer)</method>
141+
</difference>
142+
143+
<difference>
144+
<className>org/neo4j/driver/Session</className>
145+
<differenceType>7012</differenceType>
146+
<method>void executeReadWithoutResult(java.util.function.Consumer, org.neo4j.driver.TransactionConfig)</method>
147+
</difference>
148+
149+
<difference>
150+
<className>org/neo4j/driver/Session</className>
151+
<differenceType>7012</differenceType>
152+
<method>java.lang.Object executeWrite(org.neo4j.driver.TransactionCallback)</method>
153+
</difference>
154+
155+
<difference>
156+
<className>org/neo4j/driver/Session</className>
157+
<differenceType>7012</differenceType>
158+
<method>java.lang.Object executeWrite(org.neo4j.driver.TransactionCallback, org.neo4j.driver.TransactionConfig)</method>
159+
</difference>
160+
161+
<difference>
162+
<className>org/neo4j/driver/Session</className>
163+
<differenceType>7012</differenceType>
164+
<method>void executeWriteWithoutResult(java.util.function.Consumer)</method>
165+
</difference>
166+
167+
<difference>
168+
<className>org/neo4j/driver/Session</className>
169+
<differenceType>7012</differenceType>
170+
<method>void executeWriteWithoutResult(java.util.function.Consumer, org.neo4j.driver.TransactionConfig)</method>
171+
</difference>
172+
173+
<difference>
174+
<className>org/neo4j/driver/async/AsyncSession</className>
175+
<differenceType>7012</differenceType>
176+
<method>java.util.concurrent.CompletionStage executeReadAsync(org.neo4j.driver.async.AsyncTransactionCallback)</method>
177+
</difference>
178+
179+
<difference>
180+
<className>org/neo4j/driver/async/AsyncSession</className>
181+
<differenceType>7012</differenceType>
182+
<method>java.util.concurrent.CompletionStage executeReadAsync(org.neo4j.driver.async.AsyncTransactionCallback, org.neo4j.driver.TransactionConfig)
183+
</method>
184+
</difference>
185+
186+
<difference>
187+
<className>org/neo4j/driver/async/AsyncSession</className>
188+
<differenceType>7012</differenceType>
189+
<method>java.util.concurrent.CompletionStage executeReadWithoutResultAsync(java.util.function.Consumer)</method>
190+
</difference>
191+
192+
<difference>
193+
<className>org/neo4j/driver/async/AsyncSession</className>
194+
<differenceType>7012</differenceType>
195+
<method>java.util.concurrent.CompletionStage executeReadWithoutResultAsync(java.util.function.Consumer, org.neo4j.driver.TransactionConfig)</method>
196+
</difference>
197+
198+
<difference>
199+
<className>org/neo4j/driver/async/AsyncSession</className>
200+
<differenceType>7012</differenceType>
201+
<method>java.util.concurrent.CompletionStage executeWriteAsync(org.neo4j.driver.async.AsyncTransactionCallback)</method>
202+
</difference>
203+
204+
<difference>
205+
<className>org/neo4j/driver/async/AsyncSession</className>
206+
<differenceType>7012</differenceType>
207+
<method>java.util.concurrent.CompletionStage executeWriteAsync(org.neo4j.driver.async.AsyncTransactionCallback, org.neo4j.driver.TransactionConfig)
208+
</method>
209+
</difference>
210+
211+
<difference>
212+
<className>org/neo4j/driver/async/AsyncSession</className>
213+
<differenceType>7012</differenceType>
214+
<method>java.util.concurrent.CompletionStage executeWriteWithoutResultAsync(java.util.function.Consumer)</method>
215+
</difference>
216+
217+
<difference>
218+
<className>org/neo4j/driver/async/AsyncSession</className>
219+
<differenceType>7012</differenceType>
220+
<method>java.util.concurrent.CompletionStage executeWriteWithoutResultAsync(java.util.function.Consumer, org.neo4j.driver.TransactionConfig)</method>
221+
</difference>
222+
223+
<difference>
224+
<className>org/neo4j/driver/reactive/RxSession</className>
225+
<differenceType>7012</differenceType>
226+
<method>org.reactivestreams.Publisher executeRead(org.neo4j.driver.reactive.RxTransactionCallback)</method>
227+
</difference>
228+
229+
<difference>
230+
<className>org/neo4j/driver/reactive/RxSession</className>
231+
<differenceType>7012</differenceType>
232+
<method>org.reactivestreams.Publisher executeRead(org.neo4j.driver.reactive.RxTransactionCallback, org.neo4j.driver.TransactionConfig)</method>
233+
</difference>
234+
235+
<difference>
236+
<className>org/neo4j/driver/reactive/RxSession</className>
237+
<differenceType>7012</differenceType>
238+
<method>org.reactivestreams.Publisher executeReadWithoutResult(java.util.function.Consumer)</method>
239+
</difference>
240+
241+
<difference>
242+
<className>org/neo4j/driver/reactive/RxSession</className>
243+
<differenceType>7012</differenceType>
244+
<method>org.reactivestreams.Publisher executeReadWithoutResult(java.util.function.Consumer, org.neo4j.driver.TransactionConfig)</method>
245+
</difference>
246+
247+
<difference>
248+
<className>org/neo4j/driver/reactive/RxSession</className>
249+
<differenceType>7012</differenceType>
250+
<method>org.reactivestreams.Publisher executeWrite(org.neo4j.driver.reactive.RxTransactionCallback)</method>
251+
</difference>
252+
253+
<difference>
254+
<className>org/neo4j/driver/reactive/RxSession</className>
255+
<differenceType>7012</differenceType>
256+
<method>org.reactivestreams.Publisher executeWrite(org.neo4j.driver.reactive.RxTransactionCallback, org.neo4j.driver.TransactionConfig)</method>
257+
</difference>
258+
259+
<difference>
260+
<className>org/neo4j/driver/reactive/RxSession</className>
261+
<differenceType>7012</differenceType>
262+
<method>org.reactivestreams.Publisher executeWriteWithoutResult(java.util.function.Consumer)</method>
263+
</difference>
264+
265+
<difference>
266+
<className>org/neo4j/driver/reactive/RxSession</className>
267+
<differenceType>7012</differenceType>
268+
<method>org.reactivestreams.Publisher executeWriteWithoutResult(java.util.function.Consumer, org.neo4j.driver.TransactionConfig)</method>
269+
</difference>
270+
125271
</differences>

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

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -18,147 +18,11 @@
1818
*/
1919
package org.neo4j.driver;
2020

21-
import java.util.Map;
22-
2321
/**
24-
* Common interface for components that can execute Neo4j queries.
25-
*
26-
* <h2>Important notes on semantics</h2>
27-
* <p>
28-
* queries run in the same {@link QueryRunner} are guaranteed
29-
* to execute in order, meaning changes made by one query will be seen
30-
* by all subsequent queries in the same {@link QueryRunner}.
31-
* <p>
32-
* However, to allow handling very large results, and to improve performance,
33-
* result streams are retrieved lazily from the network.
34-
* This means that when any of {@link #run(Query)}
35-
* methods return a result, the query has only started executing - it may not
36-
* have completed yet. Most of the time, you will not notice this, because the
37-
* driver automatically waits for queries to complete at specific points to
38-
* fulfill its contracts.
39-
* <p>
40-
* Specifically, the driver will ensure all outstanding queries are completed
41-
* whenever you:
22+
* An {@link AutoCloseable} extension of the {@link SimpleQueryRunner}.
4223
*
43-
* <ul>
44-
* <li>Read from or discard a result, for instance via
45-
* {@link Result#next()} or {@link Result#consume()} </li>
46-
* <li>Explicitly commit/rollback a transaction using blocking {@link Transaction#close()} </li>
47-
* <li>Close a session using blocking {@link Session#close()}</li>
48-
* </ul>
49-
* <p>
50-
* As noted, most of the time, you will not need to consider this - your writes will
51-
* always be durably stored as long as you either use the results, explicitly commit
52-
* {@link Transaction transactions} or close the session you used using {@link Session#close()}.
53-
* <p>
54-
* While these semantics introduce some complexity, it gives the driver the ability
55-
* to handle infinite result streams (like subscribing to events), significantly lowers
56-
* the memory overhead for your application and improves performance.
57-
*
58-
* @see Session
59-
* @see Transaction
6024
* @since 1.0
6125
*/
62-
public interface QueryRunner extends AutoCloseable
26+
public interface QueryRunner extends SimpleQueryRunner, AutoCloseable
6327
{
64-
/**
65-
* Run a query and return a result stream.
66-
* <p>
67-
* This method takes a set of parameters that will be injected into the
68-
* query by Neo4j. Using parameters is highly encouraged, it helps avoid
69-
* dangerous cypher injection attacks and improves database performance as
70-
* Neo4j can re-use query plans more often.
71-
* <p>
72-
* This particular method takes a {@link Value} as its input. This is useful
73-
* if you want to take a map-like value that you've gotten from a prior result
74-
* and send it back as parameters.
75-
* <p>
76-
* If you are creating parameters programmatically, {@link #run(String, Map)}
77-
* might be more helpful, it converts your map to a {@link Value} for you.
78-
*
79-
* <h2>Example</h2>
80-
* <pre class="doctest:QueryRunnerDocIT#parameterTest">
81-
* {@code
82-
*
83-
* Result result = session.run( "MATCH (n) WHERE n.name = $myNameParam RETURN (n)",
84-
* Values.parameters( "myNameParam", "Bob" ) );
85-
* }
86-
* </pre>
87-
*
88-
* @param query text of a Neo4j query
89-
* @param parameters input parameters, should be a map Value, see {@link Values#parameters(Object...)}.
90-
* @return a stream of result values and associated metadata
91-
*/
92-
Result run(String query, Value parameters );
93-
94-
/**
95-
* Run a query and return a result stream.
96-
* <p>
97-
* This method takes a set of parameters that will be injected into the
98-
* query by Neo4j. Using parameters is highly encouraged, it helps avoid
99-
* dangerous cypher injection attacks and improves database performance as
100-
* Neo4j can re-use query plans more often.
101-
* <p>
102-
* This version of run takes a {@link Map} of parameters. The values in the map
103-
* must be values that can be converted to Neo4j types. See {@link Values#parameters(Object...)} for
104-
* a list of allowed types.
105-
*
106-
* <h2>Example</h2>
107-
* <pre class="doctest:QueryRunnerDocIT#parameterTest">
108-
* {@code
109-
*
110-
* Map<String, Object> parameters = new HashMap<String, Object>();
111-
* parameters.put("myNameParam", "Bob");
112-
*
113-
* Result result = session.run( "MATCH (n) WHERE n.name = $myNameParam RETURN (n)",
114-
* parameters );
115-
* }
116-
* </pre>
117-
*
118-
* @param query text of a Neo4j query
119-
* @param parameters input data for the query
120-
* @return a stream of result values and associated metadata
121-
*/
122-
Result run(String query, Map<String,Object> parameters );
123-
124-
/**
125-
* Run a query and return a result stream.
126-
* <p>
127-
* This method takes a set of parameters that will be injected into the
128-
* query by Neo4j. Using parameters is highly encouraged, it helps avoid
129-
* dangerous cypher injection attacks and improves database performance as
130-
* Neo4j can re-use query plans more often.
131-
* <p>
132-
* This version of run takes a {@link Record} of parameters, which can be useful
133-
* if you want to use the output of one query as input for another.
134-
*
135-
* @param query text of a Neo4j query
136-
* @param parameters input data for the query
137-
* @return a stream of result values and associated metadata
138-
*/
139-
Result run(String query, Record parameters );
140-
141-
/**
142-
* Run a query and return a result stream.
143-
*
144-
* @param query text of a Neo4j query
145-
* @return a stream of result values and associated metadata
146-
*/
147-
Result run(String query );
148-
149-
/**
150-
* Run a query and return a result stream.
151-
* <h2>Example</h2>
152-
* <pre class="doctest:QueryRunnerDocIT#queryObjectTest">
153-
* {@code
154-
*
155-
* Query query = new Query( "MATCH (n) WHERE n.name = $myNameParam RETURN n.age" );
156-
* Result result = session.run( query.withParameters( Values.parameters( "myNameParam", "Bob" ) ) );
157-
* }
158-
* </pre>
159-
*
160-
* @param query a Neo4j query
161-
* @return a stream of result values and associated metadata
162-
*/
163-
Result run(Query query);
16428
}

0 commit comments

Comments
 (0)