public void manipulate(Property p, DataObject dataInner) throws Exception { s_log.debug("checking property: " + p.getName()); Object currentVal = dataInner.get(p.getName()); DataObjectManipulator.SimpleTypeManipulator manip = m_manipulator.getManipulator(p); Object defaultVal = manip.getDefaultValue(); manip.checkEquals(p.getName(), defaultVal, currentVal); }
/** * Attempts to update the Property to a given value. If an invalid failure to update occurs, an * exception is thrown. If the update appears successful, the DataObject is re-fetched from the * database, and the property value compared to what it should be. If they differ, an exception * is thrown. * * @param p The property to update. * @param data The DataObject to save. * @param value The value to update the property with. * @pre p.equals(data.getObjectType.getProperty(p.getName())) */ void setProperty(Property p, DataObject data, Object value) throws Exception { final String propName = p.getName(); OID id = data.getOID(); s_log.debug( "setting property : " + data.getObjectType().getQualifiedName() + "." + data.getObjectType().getName() + "." + p.getName()); // + " to value: " + value); s_log.debug("Old value was: " + data.get(p.getName())); final boolean valueIsNull = (value == null || value instanceof String && ((String) value).length() == 0); boolean savedNullInRequiredField = false; try { data.set(p.getName(), value); data.save(); // This is neccessary since fail cannot be called here. // Its exception would be caught. Need to check this // value after the catch block savedNullInRequiredField = (p.isRequired() && valueIsNull); } catch (Exception t) { if (p.isRequired() && valueIsNull) { return; } if (p.isNullable() && valueIsNull) { String msg = "Failed to save DataObject: " + data.getObjectType().getName(); msg += "\nTried to update nullable property " + p.getName(); msg += " with null value and failed!"; msg += "\nException is: " + t.getMessage(); s_log.debug(msg); throw new CheckedWrapperException(msg, t); } else { s_log.debug("Failed to set property " + p.getName()); s_log.debug("Checking error"); checkSetError(t, p, data, value); // if (DbHelper.getDatabase(getSession().getConnection()) == // DbHelper.DB_POSTGRES) { throw new AbortMetaTestException(); // } else { // return; // } } } if (savedNullInRequiredField) { String msg = "DataObject saved null value in a required Property: " + p.getName(); s_log.debug(msg); throw new Exception(msg); } DataObject fromDatabase = SessionManager.getSession().retrieve(id); Object newValue = fromDatabase.get(p.getName()); checkEquals(p.getName(), value, newValue); }