From 1522ec2bdc5e0b716df09658353f99116bb3e575 Mon Sep 17 00:00:00 2001 From: Lorrin Nelson Date: Mon, 22 Jul 2013 23:19:26 -0700 Subject: [PATCH] Consistent int return type and add'l signature for count by state calls --- .../dropwizard/task/RetryUploadTask.java | 7 ------- .../skidroad/jdbi/DefaultJDBILogFileDAO.java | 6 +++--- .../jdbi/DefaultPostgresJDBILogFileDAO.java | 6 +++++- .../io/ifar/skidroad/jdbi/JDBILogFileDAO.java | 7 +++---- .../skidroad/jdbi/JDBILogFileDAOHelper.java | 18 ++++++++++++++++-- .../jdbi/JDBILogFileDAOWithArraySupport.java | 4 +++- .../ifar/skidroad/jdbi/JDBILogFileTracker.java | 11 ++++++++++- .../ifar/skidroad/tracking/LogFileTracker.java | 5 +++++ .../tracker/TransientLogFileTracker.java | 4 ++++ 9 files changed, 49 insertions(+), 19 deletions(-) delete mode 100644 skid-road-dropwizard/src/main/java/io/ifar/skidroad/dropwizard/task/RetryUploadTask.java diff --git a/skid-road-dropwizard/src/main/java/io/ifar/skidroad/dropwizard/task/RetryUploadTask.java b/skid-road-dropwizard/src/main/java/io/ifar/skidroad/dropwizard/task/RetryUploadTask.java deleted file mode 100644 index 2f3b286..0000000 --- a/skid-road-dropwizard/src/main/java/io/ifar/skidroad/dropwizard/task/RetryUploadTask.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.ifar.skidroad.dropwizard.task; - -/** - * - */ -public class RetryUploadTask { -} diff --git a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultJDBILogFileDAO.java b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultJDBILogFileDAO.java index 6df7c89..4095cad 100644 --- a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultJDBILogFileDAO.java +++ b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultJDBILogFileDAO.java @@ -74,7 +74,7 @@ ResultIterator 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") @@ -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); diff --git a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultPostgresJDBILogFileDAO.java b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultPostgresJDBILogFileDAO.java index fcfb7c3..0b35fb2 100644 --- a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultPostgresJDBILogFileDAO.java +++ b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/DefaultPostgresJDBILogFileDAO.java @@ -33,9 +33,13 @@ ResultIterator listLogFilesByDateAndState( Long totalSize(@Bind(value = "states", binder = StringCollectionBinder.class) Set 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 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 state, @Bind("first_ts") DateTime startDate, + int count(@Bind(value = "states", binder = StringCollectionBinder.class) Set state, @Bind("first_ts") DateTime startDate, @Bind("last_ts") DateTime endDate); } diff --git a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAO.java b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAO.java index 39740f9..9908ae7 100644 --- a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAO.java +++ b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAO.java @@ -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; @@ -34,13 +33,13 @@ public interface JDBILogFileDAO { List 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 listLogFilesByDateAndState(String state, DateTime startDate, DateTime endDate); diff --git a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOHelper.java b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOHelper.java index 94a1bb7..aa89531 100644 --- a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOHelper.java +++ b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOHelper.java @@ -79,13 +79,27 @@ public static AutoCloseableIterator listLogFilesByDate(JDBILogFileDAO d } - public static long count(JDBILogFileDAO dao, Set states, DateTime startDate, DateTime endDate) { + public static int count(JDBILogFileDAO dao, Set 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 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); } diff --git a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOWithArraySupport.java b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOWithArraySupport.java index 4d2a36c..5953c56 100644 --- a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOWithArraySupport.java +++ b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileDAOWithArraySupport.java @@ -15,7 +15,9 @@ public interface JDBILogFileDAOWithArraySupport extends JDBILogFileDAO { Long totalSize(Set states, DateTime startDate, DateTime endDate); - Long count(Set states, DateTime startDate, DateTime endDate); + int count(Set states); + + int count(Set states, DateTime startDate, DateTime endDate); ResultIterator listLogFilesByDateAndState(Set state, DateTime startDate, DateTime endDate); diff --git a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileTracker.java b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileTracker.java index 8a8f3cb..a35fd64 100644 --- a/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileTracker.java +++ b/skid-road-jdbi/src/main/java/io/ifar/skidroad/jdbi/JDBILogFileTracker.java @@ -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 states) { + Set stateStrings = new HashSet<>(states.size()); + for (LogFileState state : states) { + stateStrings.add(state.toString()); + } + return JDBILogFileDAOHelper.count(dao, stateStrings); } @Override diff --git a/skid-road/src/main/java/io/ifar/skidroad/tracking/LogFileTracker.java b/skid-road/src/main/java/io/ifar/skidroad/tracking/LogFileTracker.java index fd420f9..015a0b6 100644 --- a/skid-road/src/main/java/io/ifar/skidroad/tracking/LogFileTracker.java +++ b/skid-road/src/main/java/io/ifar/skidroad/tracking/LogFileTracker.java @@ -120,6 +120,11 @@ public interface LogFileTracker { */ int getCount(LogFileState state); + /** + * Return count of LogFile records in the specified states. + */ + int getCount(Set states); + boolean addListener(LogFileStateListener listener); boolean removeListener(LogFileStateListener listener); diff --git a/skid-road/src/test/java/io/ifar/skidroad/tracker/TransientLogFileTracker.java b/skid-road/src/test/java/io/ifar/skidroad/tracker/TransientLogFileTracker.java index 5b4f88b..06f9e94 100644 --- a/skid-road/src/test/java/io/ifar/skidroad/tracker/TransientLogFileTracker.java +++ b/skid-road/src/test/java/io/ifar/skidroad/tracker/TransientLogFileTracker.java @@ -106,4 +106,8 @@ public int getCount(LogFileState state) { return 0; } + @Override + public int getCount(Set states) { + return 0; + } }