/** * ** Returns true if the parent records in their respective parent tables exist. ** @return True * if the parent records exist. */ public boolean parentsExist() throws DBException { DBFactory<gDBR> dbFact = this.getFactory(); DBFieldValues myFldVals = this.getFieldValues(); java.util.List<String> parentList = dbFact.getParentTables(); for (String parentTable : parentList) { /* get parent table DBFactory */ Print.logInfo("[%s] Parent table: %s", this.getTableName(), parentTable); DBFactory parentFact = DBFactory.getFactoryByName(parentTable); if (parentFact == null) { Print.logError("Unexpected error finding parent table: " + parentTable); return false; } /* create parent record key with fields from this key */ DBRecordKey parentKey = parentFact.createKey(); // an empty key DBField parentKeyFlds[] = parentFact.getKeyFields(); for (DBField pkf : parentKeyFlds) { String pfn = pkf.getName(); /* get this DBField */ DBField myKeyFld = this.getField(pfn); if (myKeyFld == null) { Print.logError("Unexpected error finding field: [" + this.getTableName() + "] " + pfn); return false; } /* get parent key field value */ Object pkv = myFldVals.getFieldValue(pfn); if (pkv == null) { Print.logError("Unexpected error finding parent field: [" + parentTable + "] " + pfn); return false; } if (myKeyFld.isDefaultValue(pkv)) { Print.logInfo("This key contains a global value, skipping parent check: " + parentTable); parentKey = null; break; } parentKey.setFieldValue(pfn, pkv); } /* check parent existence */ if ((parentKey != null) && !parentKey.exists()) { Print.logError("Parent record does not exist: [" + parentTable + "] " + parentKey); return false; } } return true; }