use of org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent in project open-kilda by telstra.
the class HibernateHistoryFlowEventRepository method findEntityByTaskId.
/**
* Fetch and return hibernate {@link HibernateFlowEvent} entity, dedicated to use by others hibernate repositories.
*/
public Optional<HibernateFlowEvent> findEntityByTaskId(String taskId) {
CriteriaBuilder builder = getSession().getCriteriaBuilder();
CriteriaQuery<HibernateFlowEvent> query = builder.createQuery(HibernateFlowEvent.class);
Root<HibernateFlowEvent> root = query.from(HibernateFlowEvent.class);
query.select(root);
query.where(builder.equal(root.get(HibernateFlowEvent_.taskId), taskId));
List<HibernateFlowEvent> results = getSession().createQuery(query).getResultList();
if (1 < results.size()) {
throw new PersistenceException(String.format("Unique constraint violation on field %s of %s", HibernateFlowEvent_.taskId, HibernateFlowEvent.class.getName()));
}
if (!results.isEmpty()) {
return Optional.of(results.get(0));
}
return Optional.empty();
}
use of org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent in project open-kilda by telstra.
the class HibernateHistoryFlowEventRepository method makeEntity.
@Override
protected HibernateFlowEvent makeEntity(FlowEventData view) {
HibernateFlowEvent entity = new HibernateFlowEvent();
FlowEventCloner.INSTANCE.copyWithoutRecordsAndDumps(view, entity);
for (FlowEventAction entry : view.getEventActions()) {
HibernateFlowEventAction action = new HibernateFlowEventAction();
FlowEventActionCloner.INSTANCE.copy(entry.getData(), action);
entity.addAction(action);
}
for (FlowEventDump entry : view.getEventDumps()) {
HibernateFlowEventDump dump = new HibernateFlowEventDump();
FlowEventDumpCloner.INSTANCE.copy(entry.getData(), dump);
entity.addDump(dump);
}
return entity;
}
use of org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent in project open-kilda by telstra.
the class HibernateHistoryFlowEventRepository method fetch.
private List<HibernateFlowEvent> fetch(String flowId, Instant timeFrom, Instant timeTo, int maxCount) {
CriteriaBuilder builder = getSession().getCriteriaBuilder();
CriteriaQuery<HibernateFlowEvent> query = builder.createQuery(HibernateFlowEvent.class);
Root<HibernateFlowEvent> root = query.from(HibernateFlowEvent.class);
query.select(root);
query.where(makeQueryFilter(root, flowId, timeFrom, timeTo).toArray(new Predicate[0]));
query.orderBy(builder.desc(root.get(HibernateFlowEvent_.eventTime)), builder.desc(root.get(HibernateFlowEvent_.flowId)));
return getSession().createQuery(query).setMaxResults(maxCount).getResultList();
}
Aggregations