throws ClassCastException, RuntimeException, IllegalStateException, NullPointerException,
AttributeTypeHasValuesException, NotYetConnectedException, DmsException, DmsDocumentModificationException {
if (oDoc==null) throw new IllegalStateException(getTypeName()+" document not set before calling save() method");
if (DAO.checkConstraints) {
AtrilSession oAdm = DAO.getAdminSession("checkConstraints");
Dms oDms = oAdm.getDms();
DocumentIndexer oIdx = oAdm.getDocumentIndexer();
final Attr[] aAttrs = attributes();
final int nAttrs = (aAttrs==null ? 0 : aAttrs.length);
try {
for (int a=0; a<nAttrs; a++) {
if (aAttrs[a].required && isNull(aAttrs[a].name)) throw new NullPointerException(getTypeName()+" attribute "+aAttrs[a].name+" is required");
if (aAttrs[a].unique && !isNull(aAttrs[a].name)) {
List<Document> oLst;
if (aAttrs[a].dataType.equals(DataType.STRING))
if (getString(aAttrs[a].name).indexOf("'")<0)
oLst = oDms.query(getTypeName()+"$"+aAttrs[a].name+"='"+escape(getString(aAttrs[a].name))+"'");
else
oLst = null;
else if (aAttrs[a].dataType.equals(DataType.NUMBER))
oLst = oDms.query(getTypeName()+"$"+aAttrs[a].name+"="+get(aAttrs[a].name));
else
oLst = null;
if (null!=oLst) {
if (!oLst.isEmpty()) {
String p = parentId();
for (Document d : oLst) {
String q = d.parents().get(0).id();
if (p.equals(q) && !d.id().equals(getId()) &&
d.attribute(aAttrs[a].name).toString().equals(get(aAttrs[a].name))) {
Log.out.debug(getTypeName()+" attribute "+aAttrs[a].name+" unique constraint violation for value "+get(aAttrs[a].name)+" parent document id. is "+p+" previous document id. is "+d.id()+" current document id. is "+getId());
throw new DmsException(getTypeName()+" attribute "+aAttrs[a].name+" unique constraint violation for value "+get(aAttrs[a].name));
} // fi
}
} // fi
}
} // fi (unique)
if (aAttrs[a].fk!=null && !isNull(aAttrs[a].name)) {
try {
BaseModelObject oObj = aAttrs[a].fk.doctype.newInstance();
if (null==oObj.exists(oAdm, aAttrs[a].fk.attrib, get(aAttrs[a].name).toString())) {
throw new DmsException(getTypeName()+" attribute "+aAttrs[a].name+" foreign key violation "+get(aAttrs[a].name).toString()+" referencing "+oObj.getTypeName()+"."+aAttrs[a].fk.attrib);
}
} catch (InstantiationException e) {
Log.out.error("BaseModelObject.save() InstantiationException "+e.getMessage());
} catch (IllegalAccessException e) {
Log.out.error("BaseModelObject.save() IllegalAccessException "+e.getMessage());
}
} // fi (foreign key)
if (aAttrs[a].cc!=null) {
if (!aAttrs[a].cc.check(oAdm, oIdx, this))
throw new DmsException(getTypeName()+" attribute "+aAttrs[a].name+" constraint violation "+aAttrs[a].cc.getClass().getName());
}
} // next
} finally {
if (oAdm!=null) {
if (oAdm.isConnected()) oAdm.disconnect();
if (oAdm.isOpen()) oAdm.close();
}
}
} // fi
AttributeMultiValue oAttr;
Iterator<String> oKeys = keySet().iterator();