更具条件更新实体到数据库 @param t @param where @param args @param @return
(T t, String where, String... args)
| 136 | * @return |
| 137 | */ |
| 138 | public final <T extends IDColumn> int update(T t, String where, String... args) { |
| 139 | if (t == null) { |
| 140 | throw new NullPointerException("更新对象为NULL!"); |
| 141 | } |
| 142 | if (where == null || where.trim().length() < 1) { |
| 143 | throw new NullPointerException("缺少WHERE条件语句!"); |
| 144 | } |
| 145 | ClassInfo<T> classInfo = getClassInfo(t); |
| 146 | String tableName = classInfo.getTableName(); |
| 147 | ContentValues values = classInfo.getContentValues(t); |
| 148 | if (values.size() < 1) { |
| 149 | return -1; |
| 150 | } |
| 151 | values.remove(IDColumn.PRIMARY_KEY); |
| 152 | SQLiteDatabase database = getDatabase(); |
| 153 | database.beginTransaction(); |
| 154 | int row = database.update(tableName, values, where, args); |
| 155 | database.setTransactionSuccessful(); |
| 156 | database.endTransaction(); |
| 157 | close(database); |
| 158 | return row; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * 更新表数据 |
no test coverage detected