DATACASS-276 - Use Row.getObject(…) instead of deserialization with CodecRegistry and ProtocolVersion.
We now rely on Row.getObject(…) to retrieve data from a Cassandra Column. CodecRegistry and ProtocolVersion are configured on Cluster so there's no need to use a static configured CodecRegistry and ProtocolVersion that might not fit the configured values.
This commit is contained in:
@@ -617,8 +617,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
<T> T columnToObject(Row row, Definition columnDefinition) {
|
||||
TypeCodec<T> typeCodec = CodecRegistry.DEFAULT_INSTANCE.codecFor(columnDefinition.getType());
|
||||
return typeCodec.deserialize(row.getBytesUnsafe(columnDefinition.getName()), ProtocolVersion.NEWEST_SUPPORTED);
|
||||
return (T) row.getObject(columnDefinition.getName());
|
||||
}
|
||||
|
||||
protected Map<String, Object> toMap(Row row) {
|
||||
|
||||
@@ -21,10 +21,8 @@ import java.util.List;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
|
||||
import com.datastax.driver.core.CodecRegistry;
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
import com.datastax.driver.core.ColumnDefinitions.Definition;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
/**
|
||||
@@ -47,16 +45,13 @@ public class RowToListConverter implements Converter<Row, List<Object>> {
|
||||
return null;
|
||||
}
|
||||
|
||||
CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE;
|
||||
ColumnDefinitions cols = row.getColumnDefinitions();
|
||||
List<Object> list = new ArrayList<Object>(cols.size());
|
||||
|
||||
for (Definition def : cols.asList()) {
|
||||
String name = def.getName();
|
||||
|
||||
list.add(row.isNull(name) ? null
|
||||
: codecRegistry.codecFor(def.getType()).deserialize(row.getBytesUnsafe(name),
|
||||
ProtocolVersion.NEWEST_SUPPORTED));
|
||||
list.add(row.isNull(name) ? null : row.getObject(name));
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -22,10 +21,8 @@ import java.util.Map;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
|
||||
import com.datastax.driver.core.CodecRegistry;
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
import com.datastax.driver.core.ColumnDefinitions.Definition;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
/**
|
||||
@@ -48,7 +45,6 @@ public class RowToMapConverter implements Converter<Row, Map<String, Object>> {
|
||||
return null;
|
||||
}
|
||||
|
||||
CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE;
|
||||
ColumnDefinitions cols = row.getColumnDefinitions();
|
||||
Map<String, Object> map = new HashMap<String, Object>(cols.size());
|
||||
|
||||
@@ -56,10 +52,7 @@ public class RowToMapConverter implements Converter<Row, Map<String, Object>> {
|
||||
|
||||
String name = def.getName();
|
||||
|
||||
map.put(name,
|
||||
row.isNull(name) ? null
|
||||
: codecRegistry.codecFor(def.getType()).deserialize(row.getBytesUnsafe(name),
|
||||
ProtocolVersion.NEWEST_SUPPORTED));
|
||||
map.put(name, row.isNull(name) ? null : row.getObject(name));
|
||||
}
|
||||
|
||||
return map;
|
||||
|
||||
Reference in New Issue
Block a user