Skip to content

Commit

Permalink
In the CassandraStorage make constant the remaining select cql statem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
michaelsembwever committed May 27, 2017
1 parent c87913f commit 9e26043
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/com/spotify/reaper/storage/CassandraStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public final class CassandraStorage implements IStorage {
Session session;

/* Simple statements */
private final String getClustersStmt = "SELECT * FROM cluster";
private static final String SELECT_CLUSTER = "SELECT * FROM cluster";
private static final String SELECT_REPAIR_SCHEDULE = "SELECT * FROM repair_schedule_v1";
private static final String SELECT_REPAIR_UNIT = "SELECT * FROM repair_unit_v1";
private static final String SELECT_REPAIR_RUN = "SELECT * FROM repair_run";

/* prepared statements */
private PreparedStatement insertClusterPrepStmt;
Expand Down Expand Up @@ -141,7 +144,7 @@ public boolean isStorageConnected() {
@Override
public Collection<Cluster> getClusters() {
Collection<Cluster> clusters = Lists.<Cluster>newArrayList();
ResultSet clusterResults = session.execute(getClustersStmt);
ResultSet clusterResults = session.execute(SELECT_CLUSTER);
for(Row cluster:clusterResults){
clusters.add(new Cluster(cluster.getString("name"), cluster.getString("partitioner"), cluster.getSet("seed_hosts", String.class)));
}
Expand Down Expand Up @@ -318,7 +321,7 @@ public Collection<RepairRun> getRepairRunsWithState(RunState runState) {
// There shouldn't be many repair runs, so we'll brute force this one
// We'll switch to 2i if performance sucks IRL
Collection<RepairRun> repairRuns = Lists.<RepairRun>newArrayList();
ResultSet repairRunResults = session.execute("SELECT * FROM repair_run");
ResultSet repairRunResults = session.execute(SELECT_REPAIR_RUN);
for(Row repairRun:repairRunResults){
if(RunState.valueOf(repairRun.getString("state")).equals(runState)){
repairRuns.add(buildRepairRunFromRow(repairRun, repairRun.getUUID("id")));
Expand Down Expand Up @@ -360,7 +363,7 @@ public Optional<RepairUnit> getRepairUnit(UUID id) {
public Optional<RepairUnit> getRepairUnit(String cluster, String keyspace, Set<String> columnFamilyNames) {
// brute force again
RepairUnit repairUnit=null;
ResultSet results = session.execute("SELECT * FROM repair_unit_v1");
ResultSet results = session.execute(SELECT_REPAIR_UNIT);
for(Row repairUnitRow:results){
if(repairUnitRow.getString("cluster_name").equals(cluster)
&& repairUnitRow.getString("keyspace_name").equals(keyspace)
Expand Down Expand Up @@ -608,7 +611,7 @@ public Collection<RepairSchedule> getRepairSchedulesForClusterAndKeyspace(String
@Override
public Collection<RepairSchedule> getAllRepairSchedules() {
Collection<RepairSchedule> schedules = Lists.<RepairSchedule>newArrayList();
ResultSet scheduleResults = session.execute("SELECT * FROM repair_schedule_v1");
ResultSet scheduleResults = session.execute(SELECT_REPAIR_SCHEDULE);
for(Row scheduleRow:scheduleResults){
schedules.add(createRepairScheduleFromRow(scheduleRow));
}
Expand Down

0 comments on commit 9e26043

Please sign in to comment.