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<T, ID> 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);
}
}
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();
}
}
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();
}
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);
}
}
Aggregations