本文整理汇总了Java中com.datastax.driver.core.Row.getColumnDefinitions方法的典型用法代码示例。如果您正苦于以下问题:Java Row.getColumnDefinitions方法的具体用法?Java Row.getColumnDefinitions怎么用?Java Row.getColumnDefinitions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.Row
的用法示例。
在下文中一共展示了Row.getColumnDefinitions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValue
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
private Object getValue(Row musicRow, String colname) {
ColumnDefinitions cdef = musicRow.getColumnDefinitions();
String type = cdef.getType(colname).getName().toString().toUpperCase();
switch (type) {
case "BIGINT":
return musicRow.getLong(colname);
case "BOOLEAN":
return musicRow.getBool(colname);
case "BLOB":
return musicRow.getBytes(colname);
case "DOUBLE":
return musicRow.getDouble(colname);
case "INT":
return musicRow.getInt(colname);
case "TIMESTAMP":
return musicRow.getTimestamp(colname);
default:
logger.error("UNEXPECTED COLUMN TYPE: columname="+colname+", columntype="+type);
// fall thru
case "VARCHAR":
return musicRow.getString(colname);
}
}
示例2: select
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@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[]{});
}
示例3: syncQuorum
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
private static void syncQuorum(String key){
logger.info("Performing sync operation---");
String[] splitString = key.split("\\.");
String keyspaceName = splitString[0];
String tableName = splitString[1];
String primaryKeyValue = splitString[2];
//get the primary key d
TableMetadata tableInfo = returnColumnMetadata(keyspaceName, tableName);
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();//we only support single primary key
DataType primaryKeyType = tableInfo.getPrimaryKey().get(0).getType();
String cqlFormattedPrimaryKeyValue = convertToCQLDataType(primaryKeyType, primaryKeyValue);
//get the row of data from a quorum
String selectQuery = "SELECT * FROM "+keyspaceName+"."+tableName+ " WHERE "+primaryKeyName+"="+cqlFormattedPrimaryKeyValue+";";
ResultSet results = getDSHandle().executeCriticalGet(selectQuery);
//write it back to a quorum
Row row = results.one();
ColumnDefinitions colInfo = row.getColumnDefinitions();
int totalColumns = colInfo.size();
int counter =1;
String fieldValueString="";
for (Definition definition : colInfo){
String colName = definition.getName();
if(colName.equals(primaryKeyName))
continue;
DataType colType = definition.getType();
Object valueObj = getDSHandle().getColValue(row, colName, colType);
String valueString = convertToCQLDataType(colType,valueObj);
fieldValueString = fieldValueString+ colName+"="+valueString;
if(counter!=(totalColumns-1))
fieldValueString = fieldValueString+",";
counter = counter +1;
}
String updateQuery = "UPDATE "+keyspaceName+"."+tableName+" SET "+fieldValueString+" WHERE "+primaryKeyName+"="+cqlFormattedPrimaryKeyValue+";";
getDSHandle().executePut(updateQuery, "critical");
}
示例4: doesRowSatisfyCondition
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
public boolean doesRowSatisfyCondition(Row row, Map<String, Object> condition){
ColumnDefinitions colInfo = row.getColumnDefinitions();
for (Map.Entry<String, Object> entry : condition.entrySet()){
String colName = entry.getKey();
DataType colType = colInfo.getType(colName);
Object columnValue = getColValue(row, colName, colType);
Object conditionValue = convertToActualDataType(colType, entry.getValue());
if(columnValue.equals(conditionValue) == false)
return false;
}
return true;
}
示例5: marshalData
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
public Map<String, HashMap<String, Object>> marshalData(ResultSet results){
Map<String, HashMap<String, Object>> resultMap = new HashMap<String, HashMap<String,Object>>();
int counter =0;
for (Row row : results) {
ColumnDefinitions colInfo = row.getColumnDefinitions();
HashMap<String,Object> resultOutput = new HashMap<String, Object>();
for (Definition definition : colInfo) {
if(!definition.getName().equals("vector_ts"))
resultOutput.put(definition.getName(), getColValue(row, definition.getName(), definition.getType()));
}
resultMap.put("row "+counter, resultOutput);
counter++;
}
return resultMap;
}
示例6: selectRows
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
public List<Map<String, Object>> selectRows(final String tablename, Map<String, String> cols) {
String ns = "";
String tbl = tablename;
int ix = tbl.indexOf('.');
if (ix >= 0) {
ns = tablename.substring(0, ix);
tbl = tablename.substring(ix+1);
}
Select sel = QueryBuilder.select().all().from(ns, tbl);
Statement stmt = sel;
if (cols.size() == 1) {
// only handles 1 WHERE value right now
String k = cols.keySet().iterator().next();
Clause eqclause = QueryBuilder.eq(k, cols.get(k));
stmt = sel.where(eqclause);
}
ResultSet resultset = session.execute(stmt);
List<Map<String, Object>> results = new ArrayList<Map<String,Object>>();
for (Row row : resultset) {
Map<String, Object> map = new HashMap<String, Object>();
for (Definition definition : row.getColumnDefinitions()) {
map.put(definition.getName(), readRow(row, definition.getName(), definition.getType()));
}
results.add(map);
}
return results;
}
示例7: OLDselectRows
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@Deprecated
public List<Map<String, String>> OLDselectRows(String tablename, Map<String, String> cols) {
String query = String.format("SELECT * FROM %s", tablename);
if (cols.size() > 0) {
// add WHERE clause
// String[] parts = tablename.split("\\.");
// KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(parts[0]);
// TableMetadata tableInfo = ks.getTable(parts[1]);
String whereclause = " WHERE";
String prefix = "";
for (String key : cols.keySet()) {
String val = cols.get(key);
// DataType colType = tableInfo.getColumn(key).getType();
whereclause = String.format("%s%s %s = '%s'", whereclause, prefix, key, val);
prefix = " AND";
}
query += whereclause;
}
LOG.debug(query);
ResultSet resultset = session.execute(query);
List<Map<String, String>> results = new ArrayList<Map<String,String>>();
for (Row row : resultset) {
ColumnDefinitions colInfo = row.getColumnDefinitions();
Map<String, String> map = new HashMap<String, String>();
for (Definition definition : colInfo) {
// map.put(definition.getName(), (String)MusicDataStore.readRow(row, definition.getName(), definition.getType()));
}
results.add(map);
}
return results;
}
示例8: findRow
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
/**
* Find row.
*
* @param pk the pk
* @return the map
* @throws Exception the exception
*/
public Map<String,Object> findRow( String pk ) throws Exception {
try {
Map<String,Object> map = null;
String select = String.format("SELECT * FROM actuator_state where login_source_sensor='%s'", pk);
logger.debug("select={}",select);
long before = System.currentTimeMillis();
ResultSet rs = execute(select);
Iterator<Row> it = rs.iterator();
Row row = rs.one();
if( row != null ) {
map = new HashMap<String,Object>();
logger.info(">>> elapsed {}",(System.currentTimeMillis()-before));
ColumnDefinitions columnDefinitions = row.getColumnDefinitions();
for( ColumnDefinitions.Definition columnDefinition : columnDefinitions) {
String name = columnDefinition.getName();
Object value = row.getObject(name);
map.put( name, value );
}
}
return map;
} catch( Exception e ) {
logger.error(e.getLocalizedMessage(), e);
throw e;
}
}
示例9: readRow
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
private static Object readRow(final Class<?> rowClass, final Row row) {
final Type<?> rowType = rowClass == null ? null : N.typeOf(rowClass);
final ColumnDefinitions columnDefinitions = row.getColumnDefinitions();
final int columnCount = columnDefinitions.size();
Object res = null;
Object propValue = null;
if (rowType == null || rowType.isObjectArray()) {
final Object[] a = new Object[columnCount];
for (int i = 0; i < columnCount; i++) {
propValue = row.getObject(i);
if (propValue instanceof Row) {
a[i] = readRow(Object[].class, (Row) propValue);
} else {
a[i] = propValue;
}
}
res = a;
} else if (rowType.isCollection()) {
final Collection<Object> c = (Collection<Object>) N.newInstance(rowClass);
for (int i = 0; i < columnCount; i++) {
propValue = row.getObject(i);
if (propValue instanceof Row) {
c.add(readRow(List.class, (Row) propValue));
} else {
c.add(propValue);
}
}
res = c;
} else if (rowType.isMap()) {
final Map<String, Object> m = (Map<String, Object>) N.newInstance(rowClass);
for (int i = 0; i < columnCount; i++) {
propValue = row.getObject(i);
if (propValue instanceof Row) {
m.put(columnDefinitions.getName(i), readRow(Map.class, (Row) propValue));
} else {
m.put(columnDefinitions.getName(i), propValue);
}
}
res = m;
} else if (rowType.isEntity()) {
res = toEntity(rowClass, row);
} else {
throw new IllegalArgumentException("Unsupported row/column type: " + ClassUtil.getCanonicalClassName(rowClass));
}
return res;
}