当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.beginTransactionNonExclusive方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.beginTransactionNonExclusive方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.beginTransactionNonExclusive方法的具体用法?Java SQLiteDatabase.beginTransactionNonExclusive怎么用?Java SQLiteDatabase.beginTransactionNonExclusive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteDatabase的用法示例。


在下文中一共展示了SQLiteDatabase.beginTransactionNonExclusive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: clearLog

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void clearLog(int uid) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            if (uid < 0)
                db.delete("log", null, new String[]{});
            else
                db.delete("log", "uid = ?", new String[]{Integer.toString(uid)});

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }

        db.execSQL("VACUUM");
    } finally {
        lock.writeLock().unlock();
    }

    notifyLogChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:24,代码来源:DatabaseHelper.java

示例2: cleanupLog

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void cleanupLog(long time) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            // There an index on time
            int rows = db.delete("log", "time < ?", new String[]{Long.toString(time)});
            Log.i(TAG, "Cleanup log" +
                    " before=" + SimpleDateFormat.getDateTimeInstance().format(new Date(time)) +
                    " rows=" + rows);

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:21,代码来源:DatabaseHelper.java

示例3: setAccess

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void setAccess(long id, int block) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.put("block", block);
            cv.put("allowed", -1);

            if (db.update("access", cv, "ID = ?", new String[]{Long.toString(id)}) != 1)
                Log.e(TAG, "Set access failed");

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyAccessChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:24,代码来源:DatabaseHelper.java

示例4: clearAccess

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void clearAccess() {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            db.delete("access", null, null);

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyAccessChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:19,代码来源:DatabaseHelper.java

示例5: resetUsage

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void resetUsage(int uid) {
    lock.writeLock().lock();
    try {
        // There is a segmented index on uid
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.putNull("sent");
            cv.putNull("received");
            cv.putNull("connections");
            db.update("access", cv,
                    (uid < 0 ? null : "uid = ?"),
                    (uid < 0 ? null : new String[]{Integer.toString(uid)}));

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyAccessChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:26,代码来源:DatabaseHelper.java

示例6: cleanupDns

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void cleanupDns() {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            // There is no index on time for write performance
            long now = new Date().getTime();
            db.execSQL("DELETE FROM dns WHERE time + ttl < " + now);
            Log.i(TAG, "Cleanup DNS");

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:20,代码来源:DatabaseHelper.java

示例7: clearDns

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void clearDns() {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            db.delete("dns", null, new String[]{});

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:17,代码来源:DatabaseHelper.java

示例8: addForward

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addForward(int protocol, int dport, String raddr, int rport, int ruid) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.put("protocol", protocol);
            cv.put("dport", dport);
            cv.put("raddr", raddr);
            cv.put("rport", rport);
            cv.put("ruid", ruid);

            if (db.insert("forward", null, cv) < 0)
                Log.e(TAG, "Insert forward failed");

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyForwardChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:27,代码来源:DatabaseHelper.java

示例9: deleteForward

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void deleteForward() {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            db.delete("forward", null, null);

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyForwardChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:19,代码来源:DatabaseHelper.java

示例10: deleteVehicleWithAllData

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private int deleteVehicleWithAllData(final SQLiteDatabase db, Uri uri) {
    String[] vehicleId = new String[] { String.valueOf(ContentUris.parseId(uri)) };

    db.beginTransactionNonExclusive();

    db.delete(ExpenseEntry.TABLE_NAME, ExpenseEntry.COLUMN_VEHICLE + "=?", vehicleId);
    db.delete(FillUpEntry.TABLE_NAME, FillUpEntry.COLUMN_VEHICLE + "=?", vehicleId);
    int result = db.delete(VehicleEntry.TABLE_NAME, VehicleEntry._ID + "=?", vehicleId);

    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();

    getContext().getContentResolver().notifyChange(uri, null);
    return result;
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:17,代码来源:VehicleProvider.java

示例11: insertDns

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean insertDns(ResourceRecord rr) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            int ttl = rr.TTL;

            int min = Integer.parseInt(prefs.getString("ttl", "259200"));
            if (ttl < min)
                ttl = min;

            ContentValues cv = new ContentValues();
            cv.put("time", rr.Time);
            cv.put("ttl", ttl * 1000L);

            int rows = db.update("dns", cv, "qname = ? AND aname = ? AND resource = ?",
                    new String[]{rr.QName, rr.AName, rr.Resource});

            if (rows == 0) {
                cv.put("qname", rr.QName);
                cv.put("aname", rr.AName);
                cv.put("resource", rr.Resource);

                if (db.insert("dns", null, cv) == -1)
                    Log.e(TAG, "Insert dns failed");
            } else if (rows != 1)
                Log.e(TAG, "Update dns failed rows=" + rows);

            db.setTransactionSuccessful();

            return (rows == 0);
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:40,代码来源:DatabaseHelper.java

示例12: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    if (DBG) Log.d(TAG, "bulkInsert " + uri);
    int match = URI_MATCHER.match(uri);

    // let ScraperProvider handle that
    if (ScraperProvider.handles(match))
        return mScraperProvider.bulkInsert(uri, values);

    if (match != -1) {
        int result = 0;
        mVobHandler.onBeginTransaction();
        SQLiteDatabase db = mDbHolder.get();
        db.beginTransactionNonExclusive();
        try {
            int numValues = values.length;
            int yield = 100;
            for (int i = 0; i < numValues; i++) {
                insert(uri, values[i]);
                if (yield-- < 0) {
                    yield = 100;
                    db.yieldIfContendedSafely();
                }
            }
            result = numValues;
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
            mVobHandler.onEndTransaction();
        }
        if (result > 0)
            mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
        return result;
    }
    return 0;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:37,代码来源:VideoProvider.java

示例13: applyBatch

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    if (DBG) Log.d(TAG, "applyBatch");
    ContentProviderResult[] result = null;
    SQLiteDatabase db = mDbHolder.get();
    mVobHandler.onBeginTransaction();
    db.beginTransactionNonExclusive();
    try {
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        int yield = 100;
        for (int i = 0; i < numOperations; i++) {
            results[i] = operations.get(i).apply(this, results, i);
            if (yield-- < 0) {
                yield = 100;
                db.yieldIfContendedSafely();
            }
        }
        result = results;
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        mVobHandler.onEndTransaction();
    }
    if (result != null) {
        mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
        mCr.notifyChange(ScraperStore.ALL_CONTENT_URI, null);
    }
    return result;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:32,代码来源:VideoProvider.java

示例14: insertLog

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void insertLog(Packet packet, String dname, int connection, boolean interactive) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.put("time", packet.time);
            cv.put("version", packet.version);

            if (packet.protocol < 0)
                cv.putNull("protocol");
            else
                cv.put("protocol", packet.protocol);

            cv.put("flags", packet.flags);

            cv.put("saddr", packet.saddr);
            if (packet.sport < 0)
                cv.putNull("sport");
            else
                cv.put("sport", packet.sport);

            cv.put("daddr", packet.daddr);
            if (packet.dport < 0)
                cv.putNull("dport");
            else
                cv.put("dport", packet.dport);

            if (dname == null)
                cv.putNull("dname");
            else
                cv.put("dname", dname);

            cv.put("data", packet.data);

            if (packet.uid < 0)
                cv.putNull("uid");
            else
                cv.put("uid", packet.uid);

            cv.put("allowed", packet.allowed ? 1 : 0);

            cv.put("connection", connection);
            cv.put("interactive", interactive ? 1 : 0);

            if (db.insert("log", null, cv) == -1)
                Log.e(TAG, "Insert log failed");

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyLogChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:60,代码来源:DatabaseHelper.java

示例15: updateAccess

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean updateAccess(Packet packet, String dname, int block) {
    int rows;

    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.put("time", packet.time);
            cv.put("allowed", packet.allowed ? 1 : 0);
            if (block >= 0)
                cv.put("block", block);

            // There is a segmented index on uid, version, protocol, daddr and dport
            rows = db.update("access", cv, "uid = ? AND version = ? AND protocol = ? AND daddr = ? AND dport = ?",
                    new String[]{
                            Integer.toString(packet.uid),
                            Integer.toString(packet.version),
                            Integer.toString(packet.protocol),
                            dname == null ? packet.daddr : dname,
                            Integer.toString(packet.dport)});

            if (rows == 0) {
                cv.put("uid", packet.uid);
                cv.put("version", packet.version);
                cv.put("protocol", packet.protocol);
                cv.put("daddr", dname == null ? packet.daddr : dname);
                cv.put("dport", packet.dport);
                if (block < 0)
                    cv.put("block", block);

                if (db.insert("access", null, cv) == -1)
                    Log.e(TAG, "Insert access failed");
            } else if (rows != 1)
                Log.e(TAG, "Update access failed rows=" + rows);

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyAccessChanged();
    return (rows == 0);
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:49,代码来源:DatabaseHelper.java


注:本文中的android.database.sqlite.SQLiteDatabase.beginTransactionNonExclusive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。