Search in sources :

Example 11 with Dao

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

the class Approval method deleteExpiredApprovals.

public static synchronized void deleteExpiredApprovals(Dao<Approval, Long> db, Long temporaryApprovalSeconds) throws SQLException {
    DeleteBuilder deleteExpiredPolicyAffectedApprovals = db.deleteBuilder();
    deleteExpiredPolicyAffectedApprovals.where().notIn("type", ApprovalType.READ_TEAM_DATA).and().le("approved_at", new Date(System.currentTimeMillis() - temporaryApprovalSeconds * 1000));
    deleteExpiredPolicyAffectedApprovals.delete();
    DeleteBuilder deleteExpiredReadTeamApprovals = db.deleteBuilder();
    deleteExpiredReadTeamApprovals.where().eq("type", // Always 6 hours
    ApprovalType.READ_TEAM_DATA).and().le("approved_at", new Date(System.currentTimeMillis() - (Policy.READ_TEAM_TEMPORARY_APPROVAL_SECONDS) * 1000));
    deleteExpiredReadTeamApprovals.delete();
}
Also used : DeleteBuilder(com.j256.ormlite.stmt.DeleteBuilder) Date(java.util.Date)

Example 12 with Dao

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

the class TableFactory method createTable.

private void createTable(Class tableClass, ConnectionSource connectionSource) throws Throwable {
    int result = 0;
    String logTableName = this.getDatabaseName() + "/" + getTableName(tableClass);
    try {
        result = ApsTableUtils.createTable(connectionSource, tableClass);
        if (result > 0) {
            _logger.info("Created table - {}", logTableName);
            Object tableModel = tableClass.newInstance();
            if (tableModel instanceof ExtendedColumnDefinition) {
                String[] extensions = ((ExtendedColumnDefinition) tableModel).extensions(this.getType());
                if (null != extensions && extensions.length > 0) {
                    Dao dao = DaoManager.createDao(connectionSource, tableClass);
                    for (int i = 0; i < extensions.length; i++) {
                        String query = extensions[i];
                        dao.executeRaw(query);
                    }
                }
            }
        } else {
            throw new RuntimeException("Error creating table from class " + logTableName);
        }
    } catch (Throwable t) {
        _logger.error("Error creating table {}", logTableName, t);
        if (result > 0) {
            TableUtils.dropTable(connectionSource, tableClass, true);
        }
        throw new ApsSystemException("Error creating table " + logTableName, t);
    }
}
Also used : Dao(com.j256.ormlite.dao.Dao) ExtendedColumnDefinition(org.entando.entando.aps.system.init.model.ExtendedColumnDefinition) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 13 with Dao

use of com.j256.ormlite.dao.Dao in project BachelorPraktikum by lucasbuschlinger.

the class VaultDAO method initDb.

/**
 * Initializes the actual database as a {@link JdbcConnectionSource}.
 *
 * @throws SQLException Thrown if the database can not be successfully initialized.
 */
private void initDb() throws SQLException {
    // create a connection source to our database
    connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "", new HsqldbDatabaseType());
    // instantiate the DAO
    vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
    if (!vaultDao.isTableExists()) {
        TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
    } else {
        LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
    }
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
Also used : VaultEntry(de.opendiabetes.vault.container.VaultEntry) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) HsqldbDatabaseType(com.j256.ormlite.db.HsqldbDatabaseType)

Example 14 with Dao

use of com.j256.ormlite.dao.Dao in project ETSMobile-Android2 by ApplETS.

the class NoteManager method deleteExpiredElementsEvaluation.

/**
 * Deletes marks in DB that doesn't exist on API
 *
 * @param
 */
public void deleteExpiredElementsEvaluation(ListeDesElementsEvaluation listeDesElementsEvaluation) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, ElementEvaluation> elementEvaluationHashMap = new HashMap<String, ElementEvaluation>();
    for (ElementEvaluation elem : listeDesElementsEvaluation.liste) {
        String id = listeDesElementsEvaluation.id + elem.nom;
        elementEvaluationHashMap.put(id, elem);
    }
    List<ElementEvaluation> elementEvaluationList = null;
    try {
        Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
        QueryBuilder<ElementEvaluation, String> builder = elementsEvaluationDao.queryBuilder();
        Where where = builder.where();
        where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
        elementEvaluationList = builder.query();
        for (ElementEvaluation element : elementEvaluationList) {
            if (!elementEvaluationHashMap.containsKey(element.id))
                elementsEvaluationDao.deleteById(element.id);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Where(com.j256.ormlite.stmt.Where) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

Example 15 with Dao

use of com.j256.ormlite.dao.Dao in project ETSMobile-Android2 by ApplETS.

the class NoteManager method getElementsEvaluation.

public List<ElementEvaluation> getElementsEvaluation(ListeDesElementsEvaluation listeDesElementsEvaluation) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    List<ElementEvaluation> elementEvaluationList = null;
    try {
        Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
        QueryBuilder<ElementEvaluation, String> builder = elementsEvaluationDao.queryBuilder();
        Where where = builder.where();
        where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
        elementEvaluationList = builder.query();
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
    return elementEvaluationList;
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) Where(com.j256.ormlite.stmt.Where) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

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