public static void parseModelToContentValues(Object model,ContentValues contentValues){
  if (contentValues.size() > 0)   contentValues.clear();
  Class<?> clazz=model.getClass();
  Field[] fields=clazz.getDeclaredFields();
  Class<?> fieldType=null;
  Object fieldVal=null;
  for (  Field field : fields) {
    try {
      if (field.isAccessible() == false)       field.setAccessible(true);
      Column column=field.getAnnotation(Column.class);
      fieldType=field.getType();
      fieldVal=field.get(model);
      if (column == null || fieldVal == null)       continue;
      if (fieldType.equals(int.class)) {
        contentValues.put(column.name(),field.getInt(model));
      }
 else       if (fieldType.equals(Integer.class)) {
        contentValues.put(column.name(),(Integer)field.get(model));
      }
 else       if (fieldType.equals(short.class)) {
        contentValues.put(column.name(),field.getShort(model));
      }
 else       if (fieldType.equals(Short.class)) {
        contentValues.put(column.name(),(Short)field.get(model));
      }
 else       if (fieldType.equals(long.class)) {
        contentValues.put(column.name(),field.getLong(model));
      }
 else       if (fieldType.equals(Long.class)) {
        contentValues.put(column.name(),(Long)field.get(model));
      }
 else       if (fieldType.equals(float.class)) {
        contentValues.put(column.name(),field.getFloat(model));
      }
 else       if (fieldType.equals(Float.class)) {
        contentValues.put(column.name(),(Float)field.get(model));
      }
 else       if (fieldType.equals(double.class)) {
        contentValues.put(column.name(),field.getDouble(model));
      }
 else       if (fieldType.equals(Double.class)) {
        contentValues.put(column.name(),(Double)field.get(model));
      }
 else       if (fieldType.equals(boolean.class)) {
        if (field.getBoolean(model) == true) {
          contentValues.put(column.name(),"1");
        }
 else {
          contentValues.put(column.name(),"0");
        }
      }
 else       if (fieldType.equals(Boolean.class)) {
        if ((Boolean)field.get(model) == true) {
          contentValues.put(column.name(),"1");
        }
 else {
          contentValues.put(column.name(),"0");
        }
      }
 else       if (fieldType.equals(String.class)) {
        contentValues.put(column.name(),(String)field.get(model));
      }
 else       if (fieldType.equals(byte[].class)) {
        contentValues.put(column.name(),(byte[])field.get(model));
      }
 else       if (fieldType.equals(Date.class)) {
        Date date=(Date)field.get(model);
        contentValues.put(column.name(),DateUtils.formatDate2Str(date));
      }
    }
 catch (    IllegalArgumentException e) {
      e.printStackTrace();
    }
catch (    IllegalAccessException e) {
      e.printStackTrace();
    }
  }
}

public static void parseModelToContentValues ( Object model , ContentValues contentValues ) { if ( contentValues . size ( ) > 0 ) contentValues . clear ( ) ; Class < ? > clazz = model . getClass ( ) ; Field [ ] fields = clazz . getDeclaredFields ( ) ; Class < ? > fieldType = null ; Object fieldVal = null ; for ( Field field : fields ) { try { if ( field . isAccessible ( ) == false ) field . setAccessible ( true ) ; Column column = field . getAnnotation ( Column . class ) ; fieldType = field . getType ( ) ; fieldVal = field . get ( model ) ; if ( column == null || fieldVal == null ) continue ; if ( fieldType . equals ( int . class ) ) { contentValues . put ( column . name ( ) , field . getInt ( model ) ) ; } else if ( fieldType . equals ( Integer . class ) ) { contentValues . put ( column . name ( ) , ( Integer ) field . get ( model ) ) ; } else if ( fieldType . equals ( short . class ) ) { contentValues . put ( column . name ( ) , field . getShort ( model ) ) ; } else if ( fieldType . equals ( Short . class ) ) { contentValues . put ( column . name ( ) , ( Short ) field . get ( model ) ) ; } else if ( fieldType . equals ( long . class ) ) { contentValues . put ( column . name ( ) , field . getLong ( model ) ) ; } else if ( fieldType . equals ( Long . class ) ) { contentValues . put ( column . name ( ) , ( Long ) field . get ( model ) ) ; } else if ( fieldType . equals ( float . class ) ) { contentValues . put ( column . name ( ) , field . getFloat ( model ) ) ; } else if ( fieldType . equals ( Float . class ) ) { contentValues . put ( column . name ( ) , ( Float ) field . get ( model ) ) ; } else if ( fieldType . equals ( double . class ) ) { contentValues . put ( column . name ( ) , field . getDouble ( model ) ) ; } else if ( fieldType . equals ( Double . class ) ) { contentValues . put ( column . name ( ) , ( Double ) field . get ( model ) ) ; } else if ( fieldType . equals ( boolean . class ) ) { if ( field . getBoolean ( model ) == true ) { contentValues . put ( column . name ( ) , "1" ) ; } else { contentValues . put ( column . name ( ) , "0" ) ; } } else if ( fieldType . equals ( Boolean . class ) ) { if ( ( Boolean ) field . get ( model ) == true ) { contentValues . put ( column . name ( ) , "1" ) ; } else { contentValues . put ( column . name ( ) , "0" ) ; } } else if ( fieldType . equals ( String . class ) ) { contentValues . put ( column . name ( ) , ( String ) field . get ( model ) ) ; } else if ( fieldType . equals ( byte [ ] . class ) ) { contentValues . put ( column . name ( ) , ( byte [ ] ) field . get ( model ) ) ; } else if ( fieldType . equals ( Date . class ) ) { Date date = ( Date ) field . get ( model ) ; contentValues . put ( column . name ( ) , DateUtils . formatDate2Str ( date ) ) ; } } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } } }
use reflection to parse model ' s value to contentvalues
