Java Code Examples for com.lzy.okgo.utils.OkLogger#printStackTrace()

The following examples show how to use com.lzy.okgo.utils.OkLogger#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBUtils.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
public static boolean isFieldExists(SQLiteDatabase db, String tableName, String fieldName) {
    if (tableName == null || db == null || fieldName == null || !db.isOpen()) return false;

    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " LIMIT 0", null);
        return cursor != null && cursor.getColumnIndex(fieldName) != -1;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 2
Source File: BaseDao.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
/** 更新一条记录 */
public boolean update(ContentValues contentValues, String whereClause, String[] whereArgs) {
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.update(getTableName(), contentValues, whereClause, whereArgs);
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " updateContentValues");
    }
    return false;
}
 
Example 3
Source File: BaseDao.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
public boolean replace(ContentValues contentValues) {
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.replace(getTableName(), null, contentValues);
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " replaceContentValues");
    }
    return false;
}
 
Example 4
Source File: BaseDao.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
/**
 * replace 语句有如下行为特点
 * 1. replace语句会删除原有的一条记录, 并且插入一条新的记录来替换原记录。
 * 2. 一般用replace语句替换一条记录的所有列, 如果在replace语句中没有指定某列, 在replace之后这列的值被置空 。
 * 3. replace语句根据主键的值确定被替换的是哪一条记录
 * 4. 如果执行replace语句时, 不存在要替换的记录, 那么就会插入一条新的记录。
 * 5. replace语句不能根据where子句来定位要被替换的记录
 * 6. 如果新插入的或替换的记录中, 有字段和表中的其他记录冲突, 那么会删除那条其他记录。
 */
public boolean replace(T t) {
    if (t == null) return false;
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.replace(getTableName(), null, getContentValues(t));
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " replaceT");
    }
    return false;
}
 
Example 5
Source File: BaseDao.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
public boolean deleteList(List<Pair<String, String[]>> where) {
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        for (Pair<String, String[]> pair : where) {
            database.delete(getTableName(), pair.first, pair.second);
        }
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " deleteList");
    }
    return false;
}
 
Example 6
Source File: BaseDao.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
/** 根据条件删除数据库中的数据 */
public boolean delete(String whereClause, String[] whereArgs) {
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.delete(getTableName(), whereClause, whereArgs);
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " delete");
    }
    return false;
}
 
Example 7
Source File: BaseDao.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/** 插入多条记录 */
public boolean insert(List<T> ts) {
    if (ts == null) return false;
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        for (T t : ts) {
            database.insert(getTableName(), null, getContentValues(t));
        }
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " insertList");
    }
    return false;
}
 
Example 8
Source File: DBUtils.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
public static boolean isFieldExists(SQLiteDatabase db, String tableName, String fieldName) {
    if (tableName == null || db == null || fieldName == null || !db.isOpen()) return false;

    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " LIMIT 0", null);
        return cursor != null && cursor.getColumnIndex(fieldName) != -1;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 9
Source File: BaseDao.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
public boolean replace(ContentValues contentValues) {
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.replace(getTableName(), null, contentValues);
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " replaceContentValues");
    }
    return false;
}
 
Example 10
Source File: BaseDao.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/** 更新一条记录 */
public boolean update(ContentValues contentValues, String whereClause, String[] whereArgs) {
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.update(getTableName(), contentValues, whereClause, whereArgs);
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " updateContentValues");
    }
    return false;
}
 
Example 11
Source File: DBUtils.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
 * SQLite数据库中一个特殊的名叫 SQLITE_MASTER 上执行一个SELECT查询以获得所有表的索引。每一个 SQLite 数据库都有一个叫 SQLITE_MASTER 的表, 它定义数据库的模式。
 * SQLITE_MASTER 表看起来如下:
 * CREATE TABLE sqlite_master (
 * type TEXT,
 * name TEXT,
 * tbl_name TEXT,
 * rootpage INTEGER,
 * sql TEXT
 * );
 * 对于表来说,type 字段永远是 ‘table’,name 字段永远是表的名字。
 */
public static boolean isTableExists(SQLiteDatabase db, String tableName) {
    if (tableName == null || db == null || !db.isOpen()) return false;

    Cursor cursor = null;
    int count = 0;
    try {
        cursor = db.rawQuery("SELECT COUNT(*) FROM sqlite_master WHERE type = ? AND name = ?", new String[]{"table", tableName});
        if (!cursor.moveToFirst()) {
            return false;
        }
        count = cursor.getInt(0);
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        if (cursor != null) cursor.close();
    }
    return count > 0;
}
 
Example 12
Source File: BaseDao.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/** 更新一条记录 */
public boolean update(T t, String whereClause, String[] whereArgs) {
    if (t == null) return false;
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        database.update(getTableName(), getContentValues(t), whereClause, whereArgs);
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " updateT");
    }
    return false;
}
 
Example 13
Source File: BaseDao.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
public boolean replace(List<T> ts) {
    if (ts == null) return false;
    long start = System.currentTimeMillis();
    lock.lock();
    try {
        database.beginTransaction();
        for (T t : ts) {
            database.replace(getTableName(), null, getContentValues(t));
        }
        database.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
        OkLogger.v(TAG, System.currentTimeMillis() - start + " replaceList");
    }
    return false;
}
 
Example 14
Source File: BaseDao.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/** 用于给外界提供事物开启的模板 */
public void startTransaction(Action action) {
    lock.lock();
    try {
        database.beginTransaction();
        action.call(database);
        database.setTransactionSuccessful();
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    } finally {
        database.endTransaction();
        lock.unlock();
    }
}
 
Example 15
Source File: HttpHeaders.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
public final String toJSONString() {
    JSONObject jsonObject = new JSONObject();
    try {
        for (Map.Entry<String, String> entry : headersMap.entrySet()) {
            jsonObject.put(entry.getKey(), entry.getValue());
        }
    } catch (JSONException e) {
        OkLogger.printStackTrace(e);
    }
    return jsonObject.toString();
}
 
Example 16
Source File: SerializableCookie.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public static Cookie bytesToCookie(byte[] bytes) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    Cookie cookie = null;
    try {
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        cookie = ((SerializableCookie) objectInputStream.readObject()).getCookie();
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    }
    return cookie;
}
 
Example 17
Source File: BaseDao.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public boolean replace(SQLiteDatabase database, List<T> ts) {
    try {
        for (T t : ts) {
            database.replace(getTableName(), null, getContentValues(t));
        }
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    }
}
 
Example 18
Source File: BodyRequest.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
protected okhttp3.Request.Builder generateRequestBuilder(RequestBody requestBody) {
    try {
        headers(HttpHeaders.HEAD_KEY_CONTENT_LENGTH, String.valueOf(requestBody.contentLength()));
    } catch (IOException e) {
        OkLogger.printStackTrace(e);
    }
    okhttp3.Request.Builder requestBuilder = new okhttp3.Request.Builder();
    return HttpUtils.appendHeaders(requestBuilder, headers);
}
 
Example 19
Source File: SerializableCookie.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public static byte[] cookieToBytes(String host, Cookie cookie) {
    SerializableCookie serializableCookie = new SerializableCookie(host, cookie);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        ObjectOutputStream outputStream = new ObjectOutputStream(os);
        outputStream.writeObject(serializableCookie);
    } catch (IOException e) {
        OkLogger.printStackTrace(e);
        return null;
    }
    return os.toByteArray();
}
 
Example 20
Source File: BaseDao.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
public boolean replace(SQLiteDatabase database, List<T> ts) {
    try {
        for (T t : ts) {
            database.replace(getTableName(), null, getContentValues(t));
        }
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    }
}