@Test public void testGetRowWithNull() { CassandraQueryExecution cqe = new CassandraQueryExecution(null, null, null); Row row = Mockito.mock(Row.class); Mockito.stub(row.isNull(0)).toReturn(true); ColumnDefinitions cd = Mockito.mock(ColumnDefinitions.class); Mockito.stub(row.getColumnDefinitions()).toReturn(cd); Mockito.stub(cd.size()).toReturn(1); Mockito.stub(cd.getType(0)).toReturn(DataType.cint()); List<?> val = cqe.getRow(row); assertNull(val.get(0)); }
List<Object> getRow(Row row) { if(row == null){ return null; } ColumnDefinitions columnDefinitions = row.getColumnDefinitions(); final List<Object> values = new ArrayList<Object>(columnDefinitions.size()); for(int i = 0; i < columnDefinitions.size(); i++){ if (row.isNull(i)) { values.add(null); continue; } switch(columnDefinitions.getType(i).getName()){ case ASCII: values.add(row.getString(i)); break; case BIGINT: values.add(Long.valueOf(row.getLong(i))); break; case BOOLEAN: values.add(Boolean.valueOf(row.getBool(i))); break; case COUNTER: values.add(Long.valueOf(row.getLong(i))); break; case DECIMAL: values.add(row.getDecimal(i)); break; case DOUBLE: values.add(Double.valueOf(row.getDouble(i))); break; case FLOAT: values.add(Float.valueOf(row.getFloat(i))); break; case INET: values.add(row.getInet(i)); break; case INT: values.add(Integer.valueOf(row.getInt(i))); break; case LIST: values.add(row.getList(i, Object.class)); break; case MAP: values.add(row.getMap(i, Object.class, Object.class)); break; case SET: values.add(row.getSet(i, Object.class)); break; case TEXT: values.add(row.getString(i)); break; case TIME: long val = row.getTime(i); Timestamp ts = new Timestamp(val/1000000); ts.setNanos((int)(val%1000000)); values.add(ts); break; case DATE: values.add(Date.valueOf(row.getDate(i).toString())); break; case TIMESTAMP: values.add(row.getTimestamp(i)); break; case TIMEUUID: values.add(row.getUUID(i)); break; case UUID: values.add(row.getUUID(i)); break; case VARCHAR: values.add(row.getString(i)); break; case VARINT: values.add(row.getVarint(i)); break; default: ByteBuffer bytesUnsafe = row.getBytesUnsafe(i); byte[] b = new byte[bytesUnsafe.remaining()]; bytesUnsafe.get(b); values.add(b); break; } } if (returnsArray) { return Arrays.asList((Object)values.toArray()); } return values; }
CassandraQueryExecution implements ResultSetExecution { List<Object> getRow(Row row) { if(row == null){ return null; } ColumnDefinitions columnDefinitions = row.getColumnDefinitions(); final List<Object> values = new ArrayList<Object>(columnDefinitions.size()); for(int i = 0; i < columnDefinitions.size(); i++){ if (row.isNull(i)) { values.add(null); continue; } switch(columnDefinitions.getType(i).getName()){ case ASCII: values.add(row.getString(i)); break; case BIGINT: values.add(Long.valueOf(row.getLong(i))); break; case BOOLEAN: values.add(Boolean.valueOf(row.getBool(i))); break; case COUNTER: values.add(Long.valueOf(row.getLong(i))); break; case DECIMAL: values.add(row.getDecimal(i)); break; case DOUBLE: values.add(Double.valueOf(row.getDouble(i))); break; case FLOAT: values.add(Float.valueOf(row.getFloat(i))); break; case INET: values.add(row.getInet(i)); break; case INT: values.add(Integer.valueOf(row.getInt(i))); break; case LIST: values.add(row.getList(i, Object.class)); break; case MAP: values.add(row.getMap(i, Object.class, Object.class)); break; case SET: values.add(row.getSet(i, Object.class)); break; case TEXT: values.add(row.getString(i)); break; case TIME: long val = row.getTime(i); Timestamp ts = new Timestamp(val/1000000); ts.setNanos((int)(val%1000000)); values.add(ts); break; case DATE: values.add(Date.valueOf(row.getDate(i).toString())); break; case TIMESTAMP: values.add(row.getTimestamp(i)); break; case TIMEUUID: values.add(row.getUUID(i)); break; case UUID: values.add(row.getUUID(i)); break; case VARCHAR: values.add(row.getString(i)); break; case VARINT: values.add(row.getVarint(i)); break; default: ByteBuffer bytesUnsafe = row.getBytesUnsafe(i); byte[] b = new byte[bytesUnsafe.remaining()]; bytesUnsafe.get(b); values.add(b); break; } } if (returnsArray) { return Arrays.asList((Object)values.toArray()); } return values; } }
CassandraQueryExecution implements ResultSetExecution { List<Object> getRow(Row row) { if(row == null){ return null; } ColumnDefinitions columnDefinitions = row.getColumnDefinitions(); final List<Object> values = new ArrayList<Object>(columnDefinitions.size()); for(int i = 0; i < columnDefinitions.size(); i++){ if (row.isNull(i)) { values.add(null); continue; } switch(columnDefinitions.getType(i).getName()){ case ASCII: values.add(row.getString(i)); break; case BIGINT: values.add(Long.valueOf(row.getLong(i))); break; case BOOLEAN: values.add(Boolean.valueOf(row.getBool(i))); break; case COUNTER: values.add(Long.valueOf(row.getLong(i))); break; case DECIMAL: values.add(row.getDecimal(i)); break; case DOUBLE: values.add(Double.valueOf(row.getDouble(i))); break; case FLOAT: values.add(Float.valueOf(row.getFloat(i))); break; case INET: values.add(row.getInet(i)); break; case INT: values.add(Integer.valueOf(row.getInt(i))); break; case LIST: values.add(row.getList(i, Object.class)); break; case MAP: values.add(row.getMap(i, Object.class, Object.class)); break; case SET: values.add(row.getSet(i, Object.class)); break; case TEXT: values.add(row.getString(i)); break; case TIME: long val = row.getTime(i); Timestamp ts = new Timestamp(val/1000000); ts.setNanos((int)(val%1000000)); values.add(ts); break; case DATE: values.add(Date.valueOf(row.getDate(i).toString())); break; case TIMESTAMP: values.add(row.getTimestamp(i)); break; case TIMEUUID: values.add(row.getUUID(i)); break; case UUID: values.add(row.getUUID(i)); break; case VARCHAR: values.add(row.getString(i)); break; case VARINT: values.add(row.getVarint(i)); break; default: ByteBuffer bytesUnsafe = row.getBytesUnsafe(i); byte[] b = new byte[bytesUnsafe.remaining()]; bytesUnsafe.get(b); values.add(b); break; } } if (returnsArray) { return Arrays.asList((Object)values.toArray()); } return values; } CassandraQueryExecution(Command query, CassandraConnection connection, ExecutionContext context); }
CassandraQueryExecution implements ResultSetExecution { List<Object> getRow(Row row) { if(row == null){ return null; } ColumnDefinitions columnDefinitions = row.getColumnDefinitions(); final List<Object> values = new ArrayList<Object>(columnDefinitions.size()); for(int i = 0; i < columnDefinitions.size(); i++){ if (row.isNull(i)) { values.add(null); continue; } switch(columnDefinitions.getType(i).getName()){ case ASCII: values.add(row.getString(i)); break; case BIGINT: values.add(Long.valueOf(row.getLong(i))); break; case BOOLEAN: values.add(Boolean.valueOf(row.getBool(i))); break; case COUNTER: values.add(Long.valueOf(row.getLong(i))); break; case DECIMAL: values.add(row.getDecimal(i)); break; case DOUBLE: values.add(Double.valueOf(row.getDouble(i))); break; case FLOAT: values.add(Float.valueOf(row.getFloat(i))); break; case INET: values.add(row.getInet(i)); break; case INT: values.add(Integer.valueOf(row.getInt(i))); break; case LIST: values.add(row.getList(i, Object.class)); break; case MAP: values.add(row.getMap(i, Object.class, Object.class)); break; case SET: values.add(row.getSet(i, Object.class)); break; case TEXT: values.add(row.getString(i)); break; case TIME: long val = row.getTime(i); Timestamp ts = new Timestamp(val/1000000); ts.setNanos((int)(val%1000000)); values.add(ts); break; case DATE: values.add(Date.valueOf(row.getDate(i).toString())); break; case TIMESTAMP: values.add(row.getTimestamp(i)); break; case TIMEUUID: values.add(row.getUUID(i)); break; case UUID: values.add(row.getUUID(i)); break; case VARCHAR: values.add(row.getString(i)); break; case VARINT: values.add(row.getVarint(i)); break; default: ByteBuffer bytesUnsafe = row.getBytesUnsafe(i); byte[] b = new byte[bytesUnsafe.remaining()]; bytesUnsafe.get(b); values.add(b); break; } } if (returnsArray) { return Arrays.asList((Object)values.toArray()); } return values; } CassandraQueryExecution(Command query, CassandraConnection connection, ExecutionContext context); @Override void close(); @Override void cancel(); @Override void execute(); @Override List<?> next(); }
CassandraQueryExecution implements ResultSetExecution { List<Object> getRow(Row row) { if(row == null){ return null; } ColumnDefinitions columnDefinitions = row.getColumnDefinitions(); final List<Object> values = new ArrayList<Object>(columnDefinitions.size()); for(int i = 0; i < columnDefinitions.size(); i++){ if (row.isNull(i)) { values.add(null); continue; } switch(columnDefinitions.getType(i).getName()){ case ASCII: values.add(row.getString(i)); break; case BIGINT: values.add(Long.valueOf(row.getLong(i))); break; case BOOLEAN: values.add(Boolean.valueOf(row.getBool(i))); break; case COUNTER: values.add(Long.valueOf(row.getLong(i))); break; case DECIMAL: values.add(row.getDecimal(i)); break; case DOUBLE: values.add(Double.valueOf(row.getDouble(i))); break; case FLOAT: values.add(Float.valueOf(row.getFloat(i))); break; case INET: values.add(row.getInet(i)); break; case INT: values.add(Integer.valueOf(row.getInt(i))); break; case LIST: values.add(row.getList(i, Object.class)); break; case MAP: values.add(row.getMap(i, Object.class, Object.class)); break; case SET: values.add(row.getSet(i, Object.class)); break; case TEXT: values.add(row.getString(i)); break; case TIME: long val = row.getTime(i); Timestamp ts = new Timestamp(val/1000000); ts.setNanos((int)(val%1000000)); values.add(ts); break; case DATE: values.add(Date.valueOf(row.getDate(i).toString())); break; case TIMESTAMP: values.add(row.getTimestamp(i)); break; case TIMEUUID: values.add(row.getUUID(i)); break; case UUID: values.add(row.getUUID(i)); break; case VARCHAR: values.add(row.getString(i)); break; case VARINT: values.add(row.getVarint(i)); break; default: ByteBuffer bytesUnsafe = row.getBytesUnsafe(i); byte[] b = new byte[bytesUnsafe.remaining()]; bytesUnsafe.get(b); values.add(b); break; } } if (returnsArray) { return Arrays.asList((Object)values.toArray()); } return values; } CassandraQueryExecution(Command query, CassandraConnection connection, ExecutionContext context); @Override void close(); @Override void cancel(); @Override void execute(); @Override List<?> next();  }