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