Skip to content

Commit a8da0f9

Browse files
author
a-brandt
committed
added query functions
1 parent 5f9f919 commit a8da0f9

File tree

5 files changed

+342
-1
lines changed

5 files changed

+342
-1
lines changed

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.lang.reflect.Type;
2020
import java.math.BigDecimal;
21+
import java.text.ParseException;
22+
import java.text.SimpleDateFormat;
2123
import java.util.ArrayList;
2224
import java.util.Collections;
2325
import java.util.Date;
@@ -58,6 +60,8 @@
5860
*/
5961
public class EntityDeserializers {
6062

63+
private static final String ALT_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
64+
6165
private static class ClassHolder {
6266
private Class<?>[] clazz;
6367
private int idx;
@@ -2031,6 +2035,93 @@ public QueryCachePropertiesEntity deserialize(
20312035

20322036
}
20332037

2038+
public static class QueriesResultEntityDeserializer implements JsonDeserializer<QueriesResultEntity> {
2039+
2040+
@Override
2041+
public QueriesResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
2042+
throws JsonParseException {
2043+
2044+
if (json.isJsonNull()) {
2045+
return null;
2046+
}
2047+
2048+
JsonArray array = json.getAsJsonArray();
2049+
Iterator<JsonElement> iterator = array.iterator();
2050+
List<QueryEntity> queries = new ArrayList<QueryEntity>();
2051+
while (iterator.hasNext()) {
2052+
JsonElement element = iterator.next();
2053+
JsonObject obj = element.getAsJsonObject();
2054+
QueryEntity entity = new QueryEntity();
2055+
2056+
if (obj.has("id")) {
2057+
entity.setId(obj.getAsJsonPrimitive("id").getAsString());
2058+
}
2059+
2060+
if (obj.has("query")) {
2061+
entity.setQuery(obj.getAsJsonPrimitive("query").getAsString());
2062+
}
2063+
2064+
if (obj.has("started")) {
2065+
String str = obj.getAsJsonPrimitive("started").getAsString();
2066+
2067+
SimpleDateFormat sdf = new SimpleDateFormat(ALT_DATE_TIME_FORMAT);
2068+
try {
2069+
entity.setStarted(sdf.parse(str));
2070+
} catch (ParseException e) {
2071+
}
2072+
}
2073+
2074+
if (obj.has("runTime")) {
2075+
entity.setRunTime(obj.getAsJsonPrimitive("runTime").getAsDouble());
2076+
}
2077+
2078+
}
2079+
2080+
return new QueriesResultEntity(queries);
2081+
}
2082+
}
2083+
2084+
public static class QueryTrackingPropertiesEntityDeserializer
2085+
implements JsonDeserializer<QueryTrackingPropertiesEntity> {
2086+
2087+
@Override
2088+
public QueryTrackingPropertiesEntity deserialize(
2089+
JsonElement json,
2090+
Type typeOfT,
2091+
JsonDeserializationContext context) throws JsonParseException {
2092+
2093+
if (json.isJsonNull()) {
2094+
return null;
2095+
}
2096+
2097+
JsonObject obj = json.getAsJsonObject();
2098+
QueryTrackingPropertiesEntity entity = deserializeBaseParameter(obj, new QueryTrackingPropertiesEntity());
2099+
2100+
if (obj.has("enabled")) {
2101+
entity.setEnabled(obj.getAsJsonPrimitive("enabled").getAsBoolean());
2102+
}
2103+
2104+
if (obj.has("trackSlowQueries")) {
2105+
entity.setTrackSlowQueries(obj.getAsJsonPrimitive("trackSlowQueries").getAsBoolean());
2106+
}
2107+
2108+
if (obj.has("maxSlowQueries")) {
2109+
entity.setMaxSlowQueries(obj.getAsJsonPrimitive("maxSlowQueries").getAsLong());
2110+
}
2111+
2112+
if (obj.has("slowQueryThreshold")) {
2113+
entity.setSlowQueryThreshold(obj.getAsJsonPrimitive("slowQueryThreshold").getAsLong());
2114+
}
2115+
2116+
if (obj.has("maxQueryStringLength")) {
2117+
entity.setMaxQueryStringLength(obj.getAsJsonPrimitive("maxQueryStringLength").getAsLong());
2118+
}
2119+
2120+
return entity;
2121+
}
2122+
2123+
}
2124+
20342125
private static JsonObject getFirstResultAsJsonObject(JsonObject obj) {
20352126
if (obj.has("result")) {
20362127
if (obj.get("result").isJsonArray()) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ public static GsonBuilder getGsonBuilder() {
115115
.registerTypeAdapter(TraversalEntity.class, new EntityDeserializers.TraversalEntityDeserializer())
116116
.registerTypeAdapter(ShortestPathEntity.class, new EntityDeserializers.ShortestPathEntityDeserializer())
117117
.registerTypeAdapter(QueryCachePropertiesEntity.class,
118-
new EntityDeserializers.QueryCachePropertiesEntityDeserializer());
118+
new EntityDeserializers.QueryCachePropertiesEntityDeserializer())
119+
.registerTypeAdapter(QueriesResultEntity.class,
120+
new EntityDeserializers.QueriesResultEntityDeserializer())
121+
.registerTypeAdapter(QueryTrackingPropertiesEntity.class,
122+
new EntityDeserializers.QueryTrackingPropertiesEntityDeserializer())
123+
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
119124
}
120125

121126
static {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.arangodb.entity;
2+
3+
import java.util.List;
4+
5+
public class QueriesResultEntity extends BaseEntity {
6+
7+
/**
8+
* The list of queries
9+
*/
10+
private List<QueryEntity> queries;
11+
12+
public QueriesResultEntity() {
13+
14+
}
15+
16+
public QueriesResultEntity(List<QueryEntity> queries) {
17+
this.queries = queries;
18+
}
19+
20+
/**
21+
* Returns the list of queries
22+
*
23+
* @return the list of queries
24+
*/
25+
public List<QueryEntity> getQueries() {
26+
return queries;
27+
}
28+
29+
/**
30+
* Sets the list of queries
31+
*
32+
* @param queries
33+
* the list of queries
34+
*/
35+
public void setQueries(List<QueryEntity> queries) {
36+
this.queries = queries;
37+
}
38+
39+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.arangodb.entity;
2+
3+
import java.util.Date;
4+
5+
public class QueryEntity {
6+
7+
/**
8+
* the query's id
9+
*/
10+
private String id;
11+
12+
/**
13+
* the query string (potentially truncated)
14+
*/
15+
private String query;
16+
17+
/**
18+
* the date and time when the query was started
19+
*/
20+
private Date started;
21+
22+
/**
23+
* the query's run time up to the point the list of queries was queried
24+
*/
25+
private Double runTime;
26+
27+
/**
28+
* Returns the query's id
29+
*
30+
* @return the query's id
31+
*/
32+
public String getId() {
33+
return id;
34+
}
35+
36+
/**
37+
* Sets the query's id
38+
*
39+
* @param id
40+
* the query's id
41+
*/
42+
public void setId(String id) {
43+
this.id = id;
44+
}
45+
46+
/**
47+
* Returns the query string (potentially truncated)
48+
*
49+
* @return
50+
*/
51+
public String getQuery() {
52+
return query;
53+
}
54+
55+
/**
56+
* Set the query string
57+
*
58+
* @param query
59+
* the query string
60+
*/
61+
public void setQuery(String query) {
62+
this.query = query;
63+
}
64+
65+
/**
66+
* Returns the date and time when the query was started
67+
*
68+
* @return the date and time
69+
*/
70+
public Date getStarted() {
71+
return started;
72+
}
73+
74+
/**
75+
* Sets the date and time when the query was started
76+
*
77+
* @param started
78+
* the date and time
79+
*/
80+
public void setStarted(Date started) {
81+
this.started = started;
82+
}
83+
84+
/**
85+
* Returns the query's run time up to the point the list of queries was
86+
* queried
87+
*
88+
* @return the query's run time
89+
*/
90+
public Double getRunTime() {
91+
return runTime;
92+
}
93+
94+
/**
95+
* Sets the query's run time up to the point the list of queries was queried
96+
*
97+
* @param runTime
98+
* the query's run time
99+
*/
100+
101+
public void setRunTime(Double runTime) {
102+
this.runTime = runTime;
103+
}
104+
105+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.entity;
18+
19+
/**
20+
* @author a-brandt
21+
*/
22+
public class QueryTrackingPropertiesEntity extends BaseEntity {
23+
24+
/**
25+
* if set to true, then queries will be tracked. If set to false, neither
26+
* queries nor slow queries will be tracked.
27+
*/
28+
private Boolean enabled;
29+
30+
/**
31+
* if set to true, then slow queries will be tracked in the list of slow
32+
* queries if their runtime exceeds the value set in slowQueryThreshold. In
33+
* order for slow queries to be tracked, the enabled property must also be
34+
* set to true.
35+
*/
36+
private Boolean trackSlowQueries;
37+
38+
/**
39+
* the maximum number of slow queries to keep in the list of slow queries.
40+
* If the list of slow queries is full, the oldest entry in it will be
41+
* discarded when additional slow queries occur.
42+
*/
43+
private Long maxSlowQueries;
44+
45+
/**
46+
* the threshold value for treating a query as slow. A query with a runtime
47+
* greater or equal to this threshold value will be put into the list of
48+
* slow queries when slow query tracking is enabled. The value for
49+
* slowQueryThreshold is specified in seconds.
50+
*/
51+
private Long slowQueryThreshold;
52+
53+
/**
54+
* the maximum query string length to keep in the list of queries. Query
55+
* strings can have arbitrary lengths, and this property can be used to save
56+
* memory in case very long query strings are used. The value is specified
57+
* in bytes.
58+
*/
59+
private Long maxQueryStringLength;
60+
61+
public Boolean getEnabled() {
62+
return enabled;
63+
}
64+
65+
public void setEnabled(Boolean enabled) {
66+
this.enabled = enabled;
67+
}
68+
69+
public Boolean getTrackSlowQueries() {
70+
return trackSlowQueries;
71+
}
72+
73+
public void setTrackSlowQueries(Boolean trackSlowQueries) {
74+
this.trackSlowQueries = trackSlowQueries;
75+
}
76+
77+
public Long getMaxSlowQueries() {
78+
return maxSlowQueries;
79+
}
80+
81+
public void setMaxSlowQueries(Long maxSlowQueries) {
82+
this.maxSlowQueries = maxSlowQueries;
83+
}
84+
85+
public Long getSlowQueryThreshold() {
86+
return slowQueryThreshold;
87+
}
88+
89+
public void setSlowQueryThreshold(Long slowQueryThreshold) {
90+
this.slowQueryThreshold = slowQueryThreshold;
91+
}
92+
93+
public Long getMaxQueryStringLength() {
94+
return maxQueryStringLength;
95+
}
96+
97+
public void setMaxQueryStringLength(Long maxQueryStringLength) {
98+
this.maxQueryStringLength = maxQueryStringLength;
99+
}
100+
101+
}

0 commit comments

Comments
 (0)