本文整理匯總了Java中com.datastax.driver.core.ResultSet類的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet類的具體用法?Java ResultSet怎麽用?Java ResultSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResultSet類屬於com.datastax.driver.core包,在下文中一共展示了ResultSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRecordById
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public Response getRecordById(String keyspaceName, String tableName, String identifier) {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Cassandra Service getRecordById method started at ==" + startTime,
LoggerEnum.PERF_LOG);
Response response = new Response();
try {
Select selectQuery = QueryBuilder.select().all().from(keyspaceName, tableName);
Where selectWhere = selectQuery.where();
Clause clause = QueryBuilder.eq(Constants.IDENTIFIER, identifier);
selectWhere.and(clause);
ResultSet results = connectionManager.getSession(keyspaceName).execute(selectQuery);
response = CassandraUtil.createResponse(results);
} catch (Exception e) {
ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + tableName + " : " + e.getMessage(), e);
throw new ProjectCommonException(ResponseCode.SERVER_ERROR.getErrorCode(),
ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
ProjectLogger.log("Cassandra Service getRecordById method end at ==" + stopTime
+ " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG);
return response;
}
示例2: getPropertiesValueById
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public Response getPropertiesValueById(String keyspaceName, String tableName, String id,
String... properties) {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Cassandra Service getPropertiesValueById method started at ==" + startTime,
LoggerEnum.PERF_LOG);
Response response = new Response();
try {
String selectQuery = CassandraUtil.getSelectStatement(keyspaceName, tableName, properties);
PreparedStatement statement = connectionManager.getSession(keyspaceName).prepare(selectQuery);
BoundStatement boundStatement = new BoundStatement(statement);
ResultSet results =
connectionManager.getSession(keyspaceName).execute(boundStatement.bind(id));
response = CassandraUtil.createResponse(results);
} catch (Exception e) {
ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + tableName + " : " + e.getMessage(), e);
throw new ProjectCommonException(ResponseCode.SERVER_ERROR.getErrorCode(),
ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
ProjectLogger.log("Cassandra Service getPropertiesValueById method end at ==" + stopTime
+ " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG);
return response;
}
示例3: selectByDeviceAndSensor
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public Status selectByDeviceAndSensor(TsPoint point, Double max, Double min, Date startTime, Date endTime) {
long costTime = 0L;
Cluster cluster = null;
try {
cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
Session session = cluster.connect(KEY_SPACE_NAME);
String createIndexCql = "CREATE INDEX IF NOT EXISTS value_index ON " + TABLE_NAME + "(value)";
// System.out.println(createIndexCql);
long startTime1 = System.nanoTime();
session.execute(createIndexCql);
String selectCql = "SELECT * FROM point WHERE device_code='" + point.getDeviceCode() + "' and sensor_code='"
+ point.getSensorCode() + "' and value<" + max + " and value>" + min + " and timestamp>="
+ startTime.getTime() + " and timestamp<=" + endTime.getTime() + " ALLOW FILTERING";
// System.out.println(selectCql);
ResultSet rs = session.execute(selectCql);
long endTime1 = System.nanoTime();
costTime = endTime1 - startTime1;
} finally {
if (cluster != null)
cluster.close();
}
// System.out.println("此次查詢消耗時間[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例4: selectMaxByDeviceAndSensor
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public Status selectMaxByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
long costTime = 0L;
Cluster cluster = null;
try {
// cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
// Session session = cluster.connect(KEY_SPACE_NAME);
Session session = SessionManager.getSession();
String selectCql = "SELECT MAX(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
+ " ALLOW FILTERING";
long startTime1 = System.nanoTime();
// System.out.println("aaa");
ResultSet rs = session.execute(selectCql);
// System.out.println("bbb");
long endTime1 = System.nanoTime();
costTime = endTime1 - startTime1;
} finally {
if (cluster != null)
cluster.close();
}
// System.out.println("此次查詢消耗時間[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例5: selectAvgByDeviceAndSensor
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public Status selectAvgByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
long costTime = 0L;
Cluster cluster = null;
try {
cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
Session session = cluster.connect(KEY_SPACE_NAME);
String selectCql = "SELECT AVG(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
+ " ALLOW FILTERING";
// System.out.println(selectCql);
long startTime1 = System.nanoTime();
ResultSet rs = session.execute(selectCql);
long endTime1 = System.nanoTime();
costTime = endTime1 - startTime1;
} finally {
if (cluster != null)
cluster.close();
}
// System.out.println("此次查詢消耗時間[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例6: selectCountByDeviceAndSensor
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public Status selectCountByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
long costTime = 0L;
Cluster cluster = null;
try {
cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
Session session = cluster.connect(KEY_SPACE_NAME);
String selectCql = "SELECT COUNT(*) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
+ " ALLOW FILTERING";
// System.out.println(selectCql);
long startTime1 = System.nanoTime();
ResultSet rs = session.execute(selectCql);
long endTime1 = System.nanoTime();
costTime = endTime1 - startTime1;
} finally {
if (cluster != null)
cluster.close();
}
// System.out.println("此次查詢消耗時間[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例7: findListByStatementAsync
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) {
if (statement != null) {
statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() {
@Nullable
@Override
public List<D> apply(@Nullable ResultSet resultSet) {
Result<E> result = getMapper().map(resultSet);
if (result != null) {
List<E> entities = result.all();
return DaoUtil.convertDataList(entities);
} else {
return Collections.emptyList();
}
}
});
}
return Futures.immediateFuture(Collections.emptyList());
}
示例8: saveIfNotExist
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
private Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptorEntity entity) {
if (entity.getId() == null) {
entity.setId(UUIDs.timeBased());
}
ResultSet rs = executeRead(QueryBuilder.insertInto(getColumnFamilyName())
.value(ModelConstants.ID_PROPERTY, entity.getId())
.value(ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY, entity.getName())
.value(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, entity.getClazz())
.value(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, entity.getType())
.value(ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY, entity.getScope())
.value(ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY, entity.getConfigurationDescriptor())
.value(ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY, entity.getActions())
.value(ModelConstants.SEARCH_TEXT_PROPERTY, entity.getSearchText())
.ifNotExists()
);
if (rs.wasApplied()) {
return Optional.of(DaoUtil.getData(entity));
} else {
return Optional.empty();
}
}
示例9: userLikedPost
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
/**
* userLikedPost
* @param postId
* @param userId
* @return true if param userId liked param postId and false otherwise
* @throws Exception
*/
public static boolean userLikedPost (
UUID postId,
UUID userId) throws Exception {
ResultSet resultSet =
PostLikesTime.i().executeSyncSelect(
postId,
userId);
if (resultSet.isExhausted() == true) {
return false;
}
return true;
}
示例10: executeSyncInsert
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
/**
* executeSyncInsert
* BLOCKING-METHOD: blocks till the ResultSet is ready
* executes Insert Query synchronously
* @param userid
* @param devicetoken
* @param authcode
* @param accesstoken
* @param refreshtoken
* @param ttl
* @return ResultSet
* @throws Exception
*/
public ResultSet executeSyncInsert (
Object userid,
Object devicetoken,
Object authcode,
Object accesstoken,
Object refreshtoken,
Object ttl) throws Exception {
return
this.getQuery(kInsertName).executeSync(
userid,
devicetoken,
authcode,
accesstoken,
refreshtoken,
ttl);
}
示例11: queryColumns
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
/**
* 描述: 查詢數據表字段名(key:字段名,value:字段類型名)
* 時間: 2017年11月15日 上午11:29:32
* @author yi.zhang
* @param table 表名
* @return
*/
public Map<String,String> queryColumns(String table){
try {
String sql = "select * from "+table;
ResultSet rs = session.execute(sql);
ColumnDefinitions rscd = rs.getColumnDefinitions();
int count = rscd.size();
Map<String,String> reflect = new HashMap<String,String>();
for (int i = 0; i < count; i++) {
String column = rscd.getName(i);
String type = rscd.getType(i).getName().name().toLowerCase();
reflect.put(column, type);
}
return reflect;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例12: executeSyncInsert
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
/**
* executeSyncInsert
* BLOCKING-METHOD: blocks till the ResultSet is ready
* executes Insert Query synchronously
* @param yearweek
* @param rank
* @param userid
* @return ResultSet
* @throws Exception
*/
public ResultSet executeSyncInsert (
Object yearweek,
Object rank,
Object userid) throws Exception {
return
this.getQuery(kInsertName).executeSync(
yearweek,
rank,
userid);
}
示例13: executeSyncSelectTopSmallerThanLimit
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
/**
* executeSyncSelectTopSmallerThanLimit
* BLOCKING-METHOD: blocks till the ResultSet is ready
* executes SelectTopSmallerThanLimit Query synchronously
* @param yearweekgridid
* @param rank
* @return ResultSet
* @throws Exception
*/
public ResultSet executeSyncSelectTopSmallerThanLimit (
Object yearweekgridid,
Object rank) throws Exception {
return
this.getQuery(kSelectTopSmallerThanLimitName).executeSync(
yearweekgridid,
rank);
}
示例14: find
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
@Override
public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) {
Select.Where select = select().from(ATTRIBUTES_KV_CF)
.where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType()))
.and(eq(ENTITY_ID_COLUMN, entityId.getId()))
.and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType))
.and(eq(ATTRIBUTE_KEY_COLUMN, attributeKey));
log.trace("Generated query [{}] for entityId {} and key {}", select, entityId, attributeKey);
return Futures.transform(executeAsyncRead(select), (Function<? super ResultSet, ? extends Optional<AttributeKvEntry>>) input ->
Optional.ofNullable(convertResultToAttributesKvEntry(attributeKey, input.one()))
, readResultsProcessingExecutor);
}
示例15: executeSyncInsert
import com.datastax.driver.core.ResultSet; //導入依賴的package包/類
/**
* executeSyncInsert
* BLOCKING-METHOD: blocks till the ResultSet is ready
* executes Insert Query synchronously
* @param yearweekcountrycode
* @param rank
* @param userid
* @return ResultSet
* @throws Exception
*/
public ResultSet executeSyncInsert (
Object yearweekcountrycode,
Object rank,
Object userid) throws Exception {
return
this.getQuery(kInsertName).executeSync(
yearweekcountrycode,
rank,
userid);
}