I'm using Android's Room library for the database interaction in an application and I'm sort of stumped on how to prevent duplicate entries from being inserted into the database.
I feel like I must be missing something because this seems like it should be simple to do. I've searched Google for various combinations of words relating to the subject to no avail.
I'm essentially using what one of the samples does for inserting and querying.
The Entity:
@Entity(tableName = "cameras")
public class CameraEntity {
@PrimaryKey(autoGenerate = true)
private int id;
private Integer accountId;
private Integer dvrId;
private String vendorId;
...
}
The DAO:
@Dao
public interface CameraDao {
@Query("SELECT * FROM cameras")
Flowable<List<CameraEntity>> getCameras();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<CameraEntity> values);
}
In terms of the Room library, is there any way to set some rules on when data should be inserted? One post I read mentioned that the auto increment ID is causing each item to be unique in terms of the primary key. If that's true, how are others using this library accounting for that?
Thanks!
CameraEntity
listing is redacted. – Lipoid