本文整理汇总了Java中com.datastax.driver.core.Row.getLong方法的典型用法代码示例。如果您正苦于以下问题:Java Row.getLong方法的具体用法?Java Row.getLong怎么用?Java Row.getLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.Row
的用法示例。
在下文中一共展示了Row.getLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColValue
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
public Object getColValue(Row row, String colName, DataType colType){
switch(colType.getName()){
case VARCHAR:
return row.getString(colName);
case UUID:
return row.getUUID(colName);
case VARINT:
return row.getVarint(colName);
case BIGINT:
return row.getLong(colName);
case INT:
return row.getInt(colName);
case FLOAT:
return row.getFloat(colName);
case DOUBLE:
return row.getDouble(colName);
case BOOLEAN:
return row.getBool(colName);
case MAP:
return row.getMap(colName, String.class, String.class);
default:
return null;
}
}
示例2: testQueryPrimeSimple
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@Test
public void testQueryPrimeSimple() throws Exception {
RequestPrime prime = HttpTestUtil.createSimplePrimedQuery("Select * FROM TABLE2");
HttpTestResponse response = server.prime(prime);
assertNotNull(response);
RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class);
assertThat(responseQuery).isEqualTo(prime);
String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
ResultSet set = HttpTestUtil.makeNativeQuery("Select * FROM TABLE2", contactPoint);
List<Row> results = set.all();
assertThat(1).isEqualTo(results.size());
Row row1 = results.get(0);
String column1 = row1.getString("column1");
assertThat(column1).isEqualTo("column1");
Long column2 = row1.getLong("column2");
assertThat(column2).isEqualTo(new Long(2));
}
示例3: testBoundStatementPositional
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@Test
public void testBoundStatementPositional() throws Exception {
HashMap<String, String> paramTypes = new HashMap<>();
paramTypes.put("c1", "ascii");
HashMap<String, Object> params = new HashMap<>();
params.put("c1", "c1");
RequestPrime prime =
HttpTestUtil.createSimpleParameterizedQuery(
"SELECT table FROM foo WHERE c1=?", params, paramTypes);
HttpTestResponse response = server.prime(prime);
assertNotNull(response);
RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class);
assertThat(responseQuery).isEqualTo(prime);
String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
ResultSet set =
HttpTestUtil.makeNativeBoundQueryWithPositionalParam(
"SELECT table FROM foo WHERE c1=?", contactPoint, "c1");
List<Row> results = set.all();
assertThat(1).isEqualTo(results.size());
Row row1 = results.get(0);
String column1 = row1.getString("column1");
assertThat(column1).isEqualTo("column1");
Long column2 = row1.getLong("column2");
}
示例4: 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);
}
}
示例5: readRow
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
private Object readRow(final Row row, final String name, final DataType colType) {
switch (colType.getName()) {
case BIGINT:
return row.getLong(name);
case BOOLEAN:
return row.getBool(name);
case DOUBLE:
return row.getDouble(name);
case FLOAT:
return row.getFloat(name);
case INT:
return row.getInt(name);
case MAP:
return row.getMap(name, String.class, String.class);
case UUID:
return row.getUUID(name);
case TEXT:
case VARCHAR:
return row.getString(name);
case VARINT:
return row.getVarint(name);
// These are not supported right now....
// ASCII
// BLOB
// COUNTER
// CUSTOM
// DECIMAL
// INET
// LIST
// SET
// TIMESTAMP
// TIMEUUID
// TUPLE
// UDT
default:
return null;
}
}
示例6: load
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@Override
public Data load(Data data, Row row) {
data.id = row.getUUID(0);
data.ticket = row.getUUID(1);
data.user = row.getString(2);
data.approver = row.getString(3);
data.type = row.getString(4);
data.status = row.getString(5);
data.memo = row.getString(6);
data.operation = row.getString(7);
if(row.getColumnDefinitions().size()>8) {
// Rows reported in MicroSeconds
data.updated = new Date(row.getLong(8)/1000);
}
return data;
}
示例7: marshalRow
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
protected IndexCreatedEvent marshalRow(Row row)
{
if (row == null)
{
return null;
}
//look up index here
Index index = new Index();
index.setName(row.getString(Columns.INDEX_NAME));
index.setTable(row.getString(Columns.DATABASE), row.getString(Columns.TABLE));
Index toUse;
try
{
toUse = indexRepo.read(index.getId());
} catch (ItemNotFoundException e)//this should only happen in tests that do not have full test data established; errors will be evident if this happens in the actual app
{
toUse = index;
}
IndexCreatedEvent i = new IndexCreatedEvent(row.getUUID(Columns.ID), row.getDate(Columns.STARTED_AT), row.getDate(Columns.UPDATED_AT), toUse, row.getLong(Columns.TOTAL_RECORDS), row.getLong(Columns.RECORDS_COMPLETED));
i.setFatalError(row.getString(Columns.FATAL_ERROR));
i.setErrors(row.getList(Columns.ERRORS, String.class));
i.calculateValues();
return i;
}
示例8: count
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
/**
* Count.
*
* @param tableName the table name
* @return the long
* @throws Exception the exception
*/
public static long count( String tableName ) throws Exception {
long cnt = -1;
try {
String selectCount = String.format("SELECT COUNT(*) FROM %s; ", tableName);
logger.debug("selectCount={}",selectCount);
ResultSet rs = execute(selectCount);
Row row = rs.one();
if( row != null ) {
cnt = row.getLong(0);
}
} catch( Exception e ) {
logger.error(e.getLocalizedMessage(), e);
throw e;
}
return cnt;
}
示例9: count
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
/**
* Count.
*
* @param tableName the table name
* @return the long
* @throws Exception the exception
*/
public long count( String tableName ) throws Exception {
long cnt = -1;
try {
String selectCount = String.format("SELECT COUNT(*) FROM %s", tableName);
logger.debug("selectCount={}",selectCount);
long before = System.currentTimeMillis();
ResultSet rs = execute(selectCount);
Row row = rs.one();
if( row != null ) {
cnt = row.getLong(0);
}
logger.info(">>> elapsed {}",(System.currentTimeMillis()-before));
} catch( Exception e ) {
logger.error(e.getLocalizedMessage(), e);
throw e;
}
return cnt;
}
示例10: testQueryPositionalParamSimple
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@Test
public void testQueryPositionalParamSimple() throws Exception {
HashMap<String, String> paramTypes = new HashMap<>();
paramTypes.put("c1", "ascii");
HashMap<String, Object> params = new HashMap<>();
params.put("c1", "c1");
RequestPrime prime =
HttpTestUtil.createSimpleParameterizedQuery(
"SELECT table FROM foo WHERE c1=?", params, paramTypes);
HttpTestResponse response = server.prime(prime);
assertNotNull(response);
RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class);
assertThat(responseQuery).isEqualTo(prime);
String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
ResultSet set =
HttpTestUtil.makeNativeQueryWithPositionalParams(
"SELECT table FROM foo WHERE c1=?", contactPoint, "c1");
List<Row> results = set.all();
assertThat(1).isEqualTo(results.size());
Row row1 = results.get(0);
String column1 = row1.getString("column1");
assertThat(column1).isEqualTo("column1");
Long column2 = row1.getLong("column2");
// Extra Param
set =
HttpTestUtil.makeNativeQueryWithPositionalParams(
"SELECT table FROM foo WHERE c1=?", contactPoint, "c1", "extraParam");
assertThat(set.all().size()).isEqualTo(0);
// Wrong Param
set =
HttpTestUtil.makeNativeQueryWithPositionalParams(
"SELECT table FROM foo WHERE ci1=?", contactPoint, "d1");
assertThat(set.all().size()).isEqualTo(0);
}
示例11: testBoundStatementNamed
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
@Test
public void testBoundStatementNamed() throws Exception {
HashMap<String, String> paramTypes = new HashMap<>();
paramTypes.put("id", "bigint");
paramTypes.put("id2", "bigint");
HashMap<String, Object> params = new HashMap<>();
params.put("id", new Long(1));
params.put("id2", new Long(2));
RequestPrime prime =
HttpTestUtil.createSimpleParameterizedQuery(
"SELECT * FROM users WHERE id = :id and id2 = :id2", params, paramTypes);
HttpTestResponse response = server.prime(prime);
assertNotNull(response);
RequestPrime responseQuery = (RequestPrime) om.readValue(response.body, RequestPrime.class);
assertThat(responseQuery).isEqualTo(prime);
Map<String, Long> values = ImmutableMap.<String, Long>of("id", new Long(1), "id2", new Long(2));
String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
ResultSet set =
HttpTestUtil.makeNativeBoundQueryWithNameParams(
"SELECT * FROM users WHERE id = :id and id2 = :id2", contactPoint, values);
List<Row> results = set.all();
assertThat(1).isEqualTo(results.size());
Row row1 = results.get(0);
String column1 = row1.getString("column1");
assertThat(column1).isEqualTo("column1");
Long column2 = row1.getLong("column2");
assertThat(column2).isEqualTo(new Long(2));
Map<String, String> values2 = ImmutableMap.<String, String>of("id", "1", "id2", "2");
}
示例12: getIdByKey
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
/**
* Get entity id by entity key.
*
* @param key the entity key
* @param tenant tenant name
* @return entity id
*/
public Long getIdByKey(String key, String tenant) {
Select select = QueryBuilder.select(ENTITY_ID_COL).from(tenant, TABLE_KEY_ID);
select.where(eq(ENTITY_KEY_COL, key));
ResultSet resultSet = session.execute(select);
Row row = resultSet.one();
return row == null ? null : row.getLong(ENTITY_ID_COL);
}
示例13: getLongValue
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
private Long getLongValue(Row row) {
if (aggregation == Aggregation.MIN || aggregation == Aggregation.MAX
|| aggregation == Aggregation.SUM || aggregation == Aggregation.AVG) {
return row.getLong(LONG_POS);
} else {
return null;
}
}
示例14: convertResultToTsKvEntry
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
private TsKvEntry convertResultToTsKvEntry(String key, Row row) {
if (row != null) {
long ts = row.getLong(ModelConstants.TS_COLUMN);
return new BasicTsKvEntry(ts, toKvEntry(row, key));
} else {
return new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(key, null));
}
}
示例15: getTokenRanges
import com.datastax.driver.core.Row; //导入方法依赖的package包/类
/**
* Gets the list of token ranges that a table occupies on a give Cassandra node.
*
* <p>NB: This method is compatible with Cassandra 2.1.5 and greater.
*/
private static List<TokenRange> getTokenRanges(Cluster cluster, String keyspace, String table) {
try (Session session = cluster.newSession()) {
ResultSet resultSet =
session.execute(
"SELECT range_start, range_end, partitions_count, mean_partition_size FROM "
+ "system.size_estimates WHERE keyspace_name = ? AND table_name = ?",
keyspace,
table);
ArrayList<TokenRange> tokenRanges = new ArrayList<>();
for (Row row : resultSet) {
TokenRange tokenRange =
new TokenRange(
row.getLong("partitions_count"),
row.getLong("mean_partition_size"),
row.getLong("range_start"),
row.getLong("range_end"));
tokenRanges.add(tokenRange);
}
// The table may not contain the estimates yet
// or have partitions_count and mean_partition_size fields = 0
// if the data was just inserted and the amount of data in the table was small.
// This is very common situation during tests,
// when we insert a few rows and immediately query them.
// However, for tiny data sets the lack of size estimates is not a problem at all,
// because we don't want to split tiny data anyways.
// Therefore, we're not issuing a warning if the result set was empty
// or mean_partition_size and partitions_count = 0.
return tokenRanges;
}
}