@@ -189,6 +189,7 @@ class DefaultRunnableSpec implements RunnableSpec {
189
189
private String targetDatabase ;
190
190
191
191
DefaultRunnableSpec (Supplier <String > cypherSupplier ) {
192
+ this .targetDatabase = Neo4jClient .verifyDatabaseName (resolveTargetDatabaseName (targetDatabase ));
192
193
this .runnableStatement = new RunnableStatement (cypherSupplier );
193
194
}
194
195
@@ -257,6 +258,19 @@ public ResultSummary run() {
257
258
throw potentiallyConvertRuntimeException (e , persistenceExceptionTranslator );
258
259
}
259
260
}
261
+
262
+ private String resolveTargetDatabaseName (@ Nullable String parameterTargetDatabase ) {
263
+ if (parameterTargetDatabase != null ) {
264
+ return parameterTargetDatabase ;
265
+ }
266
+ if (databaseSelectionProvider != null ) {
267
+ String databaseSelectionProviderValue = databaseSelectionProvider .getDatabaseSelection ().getValue ();
268
+ if (databaseSelectionProviderValue != null ) {
269
+ return databaseSelectionProviderValue ;
270
+ }
271
+ }
272
+ return DatabaseSelectionProvider .getDefaultSelectionProvider ().getDatabaseSelection ().getValue ();
273
+ }
260
274
}
261
275
262
276
class DefaultRecordFetchSpec <T > implements RecordFetchSpec <T >, MappingSpec <T > {
@@ -270,24 +284,11 @@ class DefaultRecordFetchSpec<T> implements RecordFetchSpec<T>, MappingSpec<T> {
270
284
DefaultRecordFetchSpec (String parameterTargetDatabase , RunnableStatement runnableStatement ,
271
285
BiFunction <TypeSystem , Record , T > mappingFunction ) {
272
286
273
- this .targetDatabase = resolveTargetDatabaseName ( parameterTargetDatabase ) ;
287
+ this .targetDatabase = parameterTargetDatabase ;
274
288
this .runnableStatement = runnableStatement ;
275
289
this .mappingFunction = mappingFunction ;
276
290
}
277
291
278
- private String resolveTargetDatabaseName (@ Nullable String parameterTargetDatabase ) {
279
- if (parameterTargetDatabase != null ) {
280
- return parameterTargetDatabase ;
281
- }
282
- if (databaseSelectionProvider != null ) {
283
- String databaseSelectionProviderValue = databaseSelectionProvider .getDatabaseSelection ().getValue ();
284
- if (databaseSelectionProviderValue != null ) {
285
- return databaseSelectionProviderValue ;
286
- }
287
- }
288
- return DatabaseSelectionProvider .getDefaultSelectionProvider ().getDatabaseSelection ().getValue ();
289
- }
290
-
291
292
@ Override
292
293
public RecordFetchSpec <T > mappedBy (
293
294
@ SuppressWarnings ("HiddenField" ) BiFunction <TypeSystem , Record , T > mappingFunction ) {
@@ -358,7 +359,7 @@ class DefaultRunnableDelegation<T> implements RunnableDelegation<T>, OngoingDele
358
359
359
360
DefaultRunnableDelegation (Function <QueryRunner , Optional <T >> callback , @ Nullable String targetDatabase ) {
360
361
this .callback = callback ;
361
- this .targetDatabase = targetDatabase ;
362
+ this .targetDatabase = Neo4jClient . verifyDatabaseName ( targetDatabase ) ;
362
363
}
363
364
364
365
@ Override
@@ -375,4 +376,5 @@ public Optional<T> run() {
375
376
}
376
377
}
377
378
}
379
+
378
380
}
0 commit comments