Firefox logo

Ant logo

Netbeans logo

Coding your own id generator

An id generator class is used by renderers to create unique numbers to use as primary key for tables.
csvtosql come with two default implementations of id generators:

- Incremental, generate incremental positive numbers using a long type
- Time, generate numbers using System.currentTimeMillis()

You can write your own id generator implementing class net.sf.csv2sql.idgenerators.IdGenerator, and this tutorial explain how to implements this interface. We using for example Time interface.

This is the IdGenerator interface:
    public interface IdGenerator {

        public long getID();

    }

You simply need to implement the getID() method, the ArrayList passed to this method contain the statemens already rendered.

This is a class that implements IdGenerator interfce:
    public class Time implements IdGenerator {

        long oldId;

        public long getID() {
            long currentId = System.currentTimeMillis();
            while (oldId == currentId) {
                currentId = System.currentTimeMillis();
            }
            oldId = currentId;
            return currentId;
        }

    }

The getID() method must return a numeric id.

copyright 2004 Davide Consonni (davideconsonni@users.sourceforge.net)