@@ -133,6 +133,7 @@ String getAuthority() {
133
133
return getClass ().getPackage ().getName ();
134
134
}
135
135
136
+ @ Override
136
137
public
137
138
@ NonNull
138
139
Uri getUri (@ NonNull Class model , @ Nullable String uriSuffix ) {
@@ -144,6 +145,7 @@ Uri getUri(@NonNull Class model, @Nullable String uriSuffix) {
144
145
}
145
146
}
146
147
148
+ @ Override
147
149
public
148
150
@ NonNull
149
151
Uri getUri (@ NonNull String modelDbName , @ Nullable String uriSuffix ) {
@@ -229,8 +231,9 @@ protected void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVers
229
231
protected void onPostUpgrade (int oldVersion , int newVersion ) {
230
232
}
231
233
232
- protected long insert (@ NonNull String tableName , @ NonNull ContentValues values ) {
233
- long newId = mDatabase .insert (tableName , null , values );
234
+ @ Override
235
+ protected long insert (@ NonNull String tableName , @ NonNull ContentValues values , @ NonNull Query .ConflictResolution conflictResolution ) {
236
+ long newId = mDatabase .insertWithOnConflict (tableName , null , values , convertEnum (conflictResolution ));
234
237
235
238
if (newId != -1 ) {
236
239
mContext .getContentResolver ().notifyChange (getUri (tableName , null ), null );
@@ -239,13 +242,14 @@ protected long insert(@NonNull String tableName, @NonNull ContentValues values)
239
242
return newId ;
240
243
}
241
244
242
- protected int bulkInsert (@ NonNull String tableName , @ NonNull ContentValues [] valuesArray ) {
245
+ @ Override
246
+ protected int bulkInsert (@ NonNull String tableName , @ NonNull ContentValues [] valuesArray , @ NonNull Query .ConflictResolution conflictResolution ) {
243
247
int nbInsert = 0 ;
244
248
mDatabase .beginTransaction ();
245
249
246
250
try {
247
251
for (ContentValues values : valuesArray ) {
248
- if (mDatabase .insert (tableName , null , values ) != -1 ) {
252
+ if (mDatabase .insertWithOnConflict (tableName , null , values , convertEnum ( conflictResolution ) ) != -1 ) {
249
253
nbInsert ++;
250
254
}
251
255
}
@@ -262,17 +266,19 @@ protected int bulkInsert(@NonNull String tableName, @NonNull ContentValues[] val
262
266
return nbInsert ;
263
267
}
264
268
265
- protected int bulkUpdate (@ NonNull String tableName , @ Nullable String uriSuffix , @ NonNull ContentValues [] valuesArray , @ NonNull Where [][] conditionsArray ) {
269
+ @ Override
270
+ protected int bulkUpdate (@ NonNull String tableName , @ Nullable String uriSuffix , @ NonNull ContentValues [] valuesArray , @ NonNull Where [][] conditionsArray , @ NonNull Query .ConflictResolution conflictResolution ) {
266
271
int nbUpdate = 0 ;
267
272
mDatabase .beginTransaction ();
268
273
269
274
try {
270
275
for (int i = 0 ; i < valuesArray .length ; i ++) {
271
- nbUpdate += mDatabase .update (
276
+ nbUpdate += mDatabase .updateWithOnConflict (
272
277
tableName ,
273
278
valuesArray [i ],
274
279
mClauseHelper .getCondition (conditionsArray [i ]),
275
- mClauseHelper .getConditionArgs (conditionsArray [i ])
280
+ mClauseHelper .getConditionArgs (conditionsArray [i ]),
281
+ convertEnum (conflictResolution )
276
282
);
277
283
}
278
284
@@ -288,6 +294,7 @@ protected int bulkUpdate(@NonNull String tableName, @Nullable String uriSuffix,
288
294
return nbUpdate ;
289
295
}
290
296
297
+ @ Override
291
298
protected
292
299
@ Nullable
293
300
Cursor query (@ NonNull String tableName , @ NonNull String [] columns , @ Nullable Where [] where , @ Nullable Join [] joins ,
@@ -329,6 +336,7 @@ Cursor query(@NonNull String tableName, @NonNull String[] columns, @Nullable Whe
329
336
}
330
337
}
331
338
339
+ @ Override
332
340
protected int delete (@ NonNull String tableName , @ Nullable String uriSuffix , @ Nullable Where [] where ) {
333
341
String whereClause = mClauseHelper .getCondition (where );
334
342
int nbDeleted = mDatabase .delete (
@@ -344,6 +352,7 @@ protected int delete(@NonNull String tableName, @Nullable String uriSuffix, @Nul
344
352
return nbDeleted ;
345
353
}
346
354
355
+ @ Override
347
356
protected long count (@ NonNull String tableName , @ Nullable Where [] where ) {
348
357
return DatabaseUtils .queryNumEntries (
349
358
mDatabase ,
@@ -353,6 +362,7 @@ protected long count(@NonNull String tableName, @Nullable Where[] where) {
353
362
);
354
363
}
355
364
365
+ @ Override
356
366
protected
357
367
@ Nullable
358
368
Cursor rawQuery (@ NonNull String sql ) {
@@ -363,4 +373,20 @@ Cursor rawQuery(@NonNull String sql) {
363
373
SQLiteDatabase getDatabase () {
364
374
return mDatabase ;
365
375
}
376
+
377
+ private int convertEnum (Query .ConflictResolution conflictResolution ) {
378
+ switch (conflictResolution ) {
379
+ case CONFLICT_ABORT :
380
+ return SQLiteDatabase .CONFLICT_ABORT ;
381
+ case CONFLICT_FAIL :
382
+ return SQLiteDatabase .CONFLICT_FAIL ;
383
+ case CONFLICT_REPLACE :
384
+ return SQLiteDatabase .CONFLICT_REPLACE ;
385
+ case CONFLICT_ROLLBACK :
386
+ return SQLiteDatabase .CONFLICT_ROLLBACK ;
387
+ default :
388
+ case CONFLICT_IGNORE :
389
+ return SQLiteDatabase .CONFLICT_IGNORE ;
390
+ }
391
+ }
366
392
}
0 commit comments