|
1 |
| -/* |
2 |
| - * Copyright (C) 2012,2013 tamtam180 |
3 |
| - * |
4 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| - * you may not use this file except in compliance with the License. |
6 |
| - * You may obtain a copy of the License at |
7 |
| - * |
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| - * |
10 |
| - * Unless required by applicable law or agreed to in writing, software |
11 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| - * See the License for the specific language governing permissions and |
14 |
| - * limitations under the License. |
15 |
| - */ |
16 |
| - |
17 |
| -package com.arangodb.impl; |
18 |
| - |
19 |
| -import java.util.TreeMap; |
20 |
| - |
21 |
| -import com.arangodb.ArangoConfigure; |
22 |
| -import com.arangodb.ArangoException; |
23 |
| -import com.arangodb.entity.BooleanResultEntity; |
24 |
| -import com.arangodb.entity.DatabaseEntity; |
25 |
| -import com.arangodb.entity.EntityFactory; |
26 |
| -import com.arangodb.entity.StringsResultEntity; |
27 |
| -import com.arangodb.entity.UserEntity; |
28 |
| -import com.arangodb.http.HttpManager; |
29 |
| -import com.arangodb.http.HttpResponseEntity; |
30 |
| - |
31 |
| -/** |
32 |
| - * @author tamtam180 - kirscheless at gmail.com |
33 |
| - * |
34 |
| - */ |
35 |
| -public class InternalDatabaseDriverImpl extends BaseArangoDriverImpl implements com.arangodb.InternalDatabaseDriver { |
36 |
| - |
37 |
| - private static final String API_DATABASE = "/_api/database"; |
38 |
| - |
39 |
| - InternalDatabaseDriverImpl(ArangoConfigure configure, HttpManager httpManager) { |
40 |
| - super(configure, httpManager); |
41 |
| - } |
42 |
| - |
43 |
| - @Override |
44 |
| - public DatabaseEntity getCurrentDatabase() throws ArangoException { |
45 |
| - |
46 |
| - HttpResponseEntity res = httpManager.doGet(createEndpointUrl(null, "/_api/database/current")); |
47 |
| - return createEntity(res, DatabaseEntity.class); |
48 |
| - |
49 |
| - } |
50 |
| - |
51 |
| - @Override |
52 |
| - public StringsResultEntity getDatabases(boolean currentUserAccessableOnly, String username, String password) |
53 |
| - throws ArangoException { |
54 |
| - HttpResponseEntity res = httpManager.doGet( |
55 |
| - createEndpointUrl(null, API_DATABASE, currentUserAccessableOnly ? "user" : null), null, null, username, |
56 |
| - password); |
57 |
| - return createEntity(res, StringsResultEntity.class); |
58 |
| - |
59 |
| - } |
60 |
| - |
61 |
| - @Override |
62 |
| - public BooleanResultEntity createDatabase(String database, UserEntity... users) throws ArangoException { |
63 |
| - |
64 |
| - validateDatabaseName(database, false); |
65 |
| - |
66 |
| - TreeMap<String, Object> body = new TreeMap<String, Object>(); |
67 |
| - body.put("name", database); |
68 |
| - if (users != null && users.length > 0) { |
69 |
| - body.put("users", users); |
70 |
| - } |
71 |
| - |
72 |
| - HttpResponseEntity res = httpManager.doPost(createEndpointUrl(null, API_DATABASE), null, |
73 |
| - EntityFactory.toJsonString(body)); |
74 |
| - |
75 |
| - return createEntity(res, BooleanResultEntity.class); |
76 |
| - |
77 |
| - } |
78 |
| - |
79 |
| - @Override |
80 |
| - public BooleanResultEntity deleteDatabase(String database) throws ArangoException { |
81 |
| - |
82 |
| - validateDatabaseName(database, false); |
83 |
| - |
84 |
| - TreeMap<String, Object> body = new TreeMap<String, Object>(); |
85 |
| - body.put("name", database); |
86 |
| - |
87 |
| - HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(null, API_DATABASE, database), null); |
88 |
| - |
89 |
| - return createEntity(res, BooleanResultEntity.class); |
90 |
| - |
91 |
| - } |
92 |
| - |
93 |
| -} |
| 1 | +/* |
| 2 | + * Copyright (C) 2012,2013 tamtam180 |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.arangodb.impl; |
| 18 | + |
| 19 | +import java.util.TreeMap; |
| 20 | + |
| 21 | +import com.arangodb.ArangoConfigure; |
| 22 | +import com.arangodb.ArangoException; |
| 23 | +import com.arangodb.entity.BooleanResultEntity; |
| 24 | +import com.arangodb.entity.DatabaseEntity; |
| 25 | +import com.arangodb.entity.EntityFactory; |
| 26 | +import com.arangodb.entity.StringsResultEntity; |
| 27 | +import com.arangodb.entity.UserEntity; |
| 28 | +import com.arangodb.http.HttpManager; |
| 29 | +import com.arangodb.http.HttpResponseEntity; |
| 30 | + |
| 31 | +/** |
| 32 | + * @author tamtam180 - kirscheless at gmail.com |
| 33 | + * |
| 34 | + */ |
| 35 | +public class InternalDatabaseDriverImpl extends BaseArangoDriverImpl implements com.arangodb.InternalDatabaseDriver { |
| 36 | + |
| 37 | + private static final String API_DATABASE = "/_api/database"; |
| 38 | + |
| 39 | + InternalDatabaseDriverImpl(final ArangoConfigure configure, final HttpManager httpManager) { |
| 40 | + super(configure, httpManager); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public DatabaseEntity getCurrentDatabase(final String database) throws ArangoException { |
| 45 | + |
| 46 | + final HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/database/current")); |
| 47 | + return createEntity(res, DatabaseEntity.class); |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public StringsResultEntity getDatabases( |
| 53 | + final boolean currentUserAccessableOnly, |
| 54 | + final String username, |
| 55 | + final String password) throws ArangoException { |
| 56 | + final HttpResponseEntity res = httpManager.doGet( |
| 57 | + createEndpointUrl(null, API_DATABASE, currentUserAccessableOnly ? "user" : null), null, null, username, |
| 58 | + password); |
| 59 | + return createEntity(res, StringsResultEntity.class); |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public BooleanResultEntity createDatabase(final String database, final UserEntity... users) throws ArangoException { |
| 65 | + |
| 66 | + validateDatabaseName(database, false); |
| 67 | + |
| 68 | + final TreeMap<String, Object> body = new TreeMap<String, Object>(); |
| 69 | + body.put("name", database); |
| 70 | + if (users != null && users.length > 0) { |
| 71 | + body.put("users", users); |
| 72 | + } |
| 73 | + |
| 74 | + final HttpResponseEntity res = httpManager.doPost(createEndpointUrl(null, API_DATABASE), null, |
| 75 | + EntityFactory.toJsonString(body)); |
| 76 | + |
| 77 | + return createEntity(res, BooleanResultEntity.class); |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public BooleanResultEntity deleteDatabase(final String database) throws ArangoException { |
| 83 | + |
| 84 | + validateDatabaseName(database, false); |
| 85 | + |
| 86 | + final TreeMap<String, Object> body = new TreeMap<String, Object>(); |
| 87 | + body.put("name", database); |
| 88 | + |
| 89 | + final HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(null, API_DATABASE, database), null); |
| 90 | + |
| 91 | + return createEntity(res, BooleanResultEntity.class); |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments