1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.allanbank.mongodb.client.message;
21
22 import com.allanbank.mongodb.Version;
23 import com.allanbank.mongodb.bson.Document;
24 import com.allanbank.mongodb.bson.VisitorAdapter;
25 import com.allanbank.mongodb.builder.Find;
26 import com.allanbank.mongodb.builder.GeospatialOperator;
27 import com.allanbank.mongodb.builder.MiscellaneousOperator;
28 import com.allanbank.mongodb.client.VersionRange;
29
30
31
32
33
34
35
36 public class QueryVersionVisitor extends VisitorAdapter {
37
38
39
40
41
42
43
44
45
46
47 public static VersionRange version(final Document query) {
48 final QueryVersionVisitor visitor = new QueryVersionVisitor();
49
50 if (query != null) {
51 query.accept(visitor);
52 }
53
54 return VersionRange.range(visitor.getRequiredServerVersion(),
55 visitor.getMaximumServerVersion());
56 }
57
58
59
60
61
62 private Version myMaximumServerVersion;
63
64
65 private Version myRequiredServerVersion;
66
67
68
69
70 public QueryVersionVisitor() {
71 myRequiredServerVersion = null;
72 }
73
74
75
76
77
78
79
80
81 public Version getMaximumServerVersion() {
82 return myMaximumServerVersion;
83 }
84
85
86
87
88
89
90 public Version getRequiredServerVersion() {
91 return myRequiredServerVersion;
92 }
93
94
95
96
97
98
99
100
101 @SuppressWarnings("deprecation")
102 @Override
103 protected void visitName(final String name) {
104 if (GeospatialOperator.GEO_WITHIN.getToken().equals(name)) {
105 myRequiredServerVersion = Version.later(myRequiredServerVersion,
106 GeospatialOperator.GEO_WITHIN.getVersion());
107 }
108 else if (GeospatialOperator.INTERSECT.getToken().equals(name)) {
109 myRequiredServerVersion = Version.later(myRequiredServerVersion,
110 GeospatialOperator.INTERSECT.getVersion());
111 }
112 else if (GeospatialOperator.POLYGON.equals(name)) {
113 myRequiredServerVersion = Version.later(myRequiredServerVersion,
114 GeospatialOperator.POLYGON_VERSION);
115 }
116 else if ("$maxTimeMS".equals(name)) {
117 myRequiredServerVersion = Version.later(myRequiredServerVersion,
118 Find.MAX_TIMEOUT_VERSION);
119 }
120 else if (MiscellaneousOperator.COMMENT.getToken().equals(name)) {
121 myRequiredServerVersion = Version.later(myRequiredServerVersion,
122 MiscellaneousOperator.COMMENT.getVersion());
123 }
124 else if (MiscellaneousOperator.TEXT.getToken().equals(name)) {
125 myRequiredServerVersion = Version.later(myRequiredServerVersion,
126 MiscellaneousOperator.TEXT.getVersion());
127 }
128 else if (GeospatialOperator.UNIQUE_DOCS_MODIFIER.equals(name)) {
129 myMaximumServerVersion = Version.earlier(myMaximumServerVersion,
130 GeospatialOperator.UNIQUE_DOCS_REMOVED_VERSION);
131 }
132 }
133 }