8000 Merge branch 'devel' of https://github.com/triAGENS/arangodb-java-dri… · anderick/arangodb-java-driver@66bb699 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66bb699

Browse files
committed
Merge branch 'devel' of https://github.com/triAGENS/arangodb-java-driver into devel
Conflicts: src/main/java/com/arangodb/ArangoDriver.java
2 parents 76177e1 + 1b79a63 commit 66bb699

File tree

10 files changed

+612
-72
lines changed

10 files changed

+612
-72
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.arangodb.entity.IndexEntity;
4848
import com.arangodb.entity.IndexType;
4949
import com.arangodb.entity.IndexesEntity;
50+
import com.arangodb.entity.JobsEntity;
5051
import com.arangodb.entity.Policy;
5152
import com.arangodb.entity.ReplicationApplierConfigEntity;
5253
import com.arangodb.entity.ReplicationApplierStateEntity;
@@ -140,7 +141,12 @@ private void createModuleDrivers(boolean createProxys) {
140141
this.endpointDriver = ImplFactory.createEndpointDriver(configure, this.httpManager);
141142
this.replicationDriver = ImplFactory.createReplicationDriver(configure, this.httpManager);
142143
this.graphDriver = ImplFactory.createGraphDriver(configure, cursorDriver, this.httpManager);
144+
this.jobsDriver = ImplFactory.createJobsDriver(configure, this.httpManager);
143145
} else {
146+
this.jobsDriver = (InternalJobsDriver) Proxy.newProxyInstance(
147+
InternalJobsDriver.class.getClassLoader(),
148+
new Class<?>[] { InternalJobsDriver.class },
149+
new InvocationHandlerImpl(this.jobsDriver));
144150
this.cursorDriver = (InternalCursorDriver) Proxy.newProxyInstance(
145151
InternalCursorDriver.class.getClassLoader(),
146152
new Class<?>[] { InternalCursorDriver.class },
@@ -212,13 +218,49 @@ public void startAsyncMode(boolean fireAndForget) throws ArangoException {
212218
}
213219
HttpManager.HttpMode mode = fireAndForget ? HttpManager.HttpMode.FIREANDFORGET : HttpManager.HttpMode.ASYNC;
214220
this.httpManager.setHttpMode(mode);
221+
this.createModuleDrivers(true);
222+
this.httpManager.resetJobs();
215223
}
216224

217225
public void stopAsyncMode() throws ArangoException {
218226
if (this.httpManager.getHttpMode().equals(HttpManager.HttpMode.SYNC)) {
219227
throw new ArangoException("Arango driver already set to synchronous mode.");
220228
}
221229
this.httpManager.setHttpMode(HttpManager.HttpMode.SYNC);
230+
this.createModuleDrivers(false);
231+
}
232+
233+
public String getLastJobId() {
234+
return this.httpManager.getLastJobId();
235+
}
236+
237+
public List<String> getJobIds() {
238+
return this.httpManager.getJobIds();
239+
}
240+
241+
public List<String> getJobs(JobsEntity.JobState jobState, int count) throws ArangoException {
242+
return this.jobsDriver.getJobs(getDefaultDatabase(), jobState, count);
243+
}
244+
245+
public List<String> getJobs(JobsEntity.JobState jobState) throws ArangoException {
246+
return this.jobsDriver.getJobs(getDefaultDatabase(), jobState);
247+
}
248+
249+
public void deleteAllJobs() throws ArangoException {
250+
this.jobsDriver.deleteAllJobs(getDefaultDatabase());
251+
this.httpManager.resetJobs();
252+
}
253+
254+
public void deleteJobById(String JobId) throws ArangoException {
255+
this.jobsDriver.deleteJobById(getDefaultDatabase(), JobId);
256+
}
257+
258+
public void deleteExpiredJobs(int timeStamp) throws ArangoException {
259+
this.jobsDriver.deleteExpiredJobs(getDefaultDatabase(), timeStamp);
260+
}
261+
262+
public <T> T getJobResult(String jobId) throws ArangoException {
263+
return this.jobsDriver.getJobResult(getDefaultDatabase(), jobId);
222264
}
223265

224266
public DefaultEntity executeBatch() throws ArangoException {
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
package com.arangodb;
22

3+
import com.arangodb.entity.JobsEntity;
4+
import com.arangodb.impl.BaseDriverInterface;
5+
6+
import java.util.List;
7+
38
/**
49
* Created by fbartels on 10/28/14.
510
*/
6-
public interface InternalJobsDriver {
11+
public interface InternalJobsDriver extends BaseDriverInterface {
12+
13+
List<String> getJobs(String database, JobsEntity.JobState jobState, int count) throws ArangoException;
14+
15+
List<String> getJobs(String database, JobsEntity.JobState jobState) throws ArangoException;
16+
17+
void deleteAllJobs(String database) throws ArangoException;
18+
19+
void deleteJobById(String database, String JobId) throws ArangoException;
20+
21+
void deleteExpiredJobs(String database, int timeStamp) throws ArangoException;
22+
23+
<T> T getJobResult(String database, String jobId) throws ArangoException;
24+
725
}

src/main/java/com/arangodb/entity/EntityDeserializers.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,27 @@ public AqlFunctionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeseri
472472
}
473473
}
474474

475+
476+
public static class JobsEntityDeserializer implements JsonDeserializer<JobsEntity> {
477+
478+
public JobsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
479+
throws JsonParseException {
480+
481+
if (json.isJsonNull()) {
482+
return null;
483+
}
484+
485+
JsonArray obj = json.getAsJsonArray();
486+
Iterator<JsonElement> iterator = obj.iterator();
487+
List<String> jobs = new ArrayList<String>();
488+
while(iterator.hasNext()) {
489+
JsonElement e = iterator.next();
490+
jobs.add(e.getAsString());
491+
}
492+
return new JobsEntity(jobs);
493+
}
494+
}
495+
475496
public static class CursorEntityDeserializer implements JsonDeserializer<CursorEntity<?>> {
476497
private Type bindVarsType = new TypeToken<List<String>>() {
477498
}.getType();

src/main/java/com/arangodb/entity/EntityFactory.java

Lines changed: 55 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
/**
4040
* @author tamtam180 - kirscheless at gmail.com
41-
*
4241
*/
4342
public class EntityFactory {
4443

@@ -47,67 +46,61 @@ public class EntityFactory {
4746

4847
private static GsonBuilder getBuilder() {
4948
return new GsonBuilder()
50-
.addSerializationExclusionStrategy(new ExcludeExclusionStrategy(true))
51-
.addDeserializationExclusionStrategy(new ExcludeExclusionStrategy(false))
52-
.setFieldNamingStrategy(new ArangoFieldNamingStrategy())
53-
.registerTypeAdapter(CollectionStatus.class, new CollectionStatusTypeAdapter())
54-
.registerTypeAdapter(CollectionEntity.class, new EntityDeserializers.CollectionEntityDeserializer())
55-
.registerTypeAdapter(DocumentEntity.class, new EntityDeserializers.DocumentEntityDeserializer())
56-
.registerTypeAdapter(DocumentsEntity.class, new EntityDeserializers.DocumentsEntityDeserializer())
57-
.registerTypeAdapter(AqlFunctionsEntity.class, new EntityDeserializers.AqlfunctionsEntityDeserializer())
58-
.registerTypeAdapter(ArangoVersion.class, new EntityDeserializers.VersionDeserializer())
59-
.registerTypeAdapter(ArangoUnixTime.class, new EntityDeserializers.ArangoUnixTimeDeserializer())
60-
.registerTypeAdapter(DefaultEntity.class, new EntityDeserializers.DefaultEntityDeserializer())
61-
.registerTypeAdapter(Figures.class, new EntityDeserializers.FiguresDeserializer())
62-
.registerTypeAdapter(CursorEntity.class, new EntityDeserializers.CursorEntityDeserializer())
63-
.registerTypeAdapter(IndexEntity.class, new EntityDeserializers.IndexEntityDeserializer())
64-
.registerTypeAdapter(IndexesEntity.class, new EntityDeserializers.IndexesEntityDeserializer())
65-
.registerTypeAdapter(ScalarExampleEntity.class, new EntityDeserializers.ScalarExampleEntityDeserializer())
66-
.registerTypeAdapter(SimpleByResultEntity.class, new EntityDeserializers.SimpleByResultEntityDeserializer())
67-
.registerTypeAdapter(AdminLogEntity.class, new EntityDeserializers.AdminLogEntryEntityDeserializer())
68-
.registerTypeAdapter(StatisticsEntity.class, new EntityDeserializers.StatisticsEntityDeserializer())
69-
.registerTypeAdapter(
70-
StatisticsDescriptionEntity.class,
71-
new EntityDeserializers.StatisticsDescriptionEntityDeserializer())
72-
.registerTypeAdapter(UserEntity.class, new EntityDeserializers.UserEntityDeserializer())
73-
.registerTypeAdapter(ImportResultEntity.class, new EntityDeserializers.ImportResultEntityDeserializer())
74-
.registerTypeAdapter(DatabaseEntity.class, new EntityDeserializers.DatabaseEntityDeserializer())
75-
.registerTypeAdapter(StringsResultEntity.class, new EntityDeserializers.StringsResultEntityDeserializer())
76-
.registerTypeAdapter(BooleanResultEntity.class, new EntityDeserializers.BooleanResultEntityDeserializer())
77-
.registerTypeAdapter(Endpoint.class, new EntityDeserializers.EndpointDeserializer())
78-
.registerTypeAdapter(DocumentResultEntity.class, new EntityDeserializers.DocumentResultEntityDeserializer())
79-
.registerTypeAdapter(
80-
CollectionKeyOptionDeserializer.class,
81-
new EntityDeserializers.CollectionKeyOptionDeserializer())
82-
.registerTypeAdapter(
83-
ReplicationInventoryEntity.class,
84-
new EntityDeserializers.ReplicationInventoryEntityDeserializer())
85-
.registerTypeAdapter(ReplicationDumpRecord.class, new EntityDeserializers.ReplicationDumpRecordDeserializer())
86-
.registerTypeAdapter(ReplicationSyncEntity.class, new EntityDeserializers.ReplicationSyncEntityDeserializer())
87-
.registerTypeAdapter(MapAsEntity.class, new EntityDeserializers.MapAsEntityDeserializer())
88-
.registerTypeAdapter(
89-
ReplicationLoggerConfigEntity.class,
90-
new EntityDeserializers.ReplicationLoggerConfigEntityDeserializer())
91-
.registerTypeAdapter(
92-
ReplicationApplierConfigEntity.class,
93-
new EntityDeserializers.ReplicationApplierConfigEntityDeserializer())
94-
.registerTypeAdapter(
95-
ReplicationApplierState.class,
96-
new EntityDeserializers.ReplicationApplierStateDeserializer())
97-
.registerTypeAdapter(
98-
ReplicationApplierStateEntity.class,
99-
new EntityDeserializers.ReplicationApplierStateEntityDeserializer())
100-
.registerTypeAdapter(
101-
ReplicationLoggerStateEntity.class,
102-
new EntityDeserializers.ReplicationLoggerStateEntityDeserializer())
103-
.registerTypeAdapter(
104-
ReplicationLoggerStateEntity.Client.class,
105-
new EntityDeserializers.ReplicationLoggerStateEntityClientDeserializer())
106-
.registerTypeAdapter(GraphEntity.class, new EntityDeserializers.GraphEntityDeserializer())
107-
.registerTypeAdapter(GraphsEntity.class, new EntityDeserializers.GraphsEntityDeserializer())
108-
.registerTypeAdapter(DeletedEntity.class, new EntityDeserializers.DeleteEntityDeserializer())
109-
.registerTypeAdapter(VertexEntity.class, new EntityDeserializers.VertexEntityDeserializer())
110-
.registerTypeAdapter(EdgeEntity.class, new EntityDeserializers.EdgeEntityDeserializer());
49+
.addSerializationExclusionStrategy(new ExcludeExclusionStrategy(true))
50+
.addDeserializationExclusionStrategy(new ExcludeExclusionStrategy(false))
51+
.setFieldNamingStrategy(new ArangoFieldNamingStrategy())
52+
.registerTypeAdapter(CollectionStatus.class, new CollectionStatusTypeAdapter())
53+
.registerTypeAdapter(CollectionEntity.class, new EntityDeserializers.CollectionEntityDeserializer())
54+
.registerTypeAdapter(DocumentEntity.class, new EntityDeserializers.DocumentEntityDeserializer())
55+
.registerTypeAdapter(DocumentsEntity.class, new EntityDeserializers.DocumentsEntityDeserializer())
56+
.registerTypeAdapter(AqlFunctionsEntity.class, new EntityDeserializers.AqlfunctionsEntityDeserializer())
57+
.registerTypeAdapter(JobsEntity.class, new EntityDeserializers.JobsEntityDeserializer())
58+
.registerTypeAdapter(ArangoVersion.class, new EntityDeserializers.VersionDeserializer())
59+
.registerTypeAdapter(ArangoUnixTime.class, new EntityDeserializers.ArangoUnixTimeDeserializer())
60+
.registerTypeAdapter(DefaultEntity.class, new EntityDeserializers.DefaultEntityDeserializer())
61+
.registerTypeAdapter(Figures.class, new EntityDeserializers.FiguresDeserializer())
62+
.registerTypeAdapter(CursorEntity.class, new EntityDeserializers.CursorEntityDeserializer())
63+
.registerTypeAdapter(IndexEntity.class, new EntityDeserializers.IndexEntityDeserializer())
64+
.registerTypeAdapter(IndexesEntity.class, new EntityDeserializers.IndexesEntityDeserializer())
65+
.registerTypeAdapter(ScalarExampleEntity.class, new EntityDeserializers.ScalarExampleEntityDeserializer())
66+
.registerTypeAdapter(SimpleByResultEntity.class, new EntityDeserializers.SimpleByResultEntityDeserializer())
67+
.registerTypeAdapter(AdminLogEntity.class, new EntityDeserializers.AdminLogEntryEntityDeserializer())
68+
.registerTypeAdapter(StatisticsEntity.class, new EntityDeserializers.StatisticsEntityDeserializer())
69+
.registerTypeAdapter(
70+
StatisticsDescriptionEntity.class, new EntityDeserializers.StatisticsDescriptionEntityDeserializer())
71+
.registerTypeAdapter(UserEntity.class, new EntityDeserializers.UserEntityDeserializer())
72+
.registerTypeAdapter(ImportResultEntity.class, new EntityDeserializers.ImportResultEntityDeserializer())
73+
.registerTypeAdapter(DatabaseEntity.class, new EntityDeserializers.DatabaseEntityDeserializer())
74+
.registerTypeAdapter(StringsResultEntity.class, new EntityDeserializers.StringsResultEntityDeserializer())
75+
.registerTypeAdapter(BooleanResultEntity.class, new EntityDeserializers.BooleanResultEntityDeserializer())
76+
.registerTypeAdapter(Endpoint.class, new EntityDeserializers.EndpointDeserializer())
77+
.registerTypeAdapter(DocumentResultEntity.class, new EntityDeserializers.DocumentResultEntityDeserializer())
78+
.registerTypeAdapter(
79+
CollectionKeyOptionDeserializer.class, new EntityDeserializers.CollectionKeyOptionDeserializer())
80+
.registerTypeAdapter(
81+
ReplicationInventoryEntity.class, new EntityDeserializers.ReplicationInventoryEntityDeserializer())
82+
.registerTypeAdapter(ReplicationDumpRecord.class, new EntityDeserializers.ReplicationDumpRecordDeserializer())
83+
.registerTypeAdapter(ReplicationSyncEntity.class, new EntityDeserializers.ReplicationSyncEntityDeserializer())
84+
.registerTypeAdapter(MapAsEntity.class, new EntityDeserializers.MapAsEntityDeserializer())
85+
.registerTypeAdapter(
86+
ReplicationLoggerConfigEntity.class, new EntityDeserializers.ReplicationLoggerConfigEntityDeserializer())
87+
.registerTypeAdapter(
88+
ReplicationApplierConfigEntity.class, new EntityDeserializers.ReplicationApplierConfigEntityDeserializer())
89+
.registerTypeAdapter(
90+
ReplicationApplierState.class, new EntityDeserializers.ReplicationApplierStateDeserializer())
91+
.registerTypeAdapter(
92+
ReplicationApplierStateEntity.class, new EntityDeserializers.ReplicationApplierStateEntityDeserializer())
93+
.registerTypeAdapter(
94+
ReplicationLoggerStateEntity.class, new EntityDeserializers.ReplicationLoggerStateEntityDeserializer())
95+
.registerTypeAdapter(
96+
ReplicationLoggerStateEntity.Client.class,
97+
new EntityDeserializers.ReplicationLoggerStateEntityClientDeserializer())
98+
.registerTypeAdapter(GraphEntity.class, new EntityDeserializers.GraphEntityDeserializer())
99+
.registerTypeAdapter(GraphsEntity.class, new EntityDeserializers.GraphsEntityDeserializer())
100+
.registerTypeAdapter(DeletedEntity.class, new EntityDeserializers.DeleteEntityDeserializer())
101+
.registerTypeAdapter(VertexEntity.class, new EntityDeserializers.VertexEntityDeserializer())
102+
.registerTypeAdapter(EdgeEntity.class, new EntityDeserializers.EdgeEntityDeserializer())
103+
;
111104
}
112105

113106
static {
@@ -142,7 +135,6 @@ public static <T> String toJsonString(T obj, boolean includeNullValue) {
142135
}
143136

144137
/**
145-
*
146138
* @param obj
147139
* @param includeNullValue
148140
* @return
@@ -153,7 +145,6 @@ public static <T> JsonElement toJsonElement(T obj, boolean includeNullValue) {
153145
}
154146

155147
/**
156-
*
157148
* @author tamtam180 - kirscheless at gmail.com
158149
* @since 1.4.0
159150
*/
@@ -164,7 +155,6 @@ public ExcludeExclusionStrategy(boolean serialize) {
164155
this.serialize = serialize;
165156
}
166157

167-
@Override
168158
public boolean shouldSkipField(FieldAttributes f) {
169159
Exclude annotation = f.getAnnotation(Exclude.class);
170160
if (annotation != null && (serialize ? annotation.serialize() : annotation.deserialize())) {
@@ -173,7 +163,6 @@ public boolean shouldSkipField(FieldAttributes f) {
173163
return false;
174164
}
175165

176-
@Override
177166
public boolean shouldSkipClass(Class<?> clazz) {
178167
return false;
179168
}
@@ -182,7 +171,6 @@ public boolean shouldSkipClass(Class<?> clazz) {
182171
private static class ArangoFieldNamingStrategy implements FieldNamingStrategy {
183172
private static final String KEY = "_key";
184173

185-
@Override
186174
public String translateName(Field f) {
187175
DocumentKey key = f.getAnnotation(DocumentKey.class);
188176
if (key == null) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2012 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.entity;
18+
19+
import com.arangodb.util.CollectionUtils;
20+
21+
import java.util.Iterator;
22+
import java.util.List;
23+
24+
/**
25+
* @author tamtam180 - kirscheless at gmail.com
26+
*
27+
*/
28+
public class JobsEntity extends BaseEntity {
29+
30+
public static enum JobState {
31+
DONE , PENDING;
32+
public java.lang.String getName() {
33+
if (this == DONE) {
34+
return "done";
35+
}
36+
if (this == PENDING) {
37+
return "pending";
38+
}
39+
return null;
40+
}
41+
}
42+
43+
List<String> jobs;
44+
45+
public List<String> getJobs() {
46+
return jobs;
47+
}
48+
49+
public void setJobs(List<String> jobs) {
50+
this.jobs = jobs;
51+
}
52+
53+
54+
public JobsEntity(List<String> jobs) {
55+
this.jobs = jobs;
56+
}
57+
}

0 commit comments

Comments
 (0)
0