Skip to content

Instantly share code, notes, and snippets.

@Abdallah-Abdelazim
Created March 31, 2020 01:44
Show Gist options
  • Save Abdallah-Abdelazim/7fa527f7a8d34517fdd0871e1bd6576c to your computer and use it in GitHub Desktop.
Save Abdallah-Abdelazim/7fa527f7a8d34517fdd0871e1bd6576c to your computer and use it in GitHub Desktop.
A BaseDao interface that provides the methods needed for inserting, updating & deleting an entity in a Room Dao interface.
package com.example.app.data.local.dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Update;
import java.util.List;
/**
* Provides the methods needed for inserting, updating & deleting an entity in a Room Dao interface.
* <br>
* Make your Room Dao interface extends this BaseInterface setting the generic type as the entity
* class. If you need to specify custom attributes on the Dao methods, just override
* them in your Dao.
*
* @param <T> the entity class.
* @author Abdallah Abdelazim
*/
public interface BaseDao<T> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insert(T obj);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long[] insert(T[] objs);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long[] insert(List<? extends T> objList);
@Update
int update(T obj);
@Update
int update(T[] objs);
@Update
int update(List<? extends T> objList);
@Delete
int delete(T obj);
@Delete
int delete(T[] objs);
@Delete
int delete(List<? extends T> objList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment