Skip to content

Commit

Permalink
Merge pull request #45 from shellygms/master
Browse files Browse the repository at this point in the history
DocumentDB Java SDK 1.7.0 Release
  • Loading branch information
shellygms committed Apr 25, 2016
2 parents 35fe64f + ae2c688 commit 7f01748
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
</dependency>

###Option 2: Source Via Git
Expand Down Expand Up @@ -92,9 +92,9 @@ public class SampleApp {
DocumentCollection myCollection = new DocumentCollection();
myCollection.setId(COLLECTION_ID);

// Configure the new collection performance tier to S1.
// Set the provisioned throughput for this collection to be 1000 RUs.
RequestOptions requestOptions = new RequestOptions();
requestOptions.setOfferType("S1");
requestOptions.setOfferThroughput(1000);

// Create a new collection.
myCollection = documentClient.createCollection(
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Changes in 1.7.0 : ##

- Added support for expiring documents by setting the default time-to-live on collections and time-to-live override on documents.

## Changes in 1.6.0 : ##

- Added support to set offer throughput for collections created with variable pricing structure.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Java SDK for Microsoft Azure DocumentDB</description>
<url>http://azure.microsoft.com/en-us/services/documentdb/</url>
Expand Down
6 changes: 5 additions & 1 deletion src/com/microsoft/azure/documentdb/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ static class Properties {
static final String PARTITION_KEY_PATHS = "paths";
static final String PARTITION_KIND = "kind";
static final String RESOURCE_PARTITION_KEY = "resourcePartitionKey";
}

//Time-to-Live
static final String TTL = "ttl";
static final String DEFAULT_TTL = "defaultTtl";
}

static class ResourceKeys {
static final String ATTACHMENTS = "Attachments";
Expand Down
37 changes: 37 additions & 0 deletions src/com/microsoft/azure/documentdb/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,41 @@ static Document FromObject(Object document) {
}
return typedDocument;
}

/**
* Sets the document's time-to-live value.
* <p>
* 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;
}
}
38 changes: 38 additions & 0 deletions src/com/microsoft/azure/documentdb/DocumentCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,44 @@ public PartitionKeyDefinition getPartitionKey() {
return null;
}

/**
* Sets the collection's default time-to-live value.
* <p>
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/com/microsoft/azure/documentdb/HttpConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/com/microsoft/azure/documentdb/PartitionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -416,20 +416,20 @@ public void testReadDocumentFeed() throws DocumentClientException {

FeedOptions feedOptions = new FeedOptions();
feedOptions.setEnableCrossPartitionQuery(true);
List<Document> documents = client.readDocuments(createdCollection.getSelfLink(), feedOptions).getQueryIterable().toList();
List<Document> documents = this.client.readDocuments(createdCollection.getSelfLink(), feedOptions).getQueryIterable().toList();
Assert.assertEquals(2, documents.size());

// Read document feed with partition key.
feedOptions = new FeedOptions();
feedOptions.setEnableCrossPartitionQuery(true);
feedOptions.setPartitionKey(new PartitionKey(documentId1));
documents = client.readDocuments(createdCollection.getSelfLink(), feedOptions).getQueryIterable().toList();
documents = this.client.readDocuments(createdCollection.getSelfLink(), feedOptions).getQueryIterable().toList();
Assert.assertEquals(1, documents.size());
Assert.assertEquals(sampleDocument1.getString("id"), documents.get(0).getString("id"));

feedOptions = new FeedOptions();
feedOptions.setPartitionKey(new PartitionKey(documentId2));
documents = client.readDocuments(createdCollection.getSelfLink(), feedOptions).getQueryIterable().toList();
documents = this.client.readDocuments(createdCollection.getSelfLink(), feedOptions).getQueryIterable().toList();
Assert.assertEquals(1, documents.size());
Assert.assertEquals(sampleDocument2.getString("id"), documents.get(0).getString("id"));
}
Expand Down Expand Up @@ -625,7 +625,7 @@ public void testExecuteStoredProcedure() throws DocumentClientException {
@Test
public void testCreatePermissionWithPartitionKey() throws DocumentClientException {
// Create user.
User user = client.createUser(
User user = this.client.createUser(
getDatabaseLink(this.databaseForTest, true),
new User("{ 'id': 'new user' }"),
null).getResource();
Expand Down
Loading

0 comments on commit 7f01748

Please sign in to comment.