|
| 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 | +} |
0 commit comments