Exemple #1
0
 /** Clear the key for the given property */
 public synchronized void clearValue(Property<?> property) {
   if (setValues != null && setValues.containsKey(property.getColumnName())) {
     setValues.remove(property.getColumnName());
   }
   if (values != null && values.containsKey(property.getColumnName())) {
     values.remove(property.getColumnName());
   }
 }
Exemple #2
0
 /**
  * @return true if setValues or values contains this property, and the value stored is not null
  */
 public boolean containsNonNullValue(Property<?> property) {
   if (setValues != null && setValues.containsKey(property.getColumnName())) {
     return setValues.get(property.getColumnName()) != null;
   }
   if (values != null && values.containsKey(property.getColumnName())) {
     return values.get(property.getColumnName()) != null;
   }
   return false;
 }
Exemple #3
0
  /** Turn a model into xml attributes */
  private void serializeModel(
      AbstractModel model, Property<?>[] properties, Property<?>... excludes) {
    outer:
    for (Property<?> property : properties) {
      for (Property<?> exclude : excludes) {
        if (property.name.equals(exclude.name)) {
          continue outer;
        }
      }

      try {
        property.accept(xmlWritingVisitor, model);
      } catch (Exception e) {
        Timber.e(e, e.getMessage());
      }
    }
  }
Exemple #4
0
    public synchronized void save(Property<?> property, ContentValues newStore, Object value) {
      this.store = newStore;

      // we don't allow null values, as they indicate unset properties
      // when the database was written

      if (value != null) {
        property.accept(this, value);
      }
    }
  /**
   * Turn a model into xml attributes
   *
   * @param model
   */
  private void serializeModel(
      AbstractModel model, Property<?>[] properties, Property<?>... excludes) {
    outer:
    for (Property<?> property : properties) {
      for (Property<?> exclude : excludes) if (property.name.equals(exclude.name)) continue outer;

      try {
        property.accept(xmlWritingVisitor, model);
      } catch (Exception e) {
        Log.e(
            "astrid-exporter", //$NON-NLS-1$
            "Caught exception while reading "
                + property.name
                + //$NON-NLS-1$
                " from "
                + model.getDatabaseValues(),
            e); //$NON-NLS-1$
      }
    }
  }
Exemple #6
0
  /** Reads the given property. Make sure this model has this property! */
  public synchronized <TYPE> TYPE getValue(Property<TYPE> property) {
    Object value;
    if (setValues != null && setValues.containsKey(property.getColumnName())) {
      value = setValues.get(property.getColumnName());
    } else if (values != null && values.containsKey(property.getColumnName())) {
      value = values.get(property.getColumnName());
    } else if (getDefaultValues().containsKey(property.getColumnName())) {
      value = getDefaultValues().get(property.getColumnName());
    } else {
      throw new UnsupportedOperationException(
          "Model Error: Did not read property " + property.name); // $NON-NLS-1$
    }

    // resolve properties that were retrieved with a different type than accessed
    try {
      if (value instanceof String && property instanceof LongProperty) {
        return (TYPE) Long.valueOf((String) value);
      } else if (value instanceof String && property instanceof IntegerProperty) {
        return (TYPE) Integer.valueOf((String) value);
      } else if (value instanceof Integer && property instanceof LongProperty) {
        return (TYPE) Long.valueOf(((Number) value).longValue());
      }
      return (TYPE) value;
    } catch (NumberFormatException e) {
      return (TYPE) getDefaultValues().get(property.name);
    }
  }
Exemple #7
0
  /**
   * Check whether the user has changed this property value and it should be stored for saving in
   * the database
   */
  protected synchronized <TYPE> boolean shouldSaveValue(Property<TYPE> property, TYPE newValue) {

    // we've already decided to save it, so overwrite old value
    if (setValues.containsKey(property.getColumnName())) {
      return true;
    }

    // values contains this key, we should check it out
    if (values != null && values.containsKey(property.getColumnName())) {
      TYPE value = getValue(property);
      if (value == null) {
        if (newValue == null) {
          return false;
        }
      } else if (value.equals(newValue)) {
        return false;
      }
    }

    // otherwise, good to save
    return true;
  }
Exemple #8
0
 @Override
 public Void visitString(Property<String> property, Object value) {
   store.put(property.getColumnName(), (String) value);
   return null;
 }
Exemple #9
0
 @Override
 public Void visitInteger(Property<Integer> property, Object value) {
   store.put(property.getColumnName(), (Integer) value);
   return null;
 }