/** @return a mapping of all field/value pairs merged across data sources */ public ValuesStorage getMergedValues() { ValuesStorage mergedValues = newValuesStorage(); ValuesStorage defaultValues = getDefaultValues(); if (defaultValues != null) { mergedValues.putAll(defaultValues); } if (values != null) { mergedValues.putAll(values); } if (setValues != null) { mergedValues.putAll(setValues); } return mergedValues; }
/** * Return the value of the specified {@link Property}. The model prioritizes values as follows: * <ol> * <li>values explicitly set using {@link #set(Property, Object)} or a generated setter</li> * <li>values written to the model as a result of fetching it using a {@link SquidDatabase} or constructing it from * a {@link SquidCursor}</li> * <li>the set of default values as specified by {@link #getDefaultValues()}</li> * </ol> * If a value is not found in any of those places, the result depends on the value of the throwOnFail parameter. * If true, an exception will be throw, if false, null is returned. * * @return the value of the specified property * @throws UnsupportedOperationException if the value is not found in the model */ public <TYPE> TYPE get(Property<TYPE> property, boolean throwOnFail) { if (setValues != null && setValues.containsKey(property.getName())) { return getFromValues(property, setValues); } else if (values != null && values.containsKey(property.getName())) { return getFromValues(property, values); } else if (getDefaultValues().containsKey(property.getName())) { return getFromValues(property, getDefaultValues()); } else if (throwOnFail) { throw new UnsupportedOperationException(property.getName() + " not found in model. Make sure the value was set explicitly, read from a cursor," + " or that the model has a default value for this property."); } return null; }
private static void checkCacheIntegrity(AbstractModel model, JSONProperty<?> property, String transitoryKey) { if (!model.hasTransitory(transitoryKey)) { return; } JSONObjectHolder<?> holder = getJSONTransitory(model, transitoryKey); if (model.containsValue(property) || model.getDefaultValues().containsKey(property.getName())) { String jsonValue = model.get(property); if (SqlUtils.equals(holder.jsonString, jsonValue)) { return; } } model.clearTransitory(transitoryKey); }
/** @return a mapping of all field/value pairs merged across data sources */ public ValuesStorage getMergedValues() { ValuesStorage mergedValues = newValuesStorage(); ValuesStorage defaultValues = getDefaultValues(); if (defaultValues != null) { mergedValues.putAll(defaultValues); } if (values != null) { mergedValues.putAll(values); } if (setValues != null) { mergedValues.putAll(setValues); } return mergedValues; }
/** * Return the value of the specified {@link Property}. The model prioritizes values as follows: * <ol> * <li>values explicitly set using {@link #set(Property, Object)} or a generated setter</li> * <li>values written to the model as a result of fetching it using a {@link SquidDatabase} or constructing it from * a {@link SquidCursor}</li> * <li>the set of default values as specified by {@link #getDefaultValues()}</li> * </ol> * If a value is not found in any of those places, the result depends on the value of the throwOnFail parameter. * If true, an exception will be throw, if false, null is returned. * * @return the value of the specified property * @throws UnsupportedOperationException if the value is not found in the model */ public <TYPE> TYPE get(Property<TYPE> property, boolean throwOnFail) { if (setValues != null && setValues.containsKey(property.getName())) { return getFromValues(property, setValues); } else if (values != null && values.containsKey(property.getName())) { return getFromValues(property, values); } else if (getDefaultValues().containsKey(property.getName())) { return getFromValues(property, getDefaultValues()); } else if (throwOnFail) { throw new UnsupportedOperationException(property.getName() + " not found in model. Make sure the value was set explicitly, read from a cursor," + " or that the model has a default value for this property."); } return null; }