kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | c1334e48fa02b7d3c25519ceefdad8156c470796576e3b03efce985509f401db |
|---|---|
| Author | Alexandre Dutra <adutra@users.noreply.github.com> · 2015-12-02 11:54 +01:00 |
| Committer | Alexandre Dutra <adutra@users.noreply.github.com> · 2015-12-02 11:54 +01:00 |
| Parents | 4a8096457983, 82e497d6e501 |
8 files changed
modified changelog/README.md +1 −0
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | - [bug] JAVA-988: Metadata.handleId should handle escaped double quotes. |
| 6 | 6 | - [bug] JAVA-983: QueryBuilder cannot handle collections containing function calls. |
| 7 | 7 | - [improvement] JAVA-863: Idempotence propagation in PreparedStatements. |
| 8 | +- [bug] JAVA-937: TypeCodec static initializers not always correctly executed. | |
| 8 | 9 | |
| 9 | 10 | Merged from 2.0 branch: |
| 10 | 11 |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractAddressableByIndexData.java +13 −13
| @@ -44,42 +44,42 @@ | ||
| 44 | 44 | |
| 45 | 45 | public T setBool(int i, boolean v) { |
| 46 | 46 | checkType(i, DataType.Name.BOOLEAN); |
| 47 | - return setValue(i, TypeCodec.BooleanCodec.instance.serializeNoBoxing(v)); | |
| 47 | + return setValue(i, TypeCodec.booleanCodec.serializeNoBoxing(v)); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public T setInt(int i, int v) { |
| 51 | 51 | checkType(i, DataType.Name.INT); |
| 52 | - return setValue(i, TypeCodec.IntCodec.instance.serializeNoBoxing(v)); | |
| 52 | + return setValue(i, TypeCodec.intCodec.serializeNoBoxing(v)); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public T setLong(int i, long v) { |
| 56 | 56 | checkType(i, DataType.Name.BIGINT, DataType.Name.COUNTER); |
| 57 | - return setValue(i, TypeCodec.LongCodec.instance.serializeNoBoxing(v)); | |
| 57 | + return setValue(i, TypeCodec.longCodec.serializeNoBoxing(v)); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public T setDate(int i, Date v) { |
| 61 | 61 | checkType(i, DataType.Name.TIMESTAMP); |
| 62 | - return setValue(i, v == null ? null : TypeCodec.DateCodec.instance.serialize(v)); | |
| 62 | + return setValue(i, v == null ? null : TypeCodec.dateCodec.serialize(v)); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public T setFloat(int i, float v) { |
| 66 | 66 | checkType(i, DataType.Name.FLOAT); |
| 67 | - return setValue(i, TypeCodec.FloatCodec.instance.serializeNoBoxing(v)); | |
| 67 | + return setValue(i, TypeCodec.floatCodec.serializeNoBoxing(v)); | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | public T setDouble(int i, double v) { |
| 71 | 71 | checkType(i, DataType.Name.DOUBLE); |
| 72 | - return setValue(i, TypeCodec.DoubleCodec.instance.serializeNoBoxing(v)); | |
| 72 | + return setValue(i, TypeCodec.doubleCodec.serializeNoBoxing(v)); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public T setString(int i, String v) { |
| 76 | 76 | DataType.Name type = checkType(i, DataType.Name.VARCHAR, DataType.Name.TEXT, DataType.Name.ASCII); |
| 77 | 77 | switch (type) { |
| 78 | 78 | case ASCII: |
| 79 | - return setValue(i, v == null ? null : TypeCodec.StringCodec.asciiInstance.serialize(v)); | |
| 79 | + return setValue(i, v == null ? null : TypeCodec.asciiStringCodec.serialize(v)); | |
| 80 | 80 | case TEXT: |
| 81 | 81 | case VARCHAR: |
| 82 | - return setValue(i, v == null ? null : TypeCodec.StringCodec.utf8Instance.serialize(v)); | |
| 82 | + return setValue(i, v == null ? null : TypeCodec.utf8StringCodec.serialize(v)); | |
| 83 | 83 | default: |
| 84 | 84 | throw new AssertionError(); |
| 85 | 85 | } |
| @@ -96,12 +96,12 @@ | ||
| 96 | 96 | |
| 97 | 97 | public T setVarint(int i, BigInteger v) { |
| 98 | 98 | checkType(i, DataType.Name.VARINT); |
| 99 | - return setValue(i, v == null ? null : TypeCodec.BigIntegerCodec.instance.serialize(v)); | |
| 99 | + return setValue(i, v == null ? null : TypeCodec.bigIntegerCodec.serialize(v)); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public T setDecimal(int i, BigDecimal v) { |
| 103 | 103 | checkType(i, DataType.Name.DECIMAL); |
| 104 | - return setValue(i, v == null ? null : TypeCodec.DecimalCodec.instance.serialize(v)); | |
| 104 | + return setValue(i, v == null ? null : TypeCodec.decimalCodec.serialize(v)); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | public T setUUID(int i, UUID v) { |
| @@ -114,13 +114,13 @@ | ||
| 114 | 114 | throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID", v)); |
| 115 | 115 | |
| 116 | 116 | return type == DataType.Name.UUID |
| 117 | - ? setValue(i, TypeCodec.UUIDCodec.instance.serialize(v)) | |
| 118 | - : setValue(i, TypeCodec.TimeUUIDCodec.instance.serialize(v)); | |
| 117 | + ? setValue(i, TypeCodec.uuidCodec.serialize(v)) | |
| 118 | + : setValue(i, TypeCodec.timeUuidCodec.serialize(v)); | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | public T setInet(int i, InetAddress v) { |
| 122 | 122 | checkType(i, DataType.Name.INET); |
| 123 | - return setValue(i, v == null ? null : TypeCodec.InetCodec.instance.serialize(v)); | |
| 123 | + return setValue(i, v == null ? null : TypeCodec.inetCodec.serialize(v)); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | public <E> T setList(int i, List<E> v) { |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractData.java +23 −23
| @@ -65,12 +65,12 @@ | ||
| 65 | 65 | |
| 66 | 66 | public T setBool(int i, boolean v) { |
| 67 | 67 | checkType(i, DataType.Name.BOOLEAN); |
| 68 | - return setValue(i, TypeCodec.BooleanCodec.instance.serializeNoBoxing(v)); | |
| 68 | + return setValue(i, TypeCodec.booleanCodec.serializeNoBoxing(v)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public T setBool(String name, boolean v) { |
| 72 | 72 | int[] indexes = getAllIndexesOf(name); |
| 73 | - ByteBuffer value = TypeCodec.BooleanCodec.instance.serializeNoBoxing(v); | |
| 73 | + ByteBuffer value = TypeCodec.booleanCodec.serializeNoBoxing(v); | |
| 74 | 74 | for (int i = 0; i < indexes.length; i++) { |
| 75 | 75 | checkType(indexes[i], DataType.Name.BOOLEAN); |
| 76 | 76 | setValue(indexes[i], value); |
| @@ -80,12 +80,12 @@ | ||
| 80 | 80 | |
| 81 | 81 | public T setInt(int i, int v) { |
| 82 | 82 | checkType(i, DataType.Name.INT); |
| 83 | - return setValue(i, TypeCodec.IntCodec.instance.serializeNoBoxing(v)); | |
| 83 | + return setValue(i, TypeCodec.intCodec.serializeNoBoxing(v)); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | public T setInt(String name, int v) { |
| 87 | 87 | int[] indexes = getAllIndexesOf(name); |
| 88 | - ByteBuffer value = TypeCodec.IntCodec.instance.serializeNoBoxing(v); | |
| 88 | + ByteBuffer value = TypeCodec.intCodec.serializeNoBoxing(v); | |
| 89 | 89 | for (int i = 0; i < indexes.length; i++) { |
| 90 | 90 | checkType(indexes[i], DataType.Name.INT); |
| 91 | 91 | setValue(indexes[i], value); |
| @@ -95,12 +95,12 @@ | ||
| 95 | 95 | |
| 96 | 96 | public T setLong(int i, long v) { |
| 97 | 97 | checkType(i, DataType.Name.BIGINT, DataType.Name.COUNTER); |
| 98 | - return setValue(i, TypeCodec.LongCodec.instance.serializeNoBoxing(v)); | |
| 98 | + return setValue(i, TypeCodec.longCodec.serializeNoBoxing(v)); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public T setLong(String name, long v) { |
| 102 | 102 | int[] indexes = getAllIndexesOf(name); |
| 103 | - ByteBuffer value = TypeCodec.LongCodec.instance.serializeNoBoxing(v); | |
| 103 | + ByteBuffer value = TypeCodec.longCodec.serializeNoBoxing(v); | |
| 104 | 104 | for (int i = 0; i < indexes.length; i++) { |
| 105 | 105 | checkType(indexes[i], DataType.Name.BIGINT, DataType.Name.COUNTER); |
| 106 | 106 | setValue(indexes[i], value); |
| @@ -110,12 +110,12 @@ | ||
| 110 | 110 | |
| 111 | 111 | public T setDate(int i, Date v) { |
| 112 | 112 | checkType(i, DataType.Name.TIMESTAMP); |
| 113 | - return setValue(i, v == null ? null : TypeCodec.DateCodec.instance.serialize(v)); | |
| 113 | + return setValue(i, v == null ? null : TypeCodec.dateCodec.serialize(v)); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | public T setDate(String name, Date v) { |
| 117 | 117 | int[] indexes = getAllIndexesOf(name); |
| 118 | - ByteBuffer value = v == null ? null : TypeCodec.DateCodec.instance.serialize(v); | |
| 118 | + ByteBuffer value = v == null ? null : TypeCodec.dateCodec.serialize(v); | |
| 119 | 119 | for (int i = 0; i < indexes.length; i++) { |
| 120 | 120 | checkType(indexes[i], DataType.Name.TIMESTAMP); |
| 121 | 121 | setValue(indexes[i], value); |
| @@ -125,12 +125,12 @@ | ||
| 125 | 125 | |
| 126 | 126 | public T setFloat(int i, float v) { |
| 127 | 127 | checkType(i, DataType.Name.FLOAT); |
| 128 | - return setValue(i, TypeCodec.FloatCodec.instance.serializeNoBoxing(v)); | |
| 128 | + return setValue(i, TypeCodec.floatCodec.serializeNoBoxing(v)); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | public T setFloat(String name, float v) { |
| 132 | 132 | int[] indexes = getAllIndexesOf(name); |
| 133 | - ByteBuffer value = TypeCodec.FloatCodec.instance.serializeNoBoxing(v); | |
| 133 | + ByteBuffer value = TypeCodec.floatCodec.serializeNoBoxing(v); | |
| 134 | 134 | for (int i = 0; i < indexes.length; i++) { |
| 135 | 135 | checkType(indexes[i], DataType.Name.FLOAT); |
| 136 | 136 | setValue(indexes[i], value); |
| @@ -140,12 +140,12 @@ | ||
| 140 | 140 | |
| 141 | 141 | public T setDouble(int i, double v) { |
| 142 | 142 | checkType(i, DataType.Name.DOUBLE); |
| 143 | - return setValue(i, TypeCodec.DoubleCodec.instance.serializeNoBoxing(v)); | |
| 143 | + return setValue(i, TypeCodec.doubleCodec.serializeNoBoxing(v)); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | public T setDouble(String name, double v) { |
| 147 | 147 | int[] indexes = getAllIndexesOf(name); |
| 148 | - ByteBuffer value = TypeCodec.DoubleCodec.instance.serializeNoBoxing(v); | |
| 148 | + ByteBuffer value = TypeCodec.doubleCodec.serializeNoBoxing(v); | |
| 149 | 149 | for (int i = 0; i < indexes.length; i++) { |
| 150 | 150 | checkType(indexes[i], DataType.Name.DOUBLE); |
| 151 | 151 | setValue(indexes[i], value); |
| @@ -157,10 +157,10 @@ | ||
| 157 | 157 | DataType.Name type = checkType(i, DataType.Name.VARCHAR, DataType.Name.TEXT, DataType.Name.ASCII); |
| 158 | 158 | switch (type) { |
| 159 | 159 | case ASCII: |
| 160 | - return setValue(i, v == null ? null : TypeCodec.StringCodec.asciiInstance.serialize(v)); | |
| 160 | + return setValue(i, v == null ? null : TypeCodec.asciiStringCodec.serialize(v)); | |
| 161 | 161 | case TEXT: |
| 162 | 162 | case VARCHAR: |
| 163 | - return setValue(i, v == null ? null : TypeCodec.StringCodec.utf8Instance.serialize(v)); | |
| 163 | + return setValue(i, v == null ? null : TypeCodec.utf8StringCodec.serialize(v)); | |
| 164 | 164 | default: |
| 165 | 165 | throw new AssertionError(); |
| 166 | 166 | } |
| @@ -202,12 +202,12 @@ | ||
| 202 | 202 | |
| 203 | 203 | public T setVarint(int i, BigInteger v) { |
| 204 | 204 | checkType(i, DataType.Name.VARINT); |
| 205 | - return setValue(i, v == null ? null : TypeCodec.BigIntegerCodec.instance.serialize(v)); | |
| 205 | + return setValue(i, v == null ? null : TypeCodec.bigIntegerCodec.serialize(v)); | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | public T setVarint(String name, BigInteger v) { |
| 209 | 209 | int[] indexes = getAllIndexesOf(name); |
| 210 | - ByteBuffer value = v == null ? null : TypeCodec.BigIntegerCodec.instance.serialize(v); | |
| 210 | + ByteBuffer value = v == null ? null : TypeCodec.bigIntegerCodec.serialize(v); | |
| 211 | 211 | for (int i = 0; i < indexes.length; i++) { |
| 212 | 212 | checkType(indexes[i], DataType.Name.VARINT); |
| 213 | 213 | setValue(indexes[i], value); |
| @@ -217,12 +217,12 @@ | ||
| 217 | 217 | |
| 218 | 218 | public T setDecimal(int i, BigDecimal v) { |
| 219 | 219 | checkType(i, DataType.Name.DECIMAL); |
| 220 | - return setValue(i, v == null ? null : TypeCodec.DecimalCodec.instance.serialize(v)); | |
| 220 | + return setValue(i, v == null ? null : TypeCodec.decimalCodec.serialize(v)); | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | public T setDecimal(String name, BigDecimal v) { |
| 224 | 224 | int[] indexes = getAllIndexesOf(name); |
| 225 | - ByteBuffer value = v == null ? null : TypeCodec.DecimalCodec.instance.serialize(v); | |
| 225 | + ByteBuffer value = v == null ? null : TypeCodec.decimalCodec.serialize(v); | |
| 226 | 226 | for (int i = 0; i < indexes.length; i++) { |
| 227 | 227 | checkType(indexes[i], DataType.Name.DECIMAL); |
| 228 | 228 | setValue(indexes[i], value); |
| @@ -240,13 +240,13 @@ | ||
| 240 | 240 | throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID", v)); |
| 241 | 241 | |
| 242 | 242 | return type == DataType.Name.UUID |
| 243 | - ? setValue(i, TypeCodec.UUIDCodec.instance.serialize(v)) | |
| 244 | - : setValue(i, TypeCodec.TimeUUIDCodec.instance.serialize(v)); | |
| 243 | + ? setValue(i, TypeCodec.uuidCodec.serialize(v)) | |
| 244 | + : setValue(i, TypeCodec.timeUuidCodec.serialize(v)); | |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | public T setUUID(String name, UUID v) { |
| 248 | 248 | int[] indexes = getAllIndexesOf(name); |
| 249 | - ByteBuffer value = v == null ? null : TypeCodec.UUIDCodec.instance.serialize(v); | |
| 249 | + ByteBuffer value = v == null ? null : TypeCodec.uuidCodec.serialize(v); | |
| 250 | 250 | for (int i = 0; i < indexes.length; i++) { |
| 251 | 251 | DataType.Name type = checkType(indexes[i], DataType.Name.UUID, DataType.Name.TIMEUUID); |
| 252 | 252 | if (v != null && type == DataType.Name.TIMEUUID && v.version() != 1) |
| @@ -258,12 +258,12 @@ | ||
| 258 | 258 | |
| 259 | 259 | public T setInet(int i, InetAddress v) { |
| 260 | 260 | checkType(i, DataType.Name.INET); |
| 261 | - return setValue(i, v == null ? null : TypeCodec.InetCodec.instance.serialize(v)); | |
| 261 | + return setValue(i, v == null ? null : TypeCodec.inetCodec.serialize(v)); | |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | public T setInet(String name, InetAddress v) { |
| 265 | 265 | int[] indexes = getAllIndexesOf(name); |
| 266 | - ByteBuffer value = v == null ? null : TypeCodec.InetCodec.instance.serialize(v); | |
| 266 | + ByteBuffer value = v == null ? null : TypeCodec.inetCodec.serialize(v); | |
| 267 | 267 | for (int i = 0; i < indexes.length; i++) { |
| 268 | 268 | checkType(indexes[i], DataType.Name.INET); |
| 269 | 269 | setValue(indexes[i], value); |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractGettableByIndexData.java +13 −13
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | if (value == null || value.remaining() == 0) |
| 111 | 111 | return false; |
| 112 | 112 | |
| 113 | - return TypeCodec.BooleanCodec.instance.deserializeNoBoxing(value); | |
| 113 | + return TypeCodec.booleanCodec.deserializeNoBoxing(value); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| @@ -124,7 +124,7 @@ | ||
| 124 | 124 | if (value == null || value.remaining() == 0) |
| 125 | 125 | return 0; |
| 126 | 126 | |
| 127 | - return TypeCodec.IntCodec.instance.deserializeNoBoxing(value); | |
| 127 | + return TypeCodec.intCodec.deserializeNoBoxing(value); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| @@ -138,7 +138,7 @@ | ||
| 138 | 138 | if (value == null || value.remaining() == 0) |
| 139 | 139 | return 0L; |
| 140 | 140 | |
| 141 | - return TypeCodec.LongCodec.instance.deserializeNoBoxing(value); | |
| 141 | + return TypeCodec.longCodec.deserializeNoBoxing(value); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
| @@ -152,7 +152,7 @@ | ||
| 152 | 152 | if (value == null || value.remaining() == 0) |
| 153 | 153 | return null; |
| 154 | 154 | |
| 155 | - return TypeCodec.DateCodec.instance.deserialize(value); | |
| 155 | + return TypeCodec.dateCodec.deserialize(value); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| @@ -166,7 +166,7 @@ | ||
| 166 | 166 | if (value == null || value.remaining() == 0) |
| 167 | 167 | return 0.0f; |
| 168 | 168 | |
| 169 | - return TypeCodec.FloatCodec.instance.deserializeNoBoxing(value); | |
| 169 | + return TypeCodec.floatCodec.deserializeNoBoxing(value); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
| @@ -180,7 +180,7 @@ | ||
| 180 | 180 | if (value == null || value.remaining() == 0) |
| 181 | 181 | return 0.0; |
| 182 | 182 | |
| 183 | - return TypeCodec.DoubleCodec.instance.deserializeNoBoxing(value); | |
| 183 | + return TypeCodec.doubleCodec.deserializeNoBoxing(value); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| @@ -218,8 +218,8 @@ | ||
| 218 | 218 | return null; |
| 219 | 219 | |
| 220 | 220 | return type == DataType.Name.ASCII |
| 221 | - ? TypeCodec.StringCodec.asciiInstance.deserialize(value) | |
| 222 | - : TypeCodec.StringCodec.utf8Instance.deserialize(value); | |
| 221 | + ? TypeCodec.asciiStringCodec.deserialize(value) | |
| 222 | + : TypeCodec.utf8StringCodec.deserialize(value); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
| @@ -233,7 +233,7 @@ | ||
| 233 | 233 | if (value == null || value.remaining() == 0) |
| 234 | 234 | return null; |
| 235 | 235 | |
| 236 | - return TypeCodec.BigIntegerCodec.instance.deserialize(value); | |
| 236 | + return TypeCodec.bigIntegerCodec.deserialize(value); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
| @@ -247,7 +247,7 @@ | ||
| 247 | 247 | if (value == null || value.remaining() == 0) |
| 248 | 248 | return null; |
| 249 | 249 | |
| 250 | - return TypeCodec.DecimalCodec.instance.deserialize(value); | |
| 250 | + return TypeCodec.decimalCodec.deserialize(value); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| @@ -262,8 +262,8 @@ | ||
| 262 | 262 | return null; |
| 263 | 263 | |
| 264 | 264 | return type == DataType.Name.UUID |
| 265 | - ? TypeCodec.UUIDCodec.instance.deserialize(value) | |
| 266 | - : TypeCodec.TimeUUIDCodec.instance.deserialize(value); | |
| 265 | + ? TypeCodec.uuidCodec.deserialize(value) | |
| 266 | + : TypeCodec.timeUuidCodec.deserialize(value); | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
| @@ -277,7 +277,7 @@ | ||
| 277 | 277 | if (value == null || value.remaining() == 0) |
| 278 | 278 | return null; |
| 279 | 279 | |
| 280 | - return TypeCodec.InetCodec.instance.deserialize(value); | |
| 280 | + return TypeCodec.inetCodec.deserialize(value); | |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedResultSet.java +1 −1
| @@ -430,6 +430,6 @@ | ||
| 430 | 430 | if (value == null || value.remaining() == 0) |
| 431 | 431 | return false; |
| 432 | 432 | |
| 433 | - return TypeCodec.BooleanCodec.instance.deserializeNoBoxing(value); | |
| 433 | + return TypeCodec.booleanCodec.deserializeNoBoxing(value); | |
| 434 | 434 | } |
| 435 | 435 | } |
| No newline at the end of the file |
modified driver-core/src/main/java/com/datastax/driver/core/CassandraTypeParser.java +2 −2
| @@ -102,7 +102,7 @@ | ||
| 102 | 102 | |
| 103 | 103 | String keyspace = parser.readOne(); |
| 104 | 104 | parser.skipBlankAndComma(); |
| 105 | - String typeName = TypeCodec.StringCodec.utf8Instance.deserialize(Bytes.fromHexString("0x" + parser.readOne())); | |
| 105 | + String typeName = TypeCodec.utf8StringCodec.deserialize(Bytes.fromHexString("0x" + parser.readOne())); | |
| 106 | 106 | parser.skipBlankAndComma(); |
| 107 | 107 | Map<String, String> rawFields = parser.getNameAndTypeParameters(); |
| 108 | 108 | List<UserType.Field> fields = new ArrayList<UserType.Field>(rawFields.size()); |
| @@ -316,7 +316,7 @@ | ||
| 316 | 316 | String bbHex = readNextIdentifier(); |
| 317 | 317 | String name = null; |
| 318 | 318 | try { |
| 319 | - name = TypeCodec.StringCodec.utf8Instance.deserialize(Bytes.fromHexString("0x" + bbHex)); | |
| 319 | + name = TypeCodec.utf8StringCodec.deserialize(Bytes.fromHexString("0x" + bbHex)); | |
| 320 | 320 | } catch (NumberFormatException e) { |
| 321 | 321 | throwSyntaxError(e.getMessage()); |
| 322 | 322 | } |
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +1 −1
| @@ -899,7 +899,7 @@ | ||
| 899 | 899 | @SuppressWarnings("unchecked") |
| 900 | 900 | @Override |
| 901 | 901 | TypeCodec<Object> codec(ProtocolVersion protocolVersion) { |
| 902 | - return (TypeCodec)TypeCodec.BytesCodec.instance; | |
| 902 | + return (TypeCodec)TypeCodec.bytesCodec; | |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +40 −49
| @@ -19,9 +19,12 @@ | ||
| 19 | 19 | import java.math.BigInteger; |
| 20 | 20 | import java.net.InetAddress; |
| 21 | 21 | import java.net.UnknownHostException; |
| 22 | -import java.nio.*; | |
| 23 | -import java.nio.charset.*; | |
| 24 | -import java.text.*; | |
| 22 | +import java.nio.BufferUnderflowException; | |
| 23 | +import java.nio.ByteBuffer; | |
| 24 | +import java.nio.charset.Charset; | |
| 25 | +import java.text.ParseException; | |
| 26 | +import java.text.ParsePosition; | |
| 27 | +import java.text.SimpleDateFormat; | |
| 25 | 28 | import java.util.*; |
| 26 | 29 | import java.util.regex.Pattern; |
| 27 | 30 | |
| @@ -30,30 +33,41 @@ | ||
| 30 | 33 | |
| 31 | 34 | abstract class TypeCodec<T> { |
| 32 | 35 | |
| 33 | - // Somehow those don't seem to get properly initialized if they're not here. The reason | |
| 34 | - // escape me right now so let's just leave it here for now | |
| 35 | - public static final StringCodec utf8Instance = new StringCodec(Charset.forName("UTF-8")); | |
| 36 | - public static final StringCodec asciiInstance = new StringCodec(Charset.forName("US-ASCII")); | |
| 36 | + static final StringCodec utf8StringCodec = new StringCodec(Charset.forName("UTF-8")); | |
| 37 | + static final StringCodec asciiStringCodec = new StringCodec(Charset.forName("US-ASCII")); | |
| 38 | + static final LongCodec longCodec = new LongCodec(); | |
| 39 | + static final BytesCodec bytesCodec = new BytesCodec(); | |
| 40 | + static final BooleanCodec booleanCodec = new BooleanCodec(); | |
| 41 | + static final DecimalCodec decimalCodec = new DecimalCodec(); | |
| 42 | + static final DoubleCodec doubleCodec = new DoubleCodec(); | |
| 43 | + static final FloatCodec floatCodec = new FloatCodec(); | |
| 44 | + static final InetCodec inetCodec = new InetCodec(); | |
| 45 | + static final IntCodec intCodec = new IntCodec(); | |
| 46 | + static final DateCodec dateCodec = new DateCodec(); | |
| 47 | + static final UUIDCodec uuidCodec = new UUIDCodec(); | |
| 48 | + static final BigIntegerCodec bigIntegerCodec = new BigIntegerCodec(); | |
| 49 | + static final TimeUUIDCodec timeUuidCodec = new TimeUUIDCodec(); | |
| 37 | 50 | |
| 38 | 51 | private static final Map<DataType.Name, TypeCodec<?>> primitiveCodecs = new EnumMap<DataType.Name, TypeCodec<?>>(DataType.Name.class); |
| 52 | + | |
| 39 | 53 | static { |
| 40 | - primitiveCodecs.put(DataType.Name.ASCII, StringCodec.asciiInstance); | |
| 41 | - primitiveCodecs.put(DataType.Name.BIGINT, LongCodec.instance); | |
| 42 | - primitiveCodecs.put(DataType.Name.BLOB, BytesCodec.instance); | |
| 43 | - primitiveCodecs.put(DataType.Name.BOOLEAN, BooleanCodec.instance); | |
| 44 | - primitiveCodecs.put(DataType.Name.COUNTER, LongCodec.instance); | |
| 45 | - primitiveCodecs.put(DataType.Name.DECIMAL, DecimalCodec.instance); | |
| 46 | - primitiveCodecs.put(DataType.Name.DOUBLE, DoubleCodec.instance); | |
| 47 | - primitiveCodecs.put(DataType.Name.FLOAT, FloatCodec.instance); | |
| 48 | - primitiveCodecs.put(DataType.Name.INET, InetCodec.instance); | |
| 49 | - primitiveCodecs.put(DataType.Name.INT, IntCodec.instance); | |
| 50 | - primitiveCodecs.put(DataType.Name.TEXT, StringCodec.utf8Instance); | |
| 51 | - primitiveCodecs.put(DataType.Name.TIMESTAMP, DateCodec.instance); | |
| 52 | - primitiveCodecs.put(DataType.Name.UUID, UUIDCodec.instance); | |
| 53 | - primitiveCodecs.put(DataType.Name.VARCHAR, StringCodec.utf8Instance); | |
| 54 | - primitiveCodecs.put(DataType.Name.VARINT, BigIntegerCodec.instance); | |
| 55 | - primitiveCodecs.put(DataType.Name.TIMEUUID, TimeUUIDCodec.instance); | |
| 56 | - primitiveCodecs.put(DataType.Name.CUSTOM, BytesCodec.instance); | |
| 54 | + primitiveCodecs.put(DataType.Name.ASCII, asciiStringCodec); | |
| 55 | + primitiveCodecs.put(DataType.Name.BIGINT, longCodec); | |
| 56 | + primitiveCodecs.put(DataType.Name.BLOB, bytesCodec); | |
| 57 | + primitiveCodecs.put(DataType.Name.BOOLEAN, booleanCodec); | |
| 58 | + primitiveCodecs.put(DataType.Name.COUNTER, longCodec); | |
| 59 | + primitiveCodecs.put(DataType.Name.DECIMAL, decimalCodec); | |
| 60 | + primitiveCodecs.put(DataType.Name.DOUBLE, doubleCodec); | |
| 61 | + primitiveCodecs.put(DataType.Name.FLOAT, floatCodec); | |
| 62 | + primitiveCodecs.put(DataType.Name.INET, inetCodec); | |
| 63 | + primitiveCodecs.put(DataType.Name.INT, intCodec); | |
| 64 | + primitiveCodecs.put(DataType.Name.TEXT, utf8StringCodec); | |
| 65 | + primitiveCodecs.put(DataType.Name.TIMESTAMP, dateCodec); | |
| 66 | + primitiveCodecs.put(DataType.Name.UUID, uuidCodec); | |
| 67 | + primitiveCodecs.put(DataType.Name.VARCHAR, utf8StringCodec); | |
| 68 | + primitiveCodecs.put(DataType.Name.VARINT, bigIntegerCodec); | |
| 69 | + primitiveCodecs.put(DataType.Name.TIMEUUID, timeUuidCodec); | |
| 70 | + primitiveCodecs.put(DataType.Name.CUSTOM, bytesCodec); | |
| 57 | 71 | } |
| 58 | 72 | |
| 59 | 73 | private static class PrimitiveCollectionCodecs |
| @@ -413,8 +427,6 @@ | ||
| 413 | 427 | |
| 414 | 428 | static class LongCodec extends TypeCodec<Long> { |
| 415 | 429 | |
| 416 | - public static final LongCodec instance = new LongCodec(); | |
| 417 | - | |
| 418 | 430 | private LongCodec() {} |
| 419 | 431 | |
| 420 | 432 | @Override |
| @@ -457,8 +469,6 @@ | ||
| 457 | 469 | |
| 458 | 470 | static class BytesCodec extends TypeCodec<ByteBuffer> { |
| 459 | 471 | |
| 460 | - public static final BytesCodec instance = new BytesCodec(); | |
| 461 | - | |
| 462 | 472 | private BytesCodec() {} |
| 463 | 473 | |
| 464 | 474 | @Override |
| @@ -486,8 +496,6 @@ | ||
| 486 | 496 | private static final ByteBuffer TRUE = ByteBuffer.wrap(new byte[]{1}); |
| 487 | 497 | private static final ByteBuffer FALSE = ByteBuffer.wrap(new byte[]{0}); |
| 488 | 498 | |
| 489 | - public static final BooleanCodec instance = new BooleanCodec(); | |
| 490 | - | |
| 491 | 499 | private BooleanCodec() {} |
| 492 | 500 | |
| 493 | 501 | @Override |
| @@ -529,8 +537,6 @@ | ||
| 529 | 537 | |
| 530 | 538 | static class DecimalCodec extends TypeCodec<BigDecimal> { |
| 531 | 539 | |
| 532 | - public static final DecimalCodec instance = new DecimalCodec(); | |
| 533 | - | |
| 534 | 540 | private DecimalCodec() {} |
| 535 | 541 | |
| 536 | 542 | @Override |
| @@ -577,8 +583,6 @@ | ||
| 577 | 583 | |
| 578 | 584 | static class DoubleCodec extends TypeCodec<Double> { |
| 579 | 585 | |
| 580 | - public static final DoubleCodec instance = new DoubleCodec(); | |
| 581 | - | |
| 582 | 586 | private DoubleCodec() {} |
| 583 | 587 | |
| 584 | 588 | @Override |
| @@ -621,8 +625,6 @@ | ||
| 621 | 625 | |
| 622 | 626 | static class FloatCodec extends TypeCodec<Float> { |
| 623 | 627 | |
| 624 | - public static final FloatCodec instance = new FloatCodec(); | |
| 625 | - | |
| 626 | 628 | private FloatCodec() {} |
| 627 | 629 | |
| 628 | 630 | @Override |
| @@ -665,8 +667,6 @@ | ||
| 665 | 667 | |
| 666 | 668 | static class InetCodec extends TypeCodec<InetAddress> { |
| 667 | 669 | |
| 668 | - public static final InetCodec instance = new InetCodec(); | |
| 669 | - | |
| 670 | 670 | private InetCodec() {} |
| 671 | 671 | |
| 672 | 672 | @Override |
| @@ -703,8 +703,6 @@ | ||
| 703 | 703 | |
| 704 | 704 | static class IntCodec extends TypeCodec<Integer> { |
| 705 | 705 | |
| 706 | - public static final IntCodec instance = new IntCodec(); | |
| 707 | - | |
| 708 | 706 | private IntCodec() {} |
| 709 | 707 | |
| 710 | 708 | @Override |
| @@ -764,7 +762,6 @@ | ||
| 764 | 762 | "yyyy-MM-ddZ" |
| 765 | 763 | }; |
| 766 | 764 | |
| 767 | - public static final DateCodec instance = new DateCodec(); | |
| 768 | 765 | private static final Pattern IS_LONG_PATTERN = Pattern.compile("^-?\\d+$"); |
| 769 | 766 | |
| 770 | 767 | private DateCodec() {} |
| @@ -818,19 +815,17 @@ | ||
| 818 | 815 | |
| 819 | 816 | @Override |
| 820 | 817 | public ByteBuffer serialize(Date value) { |
| 821 | - return LongCodec.instance.serializeNoBoxing(value.getTime()); | |
| 818 | + return longCodec.serializeNoBoxing(value.getTime()); | |
| 822 | 819 | } |
| 823 | 820 | |
| 824 | 821 | @Override |
| 825 | 822 | public Date deserialize(ByteBuffer bytes) { |
| 826 | - return new Date(LongCodec.instance.deserializeNoBoxing(bytes)); | |
| 823 | + return new Date(longCodec.deserializeNoBoxing(bytes)); | |
| 827 | 824 | } |
| 828 | 825 | } |
| 829 | 826 | |
| 830 | 827 | static class UUIDCodec extends TypeCodec<UUID> { |
| 831 | 828 | |
| 832 | - public static final UUIDCodec instance = new UUIDCodec(); | |
| 833 | - | |
| 834 | 829 | protected UUIDCodec() {} |
| 835 | 830 | |
| 836 | 831 | @Override |
| @@ -863,8 +858,6 @@ | ||
| 863 | 858 | |
| 864 | 859 | static class TimeUUIDCodec extends UUIDCodec { |
| 865 | 860 | |
| 866 | - public static final TimeUUIDCodec instance = new TimeUUIDCodec(); | |
| 867 | - | |
| 868 | 861 | private TimeUUIDCodec() {} |
| 869 | 862 | |
| 870 | 863 | @Override |
| @@ -886,8 +879,6 @@ | ||
| 886 | 879 | |
| 887 | 880 | static class BigIntegerCodec extends TypeCodec<BigInteger> { |
| 888 | 881 | |
| 889 | - public static final BigIntegerCodec instance = new BigIntegerCodec(); | |
| 890 | - | |
| 891 | 882 | private BigIntegerCodec() {} |
| 892 | 883 | |
| 893 | 884 | @Override |