List of usage examples for android.database.sqlite SQLiteConnection isPrimaryConnection
public boolean isPrimaryConnection()
From source file:io.requery.android.database.sqlite.SQLiteConnectionPool.java
private SQLiteConnection tryAcquirePrimaryConnectionLocked(int connectionFlags) { // If the primary connection is available, acquire it now. SQLiteConnection connection = mAvailablePrimaryConnection; if (connection != null) { mAvailablePrimaryConnection = null; finishAcquireConnectionLocked(connection, connectionFlags); // might throw return connection; }/*www.jav a 2 s. c o m*/ // Make sure that the primary connection actually exists and has just been acquired. for (SQLiteConnection acquiredConnection : mAcquiredConnections.keySet()) { if (acquiredConnection.isPrimaryConnection()) { return null; } } // Uhoh. No primary connection! Either this is the first time we asked // for it, or maybe it leaked? connection = openConnectionLocked(mConfiguration, true /*primaryConnection*/); // might throw finishAcquireConnectionLocked(connection, connectionFlags); // might throw return connection; }
From source file:io.requery.android.database.sqlite.SQLiteConnectionPool.java
/** * Returns true if the session should yield the connection due to * contention over available database connections. * * @param connection The connection owned by the session. * @param connectionFlags The connection request flags. * @return True if the session should yield its connection. * * @throws IllegalStateException if the connection was not acquired * from this pool or if it has already been released. *///from w w w.j a v a 2 s .c o m public boolean shouldYieldConnection(SQLiteConnection connection, int connectionFlags) { synchronized (mLock) { if (!mAcquiredConnections.containsKey(connection)) { throw new IllegalStateException( "Cannot perform this operation " + "because the specified connection was not acquired " + "from this pool or has already been released."); } if (!mIsOpen) { return false; } return isSessionBlockingImportantConnectionWaitersLocked(connection.isPrimaryConnection(), connectionFlags); } }
From source file:io.requery.android.database.sqlite.SQLiteConnectionPool.java
/** * Releases a connection back to the pool. * <p>/*w w w . j ava 2 s. c o m*/ * It is ok to call this method after the pool has closed, to release * connections that were still in use at the time of closure. * </p> * * @param connection The connection to release. Must not be null. * * @throws IllegalStateException if the connection was not acquired * from this pool or if it has already been released. */ public void releaseConnection(SQLiteConnection connection) { synchronized (mLock) { AcquiredConnectionStatus status = mAcquiredConnections.remove(connection); if (status == null) { throw new IllegalStateException( "Cannot perform this operation " + "because the specified connection was not acquired " + "from this pool or has already been released."); } if (!mIsOpen) { closeConnectionAndLogExceptionsLocked(connection); } else if (connection.isPrimaryConnection()) { if (recycleConnectionLocked(connection, status)) { assert mAvailablePrimaryConnection == null; mAvailablePrimaryConnection = connection; } wakeConnectionWaitersLocked(); } else if (mAvailableNonPrimaryConnections.size() >= mMaxConnectionPoolSize - 1) { closeConnectionAndLogExceptionsLocked(connection); } else { if (recycleConnectionLocked(connection, status)) { mAvailableNonPrimaryConnections.add(connection); } wakeConnectionWaitersLocked(); } } }