public ItemResult(Boss.Reader br) throws IOException { state = ItemState.values()[br.readInt()]; createdAt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(br.readLong()), ZoneId.systemDefault()); expiresAt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(br.readLong()), ZoneId.systemDefault()); haveCopy = br.read(); }
@Override public Map<ItemState, Integer> getLedgerSize(ZonedDateTime createdAfter) { return protect(() -> { try (ResultSet rs = inPool(db -> db.queryRow("select count(id), state from ledger where created_at >= ? group by state", createdAfter != null ? createdAfter.toEpochSecond() : 0))) { Map<ItemState, Integer> result = new HashMap<>(); if (rs != null) { do { int count = rs.getInt(1); ItemState state = ItemState.values()[rs.getInt(2)]; result.put(state, count); } while (rs.next()); } return result; } catch (Exception e) { e.printStackTrace(); throw e; } }); }
public void initFrom(ResultSet rs) throws SQLException { // the processing mught be already fininshed by now: if( rs == null || rs.isClosed() ) throw new SQLException("resultset or connection is closed"); recordId = rs.getLong("id"); try { id = HashId.withDigest(Do.read(rs.getBinaryStream("hash"))); } catch (IOException e) { throw new SQLException("failed to read hash from the recordset"); } state = ItemState.values()[rs.getInt("state")]; createdAt = getTime(rs.getLong("created_at")); expiresAt = getTime(rs.getLong("expires_at")); if(expiresAt == null) { // todo: what we should do with items without expiresAt? expiresAt = createdAt.plusMonths(3); } lockedByRecordId = rs.getInt("locked_by_id"); }
@Override protected void readFrom(Boss.Reader br) throws IOException { super.readFrom(br); if (!answerIsRequested()) { itemState = ItemState.values()[br.readInt()]; hasEnvironment = br.readInt(); } }