use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class PasswordAuthenticator method queryHashedPassword.
private String queryHashedPassword(String username) {
try {
QueryOptions options = QueryOptions.forInternalCalls(consistencyForRoleRead(username), Lists.newArrayList(ByteBufferUtil.bytes(username)));
ResultMessage.Rows rows = select(authenticateStatement, options);
// invalidate the cache and throw an appropriate exception.
if (rows.result.isEmpty())
return NO_SUCH_CREDENTIAL;
UntypedResultSet result = UntypedResultSet.create(rows.result);
if (!result.one().has(SALTED_HASH))
return NO_SUCH_CREDENTIAL;
return result.one().getString(SALTED_HASH);
} catch (RequestExecutionException e) {
throw new AuthenticationException("Unable to perform authentication: " + e.getMessage(), e);
}
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SystemKeyspace method getRack.
/**
* Gets the stored rack for the local node, or null if none have been set yet.
*/
public static String getRack() {
String req = "SELECT rack FROM system.%s WHERE key='%s'";
UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
// Look up the Rack (return it if found)
if (!result.isEmpty() && result.one().has("rack"))
return result.one().getString("rack");
return null;
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SystemKeyspace method loadPreparedStatement.
public static int loadPreparedStatement(MD5Digest digest, TriFunction<MD5Digest, String, String, Boolean> onLoaded) {
String query = String.format("SELECT prepared_id, logged_keyspace, query_string FROM %s.%s WHERE prepared_id = ?", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
UntypedResultSet resultSet = executeOnceInternal(query, digest.byteBuffer());
int counter = 0;
for (UntypedResultSet.Row row : resultSet) {
if (onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")), row.getString("query_string"), row.has("logged_keyspace") ? row.getString("logged_keyspace") : null))
counter++;
}
return counter;
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SystemKeyspace method getReleaseVersion.
/**
* Get release version for given endpoint.
* If release version is unknown, then this returns null.
*
* @param ep endpoint address to check
* @return Release version or null if version is unknown.
*/
public static CassandraVersion getReleaseVersion(InetAddressAndPort ep) {
try {
if (FBUtilities.getBroadcastAddressAndPort().equals(ep)) {
return CURRENT_VERSION;
}
String req = "SELECT release_version FROM system.%s WHERE peer=? AND peer_port=?";
UntypedResultSet result = executeInternal(String.format(req, PEERS_V2), ep.getAddress(), ep.getPort());
if (result != null && result.one().has("release_version")) {
return new CassandraVersion(result.one().getString("release_version"));
}
// version is unknown
return null;
} catch (IllegalArgumentException e) {
// version string cannot be parsed
return null;
}
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SystemKeyspace method loadPaxosState.
public static PaxosState loadPaxosState(DecoratedKey key, TableMetadata metadata, int nowInSec) {
String req = "SELECT * FROM system.%s WHERE row_key = ? AND cf_id = ?";
UntypedResultSet results = QueryProcessor.executeInternalWithNow(nowInSec, nanoTime(), format(req, PAXOS), key.getKey(), metadata.id.asUUID());
if (results.isEmpty())
return new PaxosState(key, metadata);
UntypedResultSet.Row row = results.one();
Commit promised = row.has("in_progress_ballot") ? new Commit(row.getUUID("in_progress_ballot"), new PartitionUpdate.Builder(metadata, key, metadata.regularAndStaticColumns(), 1).build()) : Commit.emptyCommit(key, metadata);
// either we have both a recently accepted ballot and update or we have neither
Commit accepted = row.has("proposal_version") && row.has("proposal") ? new Commit(row.getUUID("proposal_ballot"), PartitionUpdate.fromBytes(row.getBytes("proposal"), row.getInt("proposal_version"))) : Commit.emptyCommit(key, metadata);
// either most_recent_commit and most_recent_commit_at will both be set, or neither
Commit mostRecent = row.has("most_recent_commit_version") && row.has("most_recent_commit") ? new Commit(row.getUUID("most_recent_commit_at"), PartitionUpdate.fromBytes(row.getBytes("most_recent_commit"), row.getInt("most_recent_commit_version"))) : Commit.emptyCommit(key, metadata);
return new PaxosState(promised, accepted, mostRecent);
}
Aggregations