use of com.xpn.xwiki.objects.BaseElement in project xwiki-platform by xwiki.
the class XWikiHibernateStore method deleteXWikiCollection.
/**
* @deprecated This is internal to XWikiHibernateStore and may be removed in the future.
*/
@Deprecated
public void deleteXWikiCollection(BaseCollection object, XWikiContext inputxcontext, boolean bTransaction, boolean evict) throws XWikiException {
if (object == null) {
return;
}
XWikiContext context = getExecutionXContext(inputxcontext, true);
try {
if (bTransaction) {
checkHibernate(context);
bTransaction = beginTransaction(context);
}
Session session = getSession(context);
// Let's check if the class has a custom mapping
BaseClass bclass = object.getXClass(context);
List<String> handledProps = new ArrayList<String>();
if ((bclass != null) && (bclass.hasCustomMapping()) && context.getWiki().hasCustomMappings()) {
handledProps = bclass.getCustomMappingPropertyList(context);
Session dynamicSession = session.getSession(EntityMode.MAP);
Object map = dynamicSession.get(bclass.getName(), object.getId());
if (map != null) {
if (evict) {
dynamicSession.evict(map);
}
dynamicSession.delete(map);
}
}
if (object.getXClassReference() != null) {
for (BaseElement property : (Collection<BaseElement>) object.getFieldList()) {
if (!handledProps.contains(property.getName())) {
if (evict) {
session.evict(property);
}
if (session.get(property.getClass(), property) != null) {
session.delete(property);
}
}
}
}
// In case of custom class we need to force it as BaseObject to delete the xwikiobject row
if (!"".equals(bclass.getCustomClass())) {
BaseObject cobject = new BaseObject();
cobject.setDocumentReference(object.getDocumentReference());
cobject.setClassName(object.getClassName());
cobject.setNumber(object.getNumber());
if (object instanceof BaseObject) {
cobject.setGuid(((BaseObject) object).getGuid());
}
cobject.setId(object.getId());
if (evict) {
session.evict(cobject);
}
session.delete(cobject);
} else {
if (evict) {
session.evict(object);
}
session.delete(object);
}
if (bTransaction) {
endTransaction(context, true);
}
} catch (Exception e) {
Object[] args = { object.getName() };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT, "Exception while deleting object {0}", e, args);
} finally {
try {
if (bTransaction) {
endTransaction(context, false);
}
} catch (Exception e) {
}
restoreExecutionXContext();
}
}
Aggregations