Search in sources :

Example 1 with Name

use of com.datastax.driver.core.DataType.Name in project ats-framework by Axway.

the class CassandraDbProvider method extractObjectFromResultSet.

private static Object extractObjectFromResultSet(Row row, Definition columnDefinition) {
    Object object;
    String columnName = columnDefinition.getName();
    DataType dataType = columnDefinition.getType();
    Name columnTypeName = dataType.getName();
    if (columnTypeName.equals(DataType.Name.UUID)) {
        object = row.getUUID(columnName);
    } else if (columnTypeName.equals(DataType.Name.TIMEUUID)) {
        object = row.getUUID(columnName);
    } else if (columnTypeName.equals(DataType.Name.BOOLEAN)) {
        object = row.getBool(columnName);
    } else if (columnTypeName.equals(DataType.Name.INT)) {
        object = row.getInt(columnName);
    } else if (columnTypeName.equals(DataType.Name.BIGINT)) {
        object = row.getLong(columnName);
    } else if (columnTypeName.equals(DataType.Name.FLOAT)) {
        object = row.getFloat(columnName);
    } else if (columnTypeName.equals(DataType.Name.DOUBLE)) {
        object = row.getDouble(columnName);
    } else if (columnTypeName.equals(DataType.Name.COUNTER)) {
        object = row.getLong(columnName);
    } else if (columnTypeName.equals(DataType.Name.DECIMAL)) {
        object = row.getDecimal(columnName);
    } else if (columnTypeName.equals(DataType.Name.TEXT) || columnTypeName.equals(DataType.Name.VARCHAR)) {
        object = row.getString(columnName);
    } else if (columnTypeName.equals(DataType.Name.TIMESTAMP)) {
        object = row.getDate(columnName);
    } else if (columnTypeName.equals(DataType.Name.BLOB)) {
        ByteBuffer data = (ByteBuffer) row.getBytes(columnName);
        if (data != null) {
            byte[] result = new byte[data.remaining()];
            data.get(result);
            object = result;
        } else {
            object = null;
        }
    } else if (columnTypeName.equals(DataType.Name.SET)) {
        object = row.getSet(columnName, dataType.getTypeArguments().get(0).asJavaClass());
    } else if (columnTypeName.equals(DataType.Name.LIST)) {
        object = row.getList(columnName, dataType.getTypeArguments().get(0).asJavaClass());
    } else if (columnTypeName.equals(DataType.Name.MAP)) {
        object = row.getMap(columnName, dataType.getTypeArguments().get(0).asJavaClass(), dataType.getTypeArguments().get(1).asJavaClass());
    } else {
        throw new DbException("Unsupported data type '" + columnDefinition.getType().toString() + "' for table '" + columnDefinition.getTable() + "' and column '" + columnName + "'");
    }
    return object;
}
Also used : DataType(com.datastax.driver.core.DataType) ByteBuffer(java.nio.ByteBuffer) Name(com.datastax.driver.core.DataType.Name) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Aggregations

DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 DataType (com.datastax.driver.core.DataType)1 Name (com.datastax.driver.core.DataType.Name)1 ByteBuffer (java.nio.ByteBuffer)1