private synchronized void storeIDs(String tableName, boolean adjustQuantity, Connection connection) throws Exception {
    BigDecimal nextId = null;
    BigDecimal quantity = null;

    // Block on the table.  Multiple tables are allowed to ask for
    // ids simultaneously.
    // TableMap tMap = dbMap.getTable(tableName);
    // synchronized(tMap)  see comment in the getNextIds method
    // {
    if (adjustQuantity) {
      checkTiming(tableName);
    }

    boolean useNewConnection = (connection == null) || (configuration.getBoolean(DB_IDBROKER_USENEWCONNECTION, true));
    try {
      if (useNewConnection) {
        connection = Transaction.beginOptional(databaseName, transactionsSupported);
      }

      // Write the current value of quantity of keys to grab
      // to the database, primarily to obtain a write lock
      // on the table/row, but this value will also be used
      // as the starting value when an IDBroker is
      // instantiated.
      quantity = getQuantity(tableName, connection);
      updateQuantity(connection, tableName, quantity);

      // Read the next starting ID from the ID_TABLE.
      BigDecimal[] results = selectRow(connection, tableName);
      nextId = results[0]; // NEXT_ID column

      // Update the row based on the quantity in the
      // ID_TABLE.
      BigDecimal newNextId = nextId.add(quantity);
      updateNextId(connection, tableName, newNextId.toString());

      if (useNewConnection) {
        Transaction.commit(connection);
      }
    } catch (Exception e) {
      if (useNewConnection) {
        Transaction.rollback(connection);
      }
      throw e;
    }

    List availableIds = (List) ids.get(tableName);
    if (availableIds == null) {
      availableIds = new ArrayList();
      ids.put(tableName, availableIds);
    }

    // Create the ids and store them in the list of available ids.
    int numId = quantity.intValue();
    for (int i = 0; i < numId; i++) {
      availableIds.add(nextId);
      nextId = nextId.add(ONE);
    }
    // }
  }