This project has retired. For details please refer to its
        
        Attic page.
      
 
org.apache.avalon.excalibur.datasource.ids
Class TableIdGenerator
java.lang.Object
  
org.apache.avalon.framework.logger.AbstractLogEnabled
      
org.apache.avalon.excalibur.datasource.ids.AbstractIdGenerator
          
org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceIdGenerator
              
org.apache.avalon.excalibur.datasource.ids.AbstractDataSourceBlockIdGenerator
                  
org.apache.avalon.excalibur.datasource.ids.TableIdGenerator
- All Implemented Interfaces: 
 - Component, Configurable, Disposable, IdGenerator, Initializable, LogEnabled, Serviceable, ThreadSafe
 
- public class TableIdGenerator
- extends AbstractDataSourceBlockIdGenerator
  
The TableIdGenerator requests blocks of ids from a Database table.  The table consists of two
  columns one called table_name of type CHAR or VARCHAR, and the second called
  next_id of an integer type large enough to hold your largest ids.
 
 The Configuration to use a TableIdGenerator looks like the following:
 
   <id-generators>
       <table name="user-ids" big-decimals="true" block-size="1" table="ids"
           key-table="event-type" logger="cm.ids">
           <dbpool>user-db</dbpool>
       </table>
   </id-generators>
 
 Where user-db is the name of a DataSource configured in a datasources element, block-size is
  the number if ids that are allocated with each query to the databse (defaults to "10"),
  table is the name of the table which contains the ids (defaults to "ids"), and key-table is
  the table_name of the row from which the block of ids are allocated (defaults to "id").
 
 With the following roles declaration:
 
   <role name="org.apache.avalon.excalibur.datasource.ids.IdGeneratorSelector"
         shorthand="id-generators"
         default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
       <hint shorthand="table"
             class="org.apache.avalon.excalibur.datasource.ids.TableIdGenerator"/>
   </role>
 
 To configure your component to use the IdGenerator declared above, its configuration should look
  something like the following:
 
   <user-service logger="cm">
       <dbpool>user-db</dbpool>
       <id-generator>user-ids</id-generator>
   </user-service>
 
 Your component obtains a reference to an IdGenerator using the same method as it obtains a
  DataSource, by making use of a ComponentSelector.
 
 Depending on your database, the ids table should look something like the following:
 
   CREATE TABLE ids (
       table_name varchar(16) NOT NULL,
       next_id INTEGER NOT NULL,
       PRIMARY KEY (table_name)
   );
 
- Since:
 
  - 4.1
 
- Version:
 
  - CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:17 $
 
- Author:
 
  - Avalon Development Team
 
 
 
| Fields inherited from interface org.apache.avalon.excalibur.datasource.ids.IdGenerator | 
ROLE | 
 
 
| 
Method Summary | 
protected  java.math.BigDecimal | 
allocateBigDecimalIdBlock(int blockSize)
 
          Allocates a block, of the given size, of ids from the database. | 
protected  long | 
allocateLongIdBlock(int blockSize)
 
          Allocates a block, of the given size, of ids from the database. | 
 void | 
configure(Configuration configuration)
 
          Called by the Container to configure the component. | 
 
 
 
 
 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
 
TableIdGenerator
public TableIdGenerator()
allocateBigDecimalIdBlock
protected java.math.BigDecimal allocateBigDecimalIdBlock(int blockSize)
                                                  throws IdException
- Allocates a block, of the given size, of ids from the database.
- Specified by:
 allocateBigDecimalIdBlock in class AbstractDataSourceBlockIdGenerator
 
- Parameters:
 blockSize - number of Ids which are to be allocated.
- Returns:
 - The first id in the allocated block.
 - Throws:
 IdException - if there it was not possible to allocate a block of ids.
 
 
allocateLongIdBlock
protected long allocateLongIdBlock(int blockSize)
                            throws IdException
- Allocates a block, of the given size, of ids from the database.
- Specified by:
 allocateLongIdBlock in class AbstractDataSourceBlockIdGenerator
 
- Parameters:
 blockSize - number of Ids which are to be allocated.
- Returns:
 - The first id in the allocated block.
 - Throws:
 IdException - if there it was not possible to allocate a block of ids.
 
 
configure
public void configure(Configuration configuration)
               throws ConfigurationException
- Called by the Container to configure the component.
- Specified by:
 configure in interface Configurable- Overrides:
 configure in class AbstractDataSourceBlockIdGenerator
 
- Parameters:
 configuration - configuration info used to setup the component.
- Throws:
 ConfigurationException - if there are any problems with the configuration.
 
 
Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.