shillelagh-processor/src/main/java/shillelagh/internal/TableObject.java
private void emitUpdate(JavaWriter javaWriter) throws IOException {
    logger.d("emitUpdate");
    javaWriter.beginMethod("void", $$UPDATE_OBJECT_FUNCTION, EnumSet.of(PUBLIC, STATIC),
        getTargetClass(), "element", "SQLiteDatabase", "db")
        .emitStatement("ContentValues values = new ContentValues()");

    for (TableColumn column : columns) {
      String columnName = column.getColumnName();
      String memberName = column.getMemberName();
      if (column.getSqlType() == SqliteType.BLOB && !column.isByteArray()) {
        javaWriter.emitStatement("values.put(\"%s\", %s(element.%s))", columnName,
            SERIALIZE_FUNCTION, memberName);
      } else if (column.isOneToOne()) {
        javaWriter.emitStatement("values.put(\"%s\", %s%s.%s(element.%s))", columnName,
            column.getType(), $$SUFFIX, GET_ID_FUNCTION, memberName);
      } else if (column.isDate()) {
        javaWriter.emitStatement("values.put(\"%s\", element.%s.getTime())", columnName,
            memberName);
      } else if (column.isOneToMany()) {
        javaWriter.beginControlFlow("for (%s child : element.%s)",
            column.getType().replace("$", "."), column.getColumnName())
            .emitStatement("%s%s.%s(child, db)", column.getType(), $$SUFFIX,
                $$UPDATE_OBJECT_FUNCTION)
            .endControlFlow();
      } else if (column.isOneToManyChild()) {
        // TODO: actually no way of actually updating this value directly add a wrapper?
      } else {
        javaWriter.emitStatement("values.put(\"%s\", element.%s)", columnName, memberName);
      }
    }
    javaWriter.emitStatement("db.update(\"%s\", values, \"%s = \" + element.%s, null)",
        getTableName(), idColumn.getColumnName(), idColumn.getMemberName());
    javaWriter.endMethod();
  }
private void emitUpdate(JavaWriter javaWriter) throws IOException {
    logger.d("emitUpdate");
    javaWriter.beginMethod("void", $$UPDATE_OBJECT_FUNCTION, EnumSet.of(PUBLIC, STATIC),
        getTargetClass(), "element", "SQLiteDatabase", "db")
        .emitStatement("ContentValues values = new ContentValues()");

    for (TableColumn column : columns) {
      String columnName = column.getColumnName();
      String memberName = column.getMemberName();
      if (column.getSqlType() == SqliteType.BLOB && !column.isByteArray()) {
        javaWriter.emitStatement("values.put(\"%s\", %s(element.%s))", columnName,
            SERIALIZE_FUNCTION, memberName);
      } else if (column.isOneToOne()) {
        javaWriter.emitStatement("values.put(\"%s\", %s%s.%s(element.%s))", columnName,
            column.getType(), $$SUFFIX, GET_ID_FUNCTION, memberName);
      } else if (column.isDate()) {
        javaWriter.emitStatement("values.put(\"%s\", element.%s.getTime())", columnName,
            memberName);
      } else if (column.isOneToMany()) {
        javaWriter.beginControlFlow("for (%s child : element.%s)",
            column.getType().replace("$", "."), column.getColumnName())
            .emitStatement("%s%s.%s(child, db)", column.getType(), $$SUFFIX,
                $$UPDATE_OBJECT_FUNCTION)
            .endControlFlow();
      } else if (column.isOneToManyChild()) {
        // TODO: actually no way of actually updating this value directly add a wrapper?
      } else {
        javaWriter.emitStatement("values.put(\"%s\", element.%s)", columnName, memberName);
      }
    }
    javaWriter.emitStatement("db.update(\"%s\", values, \"%s = \" + element.%s, null)",
        getTableName(), idColumn.getColumnName(), idColumn.getMemberName());
    javaWriter.endMethod();
  }
private void emitUpdate ( JavaWriter javaWriter ) throws IOException { logger . d ( "emitUpdate" ) ; javaWriter . beginMethod ( "void" , $$ UPDATE_OBJECT_FUNCTION , EnumSet . of ( PUBLIC , STATIC ) , getTargetClass ( ) , "element" , "SQLiteDatabase" , "db" ) . emitStatement ( "ContentValues values = new ContentValues()" ) ; for ( TableColumn column : columns ) { String columnName = column . getColumnName ( ) ; String memberName = column . getMemberName ( ) ; if ( column . getSqlType ( ) == SqliteType . BLOB && ! column . isByteArray ( ) ) { javaWriter . emitStatement ( "values.put(\"%s\", %s(element.%s))" , columnName , SERIALIZE_FUNCTION , memberName ) ; } else if ( column . isOneToOne ( ) ) { javaWriter . emitStatement ( "values.put(\"%s\", %s%s.%s(element.%s))" , columnName , column . getType ( ) , $$ SUFFIX , GET_ID_FUNCTION , memberName ) ; } else if ( column . isDate ( ) ) { javaWriter . emitStatement ( "values.put(\"%s\", element.%s.getTime())" , columnName , memberName ) ; } else if ( column . isOneToMany ( ) ) { javaWriter . beginControlFlow ( "for (%s child : element.%s)" , column . getType ( ) . replace ( "$" , "." ) , column . getColumnName ( ) ) . emitStatement ( "%s%s.%s(child, db)" , column . getType ( ) , $$ SUFFIX , $$ UPDATE_OBJECT_FUNCTION ) . endControlFlow ( ) ; } else if ( column . isOneToManyChild ( ) ) { // TODO: actually no way of actually updating this value directly add a wrapper? } else { javaWriter . emitStatement ( "values.put(\"%s\", element.%s)" , columnName , memberName ) ; } } javaWriter . emitStatement ( "db.update(\"%s\", values, \"%s = \" + element.%s, null)" , getTableName ( ) , idColumn . getColumnName ( ) , idColumn . getMemberName ( ) ) ; javaWriter . endMethod ( ) ; }
Creates the function for updating an object
Creates the function for updating an object