Skip to content

Commit 2ef7a6f

Browse files
committed
Additional changes on new DateWithoutTime type (JAVA-404).
1 parent b066df2 commit 2ef7a6f

22 files changed

Lines changed: 473 additions & 341 deletions

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [new feature] Expose function and aggregate metadata (JAVA-747)
1111
- [new feature] Add new client exception for CQL function failure (JAVA-778)
1212
- [improvement] Expose ProtocolVersion#toInt (JAVA-700)
13+
- [new feature] Support new C* 2.2 CQL date and time types (JAVA-404)
1314

1415
Merged from 2.1 branch:
1516

driver-core/src/main/java/com/datastax/driver/core/AbstractAddressableByIndexData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public T setDate(int i, Date v) {
7373

7474
public T setTimestamp(int i, Date v) {
7575
checkType(i, DataType.Name.TIMESTAMP);
76-
return setValue(i, v == null ? null : TypeCodec.DateCodec.instance.serialize(v));
76+
return setValue(i, v == null ? null : TypeCodec.TimestampCodec.instance.serialize(v));
7777
}
7878

79-
public T setDateWithoutTime(int i, DateWithoutTime v) {
79+
public T setDate(int i, DateWithoutTime v) {
8080
checkType(i, DataType.Name.DATE);
81-
return setValue(i, TypeCodec.SimpleDateCodec.instance.serialize(v));
81+
return setValue(i, TypeCodec.DateCodec.instance.serialize(v));
8282
}
8383

8484
public T setTime(int i, long v) {

driver-core/src/main/java/com/datastax/driver/core/AbstractData.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,37 +138,29 @@ public T setLong(String name, long v) {
138138
return wrapped;
139139
}
140140

141-
public T setDate(int i, Date v) {
142-
return setTimestamp(i, v);
143-
}
144-
145-
public T setDate(String name, Date v) {
146-
return setTimestamp(name, v);
147-
}
148-
149141
public T setTimestamp(int i, Date v) {
150142
checkType(i, DataType.Name.TIMESTAMP);
151-
return setValue(i, v == null ? null : TypeCodec.DateCodec.instance.serialize(v));
143+
return setValue(i, v == null ? null : TypeCodec.TimestampCodec.instance.serialize(v));
152144
}
153145

154146
public T setTimestamp(String name, Date v) {
155147
int[] indexes = getAllIndexesOf(name);
156-
ByteBuffer value = v == null ? null : TypeCodec.DateCodec.instance.serialize(v);
148+
ByteBuffer value = v == null ? null : TypeCodec.TimestampCodec.instance.serialize(v);
157149
for (int i = 0; i < indexes.length; i++) {
158150
checkType(indexes[i], DataType.Name.TIMESTAMP);
159151
setValue(indexes[i], value);
160152
}
161153
return wrapped;
162154
}
163155

164-
public T setDateWithoutTime(int i, DateWithoutTime v) {
156+
public T setDate(int i, DateWithoutTime v) {
165157
checkType(i, DataType.Name.DATE);
166-
return setValue(i, TypeCodec.SimpleDateCodec.instance.serialize(v));
158+
return setValue(i, TypeCodec.DateCodec.instance.serialize(v));
167159
}
168160

169-
public T setDateWithoutTime(String name, DateWithoutTime v) {
161+
public T setDate(String name, DateWithoutTime v) {
170162
int[] indexes = getAllIndexesOf(name);
171-
ByteBuffer value = TypeCodec.SimpleDateCodec.instance.serialize(v);
163+
ByteBuffer value = TypeCodec.DateCodec.instance.serialize(v);
172164
for (int i = 0; i < indexes.length; i++) {
173165
checkType(indexes[i], DataType.Name.DATE);
174166
setValue(indexes[i], value);

driver-core/src/main/java/com/datastax/driver/core/AbstractGettableByIndexData.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,6 @@ public long getLong(int i) {
169169
return TypeCodec.LongCodec.instance.deserializeNoBoxing(value);
170170
}
171171

172-
/**
173-
* {@inheritDoc}
174-
*/
175-
@Override
176-
public Date getDate(int i) {
177-
return getTimestamp(i);
178-
}
179-
180172
/**
181173
* {@inheritDoc}
182174
*/
@@ -189,21 +181,21 @@ public Date getTimestamp(int i)
189181
if (value == null || value.remaining() == 0)
190182
return null;
191183

192-
return TypeCodec.DateCodec.instance.deserialize(value);
184+
return TypeCodec.TimestampCodec.instance.deserialize(value);
193185
}
194186

195187
/**
196188
* {@inheritDoc}
197189
*/
198190
@Override
199-
public DateWithoutTime getDateWithoutTime(int i) {
191+
public DateWithoutTime getDate(int i) {
200192
checkType(i, DataType.Name.DATE);
201193

202194
ByteBuffer value = getValue(i);
203195
if (value == null || value.remaining() == 0)
204196
return null;
205197

206-
return TypeCodec.SimpleDateCodec.instance.deserialize(value);
198+
return TypeCodec.DateCodec.instance.deserialize(value);
207199
}
208200

209201
/**

driver-core/src/main/java/com/datastax/driver/core/AbstractGettableData.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ public long getLong(String name) {
9797
return getLong(getIndexOf(name));
9898
}
9999

100-
/**
101-
* {@inheritDoc}
102-
*/
103-
@Deprecated
104-
@Override
105-
public Date getDate(String name) {
106-
return getTimestamp(getIndexOf(name));
107-
}
108-
109100
/**
110101
* {@inheritDoc}
111102
*/
@@ -118,8 +109,8 @@ public Date getTimestamp(String name) {
118109
* {@inheritDoc}
119110
*/
120111
@Override
121-
public DateWithoutTime getDateWithoutTime(String name) {
122-
return getDateWithoutTime(getIndexOf(name));
112+
public DateWithoutTime getDate(String name) {
113+
return getDate(getIndexOf(name));
123114
}
124115

125116
/**

driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public BoundStatement setTimestamp(String name, Date v) {
519519
}
520520

521521
/**
522-
* Set the {@code i}th value to the provided date as an int in days since epoch.
522+
* Set the {@code i}th value to the provided date.
523523
*
524524
* @param i the index of the value to set.
525525
* @param v the value to set.
@@ -528,13 +528,13 @@ public BoundStatement setTimestamp(String name, Date v) {
528528
* @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
529529
* @throws InvalidTypeException if value {@code i} is not of type DATE.
530530
*/
531-
public BoundStatement setDateWithoutTime(int i, DateWithoutTime v) {
532-
return wrapper.setDateWithoutTime(i, v);
531+
public BoundStatement setDate(int i, DateWithoutTime v) {
532+
return wrapper.setDate(i, v);
533533
}
534534

535535
/**
536536
* Sets the value for (all occurrences of) variable {@code name} to the
537-
* provided date as an int in days since epoch.
537+
* provided date.
538538
*
539539
* @param name the name of the value to set; if {@code name} is present multiple
540540
* times, all its values are set.
@@ -545,8 +545,8 @@ public BoundStatement setDateWithoutTime(int i, DateWithoutTime v) {
545545
* @throws InvalidTypeException if (any occurrence of) {@code name} is
546546
* not of type DATE.
547547
*/
548-
public BoundStatement setDateWithoutTime(String name, DateWithoutTime v) {
549-
return wrapper.setDateWithoutTime(name, v);
548+
public BoundStatement setDate(String name, DateWithoutTime v) {
549+
return wrapper.setDate(name, v);
550550
}
551551

552552
/**
@@ -1281,21 +1281,6 @@ public long getLong(String name) {
12811281
return wrapper.getLong(name);
12821282
}
12831283

1284-
/**
1285-
* {@inheritDoc}
1286-
*/
1287-
@Deprecated
1288-
public Date getDate(int i) {
1289-
return wrapper.getTimestamp(i);
1290-
}
1291-
1292-
/**
1293-
* {@inheritDoc}
1294-
*/
1295-
public Date getDate(String name) {
1296-
return wrapper.getTimestamp(name);
1297-
}
1298-
12991284
/**
13001285
* {@inheritDoc}
13011286
*/
@@ -1313,15 +1298,15 @@ public Date getTimestamp(String name) {
13131298
/**
13141299
* {@inheritDoc}
13151300
*/
1316-
public DateWithoutTime getDateWithoutTime(int i) {
1317-
return wrapper.getDateWithoutTime(i);
1301+
public DateWithoutTime getDate(int i) {
1302+
return wrapper.getDate(i);
13181303
}
13191304

13201305
/**
13211306
* {@inheritDoc}
13221307
*/
1323-
public DateWithoutTime getDateWithoutTime(String name) {
1324-
return wrapper.getDateWithoutTime(name);
1308+
public DateWithoutTime getDate(String name) {
1309+
return wrapper.getDate(name);
13251310
}
13261311

13271312
/**

0 commit comments

Comments
 (0)