Search in sources :

Example 1 with HibernateFlowEvent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) HibernateFlowEvent(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent)

Example 2 with HibernateFlowEvent

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;
}
Also used : HibernateFlowEventAction(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEventAction) HibernateFlowEventDump(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEventDump) HibernateFlowEventAction(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEventAction) FlowEventAction(org.openkilda.model.history.FlowEventAction) HibernateFlowEvent(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent) FlowEventDump(org.openkilda.model.history.FlowEventDump) HibernateFlowEventDump(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEventDump)

Example 3 with HibernateFlowEvent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) HibernateFlowEvent(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent) Predicate(javax.persistence.criteria.Predicate)

Aggregations

HibernateFlowEvent (org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)1 FlowEventAction (org.openkilda.model.history.FlowEventAction)1 FlowEventDump (org.openkilda.model.history.FlowEventDump)1 PersistenceException (org.openkilda.persistence.exceptions.PersistenceException)1 HibernateFlowEventAction (org.openkilda.persistence.hibernate.entities.history.HibernateFlowEventAction)1 HibernateFlowEventDump (org.openkilda.persistence.hibernate.entities.history.HibernateFlowEventDump)1