Search in sources :

Example 6 with HibSession

use of org.bedework.calcorei.HibSession in project bw-calendar-engine by Bedework.

the class CoreCalendarsDAO method getChildLastModsAndPaths.

protected List<LastModAndPath> getChildLastModsAndPaths(final String parentPath) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(getChildLastModsAndPathsQuery);
    sess.setString("path", parentPath);
    sess.setString("tsfilter", BwCalendar.tombstonedFilter);
    sess.cacheableQuery();
    final List chfields = sess.getList();
    final List<LastModAndPath> res = new ArrayList<>();
    if (chfields == null) {
        return res;
    }
    for (final Object o : chfields) {
        final Object[] fs = (Object[]) o;
        res.add(new LastModAndPath((String) fs[0], (String) fs[1], (Integer) fs[2]));
    }
    return res;
}
Also used : HibSession(org.bedework.calcorei.HibSession) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with HibSession

use of org.bedework.calcorei.HibSession in project bw-calendar-engine by Bedework.

the class CoreCalendarsDAO method getSynchCollections.

protected List getSynchCollections(final String path, final String token) throws CalFacadeException {
    final HibSession sess = getSess();
    if (path == null) {
        sess.rollback();
        throw new CalFacadeBadRequest("Missing path");
    }
    if ((token != null) && (token.length() < 18)) {
        sess.rollback();
        throw new CalFacadeInvalidSynctoken(token);
    }
    final StringBuilder sb = new StringBuilder();
    sb.append("from ");
    sb.append(BwCalendar.class.getName());
    sb.append(" col ");
    sb.append("where col.colPath=:path ");
    if (token != null) {
        /* We want any undeleted alias or external subscription or 
         any collection with a later change token.
       */
        sb.append(" and ((col.calType=7 or col.calType=8) or " + "(col.lastmod.timestamp>:lastmod" + "   or (col.lastmod.timestamp=:lastmod and " + "  col.lastmod.sequence>:seq)))");
    } else {
        // No deleted collections for null sync-token
        sb.append("and (col.filterExpr is null or col.filterExpr <> :tsfilter)");
    }
    sess.createQuery(sb.toString());
    sess.setString("path", path);
    if (token != null) {
        sess.setString("lastmod", token.substring(0, 16));
        sess.setInt("seq", Integer.parseInt(token.substring(17), 16));
    } else {
        sess.setString("tsfilter", BwCalendar.tombstonedFilter);
    }
    sess.cacheableQuery();
    return sess.getList();
}
Also used : HibSession(org.bedework.calcorei.HibSession) CalFacadeBadRequest(org.bedework.calfacade.exc.CalFacadeBadRequest) CalFacadeInvalidSynctoken(org.bedework.calfacade.exc.CalFacadeInvalidSynctoken) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 8 with HibSession

use of org.bedework.calcorei.HibSession in project bw-calendar-engine by Bedework.

the class CoreCalendarsDAO method removeTombstoned.

protected void removeTombstoned(final String path) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(removeTombstonedCollectionEventsQuery);
    sess.setString("path", path);
    sess.executeUpdate();
    sess.createQuery(getTombstonedCollectionsQuery);
    sess.setString("path", path);
    sess.setString("tsfilter", BwCalendar.tombstonedFilter);
    @SuppressWarnings("unchecked") final List<BwCalendar> cols = sess.getList();
    if (!Util.isEmpty(cols)) {
        for (final BwCalendar col : cols) {
            sess.delete(col);
        }
    }
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 9 with HibSession

use of org.bedework.calcorei.HibSession in project bw-calendar-engine by Bedework.

the class CoreEventPropertiesDAO method getRefsCount.

private long getRefsCount(final BwEventProperty val, final String query) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(query);
    sess.setEntity("ent", val);
    /* May get multiple counts back for events and annotations. */
    @SuppressWarnings("unchecked") final Collection<Long> counts = sess.getList();
    long total = 0;
    if (debug) {
        debug(" ----------- count = " + counts.size());
        if (counts.size() > 0) {
            debug(" ---------- first el class is " + counts.iterator().next().getClass().getName());
        }
    }
    for (final Long l : counts) {
        total += l;
    }
    return total;
}
Also used : HibSession(org.bedework.calcorei.HibSession)

Example 10 with HibSession

use of org.bedework.calcorei.HibSession in project bw-calendar-engine by Bedework.

the class CoreEventPropertiesDAO method checkUnique.

public void checkUnique(final BwString val, final String ownerHref) throws CalFacadeException {
    if (findCountQuery == null) {
        findCountQuery = "select count(*) from " + className + " ent where ";
    }
    doFind(findCountQuery, val, ownerHref);
    final HibSession sess = getSess();
    // noinspection unchecked
    final Collection<Long> counts = sess.getList();
    if (counts.iterator().next() > 1) {
        sess.rollback();
        throw new CalFacadeException("org.bedework.duplicate.object");
    }
}
Also used : HibSession(org.bedework.calcorei.HibSession) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

HibSession (org.bedework.calcorei.HibSession)60 Collection (java.util.Collection)4 BwCalendar (org.bedework.calfacade.BwCalendar)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 BwGroup (org.bedework.calfacade.BwGroup)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 BwEvent (org.bedework.calfacade.BwEvent)2 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)2 BwEventProperty (org.bedework.calfacade.BwEventProperty)2 BwEventProxy (org.bedework.calfacade.BwEventProxy)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 BwCalSuite (org.bedework.calfacade.svc.BwCalSuite)2 BwCategory (org.bedework.calfacade.BwCategory)1 BwContact (org.bedework.calfacade.BwContact)1 BwDateTime (org.bedework.calfacade.BwDateTime)1 BwFilterDef (org.bedework.calfacade.BwFilterDef)1 BwLocation (org.bedework.calfacade.BwLocation)1 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)1