Skip to content

Commit 2a5b30d

Browse files
committed
Remove deprecated ServerVersion
1 parent fb143f4 commit 2a5b30d

File tree

47 files changed

+170
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+170
-644
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@
4343
<method>org.reactivestreams.Publisher close()</method>
4444
</difference>
4545

46+
<difference>
47+
<className>org/neo4j/driver/summary/ServerInfo</className>
48+
<differenceType>7002</differenceType>
49+
<method>java.lang.String version()</method>
50+
</difference>
51+
4652
</differences>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.neo4j.driver.exceptions.ClientException;
2222
import org.neo4j.driver.internal.messaging.v44.BoltProtocolV44;
2323
import org.neo4j.driver.internal.spi.Connection;
24-
import org.neo4j.driver.internal.util.ServerVersion;
2524

2625
public class ImpersonationUtil
2726
{
@@ -40,7 +39,6 @@ public static Connection ensureImpersonationSupport( Connection connection, Stri
4039

4140
private static boolean supportsImpersonation( Connection connection )
4241
{
43-
return connection.serverVersion().greaterThanOrEqual( ServerVersion.v4_4_0 ) &&
44-
connection.protocol().version().compareTo( BoltProtocolV44.VERSION ) >= 0;
42+
return connection.protocol().version().compareTo( BoltProtocolV44.VERSION ) >= 0;
4543
}
4644
}

driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.neo4j.driver.internal.spi.Connection;
4444
import org.neo4j.driver.internal.spi.ResponseHandler;
4545
import org.neo4j.driver.internal.util.Clock;
46-
import org.neo4j.driver.internal.util.ServerVersion;
4746

4847
import static java.util.Collections.emptyMap;
4948
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.poolId;
@@ -61,7 +60,6 @@ public class NetworkConnection implements Connection
6160
private final InboundMessageDispatcher messageDispatcher;
6261
private final String serverAgent;
6362
private final BoltServerAddress serverAddress;
64-
private final ServerVersion serverVersion;
6563
private final BoltProtocol protocol;
6664
private final ExtendedChannelPool channelPool;
6765
private final CompletableFuture<Void> releaseFuture;
@@ -81,7 +79,6 @@ public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Cloc
8179
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
8280
this.serverAgent = ChannelAttributes.serverAgent( channel );
8381
this.serverAddress = ChannelAttributes.serverAddress( channel );
84-
this.serverVersion = ChannelAttributes.serverVersion( channel );
8582
this.protocol = BoltProtocol.forChannel( channel );
8683
this.channelPool = channelPool;
8784
this.releaseFuture = new CompletableFuture<>();
@@ -213,12 +210,6 @@ public BoltServerAddress serverAddress()
213210
return serverAddress;
214211
}
215212

216-
@Override
217-
public ServerVersion serverVersion()
218-
{
219-
return serverVersion;
220-
}
221-
222213
@Override
223214
public BoltProtocol protocol()
224215
{

driver/src/main/java/org/neo4j/driver/internal/async/connection/ChannelAttributes.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.neo4j.driver.internal.BoltServerAddress;
2727
import org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher;
2828
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
29-
import org.neo4j.driver.internal.util.ServerVersion;
3029

3130
import static io.netty.util.AttributeKey.newInstance;
3231

@@ -37,7 +36,6 @@ public final class ChannelAttributes
3736
private static final AttributeKey<BoltProtocolVersion> PROTOCOL_VERSION = newInstance( "protocolVersion" );
3837
private static final AttributeKey<String> SERVER_AGENT = newInstance( "serverAgent" );
3938
private static final AttributeKey<BoltServerAddress> ADDRESS = newInstance( "serverAddress" );
40-
private static final AttributeKey<ServerVersion> SERVER_VERSION = newInstance( "serverVersion" );
4139
private static final AttributeKey<Long> CREATION_TIMESTAMP = newInstance( "creationTimestamp" );
4240
private static final AttributeKey<Long> LAST_USED_TIMESTAMP = newInstance( "lastUsedTimestamp" );
4341
private static final AttributeKey<InboundMessageDispatcher> MESSAGE_DISPATCHER = newInstance( "messageDispatcher" );
@@ -101,16 +99,6 @@ public static void setServerAddress( Channel channel, BoltServerAddress address
10199
setOnce( channel, ADDRESS, address );
102100
}
103101

104-
public static ServerVersion serverVersion( Channel channel )
105-
{
106-
return get( channel, SERVER_VERSION );
107-
}
108-
109-
public static void setServerVersion( Channel channel, ServerVersion version )
110-
{
111-
setOnce( channel, SERVER_VERSION, version );
112-
}
113-
114102
public static long creationTimestamp( Channel channel )
115103
{
116104
return get( channel, CREATION_TIMESTAMP );

driver/src/main/java/org/neo4j/driver/internal/async/connection/DirectConnection.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.neo4j.driver.internal.messaging.Message;
2929
import org.neo4j.driver.internal.spi.Connection;
3030
import org.neo4j.driver.internal.spi.ResponseHandler;
31-
import org.neo4j.driver.internal.util.ServerVersion;
3231

3332
/**
3433
* This is a connection used by {@link DirectConnectionProvider} to connect to a remote database.
@@ -125,12 +124,6 @@ public BoltServerAddress serverAddress()
125124
return delegate.serverAddress();
126125
}
127126

128-
@Override
129-
public ServerVersion serverVersion()
130-
{
131-
return delegate.serverVersion();
132-
}
133-
134127
@Override
135128
public BoltProtocol protocol()
136129
{

driver/src/main/java/org/neo4j/driver/internal/async/connection/RoutingConnection.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.neo4j.driver.internal.messaging.Message;
3030
import org.neo4j.driver.internal.spi.Connection;
3131
import org.neo4j.driver.internal.spi.ResponseHandler;
32-
import org.neo4j.driver.internal.util.ServerVersion;
3332

3433
/**
3534
* A connection used by the routing driver.
@@ -123,12 +122,6 @@ public BoltServerAddress serverAddress()
123122
return delegate.serverAddress();
124123
}
125124

126-
@Override
127-
public ServerVersion serverVersion()
128-
{
129-
return delegate.serverVersion();
130-
}
131-
132125
@Override
133126
public BoltProtocol protocol()
134127
{

driver/src/main/java/org/neo4j/driver/internal/cluster/MultiDatabasesRoutingProcedureRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.neo4j.driver.internal.DatabaseName;
2929
import org.neo4j.driver.internal.ReadOnlyBookmarkHolder;
3030
import org.neo4j.driver.internal.async.connection.DirectConnection;
31+
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
3132
import org.neo4j.driver.internal.spi.Connection;
32-
import org.neo4j.driver.internal.util.ServerVersion;
3333

3434
import static org.neo4j.driver.Values.value;
3535
import static org.neo4j.driver.internal.DatabaseNameUtil.systemDatabase;
@@ -56,7 +56,7 @@ BookmarkHolder bookmarkHolder( Bookmark bookmark )
5656
}
5757

5858
@Override
59-
Query procedureQuery(ServerVersion serverVersion, DatabaseName databaseName )
59+
Query procedureQuery( BoltProtocolVersion protocolVersion, DatabaseName databaseName )
6060
{
6161
HashMap<String,Value> map = new HashMap<>();
6262
map.put( ROUTING_CONTEXT, value( context.toMap() ) );

driver/src/main/java/org/neo4j/driver/internal/cluster/SingleDatabaseRoutingProcedureRunner.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import org.neo4j.driver.internal.BookmarkHolder;
3434
import org.neo4j.driver.internal.DatabaseName;
3535
import org.neo4j.driver.internal.async.connection.DirectConnection;
36+
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
3637
import org.neo4j.driver.internal.spi.Connection;
3738
import org.neo4j.driver.internal.util.Futures;
38-
import org.neo4j.driver.internal.util.ServerVersion;
3939

4040
import static org.neo4j.driver.Values.parameters;
4141
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
@@ -61,7 +61,7 @@ public SingleDatabaseRoutingProcedureRunner( RoutingContext context )
6161
public CompletionStage<RoutingProcedureResponse> run( Connection connection, DatabaseName databaseName, Bookmark bookmark, String impersonatedUser )
6262
{
6363
DirectConnection delegate = connection( connection );
64-
Query procedure = procedureQuery( connection.serverVersion(), databaseName );
64+
Query procedure = procedureQuery( connection.protocol().version(), databaseName );
6565
BookmarkHolder bookmarkHolder = bookmarkHolder( bookmark );
6666
return runProcedure( delegate, procedure, bookmarkHolder )
6767
.thenCompose( records -> releaseConnection( delegate, records ) )
@@ -73,13 +73,13 @@ DirectConnection connection( Connection connection )
7373
return new DirectConnection( connection, defaultDatabase(), AccessMode.WRITE, null );
7474
}
7575

76-
Query procedureQuery(ServerVersion serverVersion, DatabaseName databaseName )
76+
Query procedureQuery( BoltProtocolVersion protocolVersion, DatabaseName databaseName )
7777
{
7878
if ( databaseName.databaseName().isPresent() )
7979
{
8080
throw new FatalDiscoveryException( String.format(
81-
"Refreshing routing table for multi-databases is not supported in server version lower than 4.0. " +
82-
"Current server version: %s. Database name: '%s'", serverVersion, databaseName.description() ) );
81+
"Refreshing routing table for multi-databases is not supported over Bolt protocol lower than 4.0. " +
82+
"Current protocol version: %s. Database name: '%s'", protocolVersion, databaseName.description() ) );
8383
}
8484
return new Query( GET_ROUTING_TABLE, parameters( ROUTING_CONTEXT, context.toMap() ) );
8585
}

driver/src/main/java/org/neo4j/driver/internal/handlers/HelloResponseHandler.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@
2626
import java.util.function.Supplier;
2727

2828
import org.neo4j.driver.Value;
29-
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
30-
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
3129
import org.neo4j.driver.internal.spi.ResponseHandler;
3230

3331
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionId;
3432
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionReadTimeout;
3533
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAgent;
36-
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
37-
import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
3834
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
39-
import static org.neo4j.driver.internal.util.ServerVersion.fromBoltProtocolVersion;
4035

4136
public class HelloResponseHandler implements ResponseHandler
4237
{
@@ -46,33 +41,20 @@ public class HelloResponseHandler implements ResponseHandler
4641

4742
private final ChannelPromise connectionInitializedPromise;
4843
private final Channel channel;
49-
private final BoltProtocolVersion protocolVersion;
5044

51-
public HelloResponseHandler( ChannelPromise connectionInitializedPromise, BoltProtocolVersion protocolVersion )
45+
public HelloResponseHandler( ChannelPromise connectionInitializedPromise )
5246
{
5347
this.connectionInitializedPromise = connectionInitializedPromise;
5448
this.channel = connectionInitializedPromise.channel();
55-
this.protocolVersion = protocolVersion;
5649
}
5750

5851
@Override
5952
public void onSuccess( Map<String,Value> metadata )
6053
{
6154
try
6255
{
63-
Value serverValue = extractServer( metadata );
64-
setServerAgent( channel, serverValue.asString() );
65-
66-
// From Server V4 extracting server from metadata in the success message is unreliable
67-
// so we fix the Server version against the Bolt Protocol version for Server V4 and above.
68-
if ( BoltProtocolV3.VERSION.equals( protocolVersion ) )
69-
{
70-
setServerVersion( channel, extractNeo4jServerVersion( metadata ) );
71-
}
72-
else
73-
{
74-
setServerVersion( channel, fromBoltProtocolVersion( protocolVersion ) );
75-
}
56+
String serverAgent = extractServer( metadata ).asString();
57+
setServerAgent( channel, serverAgent );
7658

7759
String connectionId = extractConnectionId( metadata );
7860
setConnectionId( channel, connectionId );

driver/src/main/java/org/neo4j/driver/internal/handlers/InitResponseHandler.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919
package org.neo4j.driver.internal.handlers;
2020

2121
import io.netty.channel.Channel;
22-
import io.netty.channel.ChannelPipeline;
2322
import io.netty.channel.ChannelPromise;
2423

2524
import java.util.Map;
2625

27-
import org.neo4j.driver.internal.async.outbound.OutboundMessageHandler;
28-
import org.neo4j.driver.internal.spi.ResponseHandler;
29-
import org.neo4j.driver.internal.util.ServerVersion;
3026
import org.neo4j.driver.Value;
27+
import org.neo4j.driver.exceptions.UntrustedServerException;
28+
import org.neo4j.driver.internal.spi.ResponseHandler;
3129

32-
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
33-
import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
30+
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
3431

3532
public class InitResponseHandler implements ResponseHandler
3633
{
@@ -48,8 +45,13 @@ public void onSuccess( Map<String,Value> metadata )
4845
{
4946
try
5047
{
51-
ServerVersion serverVersion = extractNeo4jServerVersion( metadata );
52-
setServerVersion( channel, serverVersion );
48+
String serverAgent = extractServer( metadata ).asString();
49+
50+
if ( !serverAgent.startsWith( "Neo4j/" ) )
51+
{
52+
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + serverAgent + "'" );
53+
}
54+
5355
connectionInitializedPromise.setSuccess();
5456
}
5557
catch ( Throwable error )

driver/src/main/java/org/neo4j/driver/internal/messaging/request/MultiDatabaseUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.neo4j.driver.internal.messaging.v4.BoltProtocolV4;
2525
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
2626
import org.neo4j.driver.internal.spi.Connection;
27-
import org.neo4j.driver.internal.util.ServerVersion;
2827

2928
public final class MultiDatabaseUtil
3029
{
@@ -39,8 +38,7 @@ public static void assertEmptyDatabaseName( DatabaseName databaseName, BoltProto
3938

4039
public static boolean supportsMultiDatabase( Connection connection )
4140
{
42-
return connection.serverVersion().greaterThanOrEqual( ServerVersion.v4_0_0 ) &&
43-
connection.protocol().version().compareTo( BoltProtocolV4.VERSION ) >= 0;
41+
return connection.protocol().version().compareTo( BoltProtocolV4.VERSION ) >= 0;
4442
}
4543

4644
public static boolean supportsRouteMessage( Connection connection )

driver/src/main/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void initializeChannel( String userAgent, AuthToken authToken, RoutingCon
9191
message = new HelloMessage( userAgent, ( ( InternalAuthToken ) authToken ).toMap(), null );
9292
}
9393

94-
HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise, version() );
94+
HelloResponseHandler handler = new HelloResponseHandler( channelInitializedPromise );
9595

9696
messageDispatcher( channel ).enqueue( handler );
9797
channel.writeAndFlush( message, channel.voidPromise() );

driver/src/main/java/org/neo4j/driver/internal/spi/Connection.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.neo4j.driver.internal.DatabaseName;
2626
import org.neo4j.driver.internal.messaging.BoltProtocol;
2727
import org.neo4j.driver.internal.messaging.Message;
28-
import org.neo4j.driver.internal.util.ServerVersion;
2928

3029
import static java.lang.String.format;
3130

@@ -55,8 +54,6 @@ public interface Connection
5554

5655
BoltServerAddress serverAddress();
5756

58-
ServerVersion serverVersion();
59-
6057
BoltProtocol protocol();
6158

6259
default AccessMode mode()

driver/src/main/java/org/neo4j/driver/internal/summary/InternalServerInfo.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@
2222

2323
import org.neo4j.driver.internal.BoltServerAddress;
2424
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
25-
import org.neo4j.driver.internal.util.ServerVersion;
2625
import org.neo4j.driver.summary.ServerInfo;
2726

2827
public class InternalServerInfo implements ServerInfo
2928
{
29+
private static final String TO_STRING_FMT = "%s{address='%s'}";
30+
3031
private final String agent;
3132
private final String address;
32-
private final String version;
3333
private final String protocolVersion;
3434

35-
public InternalServerInfo( String agent, BoltServerAddress address, ServerVersion version, BoltProtocolVersion protocolVersion )
35+
public InternalServerInfo( String agent, BoltServerAddress address, BoltProtocolVersion protocolVersion )
3636
{
3737
this.agent = agent;
3838
this.address = address.toString();
39-
this.version = version.toString();
4039
this.protocolVersion = protocolVersion.toString();
4140
}
4241

@@ -52,12 +51,6 @@ public String address()
5251
return address;
5352
}
5453

55-
@Override
56-
public String version()
57-
{
58-
return version;
59-
}
60-
6154
@Override
6255
public String protocolVersion()
6356
{
@@ -76,18 +69,18 @@ public boolean equals( Object o )
7669
return false;
7770
}
7871
InternalServerInfo that = (InternalServerInfo) o;
79-
return Objects.equals( address, that.address ) && Objects.equals( version, that.version );
72+
return Objects.equals( address, that.address );
8073
}
8174

8275
@Override
8376
public int hashCode()
8477
{
85-
return Objects.hash( address, version );
78+
return Objects.hash( address );
8679
}
8780

8881
@Override
8982
public String toString()
9083
{
91-
return "InternalServerInfo{" + "address='" + address + '\'' + ", version='" + version + '\'' + '}';
84+
return String.format( TO_STRING_FMT, this.getClass().getSimpleName(), address );
9285
}
9386
}

0 commit comments

Comments
 (0)