我的项目分为三个模块(多层架构): 应用程序(我有我的活动) 商业逻辑 DAO(我在哪里使用greenDAO版本3)
我需要知道从DAO层打开数据库会话的最佳方法,我没有任何活动(在这一刻我发送活动就像一个参数)。
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)这是我的问题,我想在哪里参加会议
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);
}
由于