Skip to content

Commit db84326

Browse files
author
Ryan CrawCour
committed
Merge pull request #31 from shipunyc/master
Implements V2 indexing policy
2 parents 08bdc63 + 75226de commit db84326

File tree

10 files changed

+202
-59
lines changed

10 files changed

+202
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
1414
<dependency>
1515
<groupId>com.microsoft.azure</groupId>
1616
<artifactId>azure-documentdb</artifactId>
17-
<version>1.0.1</version>
17+
<version>1.1.0</version>
1818
</dependency>
1919

2020
###Option 2: Source Via Git

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Changes in 1.1.0 : ##
2+
3+
- Implements V2 indexing policy

pom.xml

Lines changed: 1 addition & 1 deletion
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>1.0.1</version>
6+
<version>1.1.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>

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ static class Properties {
8989
static final String MAX_PATH_DEPTH = "maxPathDepth";
9090
static final String INDEXING_MODE = "indexingMode";
9191
static final String INDEX_TYPE = "IndexType";
92+
static final String INDEX_KIND = "kind";
93+
static final String DATA_TYPE = "dataType";
94+
static final String PRECISION = "precision";
9295

9396
static final String PATHS = "paths";
94-
static final String PATH = "Path";
95-
static final String FREQUENT_PATHS = "Frequent";
96-
static final String INCLUDED_PATHS = "IncludedPaths";
97-
static final String IN_FREQUENT_PATHS = "InFrequent";
98-
static final String EXCLUDED_PATHS = "ExcludedPaths";
97+
static final String PATH = "path";
98+
static final String INCLUDED_PATHS = "includedPaths";
99+
static final String EXCLUDED_PATHS = "excludedPaths";
100+
static final String INDEXES = "indexes";
99101

100102
//Conflict.
101103
static final String CONFLICT = "conflict";

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public DocumentCollection(JSONObject jsonObject) {
4646
* @param indexingPolicy the indexing policy.
4747
*/
4848
public void setIndexingPolicy(IndexingPolicy indexingPolicy) {
49+
if (indexingPolicy == null) {
50+
throw new IllegalArgumentException("IndexingPolicy cannot be null.");
51+
}
52+
4953
this.indexingPolicy = indexingPolicy;
5054
}
5155

@@ -120,9 +124,11 @@ public String getConflictsLink() {
120124

121125
@Override
122126
public void onSave() {
123-
if (this.indexingPolicy != null) {
124-
this.indexingPolicy.onSave();
125-
super.set(Constants.Properties.INDEXING_POLICY, this.indexingPolicy);
127+
if (this.indexingPolicy == null) {
128+
this.getIndexingPolicy();
126129
}
130+
131+
this.indexingPolicy.onSave();
132+
super.set(Constants.Properties.INDEXING_POLICY, this.indexingPolicy);
127133
}
128134
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,8 @@ public static class HttpHeaders {
147147
}
148148

149149
public static class Versions {
150-
// For DocumentServiceProperties and MediaIdFormatChange, Gateway will
151-
// work for the version later than this version.
152-
public static String DOCUMENT_SERVICE_PROPERTIES_VERSION_20131105 = "2013-11-05";
153-
public static String MEDIA_ID_FORMAT_CHANGE_VERSION_20140418 = "2014-02-25";
154-
155-
public static String CURRENT_VERSION = "2015-04-08";
156-
157-
public static String USER_AGENT = "documentdb-java-sdk-1.0.1";
150+
public static String CURRENT_VERSION = "2015-06-03";
151+
public static String USER_AGENT = "documentdb-java-sdk-1.1.0";
158152
}
159153

160154
public static class StatusCodes {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,14 @@ public enum IndexingMode {
1717
* <p>
1818
* With lazy indexing, queries are eventually consistent. The index is updated when the collection is idle.
1919
*/
20-
Lazy
20+
Lazy,
21+
22+
/**
23+
* No index is provided.
24+
* <p>
25+
* Setting IndexingMode to "None" drops the index. Use this if you don't want to maintain the index for a document
26+
* collection, to save the storage cost or improve the write throughput. Your queries will degenerate to scans of
27+
* the entire collection.
28+
*/
29+
None
2130
}

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

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
public final class IndexingPolicy extends JsonSerializable {
1414

15+
private static final String DEFAULT_PATH = "/*";
16+
17+
private Collection<IncludedPath> includedPaths;
18+
private Collection<ExcludedPath> excludedPaths;
19+
1520
/**
1621
* Constructor.
1722
*/
@@ -86,63 +91,70 @@ public IndexingMode getIndexingMode() {
8691
return result;
8792
}
8893

89-
/**
90-
* Gets or sets the path level configurations for indexing.
91-
*/
92-
private Collection<IndexingPath> included;
93-
private Collection<String> excluded;
94-
95-
9694
/**
9795
* Gets the paths that are chosen to be indexed by the user.
9896
*
9997
* @return the included paths.
10098
*/
101-
public Collection<IndexingPath> getIncludedPaths() {
102-
if (this.included == null) {
103-
this.included = super.getCollection(Constants.Properties.INCLUDED_PATHS, IndexingPath.class);
99+
public Collection<IncludedPath> getIncludedPaths() {
100+
if (this.includedPaths == null) {
101+
this.includedPaths = super.getCollection(Constants.Properties.INCLUDED_PATHS, IncludedPath.class);
104102

105-
if (this.included == null) {
106-
this.included = new ArrayList<IndexingPath>();
103+
if (this.includedPaths == null) {
104+
this.includedPaths = new ArrayList<IncludedPath>();
107105
}
108106
}
109107

110-
return this.included;
108+
return this.includedPaths;
109+
}
110+
111+
public void setIncludedPaths(Collection<IncludedPath> includedPaths) {
112+
this.includedPaths = includedPaths;
111113
}
112-
114+
113115
/**
114116
* Gets the paths that are not indexed.
115117
*
116118
* @return the excluded paths.
117119
*/
118-
public Collection<String> getExcludedPaths() {
119-
if (this.excluded == null) {
120-
this.excluded = super.getCollection(Constants.Properties.EXCLUDED_PATHS, String.class);
120+
public Collection<ExcludedPath> getExcludedPaths() {
121+
if (this.excludedPaths == null) {
122+
this.excludedPaths = super.getCollection(Constants.Properties.EXCLUDED_PATHS, ExcludedPath.class);
121123

122-
if (this.excluded == null) {
123-
this.excluded = new ArrayList<String>();
124+
if (this.excludedPaths == null) {
125+
this.excludedPaths = new ArrayList<ExcludedPath>();
124126
}
125127
}
126128

127-
return this.excluded;
129+
return this.excludedPaths;
130+
}
131+
132+
public void setExcludedPaths(Collection<ExcludedPath> excludedPaths) {
133+
this.excludedPaths = excludedPaths;
128134
}
129135

130136
@Override
131137
void onSave() {
132-
boolean bDefaultPaths = (this.included != null && this.included.size() == 0 &&
133-
this.excluded != null && this.excluded.size() == 0);
134-
135-
// If we do not have any user-specified paths, do not serialize.
136-
// If we don't do this, included and excluded will be sent as empty lists [], [] which have a different meaning
137-
// on server.
138-
if (bDefaultPaths) return;
138+
// If indexing mode is not 'none' and not paths are set, set them to the defaults
139+
if (this.getIndexingMode() != IndexingMode.None && this.getIncludedPaths().size() == 0 &&
140+
this.getExcludedPaths().size() == 0) {
141+
IncludedPath includedPath = new IncludedPath();
142+
includedPath.setPath(IndexingPolicy.DEFAULT_PATH);
143+
this.getIncludedPaths().add(includedPath);
144+
}
139145

140-
if (this.included != null) {
141-
super.set(Constants.Properties.INCLUDED_PATHS, this.included);
146+
if (this.includedPaths != null) {
147+
for (IncludedPath includedPath : this.includedPaths) {
148+
includedPath.onSave();
149+
}
150+
super.set(Constants.Properties.INCLUDED_PATHS, this.includedPaths);
142151
}
143152

144-
if (this.excluded != null) {
145-
super.set(Constants.Properties.EXCLUDED_PATHS, this.excluded);
153+
if (this.excludedPaths != null) {
154+
for (ExcludedPath excludedPath : this.excludedPaths) {
155+
excludedPath.onSave();
156+
}
157+
super.set(Constants.Properties.EXCLUDED_PATHS, this.excludedPaths);
146158
}
147159
}
148160
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Iterator;
55
import java.util.List;
66
import java.util.Map;
7-
import java.util.NoSuchElementException;
87

98

109
/**

0 commit comments

Comments
 (0)