Java Code Examples for com.datastax.driver.core.Row#getColumnDefinitions()

The following examples show how to use com.datastax.driver.core.Row#getColumnDefinitions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraIpcdDeviceDao.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private void parseOptimisticResult(ResultSet rs, String protocolAddress, UUID requiredPlace) throws IpcdDaoException {
   // not applied could imply that the device doesn't exist or the place didn't match
   if(!rs.wasApplied()) {
      Row r = rs.one();
      ColumnDefinitions colDef = r.getColumnDefinitions();

      if(colDef.contains(IpcdDeviceTable.Columns.PLACE_ID)) {
         // if the returned row contains a place id, the place id didn't match
         UUID actualPlaceId = r.getUUID(IpcdDeviceTable.Columns.PLACE_ID);
         if(!Objects.equal(requiredPlace, actualPlaceId)) {
            throw new PlaceMismatchException(requiredPlace, actualPlaceId);
         }
      }
      // special case for claiming device that is offline
      if(colDef.contains(IpcdDeviceTable.Columns.CONN_STATE) && IpcdDevice.ConnState.OFFLINE.name().equals(r.getString(IpcdDeviceTable.Columns.CONN_STATE))) {
         throw new DeviceNotFoundException(protocolAddress);
      }
      throw new DeviceNotFoundException(protocolAddress);
   }
}
 
Example 2
Source File: RawMetricMapper.java    From realtime-analytics with GNU General Public License v2.0 6 votes vote down vote up
public RawNumericMetric map(Row row) {
    RawNumericMetric metricRow =  new RawNumericMetric(row.getString(0), row.getString(1), row.getDate(2).getTime(), row.getInt(3));
    ColumnDefinitions columeDef = row.getColumnDefinitions();
    List<Definition> columeDefList = columeDef.asList();
    Map<String, String> tagMap = new HashMap<String, String>();
    for(Definition def: columeDefList){
        if(def.getName().startsWith("tag_")){
            tagMap.put(def.getName(), row.getString(def.getName()));
        }
    }
    
    if(tagMap.size()>0){
        metricRow.setTagMap(tagMap);
    }
    return metricRow;
}
 
Example 3
Source File: CassandraDbProvider.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@Override
public DbRecordValuesList[] select(
                                    DbQuery dbQuery,
                                    DbReturnModes dbReturnMode ) throws DbException {

    connect();

    ArrayList<DbRecordValuesList> dbRecords = new ArrayList<DbRecordValuesList>();

    String sqlQuery = dbQuery.getQuery();
    if (allowFiltering) {
        sqlQuery += " ALLOW FILTERING";
    }

    if (log.isDebugEnabled()) {
        log.debug(sqlQuery);
    }

    ResultSet results = session.execute(sqlQuery);

    int currentRow = 0;
    Iterator<Row> it = results.iterator();
    while (it.hasNext()) {
        Row row = it.next();

        currentRow++;
        if (log.isDebugEnabled()) {
            log.debug("Result row number: " + currentRow);
        }

        DbRecordValuesList recordList = new DbRecordValuesList();

        for (Definition columnDefinition : row.getColumnDefinitions()) {
            DbColumn dbColumn = new DbColumn(columnDefinition.getTable(), columnDefinition.getName());
            dbColumn.setColumnType(columnDefinition.getType().getName().toString());

            Object value = extractObjectFromResultSet(row, columnDefinition);

            DbRecordValue recordValue = new DbRecordValue(dbColumn, value);
            recordList.add(recordValue);
        }
        dbRecords.add(recordList);
    }

    return dbRecords.toArray(new DbRecordValuesList[]{});
}