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 | 2339 | final QueryVersionVisitor visitor = new QueryVersionVisitor(); |
49 | |
|
50 | 2339 | if (query != null) { |
51 | 2335 | query.accept(visitor); |
52 | |
} |
53 | |
|
54 | 2339 | 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 | 2339 | public QueryVersionVisitor() { |
71 | 2339 | myRequiredServerVersion = null; |
72 | 2339 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public Version getMaximumServerVersion() { |
82 | 2339 | return myMaximumServerVersion; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public Version getRequiredServerVersion() { |
91 | 2339 | return myRequiredServerVersion; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
@SuppressWarnings("deprecation") |
102 | |
@Override |
103 | |
protected void visitName(final String name) { |
104 | 2557 | if (GeospatialOperator.GEO_WITHIN.getToken().equals(name)) { |
105 | 2 | myRequiredServerVersion = Version.later(myRequiredServerVersion, |
106 | |
GeospatialOperator.GEO_WITHIN.getVersion()); |
107 | |
} |
108 | 2555 | else if (GeospatialOperator.INTERSECT.getToken().equals(name)) { |
109 | 1 | myRequiredServerVersion = Version.later(myRequiredServerVersion, |
110 | |
GeospatialOperator.INTERSECT.getVersion()); |
111 | |
} |
112 | 2554 | else if (GeospatialOperator.POLYGON.equals(name)) { |
113 | 1 | myRequiredServerVersion = Version.later(myRequiredServerVersion, |
114 | |
GeospatialOperator.POLYGON_VERSION); |
115 | |
} |
116 | 2553 | else if ("$maxTimeMS".equals(name)) { |
117 | 1 | myRequiredServerVersion = Version.later(myRequiredServerVersion, |
118 | |
Find.MAX_TIMEOUT_VERSION); |
119 | |
} |
120 | 2552 | else if (MiscellaneousOperator.COMMENT.getToken().equals(name)) { |
121 | 1 | myRequiredServerVersion = Version.later(myRequiredServerVersion, |
122 | |
MiscellaneousOperator.COMMENT.getVersion()); |
123 | |
} |
124 | 2551 | else if (MiscellaneousOperator.TEXT.getToken().equals(name)) { |
125 | 1 | myRequiredServerVersion = Version.later(myRequiredServerVersion, |
126 | |
MiscellaneousOperator.TEXT.getVersion()); |
127 | |
} |
128 | 2550 | else if (GeospatialOperator.UNIQUE_DOCS_MODIFIER.equals(name)) { |
129 | 1 | myMaximumServerVersion = Version.earlier(myMaximumServerVersion, |
130 | |
GeospatialOperator.UNIQUE_DOCS_REMOVED_VERSION); |
131 | |
} |
132 | 2557 | } |
133 | |
} |