use of keywhiz.jooq.tables.Clients.CLIENTS in project keywhiz by square.
the class ClientDAO method sawClient.
public void sawClient(Client client) {
Instant now = Instant.now();
Instant lastSeen = Optional.ofNullable(client.getLastSeen()).map(ls -> Instant.ofEpochSecond(ls.toEpochSecond())).orElse(null);
// this way we can have less granularity on lastSeen and save db writes
if (lastSeen == null || now.isAfter(lastSeen.plus(lastSeenThreshold, SECONDS))) {
dslContext.transaction(configuration -> {
Param<Long> val = DSL.val(now.getEpochSecond(), CLIENTS.LASTSEEN);
DSL.using(configuration).update(CLIENTS).set(CLIENTS.LASTSEEN, DSL.when(CLIENTS.LASTSEEN.isNull(), val).otherwise(DSL.greatest(CLIENTS.LASTSEEN, val))).where(CLIENTS.ID.eq(client.getId())).execute();
});
}
}
Aggregations