I have my project divided in three modules (multilayered architecture): App (where i have my activities) BusinessLogic DAO (where i am using greenDAO version 3)
And i need to know the best way for opening a DB session from the DAO layer, where i dont have any activity (in this moment i am sending the activiy like a parameter).
Articulo.class:
@Id
Long id;
@NotNull
String nombre;
public Articulo (){}
@Generated(hash = 742341383)
public Articulo(Long id, @NotNull String nombre) {
this.id = id;
this.nombre = nombre;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
App.class:
public static final boolean ENCRYPTED = false;
private DaoSession daoSession;
@Override
public void onCreate() {
super.onCreate();
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, ENCRYPTED ? "notes-db-encrypted" : "notes-db");
Database db = ENCRYPTED ? helper.getEncryptedWritableDb("super-secret") : helper.getWritableDb();
daoSession = new DaoMaster(db).newSession();
}
public DaoSession getDaoSession() {
return daoSession;
}
ArticuoBL.class (businessLogic) HERE IS MY PROBLEM, WHERE I WANT TO GET THE SESSION
private ArticuloDao artDAO;
public ArticuloBL(){}
public void crearArticulo(Activity act){
Articulo art = new Articulo();
art.setId(3l);
art.setNombre("New Article");
DaoSession daoSession = ((App) act.getApplication()).getDaoSession();
artDAO = daoSession.getArticuloDao();
artDAO.insertInTx(art);
}
Thanks