aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper/testing/core/db
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-04 23:42:17 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-04 23:42:17 +0100
commitb895e15d3c9bd4c7a1d420c99af9d1f2efca8a0b (patch)
tree6b2baa5593f7d621ab8319ae00b35f0b766acda8 /src/main/java/io/trygvis/esper/testing/core/db
parent1902b2c1dfff62c0225a170db38a4882df9143e6 (diff)
downloadesper-testing-b895e15d3c9bd4c7a1d420c99af9d1f2efca8a0b.tar.gz
esper-testing-b895e15d3c9bd4c7a1d420c99af9d1f2efca8a0b.tar.bz2
esper-testing-b895e15d3c9bd4c7a1d420c99af9d1f2efca8a0b.tar.xz
esper-testing-b895e15d3c9bd4c7a1d420c99af9d1f2efca8a0b.zip
o Showing recent badges on the front page.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/core/db')
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java4
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/core/db/PersonDao.java38
2 files changed, 39 insertions, 3 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java
index 463da9c..0f34347 100644
--- a/src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java
+++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java
@@ -10,12 +10,12 @@ public class PersonBadgeDto extends AbstractEntity {
UNBREAKABLE
}
- public final UUID person;
+ public final Uuid person;
public final BadgeType type;
public final int level;
public final int count;
- public PersonBadgeDto(UUID uuid, DateTime createdDate, UUID person, BadgeType type, int level, int count) {
+ public PersonBadgeDto(UUID uuid, DateTime createdDate, Uuid person, BadgeType type, int level, int count) {
super(uuid, createdDate);
this.person = person;
this.type = type;
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java
index ec1620b..0f80219 100755
--- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java
+++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java
@@ -1,5 +1,6 @@
package io.trygvis.esper.testing.core.db;
+import fj.data.*;
import io.trygvis.esper.testing.*;
import io.trygvis.esper.testing.core.db.PersonBadgeDto.*;
import io.trygvis.esper.testing.util.sql.*;
@@ -7,6 +8,7 @@ import org.joda.time.*;
import java.sql.*;
import java.util.*;
+import java.util.List;
import static io.trygvis.esper.testing.Util.*;
import static io.trygvis.esper.testing.util.sql.SqlOption.*;
@@ -36,7 +38,7 @@ public class PersonDao {
return new PersonBadgeDto(
UUID.fromString(rs.getString(i++)),
new DateTime(rs.getTimestamp(i++).getTime()),
- UUID.fromString(rs.getString(i++)),
+ Uuid.fromString(rs.getString(i++)),
BadgeType.valueOf(rs.getString(i++)),
rs.getInt(i++),
rs.getInt(i));
@@ -187,6 +189,40 @@ public class PersonDao {
}
}
+ public List<PersonBadgeDto> selectBadges(Option<Uuid> person, Option<BadgeType> type, Option<Integer> level, PageRequest page) throws SQLException {
+ String sql = "SELECT " + PERSON_BADGE + " FROM person_badge WHERE 1=1";
+
+ if (person.isSome()) {
+ sql += " AND person=?";
+ }
+
+ if (type.isSome()) {
+ sql += " AND name=?";
+ }
+
+ if (level.isSome()) {
+ sql += " AND level=?";
+ }
+
+ sql += " LIMIT ? OFFSET ?";
+
+ try (PreparedStatement s = c.prepareStatement(sql)) {
+ int i = 1;
+ if(person.isSome()) {
+ s.setString(i++, person.some().toUuidString());
+ }
+ if (type.isSome()) {
+ s.setString(i++, type.some().toString());
+ }
+ if (level.isSome()) {
+ s.setInt(i, level.some());
+ }
+ s.setInt(i++, page.count.orSome(10));
+ s.setInt(i, page.startIndex.orSome(0));
+ return toList(s, personBadge);
+ }
+ }
+
// -----------------------------------------------------------------------
// Badge Progress
// -----------------------------------------------------------------------