db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chiu Yee Weay" <ywc...@paradigm.com.my>
Subject Enhancement to the SQL task <jdbc> to support index and unique
Date Wed, 05 Nov 2003 08:39:03 GMT
Greetings Martin and all,

The task TorqueJDBCTransformTask does support the generation of XML
schema for tables with columns, primary key and foreign keys, but not
for index and unique constraints. Are there reasons behind ? The task
should have generated the index and unique constraints as parts of the
XML schema.

Here, I have written a method for retrieving the index information for
tables. Please review :

     * Retrieves a list of unique/non unique indices for a given table.
     * @param dbMeta JDBC metadata.
     * @param tableName Table from which to retrieve index information.
     * @param unique Flag to indicate whther to retrieve unique/non
unique indices.
     * @return A list of unique/non unique indices in
     * @throws SQLException
    public Collection getIndices(DatabaseMetaData dbMeta, String
tableName, boolean unique)
        throws SQLException
        Hashtable indices = new Hashtable();
        ResultSet indexInfo = null;
            indexInfo = dbMeta.getIndexInfo(null, dbSchema, tableName,
unique, false);
            while (indexInfo.next())
                short type = indexInfo.getShort(7);
                if (type != DatabaseMetaData.tableIndexStatistic)
                    boolean nonUnique = indexInfo.getBoolean(4);
                    if (nonUnique != unique)
                        String indexName = indexInfo.getString(6);
                        short ordinalPosition = indexInfo.getShort(8);
                        String columnName = indexInfo.getString(9);

                        Object[] index = (Object[])
                        Vector indexColumns;
                        if (index == null)
                            index = new Object[2];
                            index[0] = indexName;
                            indexColumns = new Vector();
                            indexColumns = (Vector) index[1];
                        if (indexColumns.size() < ordinalPosition) {
ordinalPosition - 1);
                        index[1] = indexColumns;

                        indices.put(indexName, index);
            if (indexInfo != null)
        return indices.values();

Attached please find the updated source file for
TorqueJDBCTransformTask.java, with the new getIndices method and changes
in the execute method, which are not yet committed to the CVS.

If you all agree with the changes, I would like the updates to be
committed to the CVS. But I do not have the rights to do that, thus, can
someone, probably Martin, please help me to do this ?


Chiu Yee Weay
Systems Engineer
Paradigm Systems Sdn Bhd

View raw message