Elffuss BraidHub

kikocis/java-driver public

Changelog updates, few nits
Changesetf43cc0a579a9e5b3ebebcf2eac2dc7dd3513375cb0c7dfe5fbfcae1260dc7787
AuthorSylvain Lebresne <sylvain@datastax.com> · 2013-12-10 14:38 +01:00
CommitterSylvain Lebresne <sylvain@datastax.com> · 2013-12-10 14:38 +01:00
Parents74f9324b5c47

Browse the files at this changeset

3 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -9,6 +9,8 @@
99 - [improvement] Limit internal thread pool size (JAVA-203)
1010 - [improvement] New getter to obtain a snapshot of the scores maintained by
1111 LatencyAwarePolicy.
12+- [improvement] Avoid synchronization when getting codec for collection
13+ types (JAVA-222)
1214 - [bug] Don't retain unused PreparedStatement in memory (JAVA-201, JAVA-213)
1315 - [bug] Add missing clustering order info in TableMetadata
1416 - [bug] Allow bind markers for collections in the query builder (JAVA-196)
modified driver-core/src/main/java/com/datastax/driver/core/Codec.java +10 −16
@@ -15,12 +15,12 @@
1515 */
1616 package com.datastax.driver.core;
1717
18+import java.util.Map;
19+
1820 import com.google.common.collect.ImmutableMap;
1921 import com.google.common.collect.Maps;
2022 import org.apache.cassandra.db.marshal.*;
2123
22-import java.util.Map;
23-
2424 /**
2525 * Static method to code/decode serialized data given their types.
2626 */
@@ -49,7 +49,6 @@
4949 private static Map<DataType.Name, ListType<?>> LISTS = buildLists();
5050 private static Map<DataType.Name, Map<DataType.Name, MapType<?, ?>>> MAPS = buildMaps();
5151
52-
5352 protected static Map<DataType.Name, Map<DataType.Name, MapType<?, ?>>> buildMaps() {
5453
5554 ImmutableMap.Builder<DataType.Name, Map<DataType.Name, MapType<?, ?>>> mapsBuilder = ImmutableMap.builder();
@@ -84,7 +83,6 @@
8483 return Maps.immutableEnumMap(setsBuilder.build());
8584 }
8685
87-
8886 private Codec() {}
8987
9088 @SuppressWarnings("unchecked")
@@ -123,28 +121,24 @@
123121 final DataType dataTypeArg0 = type.getTypeArguments().get(0);
124122 final DataType dateTypeArg1 = type.getTypeArguments().get(1);
125123
126- if(dataTypeArg0.getName() == DataType.Name.CUSTOM || dateTypeArg1.getName() == DataType.Name.CUSTOM) {
127- return MapType.getInstance(getCodecInternal(dataTypeArg0), getCodecInternal(dateTypeArg1));
128- }
129- return MAPS.get(dataTypeArg0.getName()).get(dateTypeArg1.getName());
124+ Map<DataType.Name, MapType<?, ?>> tmp = MAPS.get(dataTypeArg0.getName());
125+ MapType<?, ?> map = tmp == null ? null : tmp.get(dateTypeArg1.getName());
126+
127+ return map == null ? MapType.getInstance(getCodecInternal(dataTypeArg0), getCodecInternal(dateTypeArg1)) : map;
130128 }
131129
132130 private static SetType<?> getSetType(DataType type) {
133131 final DataType dataTypeArg0 = type.getTypeArguments().get(0);
134132
135- if(dataTypeArg0.getName() == DataType.Name.CUSTOM) {
136- return SetType.getInstance(getCodecInternal(dataTypeArg0));
137- }
138- return SETS.get(type.getTypeArguments().get(0).getName());
133+ SetType<?> set = SETS.get(dataTypeArg0.getName());
134+ return set == null ? SetType.getInstance(getCodecInternal(dataTypeArg0)) : set;
139135 }
140136
141137 private static ListType<?> getListType(final DataType type) {
142138 final DataType dataTypeArg0 = type.getTypeArguments().get(0);
143139
144- if(dataTypeArg0.getName() == DataType.Name.CUSTOM) {
145- return ListType.getInstance(getCodecInternal(dataTypeArg0));
146- }
147- return LISTS.get(type.getTypeArguments().get(0).getName());
140+ ListType<?> list = LISTS.get(dataTypeArg0.getName());
141+ return list == null ? ListType.getInstance(getCodecInternal(dataTypeArg0)) : list;
148142 }
149143
150144 public static DataType rawTypeToDataType(AbstractType<?> rawType) {
modified driver-core/src/test/java/com/datastax/driver/core/CodecTest.java +15 −28
@@ -16,7 +16,6 @@
1616 package com.datastax.driver.core;
1717
1818 import org.apache.cassandra.db.marshal.*;
19-import org.apache.cassandra.utils.Pair;
2019 import org.testng.Assert;
2120 import org.testng.annotations.Test;
2221 import org.testng.collections.Maps;
@@ -31,47 +30,42 @@
3130
3231 @Test(groups = "unit")
3332 public void testCustomList() throws Exception {
34- ListType listType = (ListType) Codec.getCodec(DataType.list(CUSTOM_FOO));
33+ ListType<?> listType = (ListType) Codec.getCodec(DataType.list(CUSTOM_FOO));
3534 Assert.assertNotNull(listType);
3635 Assert.assertTrue(listType.valueComparator() instanceof BytesType);
37-
3836 }
3937
40-
4138 @Test(groups = "unit")
4239 public void testCustomSet() throws Exception {
43- SetType setType = (SetType) Codec.getCodec(DataType.set(CUSTOM_FOO));
40+ SetType<?> setType = (SetType) Codec.getCodec(DataType.set(CUSTOM_FOO));
4441 Assert.assertNotNull(setType);
4542 Assert.assertEquals(setType.nameComparator().getClass(),BytesType.class);
4643 }
4744
48-
4945 @Test(groups = "unit")
5046 public void testCustomKeyMap() throws Exception {
51- MapType mapType = (MapType) Codec.getCodec(DataType.map(CUSTOM_FOO, text()));
47+ MapType<?, ?> mapType = (MapType) Codec.getCodec(DataType.map(CUSTOM_FOO, text()));
5248 Assert.assertNotNull(mapType);
5349 Assert.assertEquals(mapType.nameComparator().getClass(), BytesType.class);
5450 Assert.assertEquals(mapType.valueComparator().getClass(), UTF8Type.class);
5551 }
5652
57-
5853 @Test(groups = "unit")
5954 public void testCustomValueMap() throws Exception {
60- MapType mapType = (MapType) Codec.getCodec(DataType.map(text(), CUSTOM_FOO));
55+ MapType<?, ?> mapType = (MapType) Codec.getCodec(DataType.map(text(), CUSTOM_FOO));
6156 Assert.assertNotNull(mapType);
6257 Assert.assertEquals(mapType.nameComparator().getClass(), UTF8Type.class);
6358 Assert.assertEquals(mapType.valueComparator().getClass(), BytesType.class);
6459 }
6560
66-
6761 @Test(groups = "unit")
6862 public void testSetTypeCodec() throws Exception {
6963 Map<Name, SetType<?>> dateTypeSetTypeMap = new HashMap<Name, SetType<?>>(Codec.buildSets());
7064
7165 final Set<DataType> dataTypes = new HashSet<DataType>(allPrimitiveTypes());
7266
73- //Special case: DataType varchar yields Codec.rawTypeToDataType(...) => text causing assertion fail
74- //Solution: Remove DataType.varchar and check that it yields DataType.text
67+ // Special case: DataType varchar yields Codec.rawTypeToDataType(...) => text causing assertion fail
68+ // Solution: Remove DataType.varchar and check that it yields DataType.text
7569 Assert.assertTrue(dataTypes.remove(varchar()));
7670 Assert.assertEquals(Codec.rawTypeToDataType(dateTypeSetTypeMap.get(varchar().getName()).nameComparator()), text()) ;
7771 dateTypeSetTypeMap.remove(varchar().getName());
@@ -89,20 +83,18 @@
8983
9084 final Set<DataType> dataTypes = new HashSet<DataType>(allPrimitiveTypes());
9185
92- //Special case: DataType varchar yields Codec.rawTypeToDataType(...) => text causing assertion fail
93- //Solution: Remove DataType.varchar and check that it yields DataType.text
86+ // Special case: DataType varchar yields Codec.rawTypeToDataType(...) => text causing assertion fail
87+ // Solution: Remove DataType.varchar and check that it yields DataType.text
9488 Assert.assertTrue(dataTypes.remove(varchar()));
9589 final AbstractType<?> rawType = dateTypeListetTypeMap.get(varchar().getName()).valueComparator();
9690 Assert.assertEquals(Codec.rawTypeToDataType(rawType), text()) ;
9791 dateTypeListetTypeMap.remove(varchar().getName());
9892
99-
10093 for (DataType dataType : dataTypes) {
10194 final ListType<?> setType = dateTypeListetTypeMap.remove(dataType.getName());
10295 Assert.assertEquals(Codec.rawTypeToDataType(setType.valueComparator()),dataType) ;
10396 }
10497 Assert.assertTrue(dateTypeListetTypeMap.isEmpty(), "All set types should have been tested: "+dateTypeListetTypeMap);
105-
10698 }
10799
108100 @Test(groups = "unit")
@@ -123,19 +115,14 @@
123115 Assert.assertTrue(dateTypeMapTypeMap.isEmpty(), "All map types should have been tested: "+dateTypeMapTypeMap);
124116 }
125117
126- private Pair<Name, Name> convertToNamePair(Pair<DataType, DataType> pair) {
127- return Pair.create(pair.left.getName(), pair.right.getName());
128- }
129-
130-
131118 private void testPairAgainstMapType(DataType dataTypeArg0, DataType dataTypeArg1, MapType<?, ?> mapType) {
132- //Special case: DataType varchar yields Codec.rawTypeToDataType(...) => text causing assertion fail
133- //Solution: Remove DataType.varchar and check that it yields DataType.text
134-
135- //In the map case this would be quite many combinations of text/varchar so I translate varchar to text
136- //in order to expect text instead of varchar back from those cases:
137- if(dataTypeArg0.equals(varchar())) dataTypeArg0 = text();
138- if(dataTypeArg1.equals(varchar())) dataTypeArg1 = text();
119+ // Special case: DataType varchar yields Codec.rawTypeToDataType(...) => text causing assertion fail
120+ // Solution: Remove DataType.varchar and check that it yields DataType.text
121+
122+ // In the map case this would be quite many combinations of text/varchar so I translate varchar to text
123+ // in order to expect text instead of varchar back from those cases:
124+ if (dataTypeArg0.equals(varchar())) dataTypeArg0 = text();
125+ if (dataTypeArg1.equals(varchar())) dataTypeArg1 = text();
139126
140127 Assert.assertEquals(Codec.rawTypeToDataType(mapType.nameComparator()), dataTypeArg0) ;
141128 Assert.assertEquals(Codec.rawTypeToDataType(mapType.valueComparator()),dataTypeArg1) ;