Search in sources :

Example 16 with HibSession

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

the class CoreEventsDAO method calendarGuidExists.

/* Return the name of any event which has the same uid
   */
protected String calendarGuidExists(final BwEvent val, final boolean annotation, final boolean adding) throws CalFacadeException {
    final HibSession sess = getSess();
    final StringBuilder sb = new StringBuilder();
    if (!annotation) {
        sb.append(calendarGuidExistsQuery);
    } else {
        sb.append(calendarGuidAnnotationExistsQuery);
    }
    BwEvent testEvent = null;
    if (!adding) {
        if (annotation) {
            if (val instanceof BwEventProxy) {
                final BwEventProxy proxy = (BwEventProxy) val;
                testEvent = proxy.getRef();
            }
            sb.append("ev.override=false and ");
        } else if (!(val instanceof BwEventProxy)) {
            testEvent = val;
        }
    }
    if (testEvent != null) {
        sb.append("ev<>:event and ");
    }
    sb.append("ev.colPath=:colPath and ev.uid = :uid");
    sess.createQuery(sb.toString());
    if (testEvent != null) {
        sess.setEntity("event", testEvent);
    }
    sess.setString("colPath", val.getColPath());
    sess.setString("uid", val.getUid());
    final Collection refs = sess.getList();
    String res = null;
    if (refs.size() != 0) {
        res = (String) refs.iterator().next();
    }
    return res;
}
Also used : HibSession(org.bedework.calcorei.HibSession) Collection(java.util.Collection) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 17 with HibSession

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

the class CoreEventsDAO method getEventAnnotations.

public Iterator<BwEventAnnotation> getEventAnnotations() throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(getEventAnnotationsQuery);
    @SuppressWarnings("unchecked") final Collection<BwEventAnnotation> anns = sess.getList();
    return anns.iterator();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation)

Example 18 with HibSession

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

the class CoreEventsDAO method deleteTombstonedEvent.

protected void deleteTombstonedEvent(final String colPath, final String uid) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(deleteTombstonedEventQuery);
    sess.setString("path", colPath);
    sess.setString("uid", uid);
    sess.executeUpdate();
}
Also used : HibSession(org.bedework.calcorei.HibSession)

Example 19 with HibSession

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

the class CoreEventsDAO method getSynchEventObjects.

protected List getSynchEventObjects(final String path, final String token) throws CalFacadeException {
    final HibSession sess = getSess();
    if (token != null) {
        sess.createQuery(getSynchEventObjectsTokenQuery);
    } else {
        sess.createQuery(getSynchEventObjectsQuery);
    }
    sess.setString("path", path);
    if (token != null) {
        sess.setString("token", token);
    }
    return sess.getList();
}
Also used : HibSession(org.bedework.calcorei.HibSession)

Example 20 with HibSession

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

the class CoreEventsDAO method calendarNameExists.

protected boolean calendarNameExists(final BwEvent val, final boolean annotation, final boolean adding) throws CalFacadeException {
    final HibSession sess = getSess();
    final StringBuilder sb = new StringBuilder();
    if (!annotation) {
        sb.append(calendarNameExistsQuery);
    } else {
        sb.append(calendarNameAnnotationExistsQuery);
    }
    BwEvent testEvent = null;
    if (!adding) {
        if (annotation) {
            if (val instanceof BwEventProxy) {
                final BwEventProxy proxy = (BwEventProxy) val;
                testEvent = proxy.getRef();
            }
            sb.append("ev.override=false and ");
        } else if (!(val instanceof BwEventProxy)) {
            testEvent = val;
        }
    }
    if (testEvent != null) {
        sb.append("ev<>:event and ");
    }
    sb.append("ev.colPath=:colPath and ");
    sb.append("ev.name = :name");
    sess.createQuery(sb.toString());
    if (testEvent != null) {
        sess.setEntity("event", testEvent);
    }
    sess.setString("colPath", val.getColPath());
    sess.setString("name", val.getName());
    final Collection refs = sess.getList();
    final Object o = refs.iterator().next();
    final boolean res;
    /* Apparently some get a Long - others get Integer */
    if (o instanceof Long) {
        final Long ct = (Long) o;
        res = ct > 0;
    } else {
        final Integer ct = (Integer) o;
        res = ct > 0;
    }
    return res;
}
Also used : HibSession(org.bedework.calcorei.HibSession) Collection(java.util.Collection) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

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