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.

@OrmliteDao and RuntimeExceptionDao #628

Description

@tbruyelle

As mentionned in the ormlite documentation :

By default, most of the DAO methods throw SQLException which is the default internal exception for most JDBC and other SQL calls. But in Android-land, especially, most of the exceptions extend RuntimeException so having to put a lot of ignored try ... catch stanzas is inconvenient.
For this reason we’ve added a RuntimeExceptionDao which wraps all calls to the underlying DAO to rethrow the SQL exceptions as runtime exceptons.

I think the @OrmliteDao annotation should handle this. The annotated field type could be Dao or RuntimExceptionDao (currently only Dao is accepted), and according to this type, the relevant constructor will be used to assign the field.

Activity

  1. DayS commented on Jun 16, 2013

    @DayS
    Contributor

    Merged

  2. yDelouis commented on Jun 18, 2013

    @yDelouis
    Contributor

    This issue can be closed I think, unless you want to add a note in the wiki.

  3. tbruyelle commented on Jun 19, 2013

    @tbruyelle
    ContributorAuthor

    Yes we should simply tell the class RuntimeExceptionDao is also supported. Sorry I didn't find how to edit/contribute to the wiki. Can you tell me?

  4. DayS commented on Jun 20, 2013

    @DayS
    Contributor
  5. gbero commented on Oct 1, 2014

    @gbero

    Hi,

    I was wondering why not use databaseHelper_.getRuntimeExceptionDao(Entity.class) instead of using
    RuntimeExceptionDao.createDao(databaseHelper_.getConnectionSource(), Entity.class).

    The method without RuntimeException is already using databaseHelper_.getDao(Entity.class)

    I can't cast my object that extends from RuntimeExceptionDao<Entity, Integer>

  6. WonderCsabo commented on Oct 1, 2014

    @WonderCsabo
    Member

    The OrmLiteSqliteOpenHelper.getRuntimeExceptionDao method has a note in its javadoc:

    NOTE: This routing does not return RuntimeExceptionDao because of casting issues if we are assigning it to a custom DAO. Grumble.

  7. gbero commented on Oct 1, 2014

    @gbero

    I'm getting confused...

    Same remark is put in the Javadoc for the getDao...

    My code worked well when using @OrmLiteDao annotations on custom dao classes extending from BaseDaoImpl

    getDao

    public <D extends com.j256.ormlite.dao.Dao<T,?>,T> D getDao(Class clazz)
    throws SQLException
    Get a DAO for our class. This uses the DaoManager to cache the DAO for future gets.
    NOTE: This routing does not return Dao because of casting issues if we are assigning it to a custom DAO. Grumble.

    Throws:
    SQLException

  8. WonderCsabo commented on Oct 1, 2014

    @WonderCsabo
    Member

    Yeah, this note is also on the getDao method of OrmLiteSqliteOpenHelper.

    Can yo confirm that both OrmLiteSqliteOpenHelper.getRuntimeExceptionDao and OrmLiteSqliteOpenHelper.getDao returns the correct instance?

  9. gbero commented on Oct 1, 2014

    @gbero

    For me it's working fine usign getDao. Injection worked perfectly well.

    I don't understand why the javadoc state that... ?

    And when I'm trying to use @OrmliteDao on a RuntimeExceptionDao, I end up with a casting problem when generating the file. The compiler refuses to cast.

    entityDao = RuntimeExceptionDao.createDao(databaseHelper_.getConnectionSource(), Entity.class); ---> produce the compilation error

    My EntityDao classed is defined as :

    public class EntityDao extends RuntimeExceptionDao<Entity, Integer> {
    
      public EntityDao(Dao<Entity, Integer> dao) {
        super(dao);
      }
    
    }
    
  10. WonderCsabo commented on Oct 1, 2014

    @WonderCsabo
    Member

    Maybe the javadoc is outdated, or we misunderstood it. Either way, please ask this question on the OrmLite project.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions