public void updateTabBannerData(SQLiteDatabase database, TabBannerDTO tabBannerDTO) {
    try {
      database.enableWriteAheadLogging();
      ContentValues tabBannerValues = new ContentValues();
      tabBannerValues.put(KEY_TAB_ID, tabBannerDTO.getTabId());
      tabBannerValues.put(KEY_TAB_NAME, tabBannerDTO.getTabName());
      tabBannerValues.put(KEY_TAB_POSITION, tabBannerDTO.getTabIndexPosition());
      tabBannerValues.put(KEY_TAB_CREATED, tabBannerDTO.getTabCreated());
      tabBannerValues.put(KEY_TAB_MODIFIED, tabBannerDTO.getTabModified());
      tabBannerValues.put(KEY_TAB_DATA_CREATED, tabBannerDTO.getTabDataCreated());
      tabBannerValues.put(KEY_TAB_DATA_MODIFIED, tabBannerDTO.getTabDataModified());
      tabBannerValues.put(KEY_TAB_KEYWORD, tabBannerDTO.getTabKeyword());
      tabBannerValues.put(KEY_TAB_DISPLAY_TYPE, tabBannerDTO.getTabDisplayType());

      tabBannerValues.put(KEY_BANNER_ID, tabBannerDTO.getTabBannerId());
      tabBannerValues.put(KEY_BANNER_URL, tabBannerDTO.getBannerURL());
      tabBannerValues.put(KEY_BANNER_NAME, tabBannerDTO.getTabBannerName());
      tabBannerValues.put(KEY_BANNER_CREATED, tabBannerDTO.getBannerCreated());
      tabBannerValues.put(KEY_BANNER_MODIFIED, tabBannerDTO.getBannerModified());
      if (tabBannerDTO.isBannerActive()) tabBannerValues.put(KEY_IS_BANNER_ACTIVATED, 1);
      else tabBannerValues.put(KEY_IS_BANNER_ACTIVATED, 0);
      if (tabBannerDTO.isHyperlinkActive()) tabBannerValues.put(KEY_IS_HYPER_LINK_ACTIVATED, 1);
      else tabBannerValues.put(KEY_IS_HYPER_LINK_ACTIVATED, 0);
      tabBannerValues.put(KEY_ACTION_URL, tabBannerDTO.getBannerActionURL());

      database.update(
          TAB_BANNER_TABLE,
          tabBannerValues,
          KEY_TAB_ID + "=?",
          new String[] {"" + tabBannerDTO.getTabId()});
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void initDatabase(Context context) {
    try {
      mDatabase = context.openOrCreateDatabase(DATABASE_FILE, 0, null);
    } catch (SQLiteException e) {
      // try again by deleting the old db and create a new one
      if (context.deleteDatabase(DATABASE_FILE)) {
        mDatabase = context.openOrCreateDatabase(DATABASE_FILE, 0, null);
      }
    }
    mDatabase.enableWriteAheadLogging();

    // mDatabase should not be null,
    // the only case is RequestAPI test has problem to create db
    if (mDatabase == null) {
      mInitialized = true;
      notify();
      return;
    }

    if (mDatabase.getVersion() != DATABASE_VERSION) {
      mDatabase.beginTransactionNonExclusive();
      try {
        upgradeDatabase();
        mDatabase.setTransactionSuccessful();
      } finally {
        mDatabase.endTransaction();
      }
    }

    // use per table Mutex lock, turn off database lock, this
    // improves performance as database's ReentrantLock is
    // expansive
    mDatabase.setLockingEnabled(false);
  }
  private void initCacheDatabase(Context context) {
    assert !JniUtil.useChromiumHttpStack();

    try {
      mCacheDatabase = context.openOrCreateDatabase(CACHE_DATABASE_FILE, 0, null);
    } catch (SQLiteException e) {
      // try again by deleting the old db and create a new one
      if (context.deleteDatabase(CACHE_DATABASE_FILE)) {
        mCacheDatabase = context.openOrCreateDatabase(CACHE_DATABASE_FILE, 0, null);
      }
    }
    mCacheDatabase.enableWriteAheadLogging();

    // mCacheDatabase should not be null,
    // the only case is RequestAPI test has problem to create db
    if (mCacheDatabase == null) {
      mInitialized = true;
      notify();
      return;
    }

    if (mCacheDatabase.getVersion() != CACHE_DATABASE_VERSION) {
      mCacheDatabase.beginTransactionNonExclusive();
      try {
        upgradeCacheDatabase();
        bootstrapCacheDatabase();
        mCacheDatabase.setTransactionSuccessful();
      } finally {
        mCacheDatabase.endTransaction();
      }
      // Erase the files from the file system in the
      // case that the database was updated and the
      // there were existing cache content
      CacheManager.removeAllCacheFiles();
    }

    // use read_uncommitted to speed up READ
    mCacheDatabase.execSQL("PRAGMA read_uncommitted = true;");
    // as only READ can be called in the
    // non-WebViewWorkerThread, and read_uncommitted is used,
    // we can turn off database lock to use transaction.
    mCacheDatabase.setLockingEnabled(false);

    // use InsertHelper for faster insertion
    mCacheInserter = new DatabaseUtils.InsertHelper(mCacheDatabase, "cache");
    mCacheUrlColIndex = mCacheInserter.getColumnIndex(CACHE_URL_COL);
    mCacheFilePathColIndex = mCacheInserter.getColumnIndex(CACHE_FILE_PATH_COL);
    mCacheLastModifyColIndex = mCacheInserter.getColumnIndex(CACHE_LAST_MODIFY_COL);
    mCacheETagColIndex = mCacheInserter.getColumnIndex(CACHE_ETAG_COL);
    mCacheExpiresColIndex = mCacheInserter.getColumnIndex(CACHE_EXPIRES_COL);
    mCacheExpiresStringColIndex = mCacheInserter.getColumnIndex(CACHE_EXPIRES_STRING_COL);
    mCacheMimeTypeColIndex = mCacheInserter.getColumnIndex(CACHE_MIMETYPE_COL);
    mCacheEncodingColIndex = mCacheInserter.getColumnIndex(CACHE_ENCODING_COL);
    mCacheHttpStatusColIndex = mCacheInserter.getColumnIndex(CACHE_HTTP_STATUS_COL);
    mCacheLocationColIndex = mCacheInserter.getColumnIndex(CACHE_LOCATION_COL);
    mCacheContentLengthColIndex = mCacheInserter.getColumnIndex(CACHE_CONTENTLENGTH_COL);
    mCacheContentDispositionColIndex = mCacheInserter.getColumnIndex(CACHE_CONTENTDISPOSITION_COL);
    mCacheCrossDomainColIndex = mCacheInserter.getColumnIndex(CACHE_CROSSDOMAIN_COL);
  }
Esempio n. 4
0
 @Provides
 @Singleton
 SQLiteDatabase provideDb() {
   DatabaseHelper databaseHelper = new DatabaseHelper(context);
   SQLiteDatabase db = databaseHelper.getWritableDatabase();
   db.enableWriteAheadLogging();
   return db;
 }
 public void removeAllTabBannerData(SQLiteDatabase database) {
   try {
     database.enableWriteAheadLogging();
     database.execSQL("DELETE FROM " + TAB_BANNER_TABLE);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
  public ArrayList<TabBannerDTO> getAllLocalTabBannerData(SQLiteDatabase database) {
    try {
      ArrayList<TabBannerDTO> listTabBannerDTO = new ArrayList<>();
      database.enableWriteAheadLogging();
      String selectQuery = "SELECT * FROM " + TAB_BANNER_TABLE;
      Cursor cursor = database.rawQuery(selectQuery, null);
      TabBannerDTO tabBannerDTO = null;
      if (cursor != null)
        if (cursor.moveToFirst()) {
          do {
            tabBannerDTO = new TabBannerDTO();
            tabBannerDTO.setTabId(cursor.getLong(cursor.getColumnIndex(KEY_TAB_ID)));
            tabBannerDTO.setTabName(cursor.getString(cursor.getColumnIndex(KEY_TAB_NAME)));
            tabBannerDTO.setTabIndexPosition(
                cursor.getLong(cursor.getColumnIndex(KEY_TAB_POSITION)));
            tabBannerDTO.setTabCreated(
                Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_TAB_CREATED))));
            tabBannerDTO.setTabModified(
                Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_TAB_MODIFIED))));
            tabBannerDTO.setTabDataCreated(
                Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_TAB_DATA_CREATED))));
            tabBannerDTO.setTabDataModified(
                Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_TAB_DATA_MODIFIED))));
            tabBannerDTO.setTabKeyword(cursor.getString(cursor.getColumnIndex(KEY_TAB_KEYWORD)));
            tabBannerDTO.setTabDisplayType(
                cursor.getString(cursor.getColumnIndex(KEY_TAB_DISPLAY_TYPE)));

            tabBannerDTO.setTabBannerId(cursor.getLong(cursor.getColumnIndex(KEY_BANNER_ID)));
            tabBannerDTO.setTabBannerName(cursor.getString(cursor.getColumnIndex(KEY_BANNER_NAME)));
            tabBannerDTO.setBannerCreated(
                Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_BANNER_CREATED))));
            tabBannerDTO.setBannerModified(
                Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_BANNER_MODIFIED))));
            tabBannerDTO.setBannerURL(cursor.getString(cursor.getColumnIndex(KEY_BANNER_URL)));
            if (cursor.getInt(cursor.getColumnIndex(KEY_IS_BANNER_ACTIVATED)) == 1)
              tabBannerDTO.setIsBannerActive(true);
            else tabBannerDTO.setIsBannerActive(false);
            if (cursor.getInt(cursor.getColumnIndex(KEY_IS_HYPER_LINK_ACTIVATED)) == 1)
              tabBannerDTO.setIsHyperlinkActive(true);
            else tabBannerDTO.setIsHyperlinkActive(false);

            tabBannerDTO.setBannerActionURL(
                cursor.getString(cursor.getColumnIndex(KEY_ACTION_URL)));
            listTabBannerDTO.add(tabBannerDTO);
          } while (cursor.moveToNext());
        }

      cursor.close();
      return listTabBannerDTO;
    } catch (NumberFormatException e) {
      e.printStackTrace();
      return null;
    }
  }
 public int getTabBannerCount(SQLiteDatabase database) {
   int count = 0;
   try {
     database.enableWriteAheadLogging();
     String selectQuery = "SELECT * FROM " + TAB_BANNER_TABLE;
     Cursor cursor = database.rawQuery(selectQuery, null);
     if (cursor != null) count = cursor.getCount();
     cursor.close();
     return count;
   } catch (NumberFormatException e) {
     e.printStackTrace();
     return count;
   }
 }
  public void updateTabData(SQLiteDatabase database, TabBannerDTO tabBannerDTO) {
    try {
      database.enableWriteAheadLogging();
      ContentValues tabValues = new ContentValues();
      tabValues.put(KEY_TAB_ID, tabBannerDTO.getTabId());
      tabValues.put(KEY_TAB_NAME, tabBannerDTO.getTabName());
      tabValues.put(KEY_TAB_POSITION, tabBannerDTO.getTabIndexPosition());
      tabValues.put(KEY_TAB_CREATED, tabBannerDTO.getTabCreated());
      tabValues.put(KEY_TAB_MODIFIED, tabBannerDTO.getTabModified());
      tabValues.put(KEY_TAB_DATA_CREATED, tabBannerDTO.getTabDataCreated());
      tabValues.put(KEY_TAB_DATA_MODIFIED, tabBannerDTO.getTabDataModified());
      tabValues.put(KEY_TAB_KEYWORD, tabBannerDTO.getTabKeyword());
      tabValues.put(KEY_TAB_DISPLAY_TYPE, tabBannerDTO.getTabDisplayType());

      database.update(
          TAB_BANNER_TABLE,
          tabValues,
          KEY_TAB_ID + "=?",
          new String[] {"" + tabBannerDTO.getTabId()});
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void updateBannerData(SQLiteDatabase database, TabBannerDTO tabBannerDTO) {
    try {
      database.enableWriteAheadLogging();
      ContentValues bannerValues = new ContentValues();
      bannerValues.put(KEY_BANNER_ID, tabBannerDTO.getTabBannerId());
      bannerValues.put(KEY_BANNER_URL, tabBannerDTO.getBannerURL());
      if (tabBannerDTO.isBannerActive()) bannerValues.put(KEY_IS_BANNER_ACTIVATED, 1);
      else bannerValues.put(KEY_IS_BANNER_ACTIVATED, 0);
      if (tabBannerDTO.isHyperlinkActive()) bannerValues.put(KEY_IS_HYPER_LINK_ACTIVATED, 1);
      else bannerValues.put(KEY_IS_HYPER_LINK_ACTIVATED, 0);
      bannerValues.put(KEY_ACTION_URL, tabBannerDTO.getBannerActionURL());
      bannerValues.put(KEY_BANNER_CREATED, tabBannerDTO.getBannerCreated());
      bannerValues.put(KEY_BANNER_MODIFIED, tabBannerDTO.getBannerModified());
      bannerValues.put(KEY_BANNER_NAME, tabBannerDTO.getTabBannerName());

      database.update(
          TAB_BANNER_TABLE,
          bannerValues,
          KEY_TAB_ID + "=?",
          new String[] {"" + tabBannerDTO.getTabId()});
    } catch (Exception e) {
      e.printStackTrace();
    }
  }