本文整理匯總了Java中com.datastax.driver.core.ResultSet.one方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet.one方法的具體用法?Java ResultSet.one怎麽用?Java ResultSet.one使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.ResultSet
的用法示例。
在下文中一共展示了ResultSet.one方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUserLastGeoCoordinates
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
/**
* getUserLastGeoCoordinates
* @param userId
* @return user's last geo coordinates and null if it doesn't exist
* @throws Exception
*/
public static GeoCoordinates getUserLastGeoCoordinates (
UUID userId) throws Exception {
ResultSet resultSet =
UsersInfo.i().executeSyncSelectLastLocation(userId);
if (resultSet.isExhausted() == false) {
Row row = resultSet.one();
double latitude =
row.getDouble(UsersInfo.kLastLatitudeColumnName);
double longitude =
row.getDouble(UsersInfo.kLastLongitudeColumnName);
return new GeoCoordinates(latitude, longitude);
} else {
return null;
}
}
示例2: getIdByKey
import com.datastax.driver.core.ResultSet; //導入方法依賴的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);
}
示例3: getKeyById
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
/**
* Get entity key by entity id.
*
* @param entityId entity id
* @param tenant tenant name
* @return entity key
*/
public String getKeyById(Long entityId, String tenant) {
Select select = QueryBuilder.select(ENTITY_KEY_COL).from(tenant, VIEW_ID_KEY);
select.where(eq(ENTITY_ID_COL, entityId));
ResultSet resultSet = session.execute(select);
Row row = resultSet.one();
return row == null ? null : row.getString(ENTITY_KEY_COL);
}
示例4: get
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
/**
* Loads a {@link DecisionTreeRuleSet} from Cassandra using the defined keyspace.
*
* @return {@link Result} indicating if the load succeeded, storing any exception if the load failed.
*/
@Override
public Result<DecisionTreeRuleSet> get() {
try {
ResultSet resultSet = this.session.execute(CQL_GET_RULESET_FROM_RULESETNAME,
"DEFAULT", this.ruleSetName);
EhSupport.ensure(!resultSet.isExhausted(), "RuleSet %s does not exist in %s.", this.ruleSetName,
this.keyspace);
final Row resultsRow = resultSet.one();
final List<String> driverList = resultsRow.getList("drivers", String.class);
final DriverCache driverCache = new DriverCache();
resultSet = this.session.execute(CQL_GET_RULES_FOR_RULESET, this.ruleSetName);
final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = RuleSetBuilder.creator(driverList);
ruleSetBuilder.with(RuleSetBuilder::setName, this.ruleSetName);
ruleSetBuilder.with(RuleSetBuilder::groups, getValueGroupsForRuleSet(this.ruleSetName));
ruleSetBuilder.with(RuleSetBuilder::setCache, driverCache);
resultSet.iterator().forEachRemaining(row -> ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
.with(RuleBuilder::cache, driverCache)
.with(RuleBuilder::setId, row.get("id", UUID.class))
.with(RuleBuilder::setCode, row.get("code", UUID.class))
.with(RuleBuilder::start, row.get("start", Instant.class))
.with(RuleBuilder::end, row.get("end", Instant.class))
.with(RuleBuilder::input, row.getList("drivers", String.class))
.with(RuleBuilder::output, row.getList("outputs", String.class))
));
final DecisionTreeRuleSet loadedRuleSet = ruleSetBuilder.build();
return Result.success(loadedRuleSet);
} catch (final Exception exception) {
return Result.failure(() -> exception);
}
}
示例5: getSingleValue
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
public static Object getSingleValue(ResultSet resultSet) {
Row one = resultSet.one();
return one != null ? one.getObject(0) : null;
}
示例6: authenticateRequest
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
@Override
protected void authenticateRequest (
final Request request) throws Exception {
// get request's body
RequestLoginEmail requestLoginEmail =
(RequestLoginEmail)request.getRequestJsonBody();
// select user's password
ResultSet resultSet =
EmailCreds.i().executeSyncSelect(requestLoginEmail.email);
// email isn't registered?
if (resultSet.isExhausted() == true) {
throw new BadRequestException(
421,
1,
"Email ["
+ requestLoginEmail.email
+ "] isn't registered, request sent from device_token ["
+ requestLoginEmail.device_token
+ "]",
ExceptionClass.AUTHENTICATION);
}
// extract password
Row row = resultSet.one();
String password = row.getString(EmailCreds.kPasswordColumnName);
// wrong password?
if (requestLoginEmail.password.compareTo(password) != 0) {
throw new BadRequestException(
421,
2,
"Wrong password ["
+ requestLoginEmail.password
+ "], expected password ["
+ password
+ "] for email ["
+ requestLoginEmail.email
+ "], request sent from device_token ["
+ requestLoginEmail.device_token
+ "]",
ExceptionClass.AUTHENTICATION);
}
}
示例7: processRequest
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
@Override
protected void processRequest (final Request request) throws Exception {
// use the following request Object to process the request and set
// the response to be returned
RequestLoginEmail requestLoginEmail =
(RequestLoginEmail)request.getRequestJsonBody();
// select user's password and user_id
ResultSet resultSet =
EmailCreds.i().executeSyncSelect(requestLoginEmail.email);
// email isn't registered? -- in case authentication is disabled
if (resultSet.isExhausted() == true) {
throw new BadRequestException(
421,
3,
"Email ["
+ requestLoginEmail.email
+ "] isn't registered, request sent from device_token ["
+ requestLoginEmail.device_token
+ "]",
ExceptionClass.AUTHENTICATION);
}
// extract user_id
Row row = resultSet.one();
UUID userId = row.getUUID(EmailCreds.kUserIdColumnName);
// set user's id
request.setUserId(userId);
// generate new authentication tokens
OAuth2Tokens oAuth2Tokens = new OAuth2Tokens();
// insert into ig_auth.auth_codes
AuthCodes.i().executeSyncInsert(
userId,
requestLoginEmail.device_token,
oAuth2Tokens.getAuthorizationCode(),
oAuth2Tokens.getAccessToken(),
oAuth2Tokens.getRefreshToken(),
((int)Constants.kAuthCodeLifeTime.getAs(
TimeUnitType.SECOND).getValue() ) );
// set response
((ResponseLoginEmail)request.getResponseBody() ).set(
requestLoginEmail.request_tracking_id,
userId.toString(),
oAuth2Tokens.getAuthorizationCode() );
}
示例8: processRequest
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
@Override
protected void processRequest (final Request request) throws Exception {
// use the following request Object to process the request and set
// the response to be returned
RequestUpdateLocation requestUpdateLocation =
(RequestUpdateLocation)request.getRequestJsonBody();
// get last user's location
ResultSet resultSet =
UsersInfo.i().executeSyncSelectLastLocation(
requestUpdateLocation.getUserId() );
Row row = resultSet.one();
// extract location's coordinates
double lastLatitude = row.getDouble(UsersInfo.kLastLatitudeColumnName);
double lastLongitude = row.getDouble(UsersInfo.kLastLongitudeColumnName);
// first time to update location?
if (lastLatitude == 0.0 && lastLongitude == 0.0) {
// get location's continent code
ReverseGeoCode reverseGeoCode =
ReverseGeoCoding.i().getReverseGeoCode(lastLatitude, lastLongitude);
// get user's registration time
resultSet =
UsersInfo.i().executeSyncSelectRegistrationTime(
requestUpdateLocation.getUserId() );
long registrationTime =
resultSet.one().getLong(UsersInfo.kRegistrationTimeColumnName);
Calendar registrationCalendar =
CalendarAndDateOperationsInl.getCalendarFromUnixTime(
registrationTime);
// dispatch analytics
// ig_analytics.annual_regional_counters.increment_new_users
request.getDispatcher().addDispatchMessage(
AnnualRegionalCounters.i().getQueryDispatchableIncrementNewUsers(
CalendarFormatterInl.concatCalendarFields(
registrationCalendar,
Calendar.YEAR)
+ Constants.kCassandraIdConcat
+ reverseGeoCode.getContinentCode() ) );
// ig_analytics.daily_regional_counters.increment_new_users
request.getDispatcher().addDispatchMessage(
DailyRegionalCounters.i().getQueryDispatchableIncrementNewUsers(
CalendarFormatterInl.concatCalendarFields(
registrationCalendar,
Calendar.YEAR,
Calendar.MONTH,
Calendar.DAY_OF_MONTH)
+ Constants.kCassandraIdConcat
+ reverseGeoCode.getContinentCode() ) );
}
// update last_latitude and last_longitude
UsersInfo.i().executeSyncSetLastLocation(
requestUpdateLocation.latitude,
requestUpdateLocation.longitude,
requestUpdateLocation.getUserId() );
// set response
((ResponseUpdateLocation)request.getResponseBody() ).set(
requestUpdateLocation.request_tracking_id,
request.getStartTime() );
}
示例9: processRequest
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
@Override
protected void processRequest (final Request request) throws Exception {
// use the following request Object to process the request and set
// the response to be returned
RequestGetFeedPosts requestGetFeedPosts =
(RequestGetFeedPosts)request.getRequestJsonBody();
// set count limit
// CURRENTLY DISABLED - set to 30
// int countLimit;
//
// if (requestGetFeedPosts.isValidParam(
// RequestGetFeedPosts.kCountLimitName) == true) {
//
// countLimit =
// NumbersInl.trim(
// requestGetFeedPosts.count_limit,
// Constants.kMinGettersCountLimit,
// Constants.kMaxGettersCountLimit);
// } else {
//
// countLimit = Constants.kDefaultGettersCountLimit;
// }
// select feed posts from the database
ResultSet resultSet;
if (requestGetFeedPosts.isValidParam(
RequestGetFeedPosts.kAtOrBeforeTimeName) == true) {
resultSet =
UserFeedPosts.i().executeSyncSelectAtOrBeforeTimeLimit(
requestGetFeedPosts.getUserId(),
requestGetFeedPosts.at_or_before_time);
} else {
resultSet =
UserFeedPosts.i().executeSyncSelectRecentLimit(
requestGetFeedPosts.getUserId() );
}
// extract response data
Row row;
ArrayList<ResponseFeedPost> feedPosts = new ArrayList<ResponseFeedPost>();
while (resultSet.isExhausted() == false) {
row = resultSet.one();
feedPosts.add(
new ResponseFeedPost(
row.getUUID(UserFeedPosts.kPostIdColumnName).toString(),
row.getLong(UserFeedPosts.kPostTimeColumnName) ) );
}
// set response
((ResponseGetFeedPosts)request.getResponseBody() ).set(
requestGetFeedPosts.request_tracking_id,
feedPosts.toArray(new ResponseFeedPost[0] ) );
}
示例10: getReleaseVersion
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
/**
* Retrieve the Cassandra release version.
*
* @param session must not be {@literal null}.
* @return the release {@link Version}.
*/
public static Version getReleaseVersion(Session session) {
Assert.notNull(session, "Session must not be null");
ResultSet resultSet = session.execute("SELECT release_version FROM system.local;");
Row row = resultSet.one();
return Version.parse(row.getString(0));
}