Search in sources :

Example 1 with Dao

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

the class Approval method isGitTagApprovedNow.

public static synchronized boolean isGitTagApprovedNow(Dao<Approval, Long> db, UUID pairingUUID, Long temporaryApprovalSeconds) throws SQLException {
    deleteExpiredApprovals(db, temporaryApprovalSeconds);
    QueryBuilder query = db.queryBuilder();
    return query.where().eq("pairing_uuid", pairingUUID).and().eq("type", ApprovalType.GIT_TAG_SIGNATURES).countOf() > 0;
}
Also used : QueryBuilder(com.j256.ormlite.stmt.QueryBuilder)

Example 2 with Dao

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

the class Approval method isSSHAnyHostApprovedNow.

public static synchronized boolean isSSHAnyHostApprovedNow(Dao<Approval, Long> db, UUID pairingUUID, Long temporaryApprovalSeconds) throws SQLException {
    deleteExpiredApprovals(db, temporaryApprovalSeconds);
    QueryBuilder query = db.queryBuilder();
    return query.where().eq("pairing_uuid", pairingUUID).and().eq("type", ApprovalType.SSH_ANY_HOST).countOf() > 0;
}
Also used : QueryBuilder(com.j256.ormlite.stmt.QueryBuilder)

Example 3 with Dao

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

the class NoteManager method deleteExpiredListeDesElementsEvaluation.

/**
 * Deletes marks in DB that doesn't exist on API
 *
 * @param
 */
private void deleteExpiredListeDesElementsEvaluation(String id) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    try {
        Dao<ListeDesElementsEvaluation, String> listeDesElementsEvaluationDao = dbHelper.getDao(ListeDesElementsEvaluation.class);
        ListeDesElementsEvaluation listeDesElementsEvaluation = listeDesElementsEvaluationDao.queryForId(id);
        if (listeDesElementsEvaluation != null) {
            Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
            DeleteBuilder<ElementEvaluation, String> deleteBuilder = elementsEvaluationDao.deleteBuilder();
            Where where = deleteBuilder.where();
            where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
            deleteBuilder.delete();
        }
        listeDesElementsEvaluationDao.deleteById(id);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ListeDesElementsEvaluation(ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation) Where(com.j256.ormlite.stmt.Where) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

Example 4 with Dao

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

the class BottinFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.menu_item_update:
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.menu_bottin_refresh).setView(getActivity().getLayoutInflater().inflate(R.layout.dialog_bottin, null)).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //Suppression du bottin
                    DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
                    try {
                        Dao<FicheEmploye, ?> ficheEmployeDao = dbHelper.getDao(FicheEmploye.class);
                        List<FicheEmploye> ficheEmployeList = ficheEmployeDao.queryForAll();
                        for (FicheEmploye ficheEmploye : ficheEmployeList) {
                            ficheEmployeDao.delete(ficheEmploye);
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    //Mise à jour de la liste
                    listDataHeader = new ArrayList<>();
                    listDataChild = new HashMap<>();
                    listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
                    expListView.setAdapter(listAdapter);
                    updateUI();
                    dialogInterface.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            });
            builder.create().show();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) ExpandableListAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) OnClickListener(android.view.View.OnClickListener)

Example 5 with Dao

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

the class Utility method loadNotifications.

/**
     * Gets MonÉTS notifications and update DB
     * @param context
     * @param requestListener
     */
public static void loadNotifications(Context context, final RequestListener<Object> requestListener) {
    final SecurePreferences securePreferences = new SecurePreferences(context);
    final boolean allNotifsLoaded = securePreferences.getBoolean(Constants.ALL_NOTIFS_LOADED, false);
    MonETSNotificationsRequest monETSNotificationsRequest;
    if (!allNotifsLoaded) {
        monETSNotificationsRequest = new MonETSNotificationsRequest(context, false);
    } else {
        monETSNotificationsRequest = new MonETSNotificationsRequest(context, true);
    }
    final DataManager dataManager = DataManager.getInstance(context);
    dataManager.start();
    final DatabaseHelper databaseHelper = new DatabaseHelper(context);
    dataManager.sendRequest(monETSNotificationsRequest, new RequestListener<Object>() {

        @Override
        public void onRequestFailure(SpiceException spiceException) {
            requestListener.onRequestFailure(spiceException);
            dataManager.stop();
        }

        @Override
        public void onRequestSuccess(Object o) {
            if (o instanceof MonETSNotificationList) {
                try {
                    Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
                    MonETSNotificationList list = (MonETSNotificationList) o;
                    for (MonETSNotification monETSNotification : list) {
                        dao.createOrUpdate(monETSNotification);
                    }
                    if (!allNotifsLoaded) {
                        securePreferences.edit().putBoolean(Constants.ALL_NOTIFS_LOADED, true).commit();
                    }
                    requestListener.onRequestSuccess(list);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            dataManager.stop();
        }
    });
}
Also used : MonETSNotificationList(ca.etsmtl.applets.etsmobile.model.MonETSNotificationList) MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) SQLException(java.sql.SQLException) DataManager(ca.etsmtl.applets.etsmobile.http.DataManager) Dao(com.j256.ormlite.dao.Dao) MonETSNotificationsRequest(ca.etsmtl.applets.etsmobile.http.MonETSNotificationsRequest) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper)

Aggregations

SQLException (java.sql.SQLException)6 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)5 QueryBuilder (com.j256.ormlite.stmt.QueryBuilder)5 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 HsqldbDatabaseType (com.j256.ormlite.db.HsqldbDatabaseType)1