com.netflix.astyanax.cql.CqlStatementResult Java Examples
The following examples show how to use
com.netflix.astyanax.cql.CqlStatementResult.
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: CassandraHealthCheck.java From emodb with Apache License 2.0 | 6 votes |
private Result pingAll() { try { StringBuilder message = new StringBuilder(); OperationResult<CqlStatementResult> astyanaxResult = pingAstyanax(); message.append("Astyanax: ").append(astyanaxResult.getHost()).append(" ") .append(astyanaxResult.getLatency(TimeUnit.MICROSECONDS)).append("us"); if (astyanaxResult.getAttemptsCount() != 1) { message.append(", ").append(astyanaxResult.getAttemptsCount()).append(" attempts"); } Stopwatch cqlTimer = Stopwatch.createStarted(); ResultSet cqlResult = pingCql(); long queryDurationMicros = cqlTimer.elapsed(TimeUnit.MICROSECONDS); Host host = cqlResult.getExecutionInfo().getQueriedHost(); message.append(" | CQL: ").append(host).append(" ").append(queryDurationMicros).append("us"); return Result.healthy(message.toString()); } catch (Throwable t) { return Result.unhealthy(t); } }
Example #2
Source File: AstyanaxMetaDaoImpl.java From staash with Apache License 2.0 | 5 votes |
public Map<String, JsonObject> runQuery(String key, String col) { OperationResult<CqlStatementResult> rs; Map<String, JsonObject> resultMap = new HashMap<String, JsonObject>(); try { String queryStr = ""; if (col != null && !col.equals("*")) { queryStr = "select column1, value from "+MetaConstants.META_KEY_SPACE + "." + MetaConstants.META_COLUMN_FAMILY +" where key='" + key + "' and column1='" + col + "';"; } else { queryStr = "select column1, value from "+MetaConstants.META_KEY_SPACE + "." + MetaConstants.META_COLUMN_FAMILY +" where key='" + key + "';"; } rs = keyspace.prepareCqlStatement().withCql(queryStr).execute(); for (Row<String, String> row : rs.getResult().getRows(METACF)) { ColumnList<String> columns = row.getColumns(); String key1 = columns.getStringValue("column1", null); String val1 = columns.getStringValue("value", null); resultMap.put(key1, new JsonObject(val1)); } } catch (ConnectionException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } return resultMap; }
Example #3
Source File: QueryUtils.java From staash with Apache License 2.0 | 5 votes |
public static String formatQueryResult(CqlStatementResult rs, String cfname) { // TODO Auto-generated method stub String value = ""; JsonObject response = new JsonObject(); ColumnFamily<String, String> cf = ColumnFamily .newColumnFamily(cfname, StringSerializer.get(), StringSerializer.get()); Rows<String, String> rows = rs.getRows(cf); int rcount = 1; for (com.netflix.astyanax.model.Row<String, String> row : rows) { ColumnList<String> columns = row.getColumns(); Collection<String> colnames = columns.getColumnNames(); String rowStr = ""; String colStr = ""; if (colnames.contains("key") && colnames.contains("column1")) { colStr = colStr + columns.getDateValue("column1", null).toGMTString(); rowStr = rowStr + columns.getStringValue("value", null); response.putString(colStr, rowStr); } else { JsonObject rowObj = new JsonObject(); for (String colName:colnames) { //colStr = colStr+colname+","; value = columns.getStringValue(colName, null); //rowStr=rowStr+value+","; rowObj.putString(colName, value); } //rowobj.putString("columns", colStr); //rowobj.putString("values", rowStr); response.putObject(""+rcount++, rowObj); } } return response.toString(); }
Example #4
Source File: CassandraHealthCheck.java From emodb with Apache License 2.0 | 4 votes |
private OperationResult<CqlStatementResult> pingAstyanax() throws Exception { return _keyspace.getAstyanaxKeyspace().prepareCqlStatement() .withCql(_healthCheckCql) .withConsistencyLevel(CL_ONE) .execute(); }