Lines Matching defs:connection

39  * At any given time, a connection is either owned by the pool, or it has been
41 * finished with the connection it is using, it must return the connection
47 * that the connection pool can detect when connections have been improperly
50 * The connection pool is thread-safe (but the connections themselves are not).
76 // and logging a message about the connection pool being busy.
96 // Describes what should happen to an acquired connection when it is returned to the pool.
98 // The connection should be returned to the pool as usual.
101 // The connection must be reconfigured before being returned.
104 // The connection must be closed and discarded.
109 // indicates whether the connection must be reconfigured before being
110 // returned to the available connection list or discarded.
119 * This flag indicates that the connection will only be used to
126 * Connection flag: Primary connection affinity.
128 * This flag indicates that the primary connection is required.
130 * operations to be serialized by locking the primary database connection.
133 * the primary connection.
141 * This flag indicates that the connection is needed by the UI thread.
142 * The connection pool can use this flag to elevate the priority
143 * of the database connection request.
163 * Opens a connection pool for the specified database.
166 * @return The connection pool.
183 // Open the primary connection.
194 * Closes the connection pool.
196 * When the connection pool is closed, it will refuse all further requests
230 Log.i(TAG, "The connection pool for " + mConfiguration.label
242 * Reconfigures the database configuration of the connection pool and all of its
266 // because we need to close all but the primary connection first.
296 // we have no choice but to close the primary connection beforehand
297 // because there can only be one connection open when we change WAL mode.
302 // Try to reopen the primary connection using the new open flags then
329 * Acquires a connection from the pool.
331 * The caller must call {@link #releaseConnection} to release the connection
336 * @param sql If not null, try to find a connection that already has
338 * @param connectionFlags The connection request flags.
340 * @return The connection that was acquired, never null.
352 * Releases a connection back to the pool.
358 * @param connection The connection to release. Must not be null.
360 * @throws IllegalStateException if the connection was not acquired
363 public void releaseConnection(SQLiteConnection connection) {
365 AcquiredConnectionStatus status = mAcquiredConnections.remove(connection);
368 + "because the specified connection was not acquired "
373 closeConnectionAndLogExceptionsLocked(connection);
374 } else if (connection.isPrimaryConnection()) {
375 if (recycleConnectionLocked(connection, status)) {
377 mAvailablePrimaryConnection = connection;
381 closeConnectionAndLogExceptionsLocked(connection);
383 if (recycleConnectionLocked(connection, status)) {
384 mAvailableNonPrimaryConnections.add(connection);
392 private boolean recycleConnectionLocked(SQLiteConnection connection,
396 connection.reconfigure(mConfiguration); // might throw
398 Log.e(TAG, "Failed to reconfigure released connection, closing it: "
399 + connection, ex);
404 closeConnectionAndLogExceptionsLocked(connection);
411 * Returns true if the session should yield the connection due to
414 * @param connection The connection owned by the session.
415 * @param connectionFlags The connection request flags.
416 * @return True if the session should yield its connection.
418 * @throws IllegalStateException if the connection was not acquired
421 public boolean shouldYieldConnection(SQLiteConnection connection, int connectionFlags) {
423 if (!mAcquiredConnections.containsKey(connection)) {
425 + "because the specified connection was not acquired "
434 connection.isPrimaryConnection(), connectionFlags);
439 * Collects statistics about database connection memory usage.
449 for (SQLiteConnection connection : mAvailableNonPrimaryConnections) {
450 connection.collectDbStats(dbStatsList);
453 for (SQLiteConnection connection : mAcquiredConnections.keySet()) {
454 connection.collectDbStatsUnsafe(dbStatsList);
470 // We don't know whether it is just the connection that has been finalized (and leaked)
471 // or whether the connection pool has also been or is about to be finalized.
485 // several seconds while waiting for a leaked connection to be detected and recreated,
519 SQLiteConnection connection =
521 closeConnectionAndLogExceptionsLocked(connection);
526 private void closeConnectionAndLogExceptionsLocked(SQLiteConnection connection) {
528 connection.close(); // might throw
530 Log.e(TAG, "Failed to close connection, its fate is now in the hands "
531 + "of the merciful GC: " + connection, ex);
546 Log.e(TAG, "Failed to reconfigure available primary connection, closing it: "
555 final SQLiteConnection connection = mAvailableNonPrimaryConnections.get(i);
557 connection.reconfigure(mConfiguration); // might throw
559 Log.e(TAG, "Failed to reconfigure available non-primary connection, closing it: "
560 + connection, ex);
561 closeConnectionAndLogExceptionsLocked(connection);
606 // Try to acquire a connection.
607 SQLiteConnection connection = null;
609 connection = tryAcquireNonPrimaryConnectionLocked(
612 if (connection == null) {
613 connection = tryAcquirePrimaryConnectionLocked(connectionFlags); // might throw
615 if (connection != null) {
616 return connection;
657 // Park the thread until a connection is assigned or the pool is closed.
662 // Detect and recover from connection leaks.
679 final SQLiteConnection connection = waiter.mAssignedConnection;
681 if (connection != null || ex != null) {
683 if (connection != null) {
684 return connection;
740 msg.append("The connection pool for database '").append(mConfiguration.label);
741 msg.append("' has been unable to grant a connection to thread ");
750 for (SQLiteConnection connection : mAcquiredConnections.keySet()) {
751 String description = connection.describeCurrentOperationUnsafe();
794 SQLiteConnection connection = null;
796 connection = tryAcquireNonPrimaryConnectionLocked(
798 if (connection == null) {
802 if (connection == null && !primaryConnectionNotAvailable) {
803 connection = tryAcquirePrimaryConnectionLocked(
805 if (connection == null) {
809 if (connection != null) {
810 waiter.mAssignedConnection = connection;
814 // We cannot fulfill any more connection requests, so stop here.
818 // Let the waiter handle the exception from acquiring a connection.
843 // If the primary connection is available, acquire it now.
844 SQLiteConnection connection = mAvailablePrimaryConnection;
845 if (connection != null) {
847 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
848 return connection;
851 // Make sure that the primary connection actually exists and has just been acquired.
858 // Uhoh. No primary connection! Either this is the first time we asked
860 connection = openConnectionLocked(mConfiguration,
862 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
863 return connection;
869 // Try to acquire the next connection in the queue.
870 SQLiteConnection connection;
873 // If we have a choice, then prefer a connection that has the
876 connection = mAvailableNonPrimaryConnections.get(i);
877 if (connection.isPreparedStatementInCache(sql)) {
879 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
880 return connection;
886 connection = mAvailableNonPrimaryConnections.remove(availableCount - 1);
887 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
888 return connection;
899 connection = openConnectionLocked(mConfiguration,
901 finishAcquireConnectionLocked(connection, connectionFlags); // might throw
902 return connection;
906 private void finishAcquireConnectionLocked(SQLiteConnection connection, int connectionFlags) {
909 connection.setOnlyAllowReadOnlyOperations(readOnly);
911 mAcquiredConnections.put(connection, AcquiredConnectionStatus.NORMAL);
913 Log.e(TAG, "Failed to prepare acquired connection for session, closing it: "
914 + connection +", connectionFlags=" + connectionFlags);
915 closeConnectionAndLogExceptionsLocked(connection);
931 // If we are holding the primary connection then we are blocking the waiter.
932 // Likewise, if we are holding a non-primary connection and the waiter
933 // would accept a non-primary connection, then we are blocking the waier.
952 // TODO: We don't actually need to restrict the connection pool size to 1
953 // for non-WAL databases. There might be reasons to use connection pooling
954 // with other journal modes. For now, enabling connection pooling and
963 + "because the connection pool has been closed.");
996 * Dumps debugging information about this connection pool.
1008 printer.println(" Available primary connection:");
1029 final SQLiteConnection connection = entry.getKey();
1030 connection.dumpUnsafe(indentedPrinter, verbose);