Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit de23ae9

Browse files
author
Rob Rudin
committed
#135 Using new approach for loading schemas
1 parent c5ccb96 commit de23ae9

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repositories {
1515
}
1616

1717
dependencies {
18-
compile 'com.marklogic:ml-javaclient-util:2.12.DEV'
18+
compile 'com.marklogic:ml-javaclient-util:2.13.DEV'
1919
compile 'jaxen:jaxen:1.1.6'
2020
compile 'org.apache.httpcomponents:httpclient:4.3.5'
2121
compile 'org.springframework:spring-web:4.3.5.RELEASE'

src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public Integer getExecuteSortOrder() {
4141
* @param filenames
4242
*/
4343
public void setFilenamesToIgnore(String... filenames) {
44+
if (filenames == null || filenames.length == 0) {
45+
return;
46+
}
4447
if (resourceFilenameFilter != null && resourceFilenameFilter instanceof ResourceFilenameFilter) {
4548
ResourceFilenameFilter rff = (ResourceFilenameFilter) resourceFilenameFilter;
4649
Set<String> set = null;
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
package com.marklogic.appdeployer.command.schemas;
22

3-
import java.io.File;
4-
53
import com.marklogic.appdeployer.AppConfig;
64
import com.marklogic.appdeployer.command.AbstractCommand;
75
import com.marklogic.appdeployer.command.CommandContext;
86
import com.marklogic.appdeployer.command.SortOrderConstants;
97
import com.marklogic.client.DatabaseClient;
108
import com.marklogic.client.FailedRequestException;
119
import com.marklogic.client.schemasloader.SchemasLoader;
12-
import com.marklogic.client.schemasloader.impl.DefaultSchemasFinder;
1310
import com.marklogic.client.schemasloader.impl.DefaultSchemasLoader;
1411

1512
public class LoadSchemasCommand extends AbstractCommand {
1613

17-
private SchemasLoader schemasLoader;
18-
1914
public LoadSchemasCommand() {
2015
setExecuteSortOrder(SortOrderConstants.LOAD_SCHEMAS);
2116
}
@@ -26,16 +21,13 @@ public void execute(CommandContext context) {
2621
}
2722

2823
protected void loadSchemasIntoSchemasDatabase(CommandContext context) {
29-
if (schemasLoader == null) {
30-
initializeDefaultSchemasLoader(context);
31-
}
32-
3324
AppConfig config = context.getAppConfig();
3425
DatabaseClient client = config.newSchemasDatabaseClient();
26+
SchemasLoader schemasLoader = new DefaultSchemasLoader(client);
3527
try {
3628
String schemasPath = config.getSchemasPath();
3729
logger.info("Loading schemas database data from path: " + schemasPath);
38-
schemasLoader.loadSchemas(new File(schemasPath), new DefaultSchemasFinder(), client);
30+
schemasLoader.loadSchemas(schemasPath);
3931
} catch (FailedRequestException fre) {
4032
if (fre.getMessage().contains("NOSUCHDB")) {
4133
logger.warn("Unable to load schemas because no schemas database exists; cause: " + fre.getMessage());
@@ -47,10 +39,4 @@ protected void loadSchemasIntoSchemasDatabase(CommandContext context) {
4739
client.release();
4840
}
4941
}
50-
51-
private void initializeDefaultSchemasLoader(CommandContext context) {
52-
logger.info("Initializing instance of DefaultSchemasLoader");
53-
this.schemasLoader = new DefaultSchemasLoader();
54-
}
55-
5642
}

src/test/java/com/marklogic/appdeployer/command/schemas/LoadSchemasTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public void testSchemaLoading() {
2626
GenericDocumentManager docMgr = client.newDocumentManager();
2727

2828
assertNull("Rules document loaded", docMgr.exists("notExists"));
29-
assertNotNull("Rules document loaded", docMgr.exists("my.rules").getUri());
30-
assertNotNull("XSD document loaded", docMgr.exists("x.xsd").getUri());
29+
assertNotNull("Rules document loaded", docMgr.exists("/my.rules").getUri());
30+
assertNotNull("XSD document loaded", docMgr.exists("/x.xsd").getUri());
3131
}
3232

3333
@Test
@@ -41,10 +41,10 @@ public void testSchemaCustomSchemasPath() {
4141

4242
GenericDocumentManager docMgr = client.newDocumentManager();
4343

44-
assertNotNull("TDEXML document loaded", docMgr.exists("x.tdex").getUri());
45-
assertNotNull("TDEJSON document loaded", docMgr.exists("x.tdej").getUri());
44+
assertNotNull("TDEXML document loaded", docMgr.exists("/x.tdex").getUri());
45+
assertNotNull("TDEJSON document loaded", docMgr.exists("/x.tdej").getUri());
4646

47-
for (String uri : new String[] { "x.tdex", "x.tdej" }) {
47+
for (String uri : new String[] { "/x.tdex", "/x.tdej" }) {
4848
DocumentMetadataHandle h = docMgr.readMetadata(uri, new DocumentMetadataHandle());
4949
assertEquals("Files ending in tdex and tdej go into a special collection", "http://marklogic.com/xdmp/tde",
5050
h.getCollections().iterator().next());

0 commit comments

Comments
 (0)