mardi 25 août 2015

ActiveAndroid : how to create generic helper method for inserting values to SQLLite in the right way?

I just started using ActiveAndroid library and i faced with following problem:

I would like to create generic helper for CRUD operations (in this case with method for inserting values). Method for inserting should to take following params:

  • ModelName (name or object of the model class) ModelParams (filled

  • List item attributes of the model variables)

  • Or whole instatiated object (maybe should be better)

So calling from controller/activity should be following:

User user = new User();
        user.UserId = 1;
        user.UserLogin = "TEST";
        mDatabaseHelperClass.insertValue(user);

And helper:

public class DatabaseHelperClass {

    public DatabaseHelperClass() {

    }

    public void insertValue(Class model) {
        try {
            model.save();
            Logger.i("SQL insert done!");
        } catch (Exception e) {
            Logger.e(e.getMessage());
        }

    }

}

How can i do something like this in the right and effective way please?

Many thanks for any advice.

Aucun commentaire:

Enregistrer un commentaire