db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashley Hayes <ashley.ha...@macalla.com>
Subject IDBroker uses two new DB connections on forced ID retrieval
Date Tue, 14 Oct 2003 11:36:07 GMT
  I was looking at the preformace of my application and noticed that the
IDBroker grabs 
an unnecessary connection to the DB. 
If "getQuantity" method is called from "storeIDs" - the connection object
will be a valid and based
the value of the DB_IDBROKER_USENEWCONNECTION property.
However the current "getQuantity" method checks the
DB_IDBROKER_USENEWCONNECTION again, if true it will create a 2nd new
connection to get the quantity value. Not really necessary.. as the update
below shows...

Also the update is a patch for another problem I noticed in the "getQuanity"
if DB_IDBROKER_USENEWCONNECTION is set to false and the connection parameter
is not null ( in the case of a forced id retrieval) then the dbCon object
will be left as null, causing two NullPointerExecption  and the use of the
default quanity. 

For the case of the broker background thread, the behaviour seems ok, just
gets and releases the conns as they are needed in each method.

Hope this update helps,
thanks for the great work,

	  private BigDecimal getQuantity(String tableName, Connection
            BigDecimal quantity = null;

            // If prefetch is turned off we simply return 1
            if (!configuration.getBoolean(DB_IDBROKER_PREFETCH, true))
                quantity = new BigDecimal(1);
            // Initialize quantity, if necessary.
            else if (quantityStore.containsKey(tableName))
                quantity = (BigDecimal) quantityStore.get(tableName);
                //connection will already be new if
                boolean newConnection = (connection == null);
                    if (newConnection)
                        String databaseName =
                        // Get a connection to the db
                        connection = Torque.getConnection(databaseName);

                    // Read the row from the ID_TABLE.
                    BigDecimal[] results = selectRow(connection, tableName);

                    // QUANTITY column.
                    quantity = results[1];
                    quantityStore.put(tableName, quantity);
                catch (Exception e)
                    quantity = new BigDecimal(10);
                    // Return the connection to the pool.
                        catch (Exception e)
                            log.error("Release of connection failed.", e);
            return quantity;

To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message