Holger's
Java API

com.antelmann.sql
Class IDSQLGenerator

java.lang.Object
  extended by com.antelmann.sql.IDSQLGenerator

public class IDSQLGenerator
extends Object

an IDSQLGenerator is a helper class that provides new IDs as counters based on flexible intervals. An example would be to generate counters based on years, hence using a SimpleDateFormat formatter of the form "yyyy".

Author:
Holger Antelmann

Constructor Summary
IDSQLGenerator(Connection con, String table, String itemField, String intervalField, String countField, String separator)
          constructs a generator by initializing all configuration data.
 
Method Summary
protected  int generateNewCountFor(String item, String interval)
          returns the counter for the given item and interval after updating the database.
 String generateNewIDFor(String item, Date date, DateFormat format)
           
 String generateNewIDFor(String item, String interval)
          returns a String constructed from the interval, the separator and the calculated counter
 int getCount(String item, String interval)
           
 void setCount(String item, String interval, int count)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDSQLGenerator

public IDSQLGenerator(Connection con,
                      String table,
                      String itemField,
                      String intervalField,
                      String countField,
                      String separator)
constructs a generator by initializing all configuration data.

Parameters:
con - the database connection to be used
table - the name of the table containing the counting data
itemField - the name of the column to be queried for the item to be counted (as String)
intervalField - the name of the column holding the time interval as a String (for most flexibility)
countField - the name of the column holding the counter as an integer
separator - the characters to be used to separate the intervalField from the counter for returning the id
Method Detail

getCount

public int getCount(String item,
                    String interval)
             throws SQLException
Throws:
SQLException

setCount

public void setCount(String item,
                     String interval,
                     int count)
              throws SQLException
Throws:
SQLException

generateNewIDFor

public String generateNewIDFor(String item,
                               Date date,
                               DateFormat format)
                        throws SQLException
Throws:
SQLException

generateNewIDFor

public String generateNewIDFor(String item,
                               String interval)
                        throws SQLException
returns a String constructed from the interval, the separator and the calculated counter

Throws:
SQLException

generateNewCountFor

protected int generateNewCountFor(String item,
                                  String interval)
                           throws SQLException
returns the counter for the given item and interval after updating the database. If the configured table doesn't contain an entry for the given parameters, 1 is stored along with the given parameters and returned. If an entry is found, the counter will be increased by 1 and returned.

Throws:
SQLException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads