MCPcopy Index your code
hub / github.com/Sopage/android-orm / insert

Method insert

library/src/main/java/com/sanders/db/DBProxy.java:63–81  ·  view source on GitHub ↗

插入对应实体到数据库 @param t @param @return

(T t)

Source from the content-addressed store, hash-verified

61 * @return
62 */
63 public final <T extends IDColumn> long insert(T t) {
64 if (t == null) {
65 throw new NullPointerException("插入对象为NULL");
66 }
67 ClassInfo<T> classInfo = getClassInfo(t);
68 String tableName = classInfo.getTableName();
69 ContentValues values = classInfo.getContentValues(t);
70 if (values.size() > 0) {
71 SQLiteDatabase database = getDatabase();
72 database.beginTransaction();
73 long id = database.insert(tableName, null, values);
74 t.setPrimaryKey(id);
75 database.setTransactionSuccessful();
76 database.endTransaction();
77 close(database);
78 return id;
79 }
80 return -1;
81 }
82
83 /**
84 * 插入数据

Callers 1

insertOrUpdateMethod · 0.95

Calls 7

getClassInfoMethod · 0.95
getDatabaseMethod · 0.95
closeMethod · 0.95
isEmptyMethod · 0.95
getTableNameMethod · 0.80
getContentValuesMethod · 0.80
setPrimaryKeyMethod · 0.80

Tested by

no test coverage detected