Skip to content

Commit 8381e64

Browse files
authored
Merge pull request #273 from zhenlineo/1.1-remove-transact
Remove transact
2 parents 94f39b6 + dd2bbb6 commit 8381e64

File tree

13 files changed

+9
-353
lines changed

13 files changed

+9
-353
lines changed

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

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,18 @@
2020
package org.neo4j.driver.internal;
2121

2222
import org.neo4j.driver.internal.security.SecurityPlan;
23-
import org.neo4j.driver.v1.AccessMode;
2423
import org.neo4j.driver.v1.Driver;
2524
import org.neo4j.driver.v1.Logger;
2625
import org.neo4j.driver.v1.Logging;
27-
import org.neo4j.driver.v1.RetryLogic;
28-
import org.neo4j.driver.v1.Session;
29-
import org.neo4j.driver.v1.Transaction;
30-
import org.neo4j.driver.v1.exceptions.NotCommittedException;
31-
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
32-
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
33-
import org.neo4j.driver.v1.util.Function;
34-
35-
import static java.lang.String.format;
3626

3727
abstract class BaseDriver implements Driver
3828
{
39-
private final DriverContract contract;
4029
private final SecurityPlan securityPlan;
4130
protected final Logger log;
4231
private final static String DRIVER_LOG_NAME = "Driver";
4332

44-
BaseDriver( DriverContract contract, SecurityPlan securityPlan, Logging logging )
33+
BaseDriver( SecurityPlan securityPlan, Logging logging )
4534
{
46-
this.contract = contract;
4735
this.securityPlan = securityPlan;
4836
this.log = logging.getLog( DRIVER_LOG_NAME );
4937
}
@@ -53,69 +41,4 @@ public boolean isEncrypted()
5341
{
5442
return securityPlan.requiresEncryption();
5543
}
56-
57-
public <T> T transact( RetryLogic logic, AccessMode mode, Function<Transaction, T> work )
58-
throws NotCommittedException, ServiceUnavailableException
59-
{
60-
int remaining = logic.attempts();
61-
while ( remaining > 0 )
62-
{
63-
try ( Session session = session( mode ) )
64-
{
65-
boolean failed = false;
66-
Transaction tx = session.beginTransaction();
67-
try {
68-
T result = work.apply( tx );
69-
tx.success();
70-
return result;
71-
}
72-
catch ( SessionExpiredException e )
73-
{
74-
failed = true;
75-
tx.failure();
76-
remaining -= 1;
77-
}
78-
finally
79-
{
80-
if ( failed )
81-
{
82-
try
83-
{
84-
tx.close();
85-
}
86-
catch ( Exception ex )
87-
{
88-
// ignore errors if we've already failed as
89-
// we already know this connection is problematic
90-
}
91-
}
92-
else
93-
{
94-
tx.close();
95-
}
96-
}
97-
}
98-
try
99-
{
100-
Thread.sleep( logic.pauseMillis() );
101-
}
102-
catch ( InterruptedException e )
103-
{
104-
throw new NotCommittedException( format( "Interrupted after %d attempts", logic.attempts() - remaining ) );
105-
}
106-
}
107-
throw new NotCommittedException( format( "Unable to commit transaction after %d attempts", logic.attempts() ) );
108-
}
109-
110-
@Override
111-
public <T> T read( Function<Transaction, T> work ) throws NotCommittedException, ServiceUnavailableException
112-
{
113-
return transact( contract.retryLogic(), AccessMode.READ, work );
114-
}
115-
116-
@Override
117-
public <T> T write( Function<Transaction, T> work ) throws NotCommittedException, ServiceUnavailableException
118-
{
119-
return transact( contract.retryLogic(), AccessMode.WRITE, work );
120-
}
12144
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
import org.neo4j.driver.v1.AccessMode;
2525
import org.neo4j.driver.v1.Logging;
2626
import org.neo4j.driver.v1.Session;
27-
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
28-
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
29-
import org.neo4j.driver.v1.util.Function;
3027

3128
import static java.lang.String.format;
3229

@@ -37,12 +34,11 @@ public class DirectDriver extends BaseDriver
3734

3835
public DirectDriver(
3936
BoltServerAddress address,
40-
DriverContract contract,
4137
ConnectionPool connections,
4238
SecurityPlan securityPlan,
4339
Logging logging )
4440
{
45-
super( contract, securityPlan, logging );
41+
super( securityPlan, logging );
4642
this.address = address;
4743
this.connections = connections;
4844
}

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

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ private static SecurityPlan verifiedSecurityPlan( SecurityPlan securityPlan )
4949
public RoutingDriver(
5050
RoutingSettings settings,
5151
BoltServerAddress seedAddress,
52-
DriverContract contract,
5352
ConnectionPool connections,
5453
SecurityPlan securityPlan,
5554
Clock clock,
5655
Logging logging )
5756
{
58-
super( contract, verifiedSecurityPlan( securityPlan ), logging );
57+
super( verifiedSecurityPlan( securityPlan ), logging );
5958
this.loadBalancer = new LoadBalancer( settings, clock, log, connections, seedAddress );
6059
}
6160

driver/src/main/java/org/neo4j/driver/v1/Config.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public class Config
6060
/** Strategy for how to trust encryption certificate */
6161
private final TrustStrategy trustStrategy;
6262

63-
/** Policy for retrying failed operations */
64-
private final RetryLogic retryLogic;
65-
6663
private final int routingFailureLimit;
6764
private final long routingRetryDelayMillis;
6865

@@ -77,8 +74,6 @@ private Config( ConfigBuilder builder)
7774
this.trustStrategy = builder.trustStrategy;
7875
this.routingFailureLimit = builder.routingFailureLimit;
7976
this.routingRetryDelayMillis = builder.routingRetryDelayMillis;
80-
81-
this.retryLogic = builder.retryLogic;
8277
}
8378

8479
/**
@@ -135,8 +130,6 @@ public TrustStrategy trustStrategy()
135130
return trustStrategy;
136131
}
137132

138-
public RetryLogic retryLogic() { return retryLogic; }
139-
140133
/**
141134
* Return a {@link ConfigBuilder} instance
142135
* @return a {@link ConfigBuilder} instance
@@ -169,7 +162,6 @@ public static class ConfigBuilder
169162
private long idleTimeBeforeConnectionTest = PoolSettings.DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST;
170163
private EncryptionLevel encryptionLevel = EncryptionLevel.REQUIRED;
171164
private TrustStrategy trustStrategy = trustAllCertificates();
172-
private RetryLogic retryLogic = RetryLogic.DEFAULT_RETRY_LOGIC;
173165
private int routingFailureLimit = 1;
174166
private long routingRetryDelayMillis = 5_000;
175167

@@ -339,18 +331,6 @@ public ConfigBuilder withRoutingRetryDelay( long delay, TimeUnit unit )
339331
return this;
340332
}
341333

342-
/**
343-
* Specify policy for retrying operations that fail but can be automatically reattempted.
344-
*
345-
* @param retryLogic
346-
* @return
347-
*/
348-
public ConfigBuilder withRetryLogic( RetryLogic retryLogic )
349-
{
350-
this.retryLogic = retryLogic;
351-
return this;
352-
}
353-
354334
/**
355335
* Create a config instance from this builder.
356336
* @return a {@link Config} instance

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222
import java.net.URI;
2323

24-
import org.neo4j.driver.v1.exceptions.NotCommittedException;
25-
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
26-
import org.neo4j.driver.v1.util.Function;
27-
2824
/**
2925
* A Neo4j database driver, through which you can create {@link Session sessions} to run statements against the database.
3026
* <p>
@@ -92,13 +88,6 @@ public interface Driver extends AutoCloseable
9288

9389
Session session(AccessMode mode);
9490

95-
<T> T transact( RetryLogic logic, AccessMode mode, Function<Transaction, T> work )
96-
throws NotCommittedException, ServiceUnavailableException;
97-
98-
<T> T read( Function<Transaction, T> work ) throws NotCommittedException, ServiceUnavailableException;
99-
100-
<T> T write( Function<Transaction, T> work ) throws NotCommittedException, ServiceUnavailableException;
101-
10291
/**
10392
* Close all the resources assigned to this driver
10493
*/

driver/src/main/java/org/neo4j/driver/v1/GraphDatabase.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import org.neo4j.driver.internal.ConnectionSettings;
2626
import org.neo4j.driver.internal.DirectDriver;
27-
import org.neo4j.driver.internal.DriverContract;
2827
import org.neo4j.driver.internal.NetworkSession;
2928
import org.neo4j.driver.internal.RoutingDriver;
3029
import org.neo4j.driver.internal.net.BoltServerAddress;
@@ -177,9 +176,6 @@ public static Driver driver( URI uri, AuthToken authToken, Config config )
177176
throw new ClientException( "Unable to establish SSL parameters", ex );
178177
}
179178

180-
// Construct driver contract
181-
DriverContract driverContract = new DriverContract( config.retryLogic() );
182-
183179
// Establish pool settings
184180
PoolSettings poolSettings = new PoolSettings(
185181
config.maxIdleConnectionPoolSize(),
@@ -191,12 +187,11 @@ public static Driver driver( URI uri, AuthToken authToken, Config config )
191187
switch ( scheme.toLowerCase() )
192188
{
193189
case "bolt":
194-
return new DirectDriver( address, driverContract, connectionPool, securityPlan, config.logging() );
190+
return new DirectDriver( address, connectionPool, securityPlan, config.logging() );
195191
case "bolt+routing":
196192
return new RoutingDriver(
197193
config.routingSettings(),
198194
address,
199-
driverContract,
200195
connectionPool,
201196
securityPlan,
202197
Clock.SYSTEM,

driver/src/main/java/org/neo4j/driver/v1/RetryLogic.java

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

driver/src/main/java/org/neo4j/driver/v1/exceptions/NotCommittedException.java

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

0 commit comments

Comments
 (0)