Skip to content

Commit d508e3c

Browse files
authored
Merge pull request #611 from zhenlineo/2.0-session-config
Changed session parameters to builder pattern
2 parents 85964dd + 98436c1 commit d508e3c

34 files changed

+493
-462
lines changed

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

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

2121
import java.util.concurrent.CompletionStage;
22-
import java.util.function.Consumer;
2322

2423
import org.neo4j.driver.async.AsyncSession;
2524
import org.neo4j.driver.exceptions.ClientException;
26-
import org.neo4j.driver.internal.SessionParameters;
25+
import org.neo4j.driver.internal.SessionConfig;
2726
import org.neo4j.driver.reactive.RxSession;
2827
import org.neo4j.driver.types.TypeSystem;
2928
import org.neo4j.driver.util.Experimental;
@@ -74,83 +73,88 @@ public interface Driver extends AutoCloseable
7473
boolean isEncrypted();
7574

7675
/**
77-
* Create a new general purpose {@link Session} with default {@link SessionParameters session parameters}.
76+
* Create a new general purpose {@link Session} with default {@link SessionConfig session configuration}.
7877
* <p>
79-
* Alias to {@link #session(Consumer)}}.
78+
* Alias to {@link #session(SessionConfig)}}.
8079
*
8180
* @return a new {@link Session} object.
8281
*/
8382
Session session();
8483

8584
/**
86-
* Create a new {@link Session} with a specified {@link SessionParametersTemplate}.
87-
* @param templateConsumer specifies how the session parameter shall be built for this session.
85+
* Create a new {@link Session} with a specified {@link SessionConfig session configuration}.
86+
* Use {@link SessionConfig#forDatabase(String)} to obtain a general purpose session configuration for the specified database.
87+
* @param sessionConfig specifies session configurations for this session.
8888
* @return a new {@link Session} object.
89-
* @see SessionParameters
89+
* @see SessionConfig
9090
*/
91-
Session session( Consumer<SessionParametersTemplate> templateConsumer );
92-
/**
93-
* Close all the resources assigned to this driver, including open connections and IO threads.
94-
* <p>
95-
* This operation works the same way as {@link #closeAsync()} but blocks until all resources are closed.
96-
*/
97-
@Override
98-
void close();
99-
100-
/**
101-
* Close all the resources assigned to this driver, including open connections and IO threads.
102-
* <p>
103-
* This operation is asynchronous and returns a {@link CompletionStage}. This stage is completed with
104-
* {@code null} when all resources are closed. It is completed exceptionally if termination fails.
105-
*
106-
* @return a {@link CompletionStage completion stage} that represents the asynchronous close.
107-
*/
108-
CompletionStage<Void> closeAsync();
91+
Session session( SessionConfig sessionConfig );
10992

11093
/**
111-
* Returns the driver metrics if metrics reporting is enabled via {@link Config.ConfigBuilder#withDriverMetrics()}.
112-
* Otherwise a {@link ClientException} will be thrown.
113-
* @return the driver metrics if enabled.
114-
* @throws ClientException if the driver metrics reporting is not enabled.
115-
*/
116-
Metrics metrics();
117-
118-
/**
119-
* Create a new general purpose {@link RxSession} with default {@link SessionParameters session parameters}.
94+
* Create a new general purpose {@link RxSession} with default {@link SessionConfig session configuration}.
12095
* The {@link RxSession} provides a reactive way to run queries and process results.
12196
* <p>
122-
* Alias to {@link #rxSession(Consumer)}}.
97+
* Alias to {@link #rxSession(SessionConfig)}}.
12398
*
12499
* @return @return a new {@link RxSession} object.
125100
*/
126101
RxSession rxSession();
127102

128103
/**
129-
* Create a new {@link RxSession} with a specified {@link SessionParametersTemplate}.
104+
* Create a new {@link RxSession} with a specified {@link SessionConfig session configuration}.
105+
* Use {@link SessionConfig#forDatabase(String)} to obtain a general purpose session configuration for the specified database.
130106
* The {@link RxSession} provides a reactive way to run queries and process results.
131-
* @param templateConsumer used to customize the session parameters.
107+
* @param sessionConfig used to customize the session.
132108
* @return @return a new {@link RxSession} object.
133109
*/
134-
RxSession rxSession( Consumer<SessionParametersTemplate> templateConsumer );
110+
RxSession rxSession( SessionConfig sessionConfig );
135111

136112
/**
137-
* Create a new general purpose {@link AsyncSession} with default {@link SessionParameters session parameters}.
113+
* Create a new general purpose {@link AsyncSession} with default {@link SessionConfig session configuration}.
138114
* The {@link AsyncSession} provides an asynchronous way to run queries and process results.
139115
* <p>
140-
* Alias to {@link #asyncSession(Consumer)}}.
116+
* Alias to {@link #asyncSession(SessionConfig)}}.
141117
*
142118
* @return @return a new {@link AsyncSession} object.
143119
*/
144120
AsyncSession asyncSession();
145121

146122
/**
147-
* Create a new {@link AsyncSession} with a specified {@link SessionParametersTemplate}.
123+
* Create a new {@link AsyncSession} with a specified {@link SessionConfig session configuration}.
124+
* Use {@link SessionConfig#forDatabase(String)} to obtain a general purpose session configuration for the specified database.
148125
* The {@link AsyncSession} provides an asynchronous way to run queries and process results.
149126
*
150-
* @param templateConsumer used to customize the session parameters.
127+
* @param sessionConfig used to customize the session.
151128
* @return a new {@link AsyncSession} object.
152129
*/
153-
AsyncSession asyncSession( Consumer<SessionParametersTemplate> templateConsumer );
130+
AsyncSession asyncSession( SessionConfig sessionConfig );
131+
132+
/**
133+
* Close all the resources assigned to this driver, including open connections and IO threads.
134+
* <p>
135+
* This operation works the same way as {@link #closeAsync()} but blocks until all resources are closed.
136+
*/
137+
@Override
138+
void close();
139+
140+
/**
141+
* Close all the resources assigned to this driver, including open connections and IO threads.
142+
* <p>
143+
* This operation is asynchronous and returns a {@link CompletionStage}. This stage is completed with
144+
* {@code null} when all resources are closed. It is completed exceptionally if termination fails.
145+
*
146+
* @return a {@link CompletionStage completion stage} that represents the asynchronous close.
147+
*/
148+
CompletionStage<Void> closeAsync();
149+
150+
/**
151+
* Returns the driver metrics if metrics reporting is enabled via {@link Config.ConfigBuilder#withDriverMetrics()}.
152+
* Otherwise a {@link ClientException} will be thrown.
153+
* @return the driver metrics if enabled.
154+
* @throws ClientException if the driver metrics reporting is not enabled.
155+
*/
156+
@Experimental
157+
Metrics metrics();
154158

155159
/**
156160
* This will return the type system supported by the driver.

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

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

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020

2121
import java.util.concurrent.CompletionStage;
2222
import java.util.concurrent.atomic.AtomicBoolean;
23-
import java.util.function.Consumer;
2423

2524
import org.neo4j.driver.Driver;
2625
import org.neo4j.driver.Logger;
2726
import org.neo4j.driver.Logging;
2827
import org.neo4j.driver.Metrics;
2928
import org.neo4j.driver.Session;
30-
import org.neo4j.driver.SessionParametersTemplate;
3129
import org.neo4j.driver.async.AsyncSession;
3230
import org.neo4j.driver.internal.async.InternalAsyncSession;
3331
import org.neo4j.driver.internal.async.NetworkSession;
@@ -61,43 +59,37 @@ public class InternalDriver implements Driver
6159
@Override
6260
public Session session()
6361
{
64-
return new InternalSession( newSession( SessionParameters.empty() ) );
62+
return new InternalSession( newSession( SessionConfig.empty() ) );
6563
}
6664

6765
@Override
68-
public Session session( Consumer<SessionParametersTemplate> templateConsumer )
66+
public Session session( SessionConfig sessionConfig )
6967
{
70-
SessionParameters.Template template = SessionParameters.template();
71-
templateConsumer.accept( template );
72-
return new InternalSession( newSession( template.build() ) );
68+
return new InternalSession( newSession( sessionConfig ) );
7369
}
7470

7571
@Override
7672
public RxSession rxSession()
7773
{
78-
return new InternalRxSession( newSession( SessionParameters.empty() ) );
74+
return new InternalRxSession( newSession( SessionConfig.empty() ) );
7975
}
8076

8177
@Override
82-
public RxSession rxSession( Consumer<SessionParametersTemplate> templateConsumer )
78+
public RxSession rxSession( SessionConfig sessionConfig )
8379
{
84-
SessionParameters.Template template = SessionParameters.template();
85-
templateConsumer.accept( template );
86-
return new InternalRxSession( newSession( template.build() ) );
80+
return new InternalRxSession( newSession( sessionConfig ) );
8781
}
8882

8983
@Override
9084
public AsyncSession asyncSession()
9185
{
92-
return new InternalAsyncSession( newSession( SessionParameters.empty() ) );
86+
return new InternalAsyncSession( newSession( SessionConfig.empty() ) );
9387
}
9488

9589
@Override
96-
public AsyncSession asyncSession( Consumer<SessionParametersTemplate> templateConsumer )
90+
public AsyncSession asyncSession( SessionConfig sessionConfig )
9791
{
98-
SessionParameters.Template template = SessionParameters.template();
99-
templateConsumer.accept( template );
100-
return new InternalAsyncSession( newSession( template.build() ) );
92+
return new InternalAsyncSession( newSession( sessionConfig ) );
10193
}
10294

10395
@Override
@@ -158,7 +150,7 @@ private static RuntimeException driverCloseException()
158150
return new IllegalStateException( "This driver instance has already been closed" );
159151
}
160152

161-
public NetworkSession newSession( SessionParameters parameters )
153+
public NetworkSession newSession( SessionConfig parameters )
162154
{
163155
assertOpen();
164156
NetworkSession session = sessionFactory.newInstance( parameters );

0 commit comments

Comments
 (0)