Skip to content

Commit 2d1e4e6

Browse files
authored
Merge pull request #1623 from marklogic/feature/search-timestamp
Exposing read/search methods that accept a server timestamp
2 parents 97e91f9 + 24e257f commit 2d1e4e6

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.marklogic.client.fastfunctest;
2+
3+
import com.marklogic.client.document.GenericDocumentManager;
4+
import com.marklogic.client.io.SearchHandle;
5+
import com.marklogic.client.query.QueryManager;
6+
import com.marklogic.client.query.StructuredQueryDefinition;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
/**
12+
* Added in 6.4.1; the 5 methods had been commented out with a comment indicating that the server APIs
13+
* were not fully fleshed out, but those APIs - specifically, how the REST API receives a server timestamp - have long
14+
* been present in the REST API.
15+
*/
16+
public class ReadAndSearchWithTimestampTest extends AbstractFunctionalTest {
17+
18+
@Test
19+
void test() {
20+
final String collection = "timestamp-test";
21+
final String[] uris = writeJsonDocs(2, collection).toArray(new String[]{});
22+
23+
final QueryManager queryManager = client.newQueryManager();
24+
final GenericDocumentManager docManager = client.newDocumentManager();
25+
final StructuredQueryDefinition collectionQuery = queryManager.newStructuredQueryBuilder().collection(collection);
26+
27+
SearchHandle searchResults = queryManager.search(collectionQuery, new SearchHandle());
28+
assertEquals(2, searchResults.getTotalResults());
29+
final long serverTimestamp = searchResults.getServerTimestamp();
30+
logger.info("Server timestamp: " + serverTimestamp);
31+
32+
// Write additional docs to the same collection and verify they are not returned by subsequent point-in-time
33+
// queries. Note that the first 2 URIs are the same as the ones originally written.
34+
writeJsonDocs(5, collection);
35+
36+
// Verify each of the exposed methods in 6.4.1
37+
assertEquals(2, docManager.read(serverTimestamp, uris).size());
38+
assertEquals(2, docManager.read(serverTimestamp, null, uris).size());
39+
assertEquals(2, docManager.search(collectionQuery, 1, serverTimestamp).size());
40+
41+
assertEquals(5, docManager.search(collectionQuery, 1).size(),
42+
"A query without a timestamp should return all of the documents in the collection.");
43+
}
44+
}

marklogic-client-api/src/main/java/com/marklogic/client/document/DocumentManager.java

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,9 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
463463
* server via getServerTimestamp() on any handle.
464464
* @param uris the database uris identifying documents to retrieve
465465
* @return the DocumentPage of matching documents and metadata
466+
* @since 6.4.1
466467
*/
467-
/* Hide the following for now because the API isn't yet fully fleshed-out
468468
DocumentPage read(long serverTimestamp, String... uris);
469-
*/
470469

471470
/**
472471
* Reads from the database a list of documents matching the provided uris. Allows
@@ -492,10 +491,9 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
492491
* @param transform the transform to be run on the server on each document (must already be installed)
493492
* @param uris the database uris identifying documents to retrieve
494493
* @return the DocumentPage of matching documents and metadata
494+
* @since 6.4.1
495495
*/
496-
/* Hide the following for now because the API isn't yet fully fleshed-out
497496
DocumentPage read(long serverTimestamp, ServerTransform transform, String... uris);
498-
*/
499497

500498
/**
501499
* Reads from the database a list of documents matching the provided uris. Allows
@@ -509,23 +507,6 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
509507
*/
510508
DocumentPage read(Transaction transaction, String... uris);
511509

512-
/**
513-
* Reads from the database a list of documents matching the provided uris. Allows
514-
* iteration across matching documents and metadata (only if setMetadataCategories
515-
* has been called to request metadata). To find out how many of your uris matched,
516-
* call the {@link DocumentPage#size() DocumentPage.size()} method.
517-
*
518-
* @param serverTimestamp the point in time at which to read these
519-
* documents. The value must be a merge timestamp obtained from the
520-
* server via getServerTimestamp() on any handle.
521-
* @param transaction the transaction in which this read is participating
522-
* @param uris the database uris identifying documents to retrieve
523-
* @return the DocumentPage of matching documents and metadata
524-
*/
525-
/* Hide the following for now because the API isn't yet fully fleshed-out
526-
DocumentPage read(long serverTimestamp, Transaction transaction, String... uris);
527-
*/
528-
529510
/**
530511
* Reads from the database a list of documents matching the provided uris. Allows
531512
* iteration across matching documents and metadata (only if setMetadataCategories
@@ -539,24 +520,6 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
539520
*/
540521
DocumentPage read(ServerTransform transform, Transaction transaction, String... uris);
541522

542-
/**
543-
* Reads from the database a list of documents matching the provided uris. Allows
544-
* iteration across matching documents and metadata (only if setMetadataCategories
545-
* has been called to request metadata). To find out how many of your uris matched,
546-
* call the {@link DocumentPage#size() DocumentPage.size()} method.
547-
*
548-
* @param serverTimestamp the point in time at which to read these
549-
* documents. The value must be a merge timestamp obtained from the
550-
* server via getServerTimestamp() on any handle.
551-
* @param transform the transform to be run on the server on each document (must already be installed)
552-
* @param transaction the transaction in which this read is participating
553-
* @param uris the database uris identifying documents to retrieve
554-
* @return the DocumentPage of matching documents and metadata
555-
*/
556-
/* Hide the following for now because the API isn't yet fully fleshed-out
557-
DocumentPage read(long serverTimestamp, ServerTransform transform, Transaction transaction, String... uris);
558-
*/
559-
560523
/**
561524
* Reads from the database the metadata for a list of documents matching the
562525
* provided uris. Allows iteration across the metadata for matching documents
@@ -619,10 +582,9 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
619582
* documents. The value must be a merge timestamp obtained from the
620583
* server via getServerTimestamp() on any handle.
621584
* @return the DocumentPage of matching documents and metadata
585+
* @since 6.4.1
622586
*/
623-
/* Hide the following for now because the API isn't yet fully fleshed-out
624587
DocumentPage search(SearchQueryDefinition querydef, long start, long serverTimestamp);
625-
*/
626588

627589
/**
628590
* Just like {@link QueryManager#search(SearchQueryDefinition, SearchReadHandle, long, Transaction) QueryManager.search}

0 commit comments

Comments
 (0)