Advertisement
FlyingSixtySix

DBPixelPlacement.java

Nov 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. package space.pxls.data;
  2.  
  3. import org.jdbi.v3.core.mapper.RowMapper;
  4. import org.jdbi.v3.core.statement.StatementContext;
  5. import space.pxls.user.Role;
  6.  
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Timestamp;
  10.  
  11. public class DBPixelPlacement {
  12.     public final int id;
  13.     public final int x;
  14.     public final int y;
  15.     public final int color;
  16.     public final int secondaryId;
  17.     public final long time;
  18.     public final int userId;
  19.     public final String username;
  20.     public final String login;
  21.     public final Role role;
  22.     public final long ban_expiry;
  23.     public final int pixel_count;
  24.     public final int pixel_count_alltime;
  25.     public final String ban_reason;
  26.     public final boolean banned;
  27.     public final boolean undoAction;
  28.     public final String userAgent;
  29.     public final String discordName;
  30.  
  31.     public DBPixelPlacement(int id, int x, int y, int color, int secondaryId, long time, int userId, String username, String login, Role role, long ban_expiry, int pixel_count, int pixel_count_alltime, String ban_reason, boolean banned, boolean undoAction, String userAgent, String discordName) {
  32.         this.id = id;
  33.         this.x = x;
  34.         this.y = y;
  35.         this.color = color;
  36.         this.secondaryId = secondaryId;
  37.         this.time = time;
  38.         this.userId = userId;
  39.         this.username = username;
  40.         this.login = login;
  41.         this.role = role;
  42.         this.ban_expiry = ban_expiry;
  43.         this.pixel_count = pixel_count;
  44.         this.pixel_count_alltime = pixel_count_alltime;
  45.         this.ban_reason = ban_reason;
  46.         this.banned = banned;
  47.         this.undoAction = undoAction;
  48.         this.userAgent = userAgent;
  49.         this.discordName = discordName;
  50.     }
  51.  
  52.     public static class Mapper implements RowMapper<DBPixelPlacement> {
  53.         @Override
  54.         public DBPixelPlacement map(ResultSet r, StatementContext ctx) throws SQLException {
  55.             Timestamp time = r.getTimestamp("time");
  56.             Timestamp ban_expiry = r.getTimestamp("users.ban_expiry");
  57.             boolean banned = Role.valueOf(r.getString("users.role")) == Role.BANNED;
  58.             if (!banned && ban_expiry != null) {
  59.                 banned = ban_expiry.getTime() > System.currentTimeMillis();
  60.             }
  61.  
  62.             return new DBPixelPlacement(
  63.                     r.getInt("id"),
  64.                     r.getInt("x"),
  65.                     r.getInt("y"),
  66.                     r.getInt("color"),
  67.                     r.getInt("secondary_id"),
  68.                     time == null ? 0 : time.getTime(),
  69.                     r.getInt("users.id"),
  70.                     r.getString("users.username"),
  71.                     r.getString("users.login"),
  72.                     Role.valueOf(r.getString("users.role")), // TODO: all users might not have valid roles
  73.                     ban_expiry == null ? 0 : ban_expiry.getTime(),
  74.                     r.getInt("pixel_count"),
  75.                     r.getInt("pixel_count_alltime"),
  76.                     r.getString("users.ban_reason"),
  77.                     banned,
  78.                     r.getBoolean("undo_action"),
  79.                     r.getString("user_agent"),
  80.                     r.getString("users.discord_name")
  81.             );
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement