Skip to content

Commit 741211e

Browse files
author
a-brandt
committed
new options
1 parent 6ce38a8 commit 741211e

File tree

2 files changed

+253
-0
lines changed

2 files changed

+253
-0
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package com.arangodb.util;
2+
3+
import java.util.Map;
4+
5+
import com.arangodb.entity.CollectionType;
6+
7+
public class ImportOptions implements OptionsInterface {
8+
9+
public enum OnDuplicate {
10+
ERROR, UPDATE, REPLACE, IGNORE
11+
}
12+
13+
private Boolean createCollection;
14+
private CollectionType createCollectionType;
15+
private Boolean overwrite;
16+
private Boolean waitForSync;
17+
private OnDuplicate onDuplicate;
18+
19+
/**
20+
* (optional) If this parameter has a value of true or yes, then the
21+
* collection is created if it does not yet exist. Other values will be
22+
* ignored so the collection must be present for the operation to succeed.
23+
*
24+
* @return this ImportOptions object
25+
*/
26+
public Boolean getCreateCollection() {
27+
return createCollection;
28+
}
29+
30+
/**
31+
* (optional) If this parameter has a value of true or yes, then the
32+
* collection is created if it does not yet exist. Other values will be
33+
* ignored so the collection must be present for the operation to succeed.
34+
*
35+
* @param createCollection
36+
* @return this ImportOptions object
37+
*/
38+
public ImportOptions setCreateCollection(Boolean createCollection) {
39+
this.createCollection = createCollection;
40+
return this;
41+
}
42+
43+
/**
44+
* createCollectionType (optional): If this parameter has a value of
45+
* document or edge, it will determine the type of collection that is going
46+
* to be created when the createCollection option is set to true. The
47+
* default value is document.
48+
*
49+
* @return
50+
*/
51+
public CollectionType getCreateCollectionType() {
52+
return createCollectionType;
53+
}
54+
55+
/**
56+
* createCollectionType (optional): If this parameter has a value of
57+
* document or edge, it will determine the type of collection that is going
58+
* to be created when the createCollection option is set to true. The
59+
* default value is document.
60+
*
61+
* @param createCollectionType
62+
* @return this ImportOptions object
63+
*/
64+
public ImportOptions setCreateCollectionType(CollectionType createCollectionType) {
65+
this.createCollectionType = createCollectionType;
66+
return this;
67+
}
68+
69+
/**
70+
* overwrite (optional): If this parameter has a value of true or yes, then
71+
* all data in the collection will be removed prior to the import. Note that
72+
* any existing index definitions will be preseved.
73+
*
74+
* @return
75+
*/
76+
public Boolean getOverwrite() {
77+
return overwrite;
78+
}
79+
80+
/**
81+
* overwrite (optional): If this parameter has a value of true or yes, then
82+
* all data in the collection will be removed prior to the import. Note that
83+
* any existing index definitions will be preseved.
84+
*
85+
*
86+
* @param overwrite
87+
* @return this ImportOptions object
88+
*/
89+
public ImportOptions setOverwrite(Boolean overwrite) {
90+
this.overwrite = overwrite;
91+
return this;
92+
}
93+
94+
/**
95+
* (optional) Wait until documents have been synced to disk before
96+
* returning.
97+
*
98+
* @return
99+
*/
100+
public Boolean getWaitForSync() {
101+
return waitForSync;
102+
}
103+
104+
/**
105+
* (optional) Wait until documents have been synced to disk before
106+
* returning.
107+
*
108+
* @param waitForSync
109+
* @return this ImportOptions object
110+
*/
111+
public ImportOptions setWaitForSync(Boolean waitForSync) {
112+
this.waitForSync = waitForSync;
113+
return this;
114+
}
115+
116+
/**
117+
* (optional) Controls what action is carried out in case of a unique key
118+
* constraint violation. Possible values are:
119+
*
120+
* OnDuplicate.ERROR: this will not import the current document because of
121+
* the unique key constraint violation. This is the default setting.
122+
*
123+
* OnDuplicate.UPDATE: this will update an existing document in the database
124+
* with the data specified in the request. Attributes of the existing
125+
* document that are not present in the request will be preseved.
126+
*
127+
* OnDuplicate.REPLACE: this will replace an existing document in the
128+
* database with the data specified in the request.
129+
*
130+
* OnDuplicate.IGNORE: this will not update an existing document and simply
131+
* ignore the error caused by the unique key constraint violation.
132+
*
133+
* @return
134+
*/
135+
public OnDuplicate getOnDuplicate() {
136+
return onDuplicate;
137+
}
138+
139+
/**
140+
* (optional) Controls what action is carried out in case of a unique key
141+
* constraint violation. Possible values are:
142+
*
143+
* OnDuplicate.ERROR: this will not import the current document because of
144+
* the unique key constraint violation. This is the default setting.
145+
*
146+
* OnDuplicate.UPDATE: this will update an existing document in the database
147+
* with the data specified in the request. Attributes of the existing
148+
* document that are not present in the request will be preseved.
149+
*
150+
* OnDuplicate.REPLACE: this will replace an existing document in the
151+
* database with the data specified in the request.
152+
*
153+
* OnDuplicate.IGNORE: this will not update an existing document and simply
154+
* ignore the error caused by the unique key constraint violation.
155+
*
156+
* @param onDuplicate
157+
* @return this ImportOptions object
158+
*/
159+
public ImportOptions setOnDuplicate(OnDuplicate onDuplicate) {
160+
this.onDuplicate = onDuplicate;
161+
return this;
162+
}
163+
164+
@Override
165+
public Map<String, Object> toMap() {
166+
MapBuilder mp = new MapBuilder();
167+
168+
if (createCollection != null) {
169+
mp.put("createCollection", createCollection);
170+
}
171+
if (createCollectionType != null) {
172+
mp.put("createCollectionType", createCollectionType.toString().toLowerCase());
173+
}
174+
if (overwrite != null) {
175+
mp.put("overwrite", overwrite);
176+
}
177+
if (waitForSync != null) {
178+
mp.put("waitForSync", waitForSync);
179+
}
180+
if (onDuplicate != null) {
181+
mp.put("onDuplicate", onDuplicate.toString().toLowerCase());
182+
}
183+
184+
return mp.get();
185+
}
186+
187+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.arangodb.util;
2+
3+
import java.util.Map;
4+
5+
public class ImportOptionsRaw extends ImportOptions {
6+
7+
public enum ImportType {
8+
DOCUMENTS, LIST, AUTO
9+
}
10+
11+
private ImportType importType;
12+
13+
/**
14+
* Determines how the body of the request will be interpreted. type can have
15+
* the following values:
16+
*
17+
* ImportType.DOCUMENTS: when this type is used, each line in the request
18+
* body is expected to be an individual JSON-encoded document. Multiple JSON
19+
* objects in the request body need to be separated by newlines.
20+
*
21+
* ImportType.LIST: when this type is used, the request body must contain a
22+
* single JSON-encoded array of individual objects to import.
23+
*
24+
* ImportType.AUTO: if set, this will automatically determine the body type
25+
* (either documents or list).
26+
*
27+
* @return
28+
*/
29+
public ImportType getImportType() {
30+
return importType;
31+
}
32+
33+
/**
34+
* Determines how the body of the request will be interpreted. type can have
35+
* the following values:
36+
*
37+
* ImportType.DOCUMENTS: when this type is used, each line in the request
38+
* body is expected to be an individual JSON-encoded document. Multiple JSON
39+
* objects in the request body need to be separated by newlines.
40+
*
41+
* ImportType.LIST: when this type is used, the request body must contain a
42+
* single JSON-encoded array of individual objects to import.
43+
*
44+
* ImportType.AUTO: if set, this will automatically determine the body type
45+
* (either documents or list).
46+
*
47+
* @param importType
48+
* @return
49+
*/
50+
public ImportOptionsRaw setImportType(ImportType importType) {
51+
this.importType = importType;
52+
return this;
53+
}
54+
55+
@Override
56+
public Map<String, Object> toMap() {
57+
Map<String, Object> map = super.toMap();
58+
59+
if (importType != null) {
60+
map.put("type", importType.toString().toLowerCase());
61+
}
62+
63+
return map;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)