Skip to content

Commit f9e8475

Browse files
committed
#400 Can now customize the DatabaseClient for a DataMovementTask
1 parent fdd7f94 commit f9e8475

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main/groovy/com/marklogic/gradle/task/datamovement/DataMovementTask.groovy

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import com.marklogic.client.ext.datamovement.listener.SimpleBatchLoggingListener
1111
import com.marklogic.gradle.task.MarkLogicTask
1212
import org.gradle.api.GradleException
1313

14+
/**
15+
* The "client" field in this task allows a user to provide a custom DatabaseClient while declaring an instance of
16+
* this task in a Gradle build file.
17+
*/
1418
class DataMovementTask extends MarkLogicTask {
1519

20+
DatabaseClient client
21+
1622
void runQueryBatcherJob(QueryBatcherJob job) {
1723
if (project.hasProperty("jobProperties")) {
1824
if (job instanceof ConfigurableJob) {
19-
ConfigurableJob cjob = (ConfigurableJob) job
2025
printJobProperties(job)
2126
} else {
2227
println "Job does not implement ConfigurableJob, cannot show its properties"
@@ -50,11 +55,16 @@ class DataMovementTask extends MarkLogicTask {
5055
}
5156
}
5257

53-
DatabaseClient client = newClient()
58+
DatabaseClient databaseClient = client
59+
if (databaseClient == null) {
60+
databaseClient = newClient()
61+
}
5462
try {
55-
job.run(client)
63+
job.run(databaseClient)
5664
} finally {
57-
client.release()
65+
if (databaseClient != null) {
66+
databaseClient.release()
67+
}
5868
}
5969
}
6070
}

0 commit comments

Comments
 (0)