/** * Initialize from a record and posession flag * * @param record record to get data from * @param haveCopy true if the node has a copy of the {@link Approvable} item (e.g. one can try go call {@link * com.icodici.universa.node2.network.Network#getItem(HashId, NodeInfo, Duration)} on it */ public ItemResult(StateRecord record, boolean haveCopy) { // if( record == null ) { // throw new IllegalStateException("record can not be null"); // } state = record.getState(); this.haveCopy = haveCopy; createdAt = record.getCreatedAt(); expiresAt = record.getExpiresAt(); }
@Override public String toString() { return "State<"+getId()+"/"+getRecordId()+":"+getState()+":"+getCreatedAt()+"/"+getExpiresAt()+">"; } }
statement.setInt(2, stateRecord.getState().ordinal()); statement.setLong(3, StateRecord.unixTime(stateRecord.getCreatedAt())); statement.setLong(4, StateRecord.unixTime(stateRecord.getExpiresAt())); statement.setLong(5, stateRecord.getLockedByRecordId()); statement.executeUpdate(); db.update("update ledger set state=?, expires_at=?, locked_by_id=? where id=?", stateRecord.getState().ordinal(), StateRecord.unixTime(stateRecord.getExpiresAt()), stateRecord.getLockedByRecordId(), stateRecord.getRecordId()
statement.setInt(2, stateRecord.getState().ordinal()); statement.setLong(3, StateRecord.unixTime(stateRecord.getCreatedAt())); statement.setLong(4, StateRecord.unixTime(stateRecord.getExpiresAt())); statement.setLong(5, stateRecord.getLockedByRecordId()); db.updateWithStatement(statement); db.update("update ledger set state=?, expires_at=?, locked_by_id=? where id=?", stateRecord.getState().ordinal(), StateRecord.unixTime(stateRecord.getExpiresAt()), stateRecord.getLockedByRecordId(), stateRecord.getRecordId()
@Test public void recordExpiration() throws Exception { // todo: expired can't be get - it should be dropped by the database HashId hashId = HashId.createRandom(); StateRecord r = ledger.findOrCreate(hashId); assertNotNull(r.getExpiresAt()); assert(r.getExpiresAt().isAfter(ZonedDateTime.now())); long recordId = r.getRecordId(); ZonedDateTime inFuture = ZonedDateTime.now().plusHours(2); r.setExpiresAt(inFuture); StateRecord r1 = ledger.getRecord(hashId); assertNotEquals(r1.getExpiresAt(), inFuture); r.save(); r1 = ledger.getRecord(hashId); assertAlmostSame(r.getExpiresAt(), r1.getExpiresAt()); r.setExpiresAt(ZonedDateTime.now().minusHours(1)); r.save(); r1 = ledger.getRecord(hashId); assertNull(r1); }
@Test public void recordExpiration() throws Exception { // todo: expired can't be get - it should be dropped by the database HashId hashId = HashId.createRandom(); StateRecord r = ledger.findOrCreate(hashId); long recordId = r.getRecordId(); ZonedDateTime inFuture = ZonedDateTime.now().plusHours(2); r.setExpiresAt(inFuture); StateRecord r1 = ledger.getRecord(hashId); assertNotEquals(r1.getExpiresAt(), inFuture); r.save(); r1 = ledger.getRecord(hashId); assertAlmostSame(r.getExpiresAt(), r1.getExpiresAt()); r.setExpiresAt(ZonedDateTime.now().minusHours(1)); r.save(); r1 = ledger.getRecord(hashId); assertNull(r1); }
r0.setExpiresAt(r0.getExpiresAt().minusHours(1)); r0.save();