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;
}
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();
}
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();
}
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();
}
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;
}
Aggregations