diff --git a/README.md b/README.md
index 1e2b498..fda9d53 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
+ * A document's time-to-live value is an optional property. If set, the document expires after the specified number + * of seconds since its last write time. The value of this property should be one of the following: + * null - indicates the time-to-live value for this document inherits from the parent collection's default time-to-live value. + * nonzero positive integer - indicates the number of seconds before the document expires. It overrides the default time-to-live + * value specified on the parent collection, unless the parent collection's default time-to-live is null. + * -1 - indicates the document never expires. It overrides the default time-to-live + * value specified on the parent collection, unless the parent collection's default time-to-live is null. + * + * @param timeToLive the document's time-to-live value in seconds. + */ + public void setTimeToLive(Integer timeToLive) { + // a "null" value is represented as a missing element on the wire. + // setting timeToLive to null should remove the property from the property bag. + if (timeToLive != null) { + super.set(Constants.Properties.TTL, timeToLive); + } + else if (super.has(Constants.Properties.TTL)) { + super.remove(Constants.Properties.TTL); + } + } + + /** + * Gets the document's time-to-live value. + * + * @return the document's time-to-live value in seconds. + */ + public Integer getTimeToLive() { + if (super.has(Constants.Properties.TTL)) { + return super.getInt(Constants.Properties.TTL); + } + + return null; + } } diff --git a/src/com/microsoft/azure/documentdb/DocumentCollection.java b/src/com/microsoft/azure/documentdb/DocumentCollection.java index 563a554..9c73946 100644 --- a/src/com/microsoft/azure/documentdb/DocumentCollection.java +++ b/src/com/microsoft/azure/documentdb/DocumentCollection.java @@ -95,6 +95,44 @@ public PartitionKeyDefinition getPartitionKey() { return null; } + /** + * Sets the collection's default time-to-live value. + *
+ * The default time-to-live value on a collection is an optional property. If set, the documents within the collection
+ * expires after the specified number of seconds since their last write time. The value of this property should be one of the following:
+ * null - indicates evaluation of time-to-live is disabled and documents within the collection will never expire, regardless whether
+ * individual documents have their time-to-live set.
+ * nonzero positive integer - indicates the default time-to-live value for all documents within the collection. This value can be overridden
+ * by individual documents' time-to-live value.
+ * -1 - indicates by default all documents within the collection never expire. This value can be overridden by individual documents'
+ * time-to-live value.
+ *
+ * @param timeToLive the default time-to-live value in seconds.
+ */
+ public void setDefaultTimeToLive(Integer timeToLive) {
+ // a "null" value is represented as a missing element on the wire.
+ // setting timeToLive to null should remove the property from the property bag.
+ if (timeToLive != null) {
+ super.set(Constants.Properties.DEFAULT_TTL, timeToLive);
+ }
+ else if (super.has(Constants.Properties.DEFAULT_TTL)) {
+ super.remove(Constants.Properties.DEFAULT_TTL);
+ }
+ }
+
+ /**
+ * Gets the collection's default time-to-live value.
+ *
+ * @return the the default time-to-live value in seconds.
+ */
+ public Integer getDefaultTimeToLive() {
+ if (super.has(Constants.Properties.DEFAULT_TTL)) {
+ return super.getInt(Constants.Properties.DEFAULT_TTL);
+ }
+
+ return null;
+ }
+
/**
* Gets the self-link for documents in a collection.
*
diff --git a/src/com/microsoft/azure/documentdb/HashPartitionResolver.java b/src/com/microsoft/azure/documentdb/HashPartitionResolver.java
index bde2f88..da938b7 100644
--- a/src/com/microsoft/azure/documentdb/HashPartitionResolver.java
+++ b/src/com/microsoft/azure/documentdb/HashPartitionResolver.java
@@ -130,7 +130,7 @@ public String resolveForCreate(Object document) {
/**
* Resolves the collection for reading/querying the documents based on the partition key.
*
- * @param partitionKey the partition key used to resolve the collection.
+ * @param partitionKey the partition key value
*
* @return collection Self link(s) or Name based link(s) which should handle the Read operation
*/
diff --git a/src/com/microsoft/azure/documentdb/HttpConstants.java b/src/com/microsoft/azure/documentdb/HttpConstants.java
index 0c30999..74a3155 100644
--- a/src/com/microsoft/azure/documentdb/HttpConstants.java
+++ b/src/com/microsoft/azure/documentdb/HttpConstants.java
@@ -166,7 +166,7 @@ public static class HttpHeaders {
public static class Versions {
public static String CURRENT_VERSION = "2015-12-16";
- public static String USER_AGENT = "documentdb-java-sdk-1.6.0";
+ public static String USER_AGENT = "documentdb-java-sdk-1.7.0";
}
public static class StatusCodes {
diff --git a/src/com/microsoft/azure/documentdb/PartitionKey.java b/src/com/microsoft/azure/documentdb/PartitionKey.java
index 9219933..b268a46 100644
--- a/src/com/microsoft/azure/documentdb/PartitionKey.java
+++ b/src/com/microsoft/azure/documentdb/PartitionKey.java
@@ -28,7 +28,7 @@ public PartitionKey(Object key) {
* Create a new instance of the PartitionKey object from a serialized JSON string.
*
* @param jsonString
- * the value of the partition key in JSON form.
+ * the JSON string representation of this PartitionKey object.
*
* @return the PartitionKey instance.
*/
diff --git a/src/com/microsoft/azure/documentdb/RangePartitionResolver.java b/src/com/microsoft/azure/documentdb/RangePartitionResolver.java
index ec88343..f49b22f 100644
--- a/src/com/microsoft/azure/documentdb/RangePartitionResolver.java
+++ b/src/com/microsoft/azure/documentdb/RangePartitionResolver.java
@@ -81,7 +81,7 @@ public String resolveForCreate(Object document) {
/**
* Resolves the collection for reading/querying the documents based on the partition key.
*
- * @param partitionKey the partition key used to resolve the collection.
+ * @param partitionKey the partition key value.
*
* @return collection Self link(s) or Name based link(s) which should handle the Read operation.
*/
diff --git a/src/com/microsoft/azure/documentdb/test/GatewayTestBase.java b/src/com/microsoft/azure/documentdb/test/GatewayTestBase.java
index 9f6ab2f..b6b8a2a 100644
--- a/src/com/microsoft/azure/documentdb/test/GatewayTestBase.java
+++ b/src/com/microsoft/azure/documentdb/test/GatewayTestBase.java
@@ -46,7 +46,7 @@ public class GatewayTestBase {
// Replace MASTER_KEY and HOST with values from your DocumentDB account.
protected static final String MASTER_KEY = "[REPLACE WITH YOUR APP MASTER KEY]";
protected static final String HOST = "[REPLACE WITH YOUR APP ENDPOINT, FOR EXAMPLE https://myapp.documents.azure.com:443]";
-
+
protected static final String DATABASES_PATH_SEGMENT = "dbs";
protected static final String USERS_PATH_SEGMENT = "users";
protected static final String PERMISSIONS_PATH_SEGMENT = "permissions";
diff --git a/src/com/microsoft/azure/documentdb/test/JavaMultiPartitionCollectionTests.java b/src/com/microsoft/azure/documentdb/test/JavaMultiPartitionCollectionTests.java
index 4ece2b9..947c068 100644
--- a/src/com/microsoft/azure/documentdb/test/JavaMultiPartitionCollectionTests.java
+++ b/src/com/microsoft/azure/documentdb/test/JavaMultiPartitionCollectionTests.java
@@ -137,7 +137,7 @@ public void testDocumentCrud() throws DocumentClientException {
Assert.assertTrue(readFail);
// Read document1 with partition key.
- document = client.readDocument(document.getSelfLink(), requestOptions).getResource();
+ document = this.client.readDocument(document.getSelfLink(), requestOptions).getResource();
Assert.assertEquals(documentId, document.getString("id"));
// Update document without partition key.
@@ -162,11 +162,11 @@ public void testDocumentCrud() throws DocumentClientException {
Assert.assertTrue(deleteFail);
// Delete document with partition key.
- client.deleteDocument(document.getSelfLink(), requestOptions);
+ this.client.deleteDocument(document.getSelfLink(), requestOptions);
readFail = false;
try {
- client.readDocument(document.getSelfLink(), requestOptions).getResource();
+ this.client.readDocument(document.getSelfLink(), requestOptions).getResource();
} catch (DocumentClientException e) {
readFail = true;
Assert.assertEquals(404, e.getStatusCode());
@@ -190,7 +190,7 @@ public void testDocumentKeyExtraction() throws DocumentClientException {
// create document without partition key
String documentId = GatewayTests.getUID();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId, documentId));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -220,7 +220,7 @@ public void testDocumentKeyExtractionNestedProperty() throws DocumentClientExcep
String documentId = GatewayTests.getUID();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId, documentId));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -249,7 +249,7 @@ public void testDocumentKeyExtractionUndefined() throws DocumentClientException
String documentId = GatewayTests.getUID();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -279,7 +279,7 @@ public void testDocumentKeyExtractionComplextTypeAsUndefined() throws DocumentCl
String documentId = GatewayTests.getUID();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -308,7 +308,7 @@ public void testDocumentKeyExtractionWithEscapeCharacters1() throws DocumentClie
String documentId = GatewayTests.getUID();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId, documentId));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -337,7 +337,7 @@ public void testDocumentKeyExtractionWithEscapeCharacters2() throws DocumentClie
String documentId = GatewayTests.getUID();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId, documentId));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -368,7 +368,7 @@ public void testNullPartitionKey() throws DocumentClientException {
String documentId = GatewayTests.getUID();
String name = JSONObject.NULL.toString();
Document sampleDocument = new Document(String.format(sampleDocumentTemplate, documentId, name));
- Document document = client.createDocument(
+ Document document = this.client.createDocument(
createdCollection.getSelfLink(),
sampleDocument,
null,
@@ -416,20 +416,20 @@ public void testReadDocumentFeed() throws DocumentClientException {
FeedOptions feedOptions = new FeedOptions();
feedOptions.setEnableCrossPartitionQuery(true);
- List