I have the app that uses ActiveAndroid ORM
and I need to save list of models with inner list and objects, that looks like this:
public class MyModel extends Model{
@Expose
@SerializedName(Columns.COLUMN_CREATED_AT)
@Column(name=Columns.COLUMN_CREATED_AT)
private Date createdAt;
.... and other fields
@Expose
@SerializedName(Columns.User)
public User users;
.... another objects
}
so, the current logic that saves List<MyModel>
do next:
1) makes all update in ActiveAndroid.beginTransaction() / ActiveAndroid.endTransaction();
block
2) for each MyModel
user model
retrieves from db, updates and saves
3) each MyModel
retrieves from db, updates and saves
so the whole process takes about 7-9 seconds.
As the user
(and others inner objects) can be the same in different MyModel
objects i've do the next:
in the loop that saves MyModel
I gets the users
and put it to HashMap
, so i got the list of unique users and saves it after MyModel
updates. (but the same transaction). now it saves data for 3-4 seconds.
BUT, looks ActiveAndroid
makes some references between MyModel
and User
table, so when i tried to remove users from table i got an exception:
FOREIGN KEY constraint failed
so, how can i deal with it?
As ActiveAndroid
is not supported for last 3 years... the solution for me was to migrate to another orm
.
one more reason against ActiveAndroid
- is slower than others