-
Notifications
You must be signed in to change notification settings - Fork 1
/
DatabaseUtils.java
36 lines (28 loc) · 1.03 KB
/
DatabaseUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.gmail.fattazzo.activeandroidexample.db.utils;
import android.content.Context;
import com.activeandroid.ActiveAndroid;
import com.activeandroid.Configuration;
import com.gmail.fattazzo.activeandroidexample.db.structure.DatabaseStructure;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;
/**
* @author fattazzo
* <p/>
* date: 21/03/18
*/
@EBean(scope = EBean.Scope.Singleton)
public class DatabaseUtils {
@RootContext
Context context;
public void use(String databaseName) {
DatabaseStructure structure = DatabaseStructureFactory.getStructure(databaseName);
if (structure != null) {
ActiveAndroid.dispose();
Configuration dbConfiguration = new Configuration.Builder(context)
.setDatabaseName(structure.getDatabaseName())
.addModelClasses(structure.getModelClasses())
.create();
ActiveAndroid.initialize(dbConfiguration);
}
}
}