Search in sources :

Example 16 with Dao

use of com.j256.ormlite.dao.Dao in project ormlite-android by j256.

the class OrmLiteSqliteOpenHelper method getRuntimeExceptionDao.

/**
 * Get a RuntimeExceptionDao for our class. This uses the {@link DaoManager} to cache the DAO for future gets.
 *
 * <p>
 * NOTE: This routing does not return RuntimeExceptionDao&lt;T, ID&gt; because of casting issues if we are assigning
 * it to a custom DAO. Grumble.
 * </p>
 */
public <D extends RuntimeExceptionDao<T, ?>, T> D getRuntimeExceptionDao(Class<T> clazz) {
    try {
        Dao<T, ?> dao = getDao(clazz);
        @SuppressWarnings({ "unchecked", "rawtypes" }) D castDao = (D) new RuntimeExceptionDao(dao);
        return castDao;
    } catch (SQLException e) {
        throw new RuntimeException("Could not create RuntimeExcepitionDao for class " + clazz, e);
    }
}
Also used : SQLException(java.sql.SQLException) RuntimeExceptionDao(com.j256.ormlite.dao.RuntimeExceptionDao)

Example 17 with Dao

use of com.j256.ormlite.dao.Dao in project mage by magefree.

the class RepositoryUtil method getDatabaseVersion.

public static long getDatabaseVersion(ConnectionSource connectionSource, String entityName) throws SQLException {
    TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
    Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
    QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
    queryBuilder.where().eq("entity", new SelectArg(entityName));
    List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
    if (dbVersions.isEmpty()) {
        return 0;
    } else {
        return dbVersions.get(0).getVersion();
    }
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg)

Example 18 with Dao

use of com.j256.ormlite.dao.Dao in project mage by magefree.

the class RepositoryUtil method isDatabaseObsolete.

public static boolean isDatabaseObsolete(ConnectionSource connectionSource, String entityName, long version) throws SQLException {
    TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
    Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
    QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
    queryBuilder.where().eq("entity", new SelectArg(entityName)).and().eq("version", new SelectArg(version));
    List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
    if (dbVersions.isEmpty()) {
        DatabaseVersion dbVersion = new DatabaseVersion();
        dbVersion.setEntity(entityName);
        dbVersion.setVersion(version);
        dbVersionDao.create(dbVersion);
    }
    return dbVersions.isEmpty();
}
Also used : SelectArg(com.j256.ormlite.stmt.SelectArg)

Example 19 with Dao

use of com.j256.ormlite.dao.Dao in project mage by magefree.

the class AuthorizedUserRepository method closeDB.

public void closeDB() {
    try {
        if (dao != null && dao.getConnectionSource() != null) {
            DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection(dao.getTableName());
            conn.executeStatement("shutdown compact", 0);
        }
    } catch (SQLException ex) {
        Logger.getLogger(AuthorizedUserRepository.class).error("Error closing authorized_user repository - ", ex);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(com.j256.ormlite.support.DatabaseConnection)

Aggregations

SQLException (java.sql.SQLException)7 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)5 QueryBuilder (com.j256.ormlite.stmt.QueryBuilder)5 SelectArg (com.j256.ormlite.stmt.SelectArg)4 ElementEvaluation (ca.etsmtl.applets.etsmobile.model.ElementEvaluation)3 Where (com.j256.ormlite.stmt.Where)3 Dao (com.j256.ormlite.dao.Dao)2 DeleteBuilder (com.j256.ormlite.stmt.DeleteBuilder)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 OnClickListener (android.view.View.OnClickListener)1 DataManager (ca.etsmtl.applets.etsmobile.http.DataManager)1 MonETSNotificationsRequest (ca.etsmtl.applets.etsmobile.http.MonETSNotificationsRequest)1 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)1 ListeDesElementsEvaluation (ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation)1 MonETSNotification (ca.etsmtl.applets.etsmobile.model.MonETSNotification)1 MonETSNotificationList (ca.etsmtl.applets.etsmobile.model.MonETSNotificationList)1 ExpandableListAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 RuntimeExceptionDao (com.j256.ormlite.dao.RuntimeExceptionDao)1