Skip to content

Commit 303e8ad

Browse files
committed
fix #36; allow deleteAll() if we can't provide deleteAll(String... collections) since the REST API doesn't support that
1 parent 25cbf40 commit 303e8ad

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/main/java/com/marklogic/client/impl/PojoRepositoryImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,25 @@ public void delete(ID... ids) {
124124
docMgr.delete(createUri(id));
125125
}
126126
}
127-
public void delete(String... collections) {
127+
public void deleteAll() {
128+
QueryManager queryMgr = client.newQueryManager();
129+
DeleteQueryDefinition deleteQuery = queryMgr.newDeleteDefinition();
130+
deleteQuery.setCollections(entityClass.getName());
131+
queryMgr.delete(deleteQuery);
132+
}
133+
/* REST API does not currently support DELETE /search with multiple collection arguments
134+
public void deleteAll(String... collections) {
135+
if ( collections == null || collections.length == 0 ) {
136+
throw new IllegalArgumentException("You must specify at least one collection");
137+
} else if ( collections[0] == null ) {
138+
throw new IllegalArgumentException("Collection argument must not be null");
139+
}
128140
QueryManager queryMgr = client.newQueryManager();
129141
DeleteQueryDefinition deleteQuery = queryMgr.newDeleteDefinition();
130142
deleteQuery.setCollections(collections);
131143
queryMgr.delete((DeleteQueryDefinition) wrapQuery(deleteQuery));
132144
}
145+
*/
133146

134147
public T read(ID id) {
135148
return read(id, null);

src/main/java/com/marklogic/client/pojo/PojoRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public interface PojoRepository<T, ID extends Serializable> {
2020
public long count(QueryDefinition query);
2121

2222
public void delete(ID... ids);
23-
public void delete(String... collections);
23+
public void deleteAll();
24+
/* REST API does not currently support DELETE /search with multiple collection arguments
25+
public void deleteAll(String... collections);
26+
*/
2427

2528
public T read(ID id);
2629
public T read(ID id, Transaction transaction);

src/test/java/com/marklogic/client/test/PojoFacadeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void testE_DeletePojos() throws Exception {
264264
assertEquals("Failed to read number of records expected", 1, page.getTotalSize());
265265

266266
// now delete them all
267-
cities.delete((String)null);
267+
cities.deleteAll();
268268
long count = cities.count();
269269
assertEquals("Failed to read number of records expected", 0, count);
270270
}

0 commit comments

Comments
 (0)