@@ -189,6 +189,7 @@ class DefaultRunnableSpec implements RunnableSpec {
189189 private String targetDatabase ;
190190
191191 DefaultRunnableSpec (Supplier <String > cypherSupplier ) {
192+ this .targetDatabase = Neo4jClient .verifyDatabaseName (resolveTargetDatabaseName (targetDatabase ));
192193 this .runnableStatement = new RunnableStatement (cypherSupplier );
193194 }
194195
@@ -257,6 +258,19 @@ public ResultSummary run() {
257258 throw potentiallyConvertRuntimeException (e , persistenceExceptionTranslator );
258259 }
259260 }
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+ }
260274 }
261275
262276 class DefaultRecordFetchSpec <T > implements RecordFetchSpec <T >, MappingSpec <T > {
@@ -270,24 +284,11 @@ class DefaultRecordFetchSpec<T> implements RecordFetchSpec<T>, MappingSpec<T> {
270284 DefaultRecordFetchSpec (String parameterTargetDatabase , RunnableStatement runnableStatement ,
271285 BiFunction <TypeSystem , Record , T > mappingFunction ) {
272286
273- this .targetDatabase = resolveTargetDatabaseName ( parameterTargetDatabase ) ;
287+ this .targetDatabase = parameterTargetDatabase ;
274288 this .runnableStatement = runnableStatement ;
275289 this .mappingFunction = mappingFunction ;
276290 }
277291
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-
291292 @ Override
292293 public RecordFetchSpec <T > mappedBy (
293294 @ SuppressWarnings ("HiddenField" ) BiFunction <TypeSystem , Record , T > mappingFunction ) {
@@ -358,7 +359,7 @@ class DefaultRunnableDelegation<T> implements RunnableDelegation<T>, OngoingDele
358359
359360 DefaultRunnableDelegation (Function <QueryRunner , Optional <T >> callback , @ Nullable String targetDatabase ) {
360361 this .callback = callback ;
361- this .targetDatabase = targetDatabase ;
362+ this .targetDatabase = Neo4jClient . verifyDatabaseName ( targetDatabase ) ;
362363 }
363364
364365 @ Override
@@ -375,4 +376,5 @@ public Optional<T> run() {
375376 }
376377 }
377378 }
379+
378380}
0 commit comments