Package org.springframework.cassandra.core.converter

Source Code of org.springframework.cassandra.core.converter.RowToMapConverter

package org.springframework.cassandra.core.converter;

import java.util.HashMap;
import java.util.Map;

import org.springframework.core.convert.converter.Converter;

import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.Row;

public class RowToMapConverter implements Converter<Row, Map<String, Object>> {

  @Override
  public Map<String, Object> convert(Row row) {

    if (row == null) {
      return null;
    }

    ColumnDefinitions cols = row.getColumnDefinitions();
    Map<String, Object> map = new HashMap<String, Object>(cols.size());

    for (Definition def : cols.asList()) {

      String name = def.getName();
      map.put(name, row.isNull(name) ? null : def.getType().deserialize(row.getBytesUnsafe(name)));
    }

    return map;
  }
}
TOP

Related Classes of org.springframework.cassandra.core.converter.RowToMapConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.