Home | History | Annotate | Download | only in sqlite

Lines Matching defs:connection

47  * At any given time, a connection is either owned by the pool, or it has been
49 * finished with the connection it is using, it must return the connection
55 * that the connection pool can detect when connections have been improperly
58 * The connection pool is thread-safe (but the connections themselves are not).
84 // and logging a message about the connection pool being busy.
109 // Describes what should happen to an acquired connection when it is returned to the pool.
111 // The connection should be returned to the pool as usual.
114 // The connection must be reconfigured before being returned.
117 // The connection must be closed and discarded.
122 // indicates whether the connection must be reconfigured before being
123 // returned to the available connection list or discarded.
130 * Connection flag: Read-only.
132 * This flag indicates that the connection will only be used to
139 * Connection flag: Primary connection affinity.
141 * This flag indicates that the primary connection is required.
143 * operations to be serialized by locking the primary database connection.
146 * the primary connection.
152 * Connection flag: Connection is being used interactively.
154 * This flag indicates that the connection is needed by the UI thread.
155 * The connection pool can use this flag to elevate the priority
156 * of the database connection request.
164 // If timeout is set, setup idle connection handler
182 * Opens a connection pool for the specified database.
185 * @return The connection pool.
202 // Open the primary connection.
219 * Closes the connection pool.
221 * When the connection pool is closed, it will refuse all further requests
255 Log.i(TAG, "The connection pool for " + mConfiguration.label
267 * Reconfigures the database configuration of the connection pool and all of its
291 // because we need to close all but the primary connection first.
320 // to rollback journal. Otherwise transient connection state will be lost
326 // we have no choice but to close the primary connection beforehand
327 // because there can only be one connection open when we change WAL mode.
332 // Try to reopen the primary connection using the new open flags then
359 * Acquires a connection from the pool.
361 * The caller must call {@link #releaseConnection} to release the connection
366 * @param sql If not null, try to find a connection that already has
368 * @param connectionFlags The connection request flags.
370 * @return The connection that was acquired, never null.
388 * Releases a connection back to the pool.
394 connection The connection to release. Must not be null.
396 * @throws IllegalStateException if the connection was not acquired
399 public void releaseConnection(SQLiteConnection connection) {
402 mIdleConnectionHandler.connectionReleased(connection);
404 AcquiredConnectionStatus status = mAcquiredConnections.remove(connection);
407 + "because the specified connection was not acquired "
412 closeConnectionAndLogExceptionsLocked(connection);
413 } else if (connection.isPrimaryConnection()) {
414 if (recycleConnectionLocked(connection, status)) {
416 mAvailablePrimaryConnection = connection;
420 closeConnectionAndLogExceptionsLocked(connection);
422 if (recycleConnectionLocked(connection, status)) {
423 mAvailableNonPrimaryConnections.add(connection);
432 private boolean recycleConnectionLocked(SQLiteConnection connection,
436 connection.reconfigure(mConfiguration); // might throw
438 Log.e(TAG, "Failed to reconfigure released connection, closing it: "
439 + connection, ex);
444 closeConnectionAndLogExceptionsLocked(connection);
451 * Returns true if the session should yield the connection due to
454 * @param connection The connection owned by the session.
455 * @param connectionFlags The connection request flags.
456 * @return True if the session should yield its connection.
458 * @throws IllegalStateException if the connection was not acquired
461 public boolean shouldYieldConnection(SQLiteConnection connection, int connectionFlags) {
463 if (!mAcquiredConnections.containsKey(connection)) {
465 + "because the specified connection was not acquired "
474 connection.isPrimaryConnection(), connectionFlags);
479 * Collects statistics about database connection memory usage.
489 for (SQLiteConnection connection : mAvailableNonPrimaryConnections) {
490 connection.collectDbStats(dbStatsList);
493 for (SQLiteConnection connection : mAcquiredConnections.keySet()) {
494 connection.collectDbStatsUnsafe(dbStatsList);
510 // We don't know whether it is just the connection that has been finalized (and leaked)
511 // or whether the connection pool has also been or is about to be finalized.
525 // several seconds while waiting for a leaked connection to be detected and recreated,
598 SQLiteConnection connection =
600 closeConnectionAndLogExceptionsLocked(connection);
606 private void closeConnectionAndLogExceptionsLocked(SQLiteConnection connection) {
608 connection.close(); // might throw
610 mIdleConnectionHandler.connectionClosed(connection);
613 Log.e(TAG, "Failed to close connection, its fate is now in the hands "
614 + "of the merciful GC: " + connection, ex);
630 Log.e(TAG, "Failed to reconfigure available primary connection, closing it: "
639 final SQLiteConnection connection = mAvailableNonPrimaryConnections.get(i);
641 connection.reconfigure(mConfiguration); // might throw
643 Log.e(TAG, "Failed to reconfigure available non-primary connection, closing it: "
644 + connection, ex);
645 closeConnectionAndLogExceptionsLocked(connection);
690 // Try to acquire a connection.
691 SQLiteConnection connection = null;
693 connection = tryAcquireNonPrimaryConnectionLocked(
696 if (connection == null) {
697 connection = tryAcquirePrimaryConnectionLocked(connectionFlags); // might throw
699 if (connection != null) {
700 return connection;
741 // Park the thread until a connection is assigned or the pool is closed.
746 // Detect and recover from connection leaks.
763 final SQLiteConnection connection = waiter.mAssignedConnection;
765 if (connection != null || ex != null) {
767 if (connection != null) {
768 return connection;
825 msg.append("The connection pool for database '").append(mConfiguration.label);
826 msg.append("' has been unable to grant a connection to thread ");
835 for (SQLiteConnection connection : mAcquiredConnections.keySet()) {
836 String description = connection.describeCurrentOperationUnsafe();
880 SQLiteConnection connection = null;
882 connection = tryAcquireNonPrimaryConnectionLocked(
884 if (connection == null) {
888 if (connection == null && !primaryConnectionNotAvailable) {
889 connection = tryAcquirePrimaryConnectionLocked(
891 if (connection == null) {
895 if (connection != null) {
896 waiter.mAssignedConnection = connection;
900 // We cannot fulfill any more connection requests, so stop here.
904 // Let the waiter handle the exception from acquiring a connection.
930 // If the primary connection is available, acquire it now.
931 SQLiteConnection connection = mAvailablePrimaryConnection;
932 if (connection != null) {
934 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
935 return connection;
938 // Make sure that the primary connection actually exists and has just been acquired.
945 // Uhoh. No primary connection! Either this is the first time we asked
947 connection = openConnectionLocked(mConfiguration,
949 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
950 return connection;
957 // Try to acquire the next connection in the queue.
958 SQLiteConnection connection;
961 // If we have a choice, then prefer a connection that has the
964 connection = mAvailableNonPrimaryConnections.get(i);
965 if (connection.isPreparedStatementInCache(sql)) {
967 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
968 return connection;
974 connection = mAvailableNonPrimaryConnections.remove(availableCount - 1);
975 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
976 return connection;
987 connection = openConnectionLocked(mConfiguration,
989 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
990 return connection;
995 private void finishAcquireConnectionLocked(SQLiteConnection connection, int connectionFlags) {
998 connection.setOnlyAllowReadOnlyOperations(readOnly);
1000 mAcquiredConnections.put(connection, AcquiredConnectionStatus.NORMAL);
1002 Log.e(TAG, "Failed to prepare acquired connection for session, closing it: "
1003 + connection +", connectionFlags=" + connectionFlags);
1004 closeConnectionAndLogExceptionsLocked(connection);
1020 // If we are holding the primary connection then we are blocking the waiter.
1021 // Likewise, if we are holding a non-primary connection and the waiter
1022 // would accept a non-primary connection, then we are blocking the waier.
1042 // We don't actually need to always restrict the connection pool size to 1
1043 // for non-WAL databases. There might be reasons to use connection pooling
1046 // For now, enabling connection pooling and using WAL are the same thing in the API.
1070 + "because the connection pool has been closed.");
1103 * Dumps debugging information about this connection pool.
1111 printer.println("Connection pool for " + mConfiguration.path + ":");
1132 " Idle connection timeout: " + mConfiguration.idleConnectionTimeoutMs);
1134 printer.println(" Available primary connection:");
1155 final SQLiteConnection connection = entry.getKey();
1156 connection.dumpUnsafe(indentedPrinter, verbose);
1163 printer.println(" Connection waiters:");
1216 Log.d(TAG, "Closed idle connection " + mConfiguration.label + " " + msg.what