1 21 package oracle.toplink.essentials.threetier; 23 24 import java.util.*; 25 import oracle.toplink.essentials.internal.databaseaccess.*; 26 import oracle.toplink.essentials.sessions.Login; 27 import oracle.toplink.essentials.exceptions.*; 28 29 36 public class ReadConnectionPool extends ConnectionPool { 37 38 42 public ReadConnectionPool() { 43 super(); 44 } 45 46 50 public ReadConnectionPool(String name, Login login, int minNumberOfConnections, int maxNumberOfConnections, ServerSession owner) { 51 super(name, login, minNumberOfConnections, maxNumberOfConnections, owner); 52 } 53 54 58 public synchronized Accessor acquireConnection() throws ConcurrencyException { 59 Accessor leastBusyConnection = null; 60 61 for (Enumeration connectionsEnum = getConnectionsAvailable().elements(); 63 connectionsEnum.hasMoreElements();) { 64 Accessor connection = (Accessor)connectionsEnum.nextElement(); 65 if (connection.getCallCount() == 0) { 66 connection.incrementCallCount(getOwner()); 67 return connection; 68 } 69 if ((leastBusyConnection == null) || (leastBusyConnection.getCallCount() > connection.getCallCount())) { 70 leastBusyConnection = connection; 71 } 72 } 73 74 if (getTotalNumberOfConnections() < getMaxNumberOfConnections()) { 76 Accessor connection = buildConnection(); 77 getConnectionsAvailable().addElement(connection); 78 connection.incrementCallCount(getOwner()); 79 return connection; 80 } 81 82 leastBusyConnection.incrementCallCount(getOwner()); 84 return leastBusyConnection; 85 } 86 87 91 public boolean hasConnectionAvailable() { 92 return true; 93 } 94 95 99 public synchronized void releaseConnection(Accessor connection) throws DatabaseException { 100 connection.decrementCallCount(); 101 } 102 } 103 | Popular Tags |