use of org.vitrivr.cottontail.client.language.dml.Update in project cineast by vitrivr.
the class LSC21TemporalUpdateCommand method run.
@Override
@SuppressWarnings("unchecked")
public void run() {
if (Config.sharedConfig().getDatabase().getSelector() != DataSource.COTTONTAIL) {
System.out.println("Other DB than Cottontail DB not supported (yet). Aborting");
return;
}
/* Preparation. */
final CottontailWrapper cottontail = new CottontailWrapper(Config.sharedConfig().getDatabase().getHost(), Config.sharedConfig().getDatabase().getPort());
long txId = cottontail.client.begin();
final Query query = new Query(ENTITY_NAME).select("*", null).txId(txId);
final TupleIterator ti = cottontail.client.query(query);
final LinkedList<Update> updates = new LinkedList<>();
int counter = 0;
int totalCounter = 0;
/* Prepare updates. */
while (ti.hasNext()) {
final Tuple t = ti.next();
final MediaSegmentDescriptor segment = convert(t);
try {
final Optional<LocalDateTime> oldt = extractTimeInformation(segment.getSegmentId());
if (!oldt.isPresent()) {
continue;
}
final LocalDateTime ldt = oldt.get();
final long msOfTheDay = ldt.getHour() * 60 * 60 * 1000 + ldt.getMinute() * 60 * 1000 + ldt.getSecond() * 1000;
final long sAbs = ldt.toInstant(ZoneOffset.UTC).toEpochMilli() / 1000L;
final Update update = new Update(ENTITY_NAME).values(new Pair<>(MediaSegmentDescriptor.SEGMENT_START_COL_NAME, (double) msOfTheDay), new Pair<>(MediaSegmentDescriptor.SEGMENT_END_COL_NAME, (double) msOfTheDay + 1), new Pair<>(MediaSegmentDescriptor.SEGMENT_STARTABS_COL_NAME, resetAbsTime ? 0.0 : sAbs), new Pair<>(MediaSegmentDescriptor.SEGMENT_ENDABS_COL_NAME, resetAbsTime ? 0.0 : (sAbs + 1))).where(new org.vitrivr.cottontail.client.language.extensions.Literal(CineastConstants.SEGMENT_ID_COLUMN_QUALIFIER, "=", segment.getSegmentId())).txId(txId);
updates.add(update);
} catch (Exception e) {
LOGGER.warn("Could not update " + segment.getSegmentId() + " due to exception: " + e.getMessage());
}
}
/* Execute updates. */
Update update;
while ((update = updates.poll()) != null) {
cottontail.client.update(update);
totalCounter++;
if (counter++ > 99) {
if (progress) {
System.out.println("Updated " + totalCounter + " rows.");
}
counter = 0;
}
}
cottontail.client.commit(txId);
System.out.println("Done.");
}
Aggregations