21
21
import java .io .IOException ;
22
22
import java .lang .reflect .InvocationTargetException ;
23
23
import java .net .URI ;
24
+ import java .net .URISyntaxException ;
24
25
import java .net .URLDecoder ;
25
26
import java .net .URLEncoder ;
26
27
import java .nio .charset .StandardCharsets ;
30
31
import java .sql .DriverManager ;
31
32
import java .sql .DriverPropertyInfo ;
32
33
import java .sql .SQLException ;
33
- import java .time .Clock ;
34
34
import java .util .ArrayList ;
35
35
import java .util .Arrays ;
36
36
import java .util .Collection ;
46
46
import java .util .ServiceLoader ;
47
47
import java .util .Set ;
48
48
import java .util .TreeMap ;
49
- import java .util .concurrent .CompletableFuture ;
50
49
import java .util .concurrent .ConcurrentHashMap ;
51
50
import java .util .function .Supplier ;
52
51
import java .util .logging .Level ;
53
52
import java .util .logging .Logger ;
54
53
import java .util .regex .Pattern ;
55
54
56
55
import io .github .cdimascio .dotenv .Dotenv ;
57
- import io .netty .channel .EventLoopGroup ;
58
- import io .netty .channel .nio .NioEventLoopGroup ;
59
- import org .neo4j .bolt .connection .AccessMode ;
60
56
import org .neo4j .bolt .connection .AuthToken ;
61
57
import org .neo4j .bolt .connection .AuthTokens ;
62
58
import org .neo4j .bolt .connection .BoltConnection ;
63
59
import org .neo4j .bolt .connection .BoltConnectionProvider ;
64
60
import org .neo4j .bolt .connection .BoltProtocolVersion ;
65
- import org .neo4j .bolt .connection .BoltServerAddress ;
66
- import org .neo4j .bolt .connection .DatabaseNameUtil ;
67
- import org .neo4j .bolt .connection .DefaultDomainNameResolver ;
68
61
import org .neo4j .bolt .connection .NotificationConfig ;
69
62
import org .neo4j .bolt .connection .RoutingContext ;
70
63
import org .neo4j .bolt .connection .SecurityPlan ;
71
64
import org .neo4j .bolt .connection .SecurityPlans ;
72
- import org .neo4j .bolt .connection .netty .NettyBoltConnectionProvider ;
65
+ import org .neo4j .bolt .connection .netty .NettyBoltConnectionProviderFactory ;
73
66
import org .neo4j .jdbc .Neo4jException .GQLError ;
74
67
import org .neo4j .jdbc .events .ConnectionListener ;
75
68
import org .neo4j .jdbc .events .DriverListener ;
@@ -228,12 +221,11 @@ public final class Neo4jDriver implements Neo4jDriverExtensions {
228
221
*/
229
222
public static final String PROPERTY_SSL_MODE = "sslMode" ;
230
223
231
- private static final EventLoopGroup DEFAULT_EVENT_LOOP_GROUP = new NioEventLoopGroup (new DriverThreadFactory ());
232
-
233
224
private static final String URL_REGEX = "^jdbc:neo4j(?:\\ +(?<transport>s(?:sc)?)?)?://(?<host>[^:/?]+):?(?<port>\\ d+)?/?(?<database>[^?]+)?\\ ??(?<urlParams>\\ S+)?$" ;
234
225
235
226
/**
236
227
* The URL pattern that this driver supports.
228
+ *
237
229
* @since 6.2.0
238
230
*/
239
231
public static final Pattern URL_PATTERN = Pattern .compile (URL_REGEX );
@@ -344,9 +336,8 @@ public static Optional<Connection> fromEnv(Path directory, String filename) thro
344
336
* machinery for JDBC.
345
337
*/
346
338
public Neo4jDriver () {
347
- this (new NettyBoltConnectionProvider (DEFAULT_EVENT_LOOP_GROUP , Clock .systemUTC (),
348
- DefaultDomainNameResolver .getInstance (), null , BoltAdapters .newLoggingProvider (),
349
- BoltAdapters .getValueFactory (), null ));
339
+ this (new NettyBoltConnectionProviderFactory ().create (BoltAdapters .newLoggingProvider (),
340
+ BoltAdapters .getValueFactory (), null , Map .of ("eventLoopThreadNamePrefix" , "Neo4jJDBCDriverIO" )));
350
341
}
351
342
352
343
Neo4jDriver (BoltConnectionProvider boltConnectionProvider ) {
@@ -358,8 +349,6 @@ public Neo4jDriver() {
358
349
public Connection connect (String url , Properties info ) throws SQLException {
359
350
var driverConfig = DriverConfig .of (url , info );
360
351
361
- var address = new BoltServerAddress (driverConfig .host , driverConfig .port );
362
-
363
352
var securityPlan = parseSSLParams (driverConfig .sslProperties );
364
353
365
354
var databaseName = driverConfig .database ;
@@ -392,9 +381,9 @@ public Connection connect(String url, Properties info) throws SQLException {
392
381
}
393
382
394
383
var targetUrl = driverConfig .toUrl ();
384
+ var boltUrl = createBoltUri (driverConfig );
395
385
var connection = new ConnectionImpl (targetUrl ,
396
- () -> establishBoltConnection (address , userAgent , connectTimeoutMillis , securityPlan , databaseName ,
397
- authToken ),
386
+ () -> establishBoltConnection (boltUrl , userAgent , connectTimeoutMillis , securityPlan , authToken ),
398
387
getSqlTranslatorSupplier (enableSqlTranslation , driverConfig .rawConfig (), translatorFactoriesSupplier ),
399
388
enableSqlTranslation , enableTranslationCaching , rewriteBatchedStatements , rewritePlaceholders ,
400
389
bookmarkManager , this .transactionMetadata , driverConfig .relationshipSampleSize (), databaseName ,
@@ -417,18 +406,26 @@ public Connection connect(String url, Properties info) throws SQLException {
417
406
return connection ;
418
407
}
419
408
420
- private BoltConnection establishBoltConnection (BoltServerAddress address , String userAgent ,
421
- int connectTimeoutMillis , SecurityPlan securityPlan , String databaseName , AuthToken authToken ) {
409
+ private BoltConnection establishBoltConnection (URI uri , String userAgent , int connectTimeoutMillis ,
410
+ SecurityPlan securityPlan , AuthToken authToken ) {
422
411
return this .boltConnectionProvider
423
- .connect (address , RoutingContext .EMPTY , BoltAdapters .newAgent (ProductVersion .getValue ()), userAgent ,
424
- connectTimeoutMillis , securityPlan , DatabaseNameUtil .database (databaseName ),
425
- () -> CompletableFuture .completedStage (authToken ), AccessMode .WRITE , Collections .emptySet (), null ,
426
- MIN_BOLT_VERSION , NotificationConfig .defaultConfig (), ignored -> {
427
- }, Collections .emptyMap ())
412
+ .connect (uri , RoutingContext .EMPTY , BoltAdapters .newAgent (ProductVersion .getValue ()), userAgent ,
413
+ connectTimeoutMillis , securityPlan , authToken , MIN_BOLT_VERSION , NotificationConfig .defaultConfig ())
428
414
.toCompletableFuture ()
429
415
.join ();
430
416
}
431
417
418
+ private static URI createBoltUri (DriverConfig driverConfig ) throws Neo4jException {
419
+ URI uri ;
420
+ try {
421
+ uri = new URI ("bolt" , null , driverConfig .host , driverConfig .port , null , null , null );
422
+ }
423
+ catch (URISyntaxException ignored ) {
424
+ throw new Neo4jException (GQLError .$22000 .withMessage ("Failed to create Bolt URI" ));
425
+ }
426
+ return uri ;
427
+ }
428
+
432
429
static String getDefaultUserAgent () {
433
430
return "neo4j-jdbc/%s" .formatted (ProductVersion .getValue ());
434
431
}
@@ -589,7 +586,7 @@ private static SecurityPlan parseSSLParams(SSLProperties sslProperties) throws S
589
586
throw new Neo4jException (withInternal (ex ));
590
587
}
591
588
}
592
- case DISABLE -> SecurityPlans . unencrypted () ;
589
+ case DISABLE -> null ;
593
590
};
594
591
}
595
592
0 commit comments