mpoeschl    02/05/07 10:13:23

  Modified:    src/java/org/apache/torque/oid AutoIncrementIdGenerator.java
                        IDBroker.java IdGenerator.java
                        SequenceIdGenerator.java
  Log:
  coding convetions
  javadocs
  
  Revision  Changes    Path
  1.4       +8 -10     
jakarta-turbine-torque/src/java/org/apache/torque/oid/AutoIncrementIdGenerator.java
  
  Index: AutoIncrementIdGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/AutoIncrementIdGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AutoIncrementIdGenerator.java     13 Aug 2001 22:26:18 -0000      1.3
  +++ AutoIncrementIdGenerator.java     7 May 2002 17:13:22 -0000       1.4
  @@ -57,7 +57,6 @@
   import java.math.BigDecimal;
   import java.sql.Connection;
   import org.apache.torque.adapter.DB;
  -import com.workingdogs.village.DataSet;
   import com.workingdogs.village.QueryDataSet;
   import com.workingdogs.village.Record;
   import com.workingdogs.village.Value;
  @@ -68,7 +67,7 @@
    * Connection.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
  - * @version $Id: AutoIncrementIdGenerator.java,v 1.3 2001/08/13 22:26:18 dlr Exp $
  + * @version $Id: AutoIncrementIdGenerator.java,v 1.4 2002/05/07 17:13:22 mpoeschl 
Exp $
    */
   public class AutoIncrementIdGenerator
       implements IdGenerator
  @@ -78,7 +77,7 @@
       /**
        * Creates an IdGenerator which will work with the specified database.
        *
  -     * @param dbAdapter, the adapter that knows the correct sql syntax.
  +     * @param adapter the adapter that knows the correct sql syntax.
        */
       public AutoIncrementIdGenerator(DB adapter)
       {
  @@ -89,7 +88,7 @@
        * Returns the last ID used by this connection.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return An int with the value for the id.
        * @exception Exception Database error.
        */
  @@ -103,7 +102,7 @@
        * Returns the last ID used by this connection.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A long with the value for the id.
        * @exception Exception Database error.
        */
  @@ -117,7 +116,7 @@
        * Returns the last ID used by this connection.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A BigDecimal with the last value auto-incremented as a
        * result of an insert.
        * @exception Exception Database error.
  @@ -133,7 +132,7 @@
        * Returns the last ID used by this connection.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A String with the last value auto-incremented as a
        * result of an insert.
        * @exception Exception Database error.
  @@ -179,13 +178,12 @@
        * Returns the last ID used by this connection.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A Village Value with the last value auto-incremented as a
        * result of an insert.
        * @exception Exception Database error.
        */
  -    private Value getIdAsVillageValue(Connection connection,
  -                                      Object keyInfo)
  +    private Value getIdAsVillageValue(Connection connection, Object keyInfo)
           throws Exception
       {
           String idSQL = dbAdapter.getIDMethodSQL(keyInfo);
  
  
  
  1.16      +57 -50    
jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java
  
  Index: IDBroker.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- IDBroker.java     29 Apr 2002 19:47:46 -0000      1.15
  +++ IDBroker.java     7 May 2002 17:13:22 -0000       1.16
  @@ -56,11 +56,9 @@
   
   import java.math.BigDecimal;
   import java.sql.Connection;
  -import java.sql.DatabaseMetaData;
   import java.sql.ResultSet;
   import java.sql.Statement;
   import java.util.ArrayList;
  -import java.util.Date;
   import java.util.Iterator;
   import java.util.Hashtable;
   import java.util.List;
  @@ -72,7 +70,6 @@
   import org.apache.torque.map.TableMap;
   import org.apache.torque.pool.DBConnection;
   import org.apache.torque.util.BasePeer;
  -import org.apache.torque.util.Criteria;
   
   //!!
   // NOTE:
  @@ -113,7 +110,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Frank Y. Kim</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
  - * @version $Id: IDBroker.java,v 1.15 2002/04/29 19:47:46 jon Exp $
  + * @version $Id: IDBroker.java,v 1.16 2002/05/07 17:13:22 mpoeschl Exp $
    */
   public class IDBroker
       implements Runnable, IdGenerator
  @@ -283,10 +280,10 @@
        * require a Connection, it just implements the KeyGenerator
        * interface.  if a Connection is needed one will be requested.
        * To force the use of the passed in connection set the configuration
  -     * property torque.idbroker.usenewconnection = false 
  +     * property torque.idbroker.usenewconnection = false
        *
        * @param connection A Connection.
  -     * @param tableName, an Object that contains additional info.
  +     * @param tableName an Object that contains additional info.
        * @return An int with the value for the id.
        * @exception Exception Database error.
        */
  @@ -302,10 +299,10 @@
        * require a Connection, it just implements the KeyGenerator
        * interface.  if a Connection is needed one will be requested.
        * To force the use of the passed in connection set the configuration
  -     * property torque.idbroker.usenewconnection = false 
  +     * property torque.idbroker.usenewconnection = false
        *
        * @param connection A Connection.
  -     * @param tableName, a String that identifies a table.
  +     * @param tableName a String that identifies a table.
        * @return A long with the value for the id.
        * @exception Exception Database error.
        */
  @@ -320,10 +317,10 @@
        * require a Connection, it just implements the KeyGenerator
        * interface.  if a Connection is needed one will be requested.
        * To force the use of the passed in connection set the configuration
  -     * property torque.idbroker.usenewconnection = false 
  +     * property torque.idbroker.usenewconnection = false
        *
        * @param connection A Connection.
  -     * @param tableName, a String that identifies a table..
  +     * @param tableName a String that identifies a table..
        * @return A BigDecimal id.
        * @exception Exception Database error.
        */
  @@ -331,7 +328,7 @@
                                           Object tableName)
           throws Exception
       {
  -        BigDecimal[] id = getNextIds((String)tableName, 1, connection);
  +        BigDecimal[] id = getNextIds((String) tableName, 1, connection);
           return id[0];
       }
   
  @@ -340,10 +337,10 @@
        * require a Connection, it just implements the KeyGenerator
        * interface.  if a Connection is needed one will be requested.
        * To force the use of the passed in connection set the configuration
  -     * property torque.idbroker.usenewconnection = false 
  +     * property torque.idbroker.usenewconnection = false
        *
        * @param connection A Connection should be null.
  -     * @param tableName, a String that identifies a table.
  +     * @param tableName a String that identifies a table.
        * @return A String id
        * @exception Exception Database error.
        */
  @@ -404,10 +401,11 @@
        * Note this method does not require a Connection.
        * If a Connection is needed one will be requested.
        * To force the use of the passed in connection set the configuration
  -     * property torque.idbroker.usenewconnection = false 
  +     * property torque.idbroker.usenewconnection = false
        *
        * @param tableName The name of the table for which we want an id.
        * @param numOfIdsToReturn The desired number of ids.
  +     * @param connection A Connection.
        * @return A BigDecimal.
        * @exception Exception Database error.
        */
  @@ -430,7 +428,7 @@
           // would be preferrable to avoid the synchronization on the
           // method
   
  -        List availableIds = (List)ids.get(tableName);
  +        List availableIds = (List) ids.get(tableName);
   
           if ( availableIds == null ||
                availableIds.size() < numOfIdsToReturn )
  @@ -444,7 +442,7 @@
                   category.info ("Forced id retrieval - " + availableIds.size());
               }
               storeIDs(tableName, true, connection);
  -            availableIds = (List)ids.get(tableName);
  +            availableIds = (List) ids.get(tableName);
           }
   
           int size = availableIds.size() < numOfIdsToReturn ?
  @@ -457,9 +455,9 @@
           // a specific table.
   //        synchronized (availableIds)
   //        {
  -            for (int i=size-1; i>=0; i--)
  +            for (int i = size - 1; i >= 0; i--)
               {
  -                    results[i] = (BigDecimal)availableIds.get(i);
  +                    results[i] = (BigDecimal) availableIds.get(i);
                       availableIds.remove(i);
               }
   //        }
  @@ -474,6 +472,7 @@
        * the row
        * @return a <code>boolean</code> value
        * @exception TorqueException if an error occurs
  +     * @exception Exception
        */
       public boolean exists(String tableName)
           throws TorqueException, Exception
  @@ -541,10 +540,10 @@
               Iterator it = ids.keySet().iterator();
               while (it.hasNext())
               {
  -                String tableName = (String)it.next();
  -                category.info("IDBroker thread checking for more keys on table: " +
  -                         tableName);
  -                List availableIds = (List)ids.get(tableName);
  +                String tableName = (String) it.next();
  +                category.info("IDBroker thread checking for more keys "
  +                        + "on table: " + tableName);
  +                List availableIds = (List) ids.get(tableName);
                   int quantity = getQuantity(tableName, null).intValue();
                   if ( quantity > availableIds.size() )
                   {
  @@ -554,13 +553,13 @@
                           // want the quantity to be adjusted for thread
                           // calls.
                           storeIDs(tableName, false, null);
  -                        category.info("Retrieved more ids for table: " +
  -                                 tableName);
  +                        category.info("Retrieved more ids for table: "
  +                                + tableName);
                       }
                       catch (Exception exc)
                       {
  -                        category.error("There was a problem getting new IDs for 
table: " +
  -                                  tableName, exc);
  +                        category.error("There was a problem getting new IDs "
  +                                + "for table: " + tableName, exc);
                       }
                   }
               }
  @@ -601,14 +600,14 @@
   
           // Get the last id request for this table.
           java.util.Date lastTime =
  -            (java.util.Date)lastQueryTime.get (tableName);
  +            (java.util.Date) lastQueryTime.get(tableName);
           java.util.Date now = new java.util.Date();
   
           if ( lastTime != null)
           {
               long thenLong = lastTime.getTime();
               long nowLong = now.getTime();
  -            int timeLapse = (int)(nowLong-thenLong);
  +            int timeLapse = (int) (nowLong - thenLong);
               if ( timeLapse < sleepPeriod && timeLapse > 0 )
               {
                   category.info("Unscheduled retrieval of more ids for table: " +
  @@ -616,12 +615,12 @@
                   // Increase quantity, so that hopefully this does not
                   // happen again.
                   float rate = getQuantity(tableName, null).floatValue()
  -                    / (float)timeLapse;
  -                quantityStore.put(tableName,
  -                    new BigDecimal(Math.ceil(sleepPeriod*rate*safetyMargin)));
  +                        / (float) timeLapse;
  +                quantityStore.put(tableName, new BigDecimal(
  +                        Math.ceil(sleepPeriod * rate * safetyMargin)));
               }
           }
  -        lastQueryTime.put (tableName,now);
  +        lastQueryTime.put(tableName, now);
       }
   
       /**
  @@ -631,6 +630,7 @@
        *
        * @param tableName The name of the table for which we want an id.
        * @param adjustQuantity True if amount should be adjusted.
  +     * @param connection a Connection
        * @exception Exception a generic exception.
        */
       private void storeIDs(String tableName,
  @@ -656,7 +656,7 @@
               try
               {
                   if (connection == null || configuration
  -                    .getBoolean(DB_IDBROKER_USENEWCONNECTION, true)) 
  +                    .getBoolean(DB_IDBROKER_USENEWCONNECTION, true))
                   {
                       String databaseName = dbMap.getName();
                       // Get a connection to the db by starting a
  @@ -669,9 +669,9 @@
                       {
                           dbCon = Torque.getConnection(databaseName);
                       }
  -                    connection = dbCon.getConnection();    
  +                    connection = dbCon.getConnection();
                   }
  -                
  +
                   // 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
  @@ -711,7 +711,7 @@
                   }
               }
   
  -            List availableIds = (List)ids.get(tableName);
  +            List availableIds = (List) ids.get(tableName);
               if ( availableIds == null )
               {
                   availableIds = new ArrayList();
  @@ -720,7 +720,7 @@
   
               // Create the ids and store them in the list of available ids.
               int numId = quantity.intValue();
  -            for (int i=0; i<numId; i++)
  +            for (int i = 0; i < numId; i++)
               {
                   availableIds.add(nextId);
                   nextId = nextId.add(ONE);
  @@ -739,6 +739,7 @@
        * only because it is going to be added to another BigDecimal.
        *
        * @param tableName The name of the table we want to query.
  +     * @param connection a Connection
        * @return An int with the number of ids cached in memory.
        */
       private BigDecimal getQuantity(String tableName, Connection connection)
  @@ -753,7 +754,7 @@
           // Initialize quantity, if necessary.
           else if (quantityStore.containsKey(tableName))
           {
  -            quantity = (BigDecimal)quantityStore.get(tableName);
  +            quantity = (BigDecimal) quantityStore.get(tableName);
           }
           else
           {
  @@ -761,7 +762,7 @@
               try
               {
                   if (connection == null || configuration
  -                    .getBoolean(DB_IDBROKER_USENEWCONNECTION, true)) 
  +                    .getBoolean(DB_IDBROKER_USENEWCONNECTION, true))
                   {
                       String databaseName = tableMap.getDatabaseMap().getName();
                       // Get a connection to the db
  @@ -785,9 +786,9 @@
                   // Return the connection to the pool.
                   try
                   {
  -                    if (dbCon != null) 
  +                    if (dbCon != null)
                       {
  -                        Torque.releaseConnection(dbCon);        
  +                        Torque.releaseConnection(dbCon);
                       }
                   }
                   catch (Exception e)
  @@ -827,7 +828,7 @@
               statement = con.createStatement();
               ResultSet rs = statement.executeQuery( stmt.toString() );
   
  -            if(rs.next())
  +            if (rs.next())
               {
                   // work around for MySQL which appears to support
                   // getBigDecimal in the source code, but the binary
  @@ -837,13 +838,16 @@
               }
               else
               {
  -                throw new TorqueException("The table "+tableName+
  +                throw new TorqueException("The table " + tableName +
                       " does not have a proper entry in the " + ID_TABLE);
               }
           }
           finally
           {
  -            if (statement != null) statement.close();
  +            if (statement != null)
  +            {
  +                statement.close();
  +            }
           }
   
           return results;
  @@ -885,11 +889,13 @@
           }
           finally
           {
  -            if (statement != null) statement.close();
  +            if (statement != null)
  +            {
  +                statement.close();
  +            }
           }
       }
   
  -
       /**
        * Helper method to update a row in the ID_TABLE.
        *
  @@ -902,10 +908,8 @@
       private void updateQuantity(Connection con,
                                   String tableName,
                                   BigDecimal quantity)
  -        throws Exception
  +            throws Exception
       {
  -
  -
           StringBuffer stmt =
               new StringBuffer(quantity.toString().length() + tableName.length()
                                + 50);
  @@ -927,7 +931,10 @@
           }
           finally
           {
  -            if (statement != null) statement.close();
  +            if (statement != null)
  +            {
  +                statement.close();
  +            }
           }
       }
   }
  
  
  
  1.7       +2 -4      
jakarta-turbine-torque/src/java/org/apache/torque/oid/IdGenerator.java
  
  Index: IdGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/IdGenerator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IdGenerator.java  26 Jan 2002 02:27:42 -0000      1.6
  +++ IdGenerator.java  7 May 2002 17:13:22 -0000       1.7
  @@ -56,7 +56,6 @@
   
   import java.sql.Connection;
   import java.math.BigDecimal;
  -import org.apache.torque.adapter.DB;
   
   /**
    * Interface to be implemented by id generators.  It is possible
  @@ -67,7 +66,7 @@
    * Connection pool service only when needed.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
  - * @version $Id: IdGenerator.java,v 1.6 2002/01/26 02:27:42 dlr Exp $
  + * @version $Id: IdGenerator.java,v 1.7 2002/05/07 17:13:22 mpoeschl Exp $
    */
   public interface IdGenerator
   {
  @@ -104,8 +103,7 @@
        * @return A BigDecimal id.
        * @exception Exception Database error.
        */
  -    BigDecimal getIdAsBigDecimal(Connection connection,
  -                                 Object keyInfo)
  +    BigDecimal getIdAsBigDecimal(Connection connection, Object keyInfo)
           throws Exception;
   
       /**
  
  
  
  1.4       +12 -14    
jakarta-turbine-torque/src/java/org/apache/torque/oid/SequenceIdGenerator.java
  
  Index: SequenceIdGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/SequenceIdGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SequenceIdGenerator.java  13 Aug 2001 22:26:18 -0000      1.3
  +++ SequenceIdGenerator.java  7 May 2002 17:13:22 -0000       1.4
  @@ -57,7 +57,6 @@
   import java.math.BigDecimal;
   import java.sql.Connection;
   import org.apache.torque.adapter.DB;
  -import com.workingdogs.village.DataSet;
   import com.workingdogs.village.QueryDataSet;
   import com.workingdogs.village.Record;
   import com.workingdogs.village.Value;
  @@ -67,7 +66,7 @@
    * getting an id prior to inserting a row into the database.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
  - * @version $Id: SequenceIdGenerator.java,v 1.3 2001/08/13 22:26:18 dlr Exp $
  + * @version $Id: SequenceIdGenerator.java,v 1.4 2002/05/07 17:13:22 mpoeschl Exp $
    */
   public class SequenceIdGenerator
       implements IdGenerator
  @@ -77,7 +76,7 @@
       /**
        * Creates an IdGenerator which will work with the specified database.
        *
  -     * @param dbAdapter, the adapter that knows the correct sql syntax.
  +     * @param adapter the adapter that knows the correct sql syntax.
        */
       public SequenceIdGenerator(DB adapter)
       {
  @@ -88,7 +87,7 @@
        * Retrieves an id as an int.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return An int with the value for the id.
        * @exception Exception Database error.
        */
  @@ -102,7 +101,7 @@
        * Retrieves an id as an long.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A long with the value for the id.
        * @exception Exception Database error.
        */
  @@ -116,7 +115,7 @@
        * Retrieves an id as a BigDecimal.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A BigDecimal id
        * @exception Exception Database error.
        */
  @@ -130,7 +129,7 @@
        * Retrieves an id as an String.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A String id
        * @exception Exception Database error.
        */
  @@ -175,12 +174,11 @@
        * Retrieves an id as a Village Value.
        *
        * @param connection A Connection.
  -     * @param keyInfo, an Object that contains additional info.
  +     * @param keyInfo an Object that contains additional info.
        * @return A Village Value id.
        * @exception Exception Database error.
        */
  -    private Value getIdAsVillageValue(Connection connection,
  -                                      Object keyInfo)
  +    private Value getIdAsVillageValue(Connection connection, Object keyInfo)
           throws Exception
       {
           String idSql = dbAdapter.getIDMethodSQL(keyInfo);
  @@ -195,11 +193,11 @@
           }
           finally
           {
  -            if (qds != null) qds.close();
  +            if (qds != null)
  +            {
  +                qds.close();
  +            }
           }
           return rec.getValue(1); // Values are 1 based.
       }
   }
  -
  -
  -
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to