Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Add support for ORMLite DAOs #226

Description

@johanpoirier

Hi,

I'm using AA with ORMLite on all my applications. I miss an annotation to declare an ORMLIte DAO in my activites / services / beans.
I would like to have something like that :

@EActivity(R.layout.main)
public class MyActivity extends Activity {

    @OrmLiteDao(model = User.class, helper = DatabaseHelper.class)
    protected UserDao userDao;

}

I'm already working on it but I'd like to have your thoughts on the issue or some advices if you have any.

Thanks,
Johan

Activity

  1. pyricau commented on Jun 8, 2012

    @pyricau
    Contributor

    This is interesting. What would the generated code look like ?

  2. johanpoirier commented on Jun 8, 2012

    @johanpoirier
    ContributorAuthor

    Currently, it looks like this from a EBean annoted class :

    @SuppressWarnings("all")
    private void init_() {
        if (context_ instanceof Activity) {
            Activity activity = ((Activity) context_);
        }
        ConnectionSource connection_source_;
        connection_source_ = OpenHelperManager.getHelper(context_, DatabaseHelper.class).getConnectionSource();
        try {
            userDao = DaoManager.createDao(connection_source_, User.class);
        } catch (SQLException _x) {
        }
    }
    
  3. pyricau commented on Jun 8, 2012

    @pyricau
    Contributor

    Ok, interesting. One thing I don't get though : what is UserDao exactly ? How does DaoManager.createDao knows it should return a UserDao (You give it User.class, not UserDao.class)? I haven't used ORMLite so I'm probably missing something here.

  4. johanpoirier commented on Jun 8, 2012

    @johanpoirier
    ContributorAuthor

    UserDao is an interface extending the ORMLite Dao<T, ID> class which is created with the DaoManager.
    If you want your own methods in your DAO, you have to extend the Dao created by ORMLite.

  5. pyricau commented on Jun 8, 2012

    @pyricau
    Contributor

    Ok, I got it, just had a look at [DaoManager.createDao()](http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/dao/DaoManager.html#createDao(com.j256.ormlite.support.ConnectionSource, java.lang.Class) and saw that it has a parameterized return type that extends Dao parameterized with the input class. This explains the uneeded cast.

    I guess AA validator should check that UserDao extends Dao parameterized with User.

  6. johanpoirier commented on Jun 8, 2012

    @johanpoirier
    ContributorAuthor

    Yes indeed. I have some work to do on the validator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions