Ejemplo n.º 1
0
  /**
   * @see
   *     org.programmerplanet.crm.data.dao.ObjectDataDao#updateObject(org.programmerplanet.crm.data.ObjectData)
   */
  public void updateObject(ObjectData objectData) {
    ObjectDefinition objectDefinition = objectData.getObjectDefinition();
    List<FieldDefinition> fieldDefinitions = objectData.getFieldDefinitions();
    Map<String, Object> data = objectData.getData();
    UUID id = objectData.getId();
    List parameters = new ArrayList();
    StringBuffer sql = new StringBuffer();
    sql.append("UPDATE ");
    sql.append(objectDefinition.getTableName());
    sql.append(" SET ");

    for (FieldDefinition fieldDefinition : fieldDefinitions) {
      // special case - skip update of autonumber field
      if (fieldDefinition.getDataType().equals(DataType.AUTO_NUMBER)) {
        continue;
      }
      String columnName = fieldDefinition.getColumnName();
      Object value = data.get(columnName);
      sql.append(columnName);
      if (value instanceof UUID) {
        sql.append(" = ?::uuid, ");
        value = value.toString();
      } else {
        sql.append(" = ?, ");
      }
      parameters.add(value);
    }
    sql.delete(sql.length() - 2, sql.length());
    sql.append(" WHERE id = ?::uuid");
    parameters.add(id.toString());
    this.getJdbcTemplate().update(sql.toString(), parameters.toArray());
  }
Ejemplo n.º 2
0
 private void convertUUIDValues(Map object, List<FieldDefinition> fieldDefinitions) {
   convertUUIDValue(object, "id");
   for (FieldDefinition fieldDefinition : fieldDefinitions) {
     if (fieldDefinition.getDataType().equals(DataType.OBJECT)) {
       String columnName = fieldDefinition.getColumnName();
       convertUUIDValue(object, columnName);
     }
   }
 }
Ejemplo n.º 3
0
 /**
  * @see
  *     org.programmerplanet.crm.data.dao.ObjectDataDao#insertObject(org.programmerplanet.crm.data.ObjectData)
  */
 public UUID insertObject(ObjectData objectData) {
   ObjectDefinition objectDefinition = objectData.getObjectDefinition();
   List<FieldDefinition> fieldDefinitions = objectData.getFieldDefinitions();
   Map<String, Object> data = objectData.getData();
   UUID id = UUID.randomUUID();
   List parameters = new ArrayList();
   StringBuffer sql = new StringBuffer();
   sql.append("INSERT INTO ");
   sql.append(objectDefinition.getTableName());
   sql.append(" (id, ");
   parameters.add(id);
   for (FieldDefinition fieldDefinition : fieldDefinitions) {
     String columnName = fieldDefinition.getColumnName();
     sql.append(columnName);
     sql.append(", ");
     Object value = data.get(columnName);
     // special case - set autonumber field manually
     if (fieldDefinition.getDataType().equals(DataType.AUTO_NUMBER)) {
       value = getNextAutoNumberValue(objectDefinition, fieldDefinition);
     }
     parameters.add(value);
   }
   sql.delete(sql.length() - 2, sql.length());
   sql.append(") VALUES (");
   for (int i = 0; i < parameters.size(); i++) {
     Object parameter = parameters.get(i);
     if (parameter instanceof UUID) {
       sql.append("?::uuid, ");
       parameters.set(i, parameter.toString());
     } else {
       sql.append("?, ");
     }
   }
   sql.delete(sql.length() - 2, sql.length());
   sql.append(")");
   this.getJdbcTemplate().update(sql.toString(), parameters.toArray());
   objectData.setId(id);
   return id;
 }