Example usage for android.database.sqlite SQLiteDatabase close

List of usage examples for android.database.sqlite SQLiteDatabase close

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase close.

Prototype

public void close() 

Source Link

Document

Releases a reference to the object, closing the object if the last reference was released.

Usage

From source file:holidayiq.com.geofenced.geofence.GeofenceTransitionsIntentService.java

public static void SendNotificationForEntry(Context mContext, String geoId, String geoName,
        String notificationStringTitle, String notificationStringContent, String notificationStringDeeplink,
        String objType, Context context, String eventType, boolean isBanner) {
    String currentTime = String.valueOf(System.currentTimeMillis());
    if (notificationStringTitle != null) {
        notificationStringTitle = notificationStringTitle.replace("$name$", geoName);
        notificationStringContent = notificationStringContent.replace("$name$", geoName);
        notificationStringDeeplink = notificationStringDeeplink.replace("$name$", Underscored(geoName));
        notificationStringDeeplink = notificationStringDeeplink.replace("$id$", geoId);
        Calendar c = new GregorianCalendar();
        c.set(Calendar.HOUR_OF_DAY, 6);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        Date d1 = c.getTime();/*from  ww  w.j  av  a  2s  .c  o m*/
        boolean isNotification = false;
        File dbFile = mContext.getDatabasePath("hiq_in_app.sqlite");
        SQLiteDatabase inAppDb = SQLiteDatabase.openDatabase(dbFile.getPath(), null,
                SQLiteDatabase.OPEN_READWRITE);
        if (geoName.equalsIgnoreCase("home")) {
            String lastTriggeredHome = HIQSharedPrefrence.getString("lastTriggeredHome", mContext);
            if (lastTriggeredHome == null) {
                sendNotification(notificationStringTitle, notificationStringContent, notificationStringDeeplink,
                        context, isBanner);
                HIQSharedPrefrence.putString("lastTriggeredHome", System.currentTimeMillis() + "", mContext);
                isNotification = true;
            } else {
                long previouslastTriggeredHome = Long
                        .parseLong(HIQSharedPrefrence.getString("lastTriggeredHome", mContext));
                if (previouslastTriggeredHome < d1.getTime()) {
                    sendNotification(notificationStringTitle, notificationStringContent,
                            notificationStringDeeplink, context, isBanner);
                    HIQSharedPrefrence.putString("lastTriggeredHome", System.currentTimeMillis() + "",
                            mContext);
                    isNotification = true;
                }
            }

        } else if (objType.equalsIgnoreCase("Hotel")) {
            String lastTriggeredHome = HIQSharedPrefrence.getString("lastTriggeredHotel", mContext);
            if (lastTriggeredHome == null) {
                sendNotification(notificationStringTitle, notificationStringContent, notificationStringDeeplink,
                        context, isBanner);
                HIQSharedPrefrence.putString("lastTriggeredHotel", System.currentTimeMillis() + "", mContext);
                isNotification = true;
            } else {
                long previouslastTriggeredHome = Long
                        .parseLong(HIQSharedPrefrence.getString("lastTriggeredHotel", mContext));
                if (previouslastTriggeredHome < d1.getTime()) {
                    sendNotification(notificationStringTitle, notificationStringContent,
                            notificationStringDeeplink, context, isBanner);
                    HIQSharedPrefrence.putString("lastTriggeredHotel", System.currentTimeMillis() + "",
                            mContext);
                    isNotification = true;
                }
            }
        } else if (objType.equalsIgnoreCase("SS")) {
            Cursor res = null;
            try {
                String lastNotificationTriggerd = null;
                res = inAppDb.rawQuery("Select * from " + GeoDbHelper.SIGHT_SEEING_TABLE_NAME + " where "
                        + GeoDbHelper.SIGHT_SEEING_COULUMN_ID + " = " + geoId, null);
                if (res != null) {
                    if (res.moveToFirst()) {
                        lastNotificationTriggerd = res.getString(res.getColumnIndex("lastTimeStamp"));
                    }
                }
                if (lastNotificationTriggerd == null) {
                    sendNotification(notificationStringTitle, notificationStringContent,
                            notificationStringDeeplink, context, isBanner);
                    isNotification = true;
                    Cursor cur = inAppDb.rawQuery("update " + GeoDbHelper.SIGHT_SEEING_TABLE_NAME
                            + " SET lastTimeStamp = '" + currentTime + "' where "
                            + GeoDbHelper.SIGHT_SEEING_COULUMN_ID + " = " + geoId, null);
                    cur.moveToFirst();
                    cur.close();
                } else {
                    long time = Long.parseLong(lastNotificationTriggerd);
                    if (time < d1.getTime()) {
                        sendNotification(notificationStringTitle, notificationStringContent,
                                notificationStringDeeplink, context, isBanner);
                        isNotification = true;
                        Cursor cur = inAppDb.rawQuery("update " + GeoDbHelper.SIGHT_SEEING_TABLE_NAME
                                + " SET lastTimeStamp = '" + currentTime + "' where "
                                + GeoDbHelper.SIGHT_SEEING_COULUMN_ID + " = " + geoId, null);
                        cur.moveToFirst();
                        cur.close();
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
                ExceptionUtils.logException(e);
            } finally {
                if (res != null && !res.isClosed()) {
                    res.close();
                }
                res = null;
                if (inAppDb != null && inAppDb.isOpen()) {
                    inAppDb.close();
                }
                inAppDb = null;
            }
        } else if (objType.equalsIgnoreCase("Destination")) {
            Cursor res = null;
            try {
                String lastNotificationTriggerd = null;
                res = inAppDb.rawQuery("Select * from " + GeoDbHelper.DESTINATION_TABLE_NAME + " where "
                        + GeoDbHelper.DESTINATION_COLUMN_ID + " = " + geoId, null);
                if (res != null) {
                    try {
                        if (res.moveToFirst()) {
                            lastNotificationTriggerd = res.getString(res.getColumnIndex("lastTimeStamp"));
                        }
                    } catch (Exception e) {

                    }
                }
                if (lastNotificationTriggerd == null) {
                    sendNotification(notificationStringTitle, notificationStringContent,
                            notificationStringDeeplink, context, isBanner);
                    isNotification = true;
                    Cursor cur = inAppDb.rawQuery("update " + GeoDbHelper.DESTINATION_TABLE_NAME
                            + " SET lastTimeStamp = '" + currentTime + "' where "
                            + GeoDbHelper.DESTINATION_COLUMN_ID + " = " + geoId, null);
                    cur.moveToFirst();
                    cur.close();
                } else {
                    long time = Long.parseLong(lastNotificationTriggerd);
                    if (time < d1.getTime()) {
                        sendNotification(notificationStringTitle, notificationStringContent,
                                notificationStringDeeplink, context, isBanner);
                        isNotification = true;
                        Cursor cur = inAppDb.rawQuery("update " + GeoDbHelper.DESTINATION_TABLE_NAME
                                + " SET lastTimeStamp = '" + currentTime + "' where "
                                + GeoDbHelper.DESTINATION_COLUMN_ID + " = " + geoId, null);
                        cur.moveToFirst();
                        cur.close();
                    }
                }

            } catch (Exception e) {
                ExceptionUtils.logException(e);
            } finally {
                if (res != null && !res.isClosed()) {
                    res.close();
                }
                res = null;
                if (inAppDb != null && inAppDb.isOpen()) {
                    inAppDb.close();
                }
                inAppDb = null;
            }
        }
        HashMap<String, Object> oMap = new HashMap<String, Object>();
        oMap.put("Type", eventType);
        oMap.put("Name", geoName);
        oMap.put("ID", geoId);
        oMap.put("Object Type", objType);
        oMap.put("Date", new Date());

        if (isNotification) {
        }
    }

    // HIQUtil.sendEventToGAFromObject("GeoFenceEvent", "GeoFenceEvent in Android", oMap);

}

From source file:com.rener.sea.DBHelper.java

private long setPath(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;/*  w ww.  j  a  va 2s.co  m*/
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);
            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.PATH_REPORT_ID))
                values.put(DBSchema.PATH_REPORT_ID, item.getLong(DBSchema.PATH_REPORT_ID));
            if (!item.isNull(DBSchema.PATH_OPTION_ID))
                values.put(DBSchema.PATH_OPTION_ID, item.getLong(DBSchema.PATH_OPTION_ID));
            if (!item.isNull(DBSchema.PATH_DATA))
                values.put(DBSchema.PATH_DATA, item.getString(DBSchema.PATH_DATA));
            if (!item.isNull(DBSchema.PATH_SEQUENCE))
                values.put(DBSchema.PATH_SEQUENCE, item.getLong(DBSchema.PATH_SEQUENCE));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);
            db.insertWithOnConflict(DBSchema.TABLE_PATH, null, values, 5);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}

From source file:com.rener.sea.DBHelper.java

private long setLocation_category(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;/*w  w  w.  j av a  2s.  c  om*/
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);

            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.LOCATION_CATEGORY_LOCATION_ID))
                values.put(DBSchema.LOCATION_CATEGORY_LOCATION_ID,
                        item.getLong(DBSchema.LOCATION_CATEGORY_LOCATION_ID));
            if (!item.isNull(DBSchema.LOCATION_CATEGORY_CATEGORY_ID))
                values.put(DBSchema.LOCATION_CATEGORY_CATEGORY_ID,
                        item.getLong(DBSchema.LOCATION_CATEGORY_CATEGORY_ID));
            if (!item.isNull(DBSchema.STATUS))
                values.put(DBSchema.STATUS, item.getString(DBSchema.STATUS));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);
            db.insertWithOnConflict(DBSchema.TABLE_LOCATION_CATEGORY, null, values, 5);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}

From source file:com.rener.sea.DBHelper.java

private long setOption(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;//w  w w  .  ja  v  a2s . c o m
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);
            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.OPTION_ID))
                values.put(DBSchema.OPTION_ID, item.getLong(DBSchema.OPTION_ID));
            if (!item.isNull(DBSchema.OPTION_PARENT_ID))
                values.put(DBSchema.OPTION_PARENT_ID, item.getLong(DBSchema.OPTION_PARENT_ID));
            if (!item.isNull(DBSchema.OPTION_NEXT_ID))
                values.put(DBSchema.OPTION_NEXT_ID, item.getLong(DBSchema.OPTION_NEXT_ID));
            if (!item.isNull(DBSchema.OPTION_LABEL))
                values.put(DBSchema.OPTION_LABEL, item.getString(DBSchema.OPTION_LABEL));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);

            db.insertWithOnConflict(DBSchema.TABLE_OPTION, null, values, 5);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}

From source file:com.rener.sea.DBHelper.java

private JSONArray getCategory() {

    JSONArray data;//from   ww  w .ja va 2 s. c  o  m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_CATEGORY,
            new String[] { DBSchema.CATEGORY_ID, DBSchema.CATEGORY_NAME }, DBSchema.MODIFIED + "=?",
            new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.CATEGORY_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.CATEGORY_NAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getSpecialization() {

    JSONArray data;/*  ww  w . j a v a 2 s. co  m*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_SPECIALIZATION,
            new String[] { DBSchema.SPECIALIZATION_ID, DBSchema.SPECIALIZATION_NAME }, DBSchema.MODIFIED + "=?",
            new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.SPECIALIZATION_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.SPECIALIZATION_NAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getLocation_category() {

    JSONArray data;//from   w  ww . j av  a 2  s .  c  om
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_LOCATION_CATEGORY,
            new String[] { DBSchema.LOCATION_CATEGORY_LOCATION_ID, DBSchema.LOCATION_CATEGORY_CATEGORY_ID },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.LOCATION_CATEGORY_LOCATION_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.LOCATION_CATEGORY_CATEGORY_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getUsers_specialization() {

    JSONArray data;/*ww w .  j a v a  2 s .c om*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_USERS_SPECIALIZATION,
            new String[] { DBSchema.USERS_SPECIALIZATION_USER_ID,
                    DBSchema.USERS_SPECIALIZATION_SPECIALIZATION_ID },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))//
                        map.put(DBSchema.USERS_SPECIALIZATION_USER_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))//
                        map.put(DBSchema.USERS_SPECIALIZATION_SPECIALIZATION_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private long setDevices(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;/*from  ww  w . j  av  a 2 s. c o  m*/
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);

            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.DEVICE_ID))
                values.put(DBSchema.DEVICE_ID, item.getLong(DBSchema.DEVICE_ID));
            if (!item.isNull(DBSchema.DEVICE_NAME))
                values.put(DBSchema.DEVICE_NAME, item.getString(DBSchema.DEVICE_NAME));
            if (!item.isNull(DBSchema.DEVICE_ID_NUMBER))
                values.put(DBSchema.DEVICE_ID_NUMBER, item.getLong(DBSchema.DEVICE_ID_NUMBER));
            if (!item.isNull(DBSchema.DEVICE_USER_ID))
                values.put(DBSchema.DEVICE_USER_ID, item.getLong(DBSchema.DEVICE_USER_ID));
            // if(!item.isNull(DBSchema.DEVICE_LATEST_SYNC))
            //                values.put(DBSchema.DEVICE_LATEST_SYNC, item.getLong(DBSchema.DEVICE_LATEST_SYNC));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);
            db.insertWithOnConflict(DBSchema.TABLE_DEVICES, null, values, 5);

        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}

From source file:com.xplink.android.carchecklist.CarCheckListActivity.java

private List<Map> restoreCheckList() {
    // check getListMem

    List<Map> tmpList = null;
    SharedPreferences shared = getSharedPreferences("mysettings", Context.MODE_PRIVATE);
    String check = "empty";
    boolean stateGetList = shared.getBoolean("stateGetList", false);
    int indexList = shared.getInt("indexList", -1);

    if (stateGetList) {
        // Log.i("inCheck_satetGetList", "inCheck_stateGetList");
        DBCarCheckList dbList = new DBCarCheckList(this);
        SQLiteDatabase sqliteList = dbList.getReadableDatabase();
        String sqlList = "SELECT * FROM " + dbList.TABLE_NAME;
        Cursor cursor = sqliteList.rawQuery(sqlList, null);
        cursor.moveToFirst();/*  w  w  w . jav a2s  .co  m*/
        int numRow = cursor.getCount();
        String[] idList = new String[numRow];
        int i = 0;

        int id = -1;
        String username = "empty";
        String data = "empty";

        while (cursor != null) {
            idList[i] = cursor.getString(0);
            i++;
            if (cursor.isLast())
                break;
            cursor.moveToNext();
        }

        // restore from save list
        String iD = idList[indexList];
        sqlList = "SELECT * FROM " + dbList.TABLE_NAME + " WHERE id=" + iD;

        Cursor cursor2 = sqliteList.rawQuery(sqlList, null);
        cursor2.moveToFirst();
        ExpandData ex = new ExpandData(getApplicationContext());
        tmpList = ex.filterData(cursor2.getString(2));
        ex.displayMap(tmpList.get(0), tmpList.get(1));
        check = " , data : " + cursor2.getString(2);

        cursor2.close();
        sqliteList.close();
        dbList.close();

        int[] expand = ex.getPercentAllList();
        // IT'S WORK FOR TEST
        // ****************************************************************
        PercenPower = expand[0];
        PercenEngine = expand[1];
        PercenExterior = expand[2];
        PercenInterior = expand[3];
        PercenDocument = expand[4];

        /*CheckPowerTotal = shared.getInt("CheckPowerTotal", 0);
        CheckEngineTotal = shared.getInt("CheckEngineTotal", 0);
        CheckExteriorTotal = shared.getInt("CheckExteriorTotal", 0);
        CheckInteriorTotal = shared.getInt("CheckInteriorTotal", 0);
        CheckDocumentTotal = shared.getInt("CheckDocumentTotal", 0);*/

        // IT'S WORK FOR TEST
        // ****************************************************************
    } else {
        Log.i("inCheck_satetGetList", "out stateGetList");
    }
    // Log.i("stateGetList2", "stateGetList >--->>" + stateGetList + check);
    // Log.i("indexList", "getIndexList >>>>>>> " + indexList);
    if (stateGetList) {
        Editor edit = shared.edit();
        edit.clear();
        edit.commit();
        Checknumcheckbox();
        edit.putInt("checknum", Checknum);
        edit.commit();
    }
    return tmpList;
}