use of org.bedework.calfacade.base.BwDbentity in project bw-calendar-engine by Bedework.
the class HibSessionImpl method beforeDelete.
private void beforeDelete(final Object o) throws CalFacadeException {
if (!(o instanceof BwDbentity)) {
return;
}
BwDbentity ent = (BwDbentity) o;
ent.beforeDeletion();
}
use of org.bedework.calfacade.base.BwDbentity in project bw-calendar-engine by Bedework.
the class ESQueryFilter method getValue.
private Object getValue(final ObjectFilter of) throws CalFacadeException {
Object o = of.getEntity();
Collection c = null;
boolean isString = o instanceof String;
if (!isString) {
if (o instanceof Collection) {
c = (Collection) o;
if (c.size() > 0) {
o = c.iterator().next();
isString = o instanceof String;
}
}
}
boolean doCaseless = isString && of.getCaseless();
if (c != null) {
// TODO - Assuming String collection
List res = new ArrayList();
for (Object co : c) {
String s = (String) co;
if (doCaseless) {
s = s.toLowerCase();
}
res.add(s);
}
return res;
}
if (o instanceof BwCalendar) {
BwCalendar cal = (BwCalendar) o;
return cal.getPath();
}
if (o instanceof BwPrincipal) {
return ((BwPrincipal) o).getPrincipalRef();
}
if (o instanceof BwDbentity) {
warn("Got db entity in search " + o);
return "";
}
if (of.getExact()) {
if (doCaseless) {
o = ((String) o).toLowerCase();
}
return o;
}
if (of.getEntity() instanceof String) {
String s = o.toString();
if (doCaseless) {
s = s.toLowerCase();
}
// warn("Fuzzy search for " + of);
return s;
// sess.setString(parPrefix + qi, "%" + s + "%");
}
// sess.setString(parPrefix + qi, "%" + o + "%");
warn("Fuzzy search for " + of);
return "";
}
use of org.bedework.calfacade.base.BwDbentity in project bw-calendar-engine by Bedework.
the class Filters method parReplace.
/* Fill in the parameters after we generated the query.
*/
private void parReplace(final FilterBase f) throws CalFacadeException {
if (f instanceof AndFilter) {
AndFilter fb = (AndFilter) f;
for (FilterBase flt : fb.getChildren()) {
parReplace(flt);
}
return;
}
if (f instanceof BwHrefFilter) {
BwHrefFilter hf = (BwHrefFilter) f;
// Special case this
sess.setString(parPrefix + qi, hf.getPathPart());
qi++;
sess.setString(parPrefix + qi, hf.getNamePart());
qi++;
}
if (f instanceof BwCategoryFilter) {
BwCategoryFilter cf = (BwCategoryFilter) f;
BwCategory cat = cf.getEntity();
/* XXX - this is what we want to be able to do
sess.setString(parPrefix + qi, cat.getUid());
*/
sess.setEntity(parPrefix + qi, cat);
qi++;
return;
}
if (f instanceof EntityTimeRangeFilter) {
doEntityTimeRangeReplace((EntityTimeRangeFilter) f);
return;
}
if (f instanceof TimeRangeFilter) {
TimeRangeFilter trf = (TimeRangeFilter) f;
TimeRange tr = trf.getEntity();
if (tr.getStart() != null) {
sess.setParameter(parPrefix + qi, tr.getStart().toString());
qi++;
}
if (tr.getEnd() != null) {
sess.setParameter(parPrefix + qi, tr.getEnd().toString());
qi++;
}
return;
}
if (f instanceof BwObjectFilter) {
ObjectFilter of = ((BwObjectFilter) f).getEntity();
Object o = of.getEntity();
Collection c = null;
boolean isString = o instanceof String;
if (!isString) {
if (o instanceof Collection) {
c = (Collection) o;
if (c.size() > 0) {
o = c.iterator().next();
isString = o instanceof String;
}
}
}
boolean doCaseless = isString && of.getCaseless();
if (c != null) {
// TODO - Assuming String collection
for (Object co : c) {
String s = (String) co;
if (doCaseless) {
s = s.toLowerCase();
}
sess.setParameter(parPrefix + qi, s);
qi++;
}
return;
}
if (o instanceof BwCalendar) {
BwCalendar cal = unwrap((BwCalendar) o);
sess.setString(parPrefix + qi, cal.getPath());
} else if (o instanceof BwPrincipal) {
sess.setString(parPrefix + qi, ((BwPrincipal) o).getPrincipalRef());
} else if (o instanceof BwDbentity) {
sess.setEntity(parPrefix + qi, o);
} else if (of.getExact()) {
if (doCaseless) {
o = ((String) o).toLowerCase();
}
sess.setParameter(parPrefix + qi, o);
} else if (of.getEntity() instanceof String) {
String s = o.toString();
if (doCaseless) {
s = s.toLowerCase();
}
sess.setString(parPrefix + qi, "%" + s + "%");
} else {
sess.setString(parPrefix + qi, "%" + o + "%");
}
qi++;
return;
}
if (f instanceof OrFilter) {
OrFilter fb = (OrFilter) f;
for (FilterBase flt : fb.getChildren()) {
parReplace(flt);
}
return;
}
}
use of org.bedework.calfacade.base.BwDbentity in project bw-calendar-engine by Bedework.
the class HibSessionImpl method beforeSave.
private void beforeSave(final Object o) throws CalFacadeException {
if (!(o instanceof BwDbentity)) {
return;
}
BwDbentity ent = (BwDbentity) o;
ent.beforeSave();
}
use of org.bedework.calfacade.base.BwDbentity in project bw-calendar-engine by Bedework.
the class HibSessionImpl method deleteSubs.
private void deleteSubs(final Object o) throws CalFacadeException {
if (!(o instanceof BwDbentity)) {
return;
}
BwDbentity ent = (BwDbentity) o;
Collection<BwDbentity> subs = ent.getDeletedEntities();
if (subs == null) {
return;
}
for (BwDbentity sub : subs) {
evict(sub);
delete(sub);
}
}
Aggregations