Skip to content

Commit

Permalink
Consistent int return type and add'l signature for count by state calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lorrin committed Jul 23, 2013
1 parent 472f13a commit 1522ec2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 19 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ResultIterator<LogFile> listLogFilesByDate(@Bind("first_ts") DateTime startDate,

@Override
@SqlQuery("select count(*) as cnt from log_files where state = :state")
int countLogFilesByState(@Bind("state") String state);
int count(@Bind("state") String state);

@Override
@SqlQuery("select sum(bytes) from log_files where state = :state and start_time >= :first_ts and start_time <= :last_ts")
Expand All @@ -83,12 +83,12 @@ Long totalSize(@Bind(value = "state") String state, @Bind("first_ts") DateTime s

@Override
@SqlQuery("select count(*) from log_files where state = :state and start_time >= :first_ts and start_time <= :last_ts")
Long count(@Bind(value = "state") String state, @Bind("first_ts") DateTime startDate,
int count(@Bind(value = "state") String state, @Bind("first_ts") DateTime startDate,
@Bind("last_ts") DateTime endDate);

@Override
@SqlQuery("select count(*) from log_files where start_time >= :first_ts and start_time <= :last_ts")
Long count(@Bind("first_ts") DateTime startDate,
int count(@Bind("first_ts") DateTime startDate,
@Bind("last_ts") DateTime endDate);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ ResultIterator<LogFile> listLogFilesByDateAndState(
Long totalSize(@Bind(value = "states", binder = StringCollectionBinder.class) Set<String> states, @Bind("first_ts") DateTime startDate,
@Bind("last_ts") DateTime endDate);

@Override
@SqlQuery("select count(*) from log_files where state = ANY(:states)")
int count(@Bind(value = "states", binder = StringCollectionBinder.class) Set<String> state);

@Override
@SqlQuery("select count(*) from log_files where state = ANY(:states) and start_time >= :first_ts and start_time <= :last_ts")
Long count(@Bind(value = "states", binder = StringCollectionBinder.class) Set<String> state, @Bind("first_ts") DateTime startDate,
int count(@Bind(value = "states", binder = StringCollectionBinder.class) Set<String> state, @Bind("first_ts") DateTime startDate,
@Bind("last_ts") DateTime endDate);
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.ifar.skidroad.LogFile;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.ResultIterator;
import org.skife.jdbi.v2.sqlobject.Bind;

import java.sql.Timestamp;
import java.util.List;
Expand Down Expand Up @@ -34,13 +33,13 @@ public interface JDBILogFileDAO {

List<CountByState> countLogFilesByState();

int countLogFilesByState(String state);
int count(String state);

Long totalSize(String state, DateTime startDate, DateTime endDate);

Long count(String state, DateTime startDate, DateTime endDate);
int count(String state, DateTime startDate, DateTime endDate);

Long count(DateTime startDate, DateTime endDate);
int count(DateTime startDate, DateTime endDate);

ResultIterator<LogFile> listLogFilesByDateAndState(String state, DateTime startDate, DateTime endDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,27 @@ public static AutoCloseableIterator<LogFile> listLogFilesByDate(JDBILogFileDAO d
}


public static long count(JDBILogFileDAO dao, Set<String> states, DateTime startDate, DateTime endDate) {
public static int count(JDBILogFileDAO dao, Set<String> states) {
if (dao instanceof JDBILogFileDAOWithArraySupport) {
return ((JDBILogFileDAOWithArraySupport)dao).count(states);
} else if (states.size() == 1) {
return dao.count(states.iterator().next());
} else {
int result = 0;
for (String state : states) {
result += dao.count(state);
}
return result;
}
}

public static int count(JDBILogFileDAO dao, Set<String> states, DateTime startDate, DateTime endDate) {
if (dao instanceof JDBILogFileDAOWithArraySupport) {
return ((JDBILogFileDAOWithArraySupport)dao).count(states, startDate, endDate);
} else if (states.size() == 1) {
return dao.count(states.iterator().next(), startDate, endDate);
} else {
long result = 0;
int result = 0;
for (String state : states) {
result += dao.count(state, startDate, endDate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public interface JDBILogFileDAOWithArraySupport extends JDBILogFileDAO {

Long totalSize(Set<String> states, DateTime startDate, DateTime endDate);

Long count(Set<String> states, DateTime startDate, DateTime endDate);
int count(Set<String> states);

int count(Set<String> states, DateTime startDate, DateTime endDate);

ResultIterator<LogFile> listLogFilesByDateAndState(Set<String> state, DateTime startDate, DateTime endDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ protected int updateSize(LogFile logFile) {

@Override
public int getCount(LogFileState state) {
return dao.countLogFilesByState(state.toString());
return dao.count(state.toString());
}

@Override
public int getCount(Set<LogFileState> states) {
Set<String> stateStrings = new HashSet<>(states.size());
for (LogFileState state : states) {
stateStrings.add(state.toString());
}
return JDBILogFileDAOHelper.count(dao, stateStrings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public interface LogFileTracker {
*/
int getCount(LogFileState state);

/**
* Return count of LogFile records in the specified states.
*/
int getCount(Set<LogFileState> states);

boolean addListener(LogFileStateListener listener);

boolean removeListener(LogFileStateListener listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ public int getCount(LogFileState state) {
return 0;
}

@Override
public int getCount(Set<LogFileState> states) {
return 0;
}
}

0 comments on commit 1522ec2

Please sign in to comment.