Elffuss BraidHub

kikocis/java-driver public

User date string in query builder to workaround CASSANDRA-6718
Changeset6a3c428100912fad29ee2dbf3cf1073978b2ba0fa33d18fa61d05c4509813ea7
AuthorSylvain Lebresne <sylvain@datastax.com> · 2014-02-18 18:24 +01:00
CommitterSylvain Lebresne <sylvain@datastax.com> · 2014-02-18 18:24 +01:00
Parents6ec239cc86dc

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -11,6 +11,7 @@
1111 - [bug] Fix potential thread leaks when shutting down Metrics (JAVA-232)
1212 - [bug] Fix potential NPE in HostConnectionPool (JAVA-231)
1313 - [bug] Make sure connections are returned to the right pools (JAVA-255)
14+- [bug] Use date string in query build to work-around CASSANDRA-6718 (JAVA-264)
1415
1516
1617 1.0.5:
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Utils.java +13 −1
@@ -19,6 +19,7 @@
1919 import java.nio.ByteBuffer;
2020 import java.util.*;
2121 import java.util.regex.Pattern;
22+import java.text.SimpleDateFormat;
2223
2324 import org.apache.cassandra.utils.ByteBufferUtil;
2425
@@ -27,6 +28,16 @@
2728
2829 private static final Pattern cnamePattern = Pattern.compile("\\w+(?:\\[.+\\])?");
2930
31+ // We currently format date as strings instead of simply longs due to JAVA-264. We could change
32+ // that back to longs (which is cheaper) once C* 1.2 gets eol (since only pre-1.2.16 versions are
33+ // affected).
34+ private static final ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat>() {
35+ @Override
36+ protected SimpleDateFormat initialValue() {
37+ return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
38+ }
39+ };
40+
3041 static StringBuilder joinAndAppend(StringBuilder sb, String separator, List<? extends Appendeable> values) {
3142 for (int i = 0; i < values.size(); i++) {
3243 if (i > 0)
@@ -100,6 +111,7 @@
100111 }
101112 }
102113
114+
103115 private static boolean appendValueIfLiteral(Object value, StringBuilder sb) {
104116 if (value instanceof Number || value instanceof UUID || value instanceof Boolean) {
105117 sb.append(value);
@@ -108,7 +120,7 @@
108120 sb.append("'").append(((InetAddress)value).getHostAddress()).append("'");
109121 return true;
110122 } else if (value instanceof Date) {
111- sb.append(((Date)value).getTime());
123+ sb.append("'").append(dateFormat.get().format((Date)value)).append("'");
112124 return true;
113125 } else if (value instanceof ByteBuffer) {
114126 sb.append("0x");