aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/Daos.java15
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/Util.java4
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/core/db/BuildDao.java16
-rwxr-xr-x[-rw-r--r--]src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java4
-rwxr-xr-x[-rw-r--r--]src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java27
5 files changed, 29 insertions, 37 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/Daos.java b/src/main/java/io/trygvis/esper/testing/Daos.java
index 1a7cb0b..0242a3a 100755
--- a/src/main/java/io/trygvis/esper/testing/Daos.java
+++ b/src/main/java/io/trygvis/esper/testing/Daos.java
@@ -9,21 +9,6 @@ import java.sql.*;
public class Daos implements Closeable {
- public enum OrderDirection {
- ASC, DESC, NONE;
-
- public String toSql(String expression) {
- switch (this) {
- case ASC:
- return expression + "expression";
- case DESC:
- return expression + "expression DESC";
- default:
- return "1";
- }
- }
- }
-
private final Connection connection;
public final FileDao fileDao;
public final GitoriousEventDao gitoriousEventDao;
diff --git a/src/main/java/io/trygvis/esper/testing/Util.java b/src/main/java/io/trygvis/esper/testing/Util.java
index 68660c4..849a6f9 100755
--- a/src/main/java/io/trygvis/esper/testing/Util.java
+++ b/src/main/java/io/trygvis/esper/testing/Util.java
@@ -77,6 +77,10 @@ public class Util {
// SQL
// -----------------------------------------------------------------------
+ public static String orderBy(String[] inputs, String... allowed) {
+ return orderBy(Arrays.asList(inputs), allowed);
+ }
+
public static String orderBy(Iterable<String> inputs, String... allowed) {
StringBuilder buffer = new StringBuilder();
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java
index 32afe42..c6a46c6 100755
--- a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java
+++ b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java
@@ -7,7 +7,7 @@ import org.joda.time.*;
import java.sql.*;
import java.util.*;
-import static io.trygvis.esper.testing.Util.toList;
+import static io.trygvis.esper.testing.Util.*;
import static io.trygvis.esper.testing.util.sql.ResultSetF.*;
import static io.trygvis.esper.testing.util.sql.SqlOption.fromRs;
import static java.lang.System.*;
@@ -15,7 +15,7 @@ import static java.lang.System.*;
public class BuildDao {
private final Connection c;
- public static final String BUILD = "uuid, created_date, timestamp, success, reference_type, reference_uuid";
+ public static final String BUILD = "UUID, created_date, TIMESTAMP, success, reference_type, reference_uuid";
public static final SqlF<ResultSet, BuildDto> build = new SqlF<ResultSet, BuildDto>() {
public BuildDto apply(ResultSet rs) throws SQLException {
@@ -91,7 +91,11 @@ public class BuildDao {
}
public List<BuildDto> selectBuildsByPerson(Uuid person, PageRequest page) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + BUILD + " FROM build b, build_participant bp WHERE bp.person=? AND b.uuid = bp.build ORDER BY created_date DESC LIMIT ? OFFSET ?")) {
+ String sql = "SELECT " + BUILD + " FROM build b, build_participant bp WHERE bp.person=? AND b.uuid = bp.build";
+ sql += orderBy(page.orderBy, "created_date", "timestamp");
+ sql += " LIMIT ? OFFSET ?";
+
+ try (PreparedStatement s = c.prepareStatement(sql)) {
int i = 1;
s.setString(i++, person.toUuidString());
s.setInt(i++, page.count.orSome(10));
@@ -101,7 +105,11 @@ public class BuildDao {
}
public List<BuildDto> selectBuilds(PageRequest page) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + BUILD + " FROM build ORDER BY created_date DESC LIMIT ? OFFSET ?")) {
+ String sql = "SELECT " + BUILD + " FROM build";
+ sql += orderBy(page.orderBy, "created_date", "timestamp");
+ sql += " LIMIT ? OFFSET ?";
+
+ try (PreparedStatement s = c.prepareStatement(sql)) {
int i = 1;
s.setInt(i++, page.count.orSome(10));
s.setInt(i, page.startIndex.orSome(0));
diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java
index 67b6d17..d60956d 100644..100755
--- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java
+++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java
@@ -38,7 +38,7 @@ public class GitoriousProjectDiscovery {
Set<GitoriousRepositoryDto> repositories = Collections.emptySet();
try (Connection c = boneCp.getConnection()) {
- repositories = new HashSet<>(new Daos(c).gitoriousRepositoryDao.select(Daos.OrderDirection.ASC));
+ repositories = new HashSet<>(new Daos(c).gitoriousRepositoryDao.select(true));
} catch (SQLException e) {
// ignore
}
@@ -53,7 +53,7 @@ public class GitoriousProjectDiscovery {
public void act(Connection c) throws Exception {
try (Daos daos = new Daos(c)) {
discoverProjects(daos);
- repositoryManager.update(daos.gitoriousRepositoryDao.select(Daos.OrderDirection.NONE));
+ repositoryManager.update(daos.gitoriousRepositoryDao.select(null));
daos.commit();
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java
index 903d74c..27e66fe 100644..100755
--- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java
+++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java
@@ -2,8 +2,7 @@ package io.trygvis.esper.testing.gitorious;
import fj.data.*;
import io.trygvis.esper.testing.*;
-import static io.trygvis.esper.testing.Util.dateToTimestamp;
-import static io.trygvis.esper.testing.Util.timestampToDate;
+import io.trygvis.esper.testing.util.sql.*;
import java.net.*;
import java.sql.*;
@@ -11,6 +10,8 @@ import java.util.*;
import java.util.Date;
import java.util.List;
+import static io.trygvis.esper.testing.Util.*;
+
public class GitoriousRepositoryDao {
private final Connection c;
@@ -38,7 +39,7 @@ public class GitoriousRepositoryDao {
}
public int countRepositories(String projectSlug, String name) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT count(*) FROM gitorious_repository WHERE project_slug=? and name=?")) {
+ try (PreparedStatement s = c.prepareStatement("SELECT count(*) FROM gitorious_repository WHERE project_slug=? AND name=?")) {
s.setString(1, projectSlug);
s.setString(2, name);
try (ResultSet rs = s.executeQuery()) {
@@ -55,21 +56,15 @@ public class GitoriousRepositoryDao {
}
}
- public List<GitoriousRepositoryDto> select(Daos.OrderDirection order) throws SQLException {
- String orderBy;
-
- switch (order) {
- case ASC:
- orderBy = "ORDER BY project_slug, name";
- break;
- case DESC:
- orderBy = "ORDER BY project_slug DESC, name DESC";
- break;
- default:
- orderBy = "";
+ public List<GitoriousRepositoryDto> select(Boolean asc) throws SQLException {
+ String sql = "SELECT " + ALL_FIELDS + " FROM gitorious_repository ";
+
+ if(asc != null) {
+ String[] orderBy = asc ? new String[]{"project_slug", "name"} : new String[]{"project_slug-", "name-"};
+ sql += orderBy(orderBy, "project_slug", "name");
}
- try (PreparedStatement s = c.prepareStatement("SELECT " + ALL_FIELDS + " FROM gitorious_repository " + orderBy)) {
+ try (PreparedStatement s = c.prepareStatement(sql)) {
return executeQuery(s);
}
}