Daniel Alvarez
Senior Software Engineer. Android, iOS, Firebase.
Marzo 2018
Librería para el mapeo de objetos SQLite
ListActivity
ContactActivity
AppDatabase
Gestor de la base de datos, sirve como principal punto de acceso a la base de datos relacional para su configuración
Entity
Representa una tabla en la base de datos
DAO
Contiene los métodos para acceder a la base de datos
@Entity(tableName = "contacts")
@TypeConverters(DateConverter.class)
public class Contact {
@PrimaryKey(autoGenerate = true)
private long id;
private String name;
private String address;
private Date birthday;
private String phone;
private String email;
@Dao
public interface ContactDao {
@Query("SELECT * FROM contacts ORDER BY name ASC")
LiveData<List<Contact>> findAllContacts();
@Query("SELECT * FROM contacts")
List<Contact> getAllContacts();
@Query("SELECT * FROM contacts WHERE id=:id")
Contact findContactById(String id);
@Query("SELECT * FROM contacts WHERE id=:id")
Contact findContact(long id);
@Insert(onConflict = IGNORE)
long insertContacto(Contact contact);
@Update
int updateContact(Contact contact);
@Update
void updateContact(List<Contact> contacts);
@Delete
void deleteContact(Contact contact);
@Query("DELETE FROM contacts")
void deleteAll();
}
@Database(entities = {Contact.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
public abstract ContactDao contactModel();
public static AppDatabase getDatabase(Context context) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "contactos")
.allowMainThreadQueries()
.build();
}
return INSTANCE;
}
Con arquitectura MVP (Modelo Vista Presentador)
UI Tests para Android en Android Studio
By Daniel Alvarez