Skip to content

Commit a07ca49

Browse files
committed
Updates to version 1.0.0: Support Offers, removes useless headers, fixes bugs
1 parent 7cf6942 commit a07ca49

18 files changed

+489
-178
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.azure</groupId>
55
<artifactId>azure-documentdb</artifactId>
6-
<version>0.9.5</version>
6+
<version>1.0.0</version>
77
<name>${project.groupId}:${project.artifactId}</name>
88
<description>Java SDK for Microsoft Azure DocumentDB</description>
99
<url>http://azure.microsoft.com/en-us/services/documentdb/</url>
@@ -168,4 +168,4 @@
168168
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
169169
</repository>
170170
</distributionManagement>
171-
</project>
171+
</project>

src/com/microsoft/azure/documentdb/AuthorizationHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ private static String getResourceSegement(ResourceType resourceType) {
160160
return Paths.DOCUMENTS_PATH_SEGMENT;
161161
case DocumentCollection:
162162
return Paths.COLLECTIONS_PATH_SEGMENT;
163+
case Offer:
164+
return Paths.OFFERS_PATH_SEGMENT;
163165
case Permission:
164166
return Paths.PERMISSIONS_PATH_SEGMENT;
165167
case StoredProcedure:

src/com/microsoft/azure/documentdb/ConnectionMode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ public enum ConnectionMode {
1414
* Use the DocumentDB gateway to route all requests. The gateway proxies requests to the right data partition.
1515
*/
1616
Gateway
17-
18-
// TODO(pushi): Implement other connection modes.
1917
}

src/com/microsoft/azure/documentdb/ConnectionPolicy.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
public final class ConnectionPolicy {
1111

12-
private static final int DEFAULT_MAX_CONNECTIONS = 20;
1312
private static final int DEFAULT_REQUEST_TIMEOUT = 60;
1413
// defaultMediaRequestTimeout is based upon the blob client timeout and the retry policy.
1514
private static final int DEFAULT_MEDIA_REQUEST_TIMEOUT = 300;
@@ -22,7 +21,6 @@ public final class ConnectionPolicy {
2221
* Constructor.
2322
*/
2423
public ConnectionPolicy() {
25-
this.maxConnections = ConnectionPolicy.DEFAULT_MAX_CONNECTIONS;
2624
this.requestTimeout = ConnectionPolicy.DEFAULT_REQUEST_TIMEOUT;
2725
this.mediaRequestTimeout = ConnectionPolicy.DEFAULT_MEDIA_REQUEST_TIMEOUT;
2826
this.connectionMode = ConnectionMode.Gateway;
@@ -32,28 +30,6 @@ public ConnectionPolicy() {
3230
this.userAgentSuffix = "";
3331
}
3432

35-
private int maxConnections;
36-
37-
/**
38-
* Gets the maximum number of simultaneous network connections with a specific data partition. Currently used only
39-
* for Protocol.Tcp.
40-
*
41-
* @return the max connections.
42-
*/
43-
public int getMaxConnections() {
44-
return this.maxConnections;
45-
}
46-
47-
/**
48-
* Sets the maximum number of simultaneous network connections with a specific data partition. Currently used only
49-
* for Protocol.Tcp.
50-
*
51-
* @param maxConnections the max connections.
52-
*/
53-
public void setMaxConnections(int maxConnections) {
54-
this.maxConnections = maxConnections;
55-
}
56-
5733
private int requestTimeout;
5834

5935
/**
@@ -97,7 +73,7 @@ public void setMediaRequestTimeout(int mediaRequestTimeout) {
9773
private ConnectionMode connectionMode;
9874

9975
/**
100-
* Gets the connection mode used the client Gateway or Direct.
76+
* Gets the connection mode used in the client. Currently only Gateway in supported.
10177
*
10278
* @return the connection mode.
10379
*/
@@ -106,7 +82,7 @@ public ConnectionMode getConnectionMode() {
10682
}
10783

10884
/**
109-
* Sets the connection mode used the client Gateway or Direct
85+
* Sets the connection mode used in the client. Currently only Gateway in supported.
11086
*
11187
* @param connectionMode the connection mode.
11288
*/

src/com/microsoft/azure/documentdb/Constants.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ static class Quota {
1515
static final String COLLECTION = "collections";
1616
static final String USER = "users";
1717
static final String PERMISSION = "permissions";
18-
static final String DOCUMENT_SIZE = "documentSize";
19-
static final String ATTACHMENT = "attachmentSize";
18+
static final String COLLECTION_SIZE = "collectionSize";
19+
static final String DOCUMENTS_SIZE = "documentsSize";
2020
static final String STORED_PROCEDURE = "storedProcedures";
2121
static final String TRIGGER = "triggers";
2222
static final String USER_DEFINED_FUNCTION = "functions";
@@ -100,7 +100,9 @@ static class Properties {
100100
//Conflict.
101101
static final String CONFLICT = "conflict";
102102
static final String OPERATION_TYPE = "operationType";
103-
103+
104+
//Offer resource
105+
static final String OFFER_TYPE = "offerType";
104106
}
105107

106108
static class ResourceKeys {
@@ -109,6 +111,7 @@ static class ResourceKeys {
109111
static final String DATABASES = "Databases";
110112
static final String DOCUMENTS = "Documents";
111113
static final String DOCUMENT_COLLECTIONS = "DocumentCollections";
114+
static final String OFFERS = "Offers";
112115
static final String PERMISSIONS = "Permissions";
113116
static final String TRIGGERS = "Triggers";
114117
static final String STOREDPROCEDURES = "StoredProcedures";

src/com/microsoft/azure/documentdb/DatabaseAccount.java

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ public class DatabaseAccount extends Resource {
1010

1111
private long maxMediaStorageUsageInMB;
1212
private long mediaStorageUsageInMB;
13-
private long capacityUnitsConsumed;
14-
private long capacityUnitsProvisioned;
15-
private long consumedDocumentStorageInMB;
16-
private long reservedDocumentStorageInMB;
17-
private long provisionedDocumentStorageInMB;
1813

1914
/**
2015
* Constructor.
@@ -124,77 +119,6 @@ void setMediaStorageUsageInMB(long value) {
124119
this.mediaStorageUsageInMB = value;
125120
}
126121

127-
/**
128-
* The number is capacity units database account is currently consuming. Value is returned from cached information
129-
* which is updated periodically and is not guaranteed to be real time.
130-
*
131-
* @return the capacity units consumed.
132-
*/
133-
public long getCapacityUnitsConsumed() {
134-
return this.capacityUnitsConsumed;
135-
}
136-
137-
void setCapacityUnitsConsumed(long value) {
138-
this.capacityUnitsConsumed = value;
139-
}
140-
141-
/**
142-
* The number of provisioned capacity units for the database account
143-
* Value is returned from cached information which is updated periodically
144-
* and is not guaranteed to be real time.
145-
*
146-
* @return the capacity units provisioned.
147-
*/
148-
public long getCapacityUnitsProvisioned() {
149-
return this.capacityUnitsProvisioned;
150-
}
151-
152-
void setCapacityUnitsProvisioned(long value) {
153-
this.capacityUnitsProvisioned = value;
154-
}
155-
156-
/**
157-
* The cumulative sum of current sizes of created collection in MB Value is returned from cached information which
158-
* is updated periodically and is not guaranteed to be real time
159-
*
160-
* @return the consumed documents storage in MB.
161-
*/
162-
public long getConsumedDocumentStorageInMB() {
163-
return this.consumedDocumentStorageInMB;
164-
}
165-
166-
void setConsumedDocumentStorageInMB(long value) {
167-
this.consumedDocumentStorageInMB = value;
168-
}
169-
170-
/**
171-
* The cumulative sum of maximum sizes of created collection in MB Value is returned from cached information which
172-
* is updated periodically and is not guaranteed to be real time.
173-
*
174-
* @return the reserved documents storage in MB.
175-
*/
176-
public long getReservedDocumentStorageInMB() {
177-
return this.reservedDocumentStorageInMB;
178-
}
179-
180-
void setReservedDocumentStorageInMB(long value) {
181-
this.reservedDocumentStorageInMB = value;
182-
}
183-
184-
/**
185-
* The provisioned documented storage capacity for the database account Value is returned from cached information
186-
* which is updated periodically and is not guaranteed to be real time.
187-
*
188-
* @return the provisioned document storage in MB.
189-
*/
190-
public long getProvisionedDocumentStorageInMB() {
191-
return this.provisionedDocumentStorageInMB;
192-
}
193-
194-
void setProvisionedDocumentStorageInMB(long value) {
195-
this.provisionedDocumentStorageInMB = value;
196-
}
197-
198122
/**
199123
* Gets the ConsistencyPolicy settings.
200124
*

src/com/microsoft/azure/documentdb/DocumentClient.java

Lines changed: 94 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,6 @@ public ResourceResponse<Database> createDatabase(Database database, RequestOptio
169169
return new ResourceResponse<Database>(this.doCreate(request), Database.class);
170170
}
171171

172-
/**
173-
* Replaces a database.
174-
*
175-
* @param database the database.
176-
* @param options the request options.
177-
* @return the resource response with the replaced database.
178-
* @throws DocumentClientException the document client exception.
179-
*/
180-
public ResourceResponse<Database> replaceDatabase(Database database,
181-
RequestOptions options)
182-
throws DocumentClientException {
183-
if (database == null) {
184-
throw new IllegalArgumentException("Database");
185-
}
186-
187-
String path = DocumentClient.joinPath(database.getSelfLink(), null);
188-
Map<String, String> requestHeaders = this.getRequestHeaders(options);
189-
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Database,
190-
path,
191-
database,
192-
requestHeaders);
193-
return new ResourceResponse<Database>(this.doReplace(request), Database.class);
194-
}
195-
196172
/**
197173
* Deletes a database.
198174
*
@@ -1741,7 +1717,7 @@ public ResourceResponse<Permission> createPermission(String userLink, Permission
17411717
* @throws DocumentClientException the document client exception.
17421718
*/
17431719
public ResourceResponse<Permission> replacePermission(Permission permission, RequestOptions options)
1744-
throws DocumentClientException {
1720+
throws DocumentClientException {
17451721

17461722
if (permission == null) {
17471723
throw new IllegalArgumentException("permission");
@@ -1873,6 +1849,95 @@ public FeedResponse<Permission> queryPermissions(String permissionLink,
18731849
Permission.class));
18741850
}
18751851

1852+
/**
1853+
* Replaces an offer.
1854+
*
1855+
* @param offer the offer to use.
1856+
* @return the resource response with the replaced offer.
1857+
* @throws DocumentClientException the document client exception.
1858+
*/
1859+
public ResourceResponse<Offer> replaceOffer(Offer offer) throws DocumentClientException {
1860+
1861+
if (offer == null) {
1862+
throw new IllegalArgumentException("offer");
1863+
}
1864+
1865+
String path = DocumentClient.joinPath(offer.getSelfLink(), null);
1866+
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Offer,
1867+
path,
1868+
offer,
1869+
null);
1870+
return new ResourceResponse<Offer>(this.doReplace(request), Offer.class);
1871+
}
1872+
1873+
/**
1874+
* Reads an offer.
1875+
*
1876+
* @param offerLink the offer link.
1877+
* @return the resource response with the read offer.
1878+
* @throws DocumentClientException the document client exception.
1879+
*/
1880+
public ResourceResponse<Offer> readOffer(String offerLink) throws DocumentClientException {
1881+
1882+
if (StringUtils.isEmpty(offerLink)) {
1883+
throw new IllegalArgumentException("offerLink");
1884+
}
1885+
1886+
String path = DocumentClient.joinPath(offerLink, null);
1887+
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Offer, path, null);
1888+
return new ResourceResponse<Offer>(this.doRead(request), Offer.class);
1889+
}
1890+
1891+
/**
1892+
* Reads offers.
1893+
*
1894+
* @param options the feed options.
1895+
* @return the feed response with the read offers.
1896+
*/
1897+
public FeedResponse<Offer> readOffers(FeedOptions options) {
1898+
String path = DocumentClient.joinPath(Paths.OFFERS_PATH_SEGMENT, null);
1899+
Map<String, String> requestHeaders = this.getFeedHeaders(options);
1900+
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Offer, path, requestHeaders);
1901+
return new FeedResponse<Offer>(new QueryIterable<Offer>(this, request, ReadType.Feed, Offer.class));
1902+
}
1903+
1904+
/**
1905+
* Query for offers in a database.
1906+
*
1907+
* @param query the query.
1908+
* @param options the feed options.
1909+
* @return the feed response with the obtained offers.
1910+
*/
1911+
public FeedResponse<Offer> queryOffers(String query, FeedOptions options) {
1912+
if (StringUtils.isEmpty(query)) {
1913+
throw new IllegalArgumentException("query");
1914+
}
1915+
1916+
return queryOffers(new SqlQuerySpec(query, null), options);
1917+
}
1918+
1919+
/**
1920+
* Query for offers in a database.
1921+
*
1922+
* @param querySpec the query specification.
1923+
* @param options the feed options.
1924+
* @return the feed response with the obtained offers.
1925+
*/
1926+
public FeedResponse<Offer> queryOffers(SqlQuerySpec querySpec, FeedOptions options) {
1927+
if (querySpec == null) {
1928+
throw new IllegalArgumentException("querySpec");
1929+
}
1930+
1931+
String path = DocumentClient.joinPath(Paths.OFFERS_PATH_SEGMENT, null);
1932+
Map<String, String> requestHeaders = this.getFeedHeaders(options);
1933+
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Offer,
1934+
path,
1935+
querySpec,
1936+
this.queryCompatibilityMode,
1937+
requestHeaders);
1938+
return new FeedResponse<Offer>(new QueryIterable<Offer>(this, request, ReadType.Query, Offer.class));
1939+
}
1940+
18761941
/**
18771942
* Gets database account information.
18781943
*
@@ -1889,20 +1954,10 @@ public DatabaseAccount getDatabaseAccount() throws DocumentClientException {
18891954
// read the headers and set to the account
18901955
Map<String, String> responseHeader = response.getResponseHeaders();
18911956

1892-
account.setCapacityUnitsConsumed(Long.valueOf(responseHeader.get(
1893-
HttpConstants.HttpHeaders.DATABASE_ACCOUNT_CAPACITY_UNITS_CONSUMED)));
1894-
account.setCapacityUnitsProvisioned(Long.valueOf(responseHeader.get(
1895-
HttpConstants.HttpHeaders.DATABASE_ACCOUNT_CAPACITY_UNITS_PROVISIONED)));
18961957
account.setMaxMediaStorageUsageInMB(Long.valueOf(responseHeader.get(
18971958
HttpConstants.HttpHeaders.MAX_MEDIA_STORAGE_USAGE_IN_MB)));
18981959
account.setMediaStorageUsageInMB(Long.valueOf(responseHeader.get(
18991960
HttpConstants.HttpHeaders.CURRENT_MEDIA_STORAGE_USAGE_IN_MB)));
1900-
account.setConsumedDocumentStorageInMB(Long.valueOf(responseHeader.get(
1901-
HttpConstants.HttpHeaders.DATABASE_ACCOUNT_CONSUMED_DOCUMENT_STORAGE_IN_MB)));
1902-
account.setReservedDocumentStorageInMB(Long.valueOf(responseHeader.get(
1903-
HttpConstants.HttpHeaders.DATABASE_ACCOUNT_RESERVED_DOCUMENT_STORAGE_IN_MB)));
1904-
account.setProvisionedDocumentStorageInMB(Long.valueOf(responseHeader.get(
1905-
HttpConstants.HttpHeaders.DATABASE_ACCOUNT_PROVISIONED_DOCUMENT_STORAGE_IN_MB)));
19061961

19071962
return account;
19081963
}
@@ -2034,6 +2089,10 @@ private Map<String, String> getRequestHeaders(RequestOptions options) {
20342089
String.valueOf(options.getResourceTokenExpirySeconds()));
20352090
}
20362091

2092+
if (options.getOfferType() != null) {
2093+
headers.put(HttpConstants.HttpHeaders.OFFER_TYPE, options.getOfferType());
2094+
}
2095+
20372096
return headers;
20382097
}
20392098

0 commit comments

Comments
 (0)