Skip to content

Commit 7d945b0

Browse files
committed
Adds missing files and deletes unused files.
1 parent db84326 commit 7d945b0

File tree

9 files changed

+448
-128
lines changed

9 files changed

+448
-128
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.microsoft.azure.documentdb;
2+
3+
public enum DataType {
4+
Number,
5+
String
6+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.microsoft.azure.documentdb;
2+
3+
import org.json.JSONObject;
4+
5+
public class ExcludedPath extends JsonSerializable {
6+
7+
/**
8+
* Constructor.
9+
*/
10+
public ExcludedPath() {
11+
super();
12+
}
13+
14+
/**
15+
* Constructor.
16+
*
17+
* @param jsonString the json string that represents the excluded path.
18+
*/
19+
public ExcludedPath(String jsonString) {
20+
super(jsonString);
21+
}
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param jsonObject the json object that represents the excluded path.
27+
*/
28+
public ExcludedPath(JSONObject jsonObject) {
29+
super(jsonObject);
30+
}
31+
32+
/**
33+
* Gets path.
34+
*
35+
* @return the path.
36+
*/
37+
public String getPath() {
38+
return super.getString(Constants.Properties.PATH);
39+
}
40+
41+
/**
42+
* Sets path.
43+
*
44+
* @param path the path.
45+
*/
46+
public void setPath(String path) {
47+
super.set(Constants.Properties.PATH, path);
48+
}
49+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.microsoft.azure.documentdb;
2+
3+
import org.apache.commons.lang3.text.WordUtils;
4+
import org.json.JSONObject;
5+
6+
public final class HashIndex extends Index {
7+
8+
/**
9+
* Constructor.
10+
*/
11+
public HashIndex(DataType dataType) {
12+
super(IndexKind.Hash);
13+
this.setDataType(dataType);
14+
}
15+
16+
/**
17+
* Constructor.
18+
*
19+
* @param jsonString the json string that represents the index.
20+
*/
21+
public HashIndex(String jsonString) {
22+
super(jsonString, IndexKind.Hash);
23+
if (this.getDataType() == null) {
24+
throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'.");
25+
}
26+
}
27+
28+
/**
29+
* Constructor.
30+
*
31+
* @param jsonObject the json object that represents the index.
32+
*/
33+
public HashIndex(JSONObject jsonObject) {
34+
super(jsonObject, IndexKind.Hash);
35+
if (this.getDataType() == null) {
36+
throw new IllegalArgumentException("The jsonObject doesn't contain a valid 'dataType'.");
37+
}
38+
}
39+
40+
/**
41+
* Gets data type.
42+
*
43+
* @return the data type.
44+
*/
45+
public DataType getDataType() {
46+
DataType result = null;
47+
try {
48+
result = DataType.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.DATA_TYPE)));
49+
} catch(IllegalArgumentException e) {
50+
e.printStackTrace();
51+
}
52+
return result;
53+
}
54+
55+
/**
56+
* Sets data type.
57+
*
58+
* @param dataType the data type.
59+
*/
60+
public void setDataType(DataType dataType) {
61+
super.set(Constants.Properties.DATA_TYPE, dataType.name());
62+
}
63+
64+
/**
65+
* Gets precision.
66+
*
67+
* @return the precision.
68+
*/
69+
public int getPrecision() {
70+
return super.getInt(Constants.Properties.PRECISION);
71+
}
72+
73+
/**
74+
* Sets precision.
75+
*
76+
* @param precision the precision.
77+
*/
78+
public void setPrecision(int precision) {
79+
super.set(Constants.Properties.PRECISION, precision);
80+
}
81+
82+
boolean hasPrecision() {
83+
return super.has(Constants.Properties.PRECISION);
84+
}
85+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package com.microsoft.azure.documentdb;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
6+
import org.apache.commons.lang3.text.WordUtils;
7+
import org.json.JSONArray;
8+
import org.json.JSONObject;
9+
10+
public class IncludedPath extends JsonSerializable {
11+
12+
// default number precisions
13+
private static final short DEFAULT_NUMBER_HASH_PRECISION = 3;
14+
private static final short DEFAULT_NUMBER_RANGE_PRECISION = -1;
15+
16+
// default string precision
17+
private static final short DEFAULT_STRING_HASH_PRECISION = 3;
18+
private static final short DEFAULT_STRING_RANGE_PRECISION = -1;
19+
20+
private Collection<Index> indexes;
21+
22+
/**
23+
* Constructor.
24+
*/
25+
public IncludedPath() {
26+
super();
27+
}
28+
29+
/**
30+
* Constructor.
31+
*
32+
* @param jsonString the json string that represents the included path.
33+
*/
34+
public IncludedPath(String jsonString) {
35+
super(jsonString);
36+
}
37+
38+
/**
39+
* Constructor.
40+
*
41+
* @param jsonObject the json object that represents the included path.
42+
*/
43+
public IncludedPath(JSONObject jsonObject) {
44+
super(jsonObject);
45+
}
46+
47+
/**
48+
* Gets path.
49+
*
50+
* @return the path.
51+
*/
52+
public String getPath() {
53+
return super.getString(Constants.Properties.PATH);
54+
}
55+
56+
/**
57+
* Sets path.
58+
*
59+
* @param path the path.
60+
*/
61+
public void setPath(String path) {
62+
super.set(Constants.Properties.PATH, path);
63+
}
64+
65+
/**
66+
* Gets the paths that are chosen to be indexed by the user.
67+
*
68+
* @return the included paths.
69+
*/
70+
public Collection<Index> getIndexes() {
71+
if (this.indexes == null) {
72+
this.indexes = this.getIndexCollection();
73+
74+
if (this.indexes == null) {
75+
this.indexes = new ArrayList<Index>();
76+
}
77+
}
78+
79+
return this.indexes;
80+
}
81+
82+
private Collection<Index> getIndexCollection() {
83+
if (this.propertyBag != null && this.propertyBag.has(Constants.Properties.INDEXES)) {
84+
JSONArray jsonArray = this.propertyBag.getJSONArray(Constants.Properties.INDEXES);
85+
Collection<Index> result = new ArrayList<Index>();
86+
87+
for (int i = 0; i < jsonArray.length(); i++) {
88+
JSONObject jsonObject = jsonArray.getJSONObject(i);
89+
90+
IndexKind indexKind = IndexKind.valueOf(WordUtils.capitalize(
91+
jsonObject.getString(Constants.Properties.INDEX_KIND)));
92+
switch (indexKind) {
93+
case Hash:
94+
result.add(new HashIndex(jsonObject.toString()));
95+
break;
96+
case Range:
97+
result.add(new RangeIndex(jsonObject.toString()));
98+
break;
99+
}
100+
}
101+
102+
return result;
103+
}
104+
105+
return null;
106+
}
107+
108+
public void setIndexes(Collection<Index> indexes) {
109+
this.indexes = indexes;
110+
}
111+
112+
@Override
113+
void onSave() {
114+
if (this.getIndexes().size() == 0) {
115+
HashIndex hashIndex = new HashIndex(DataType.String);
116+
hashIndex.setPrecision(IncludedPath.DEFAULT_STRING_HASH_PRECISION);
117+
this.indexes.add(hashIndex);
118+
119+
RangeIndex rangeIndex = new RangeIndex(DataType.Number);
120+
rangeIndex.setPrecision(IncludedPath.DEFAULT_NUMBER_RANGE_PRECISION);
121+
this.indexes.add(rangeIndex);
122+
}
123+
124+
for (Index index : this.indexes) {
125+
if (index.getKind() == IndexKind.Hash) {
126+
HashIndex hashIndex = (HashIndex)index;
127+
if (!hashIndex.hasPrecision()) {
128+
if(hashIndex.getDataType() == DataType.Number) {
129+
hashIndex.setPrecision(IncludedPath.DEFAULT_NUMBER_HASH_PRECISION);
130+
} else if(hashIndex.getDataType() == DataType.String) {
131+
hashIndex.setPrecision(IncludedPath.DEFAULT_STRING_HASH_PRECISION);
132+
}
133+
}
134+
} else if(index.getKind() == IndexKind.Range) {
135+
RangeIndex rangeIndex = (RangeIndex)index;
136+
if (!rangeIndex.hasPrecision()) {
137+
if (rangeIndex.getDataType() == DataType.Number) {
138+
rangeIndex.setPrecision(IncludedPath.DEFAULT_NUMBER_RANGE_PRECISION);
139+
} else if (rangeIndex.getDataType() == DataType.String) {
140+
rangeIndex.setPrecision(IncludedPath.DEFAULT_STRING_RANGE_PRECISION);
141+
}
142+
}
143+
}
144+
}
145+
146+
super.set(Constants.Properties.INDEXES, this.indexes);
147+
}
148+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.microsoft.azure.documentdb;
2+
3+
import org.apache.commons.lang3.text.WordUtils;
4+
import org.json.JSONObject;
5+
6+
public abstract class Index extends JsonSerializable {
7+
8+
/**
9+
* Constructor.
10+
*/
11+
protected Index(IndexKind indexKind) {
12+
super();
13+
this.setKind(indexKind);
14+
}
15+
16+
/**
17+
* Constructor.
18+
*
19+
* @param jsonString the json string that represents the index.
20+
*/
21+
protected Index(String jsonString, IndexKind indexKind) {
22+
super(jsonString);
23+
this.setKind(indexKind);
24+
}
25+
26+
/**
27+
* Constructor.
28+
*
29+
* @param jsonObject the json object that represents the index.
30+
*/
31+
protected Index(JSONObject jsonObject, IndexKind indexKind) {
32+
super(jsonObject);
33+
this.setKind(indexKind);
34+
}
35+
36+
/**
37+
* Gets index kind.
38+
*
39+
* @return the index kind.
40+
*/
41+
public IndexKind getKind() {
42+
IndexKind result = null;
43+
try {
44+
result = IndexKind.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.INDEX_KIND)));
45+
} catch(IllegalArgumentException e) {
46+
e.printStackTrace();
47+
}
48+
return result;
49+
}
50+
51+
/**
52+
* Sets index kind.
53+
*
54+
* @param indexKind the index kind.
55+
*/
56+
private void setKind(IndexKind indexKind) {
57+
super.set(Constants.Properties.INDEX_KIND, indexKind.name());
58+
}
59+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.microsoft.azure.documentdb;
2+
3+
// These are the indexing types available for indexing a path.
4+
// For additional details, refer to
5+
// http://azure.microsoft.com/documentation/articles/documentdb-indexing-policies/#ConfigPolicy.
6+
public enum IndexKind {
7+
// The index entries are hashed to serve point look up queries.
8+
// Can be used to serve queries like: SELECT * FROM docs d WHERE d.prop = 5
9+
Hash,
10+
11+
// The index entries are ordered. Range indexes are optimized for inequality predicate queries with efficient range
12+
// scans.
13+
// Can be used to serve queries like: SELECT * FROM docs d WHERE d.prop > 5
14+
Range
15+
}

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)