Java 类android.database.sqlite.SQLiteDatabaseLockedException 实例源码

项目:the-blue-alliance-android    文件:TeamsTable.java   
@Override
protected void insertCallback(Team team) {
    ContentValues cv = new ContentValues();
    mDb.beginTransaction();
    try {
        cv.put(Database.SearchTeam.KEY, team.getKey());
        cv.put(Database.SearchTeam.TITLES, Utilities.getAsciiApproximationOfUnicode(team.getSearchTitles()));
        cv.put(Database.SearchTeam.NUMBER, team.getTeamNumber());
        mDb.insert(Database.TABLE_SEARCH_TEAMS, null, cv);
        mDb.setTransactionSuccessful();
    } catch (SQLiteException ex) {
        if (ex instanceof SQLiteDatabaseLockedException) {
            TbaLogger.d("Databse locked: " + ex.getMessage());
        } else {
            TbaLogger.w("Error in team insert callback", ex);
        }
    } finally {
        mDb.endTransaction();
    }
}
项目:sqlite-android    文件:SQLiteConnection.java   
private void setJournalMode(String newValue) {
    String value = executeForString("PRAGMA journal_mode", null, null);
    if (!value.equalsIgnoreCase(newValue)) {
        try {
            String result = executeForString("PRAGMA journal_mode=" + newValue, null, null);
            if (result.equalsIgnoreCase(newValue)) {
                return;
            }
            // PRAGMA journal_mode silently fails and returns the original journal
            // mode in some cases if the journal mode could not be changed.
        } catch (SQLiteException ex) {
            // This error (SQLITE_BUSY) occurs if one connection has the database
            // open in WAL mode and another tries to change it to non-WAL.
            if (!(ex instanceof SQLiteDatabaseLockedException)) {
                throw ex;
            }
        }

        // Because we always disable WAL mode when a database is first opened
        // (even if we intend to re-enable it), we can encounter problems if
        // there is another open connection to the database somewhere.
        // This can happen for a variety of reasons such as an application opening
        // the same database in multiple processes at the same time or if there is a
        // crashing content provider service that the ActivityManager has
        // removed from its registry but whose process hasn't quite died yet
        // by the time it is restarted in a new process.
        //
        // If we don't change the journal mode, nothing really bad happens.
        // In the worst case, an application that enables WAL might not actually
        // get it, although it can still use connection pooling.
        Log.w(TAG, "Could not change the database journal mode of '"
                + mConfiguration.label + "' from '" + value + "' to '" + newValue
                + "' because the database is locked.  This usually means that "
                + "there are other open connections to the database which prevents "
                + "the database from enabling or disabling write-ahead logging mode.  "
                + "Proceeding without changing the journal mode.");
    }
}
项目:H-Viewer    文件:DnsCacheManager.java   
/**
 * 获取url缓存
 * @param url
 * @return
 */
   @Override
public DomainModel getDnsCache(String sp, String url){


    DomainModel model = data.get(url) ;

    if( model == null ){
        //缓存中没有从数据库中查找
           ArrayList<DomainModel> list = null;
           try {
               list = (ArrayList<DomainModel>) db.QueryDomainInfo(url, sp);
           } catch(SQLiteDatabaseLockedException e){
               e.printStackTrace();
           }
        if( list != null && list.size() != 0){
            model = list.get( list.size() - 1 ) ;
        }

        //查询到数据 添加到缓存中
        if( model != null )addMemoryCache(url, model) ;

    }

    if( model != null){
        //检测是否过期  
           if( isExpire(model, ip_overdue_delay) ){
               model = null ;
           }
    }

    return model ; 
}
项目:open    文件:DataUploadService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Logger.d("DataUploadService: onStartCommand");
    (new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            String permissionResponse = getPermissionResponse();
            if (!hasWritePermission(permissionResponse)) {
                stopSelf();
            }
            Cursor cursor = null;
            try {
                if (db == null) {
                    return null;
                }
                cursor = db.query(TABLE_GROUPS,
                        new String[] { COLUMN_TABLE_ID, COLUMN_MSG },
                        COLUMN_UPLOADED + " is null AND " + COLUMN_READY_FOR_UPLOAD + " == ?",
                        new String[] { "1" }, null, null, null);
                while (cursor.moveToNext()) {
                    int groupIdIndex = cursor.getColumnIndex(COLUMN_TABLE_ID);
                    int routeDescription = cursor.getColumnIndex(COLUMN_MSG);
                    generateGpxXmlFor(cursor.getString(groupIdIndex),
                            cursor.getString(routeDescription));
                }
            } catch (SQLiteDatabaseLockedException exception) {
                Logger.d("DataUpload: database is locked lets try again later");
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
            return null;
        }
    }).execute();
    return Service.START_NOT_STICKY;
}