-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#126 Reloading schemas now involves deleting "user" schemas instead o…
…f clearing the schemas database
- Loading branch information
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/groovy/com/marklogic/gradle/task/databases/DeleteUserSchemasTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.marklogic.gradle.task.databases | ||
|
||
import com.marklogic.gradle.task.MarkLogicTask | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
/** | ||
* "User schemas" is intended to be any documents in a schemas database that are loaded by a user as opposed to those | ||
* created via the deployment of resources such as temporal collections and view schemas. | ||
*/ | ||
class DeleteUserSchemasTask extends MarkLogicTask { | ||
|
||
String xquery | ||
String database | ||
|
||
@TaskAction | ||
void deleteUserSchemas() { | ||
if (xquery == null) { | ||
xquery = "cts:not-query(" + | ||
"cts:collection-query((" + | ||
"'http://marklogic.com/xdmp/temporal/axis', " + | ||
"'http://marklogic.com/xdmp/temporal/collection', 'http://marklogic.com/xdmp/view'" + | ||
"))" + | ||
")" | ||
} | ||
|
||
if (database == null) { | ||
database = getAppConfig().getSchemasDatabaseName() | ||
} | ||
|
||
|
||
String fullQuery = "cts:uris((), (), " + xquery + ") ! xdmp:document-delete(.)" | ||
println "Deleting user schemas in database '" + database + "' via : " + fullQuery | ||
|
||
def client = newClient() | ||
try { | ||
client.newServerEval().xquery(fullQuery).eval() | ||
} finally { | ||
client.release() | ||
} | ||
} | ||
} |