Return-Path: Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 35484 invoked from network); 11 Mar 2003 13:39:39 -0000 Received: from amarseille-104-1-2-47.abo.wanadoo.fr (HELO formaguide.intra) (80.14.180.47) by daedalus.apache.org with SMTP; 11 Mar 2003 13:39:39 -0000 Received: (qmail 5449 invoked from network); 11 Mar 2003 13:39:33 -0000 Received: from unknown (HELO servux) (192.168.0.199) by 192.168.0.1 with SMTP; 11 Mar 2003 13:39:33 -0000 Date: Tue, 11 Mar 2003 14:39:50 +0100 From: Emmanuel Florent To: Turbine Torque Users List Subject: Re: [PATCH] ant jdbc-task Message-ID: <20030311133950.GA7881@servux> References: <200303111417.50754.rje@epmail.ep.de> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=ISO-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200303111417.50754.rje@epmail.ep.de>; from RJentsch@electronicpartner.de on Tue, Mar 11, 2003 at 14:17:50 +0100 X-Mailer: Balsa 2.0.9 Lines: 179 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This is very nice from you . Thanks a lot. Please let me know, I'm having trouble with jdbc & pgsql. This is mentioned on Torque website. What version of postgresql do you use , what version of jdbc ? Thanks a lot again. Emmanuel Florent eflorent@devaki.org http://www.devaki.org/ On 2003.03.11 14:17 Rolf Jentsch wrote: > Hallo, > > while importing an existing database into a turbine/torque project, I > found that with the > the ant jdbc-task information about indices is not written to the > generated schema.xml. > > The included patch adds support for this feature. > > The patch should work against torque-3.0 > (src/java/org/apache/torque/task/TorqueJDBCTransformTask.java) > as well as torque-3.1-dev > (src/generator/src/java/org/apache/torque/task/TorqueJDBCTransformTask.java) > > So far it has only been tested with PostgreSQL 7.2. > > Rolf Jentsch > Produktentwicklung EDV-Anwendungen f�r Mitglieder > ElectronicPartner GmbH & Co. KG > D�sseldorf > > --- TorqueJDBCTransformTask.java.orig 2003-03-11 13:49:37.000000000 > +0100 > +++ TorqueJDBCTransformTask.java 2003-03-11 13:54:55.000000000 > +0100 > @@ -270,6 +270,7 @@ > List columns = getColumns(dbMetaData, curTable); > List primKeys = getPrimaryKeys(dbMetaData, curTable); > Collection forgnKeys = getForeignKeys(dbMetaData, > curTable); > + Collection indexData = getIndexData(dbMetaData, > curTable); > > // Set the primary keys. > primaryKeys = new Hashtable(); > @@ -366,6 +367,35 @@ > } > table.appendChild(fk); > } > + // Indices for this table. > + for (Iterator l = indexData.iterator(); l.hasNext(); ) > + { > + Object[] indexD = (Object[]) l.next(); > + Boolean notUnique = (Boolean) indexD[2]; > + List cols = (List) indexD[1]; > + Element ix; > + if ( notUnique.booleanValue() ) > + ix = doc.createElement("index"); > + else > + { > + if ( checkPKey(cols,primKeys) ) > + continue; > + ix = doc.createElement("unique"); > + } > + //FIXME: find out the correct indexname > + //ix.setAttribute("name",(String)indexD[0]); > + for ( int m = 0 ;m < cols.size();m++ ) > + { > + Element col; > + if ( notUnique.booleanValue() ) > + col = doc.createElement("index-column"); > + else > + col = doc.createElement("unique-column"); > + col.setAttribute("name",(String)cols.get(m)); > + ix.appendChild(col); > + } > + table.appendChild(ix); > + } > databaseNode.appendChild(table); > } > doc.appendChild(databaseNode); > @@ -542,4 +572,79 @@ > } > return fks.values(); > } > + /** > + * Retrieves a list of index definitions for a given table. > + * > + * @param dbMeta JDBC metadata. > + * @param tableName Table from which to retrieve IX information. > + * @return A list of index definitions in tableName. > + * @throws SQLException > + */ > + public Collection getIndexData(DatabaseMetaData dbMeta, String > tableName) > + throws SQLException > + { > + Hashtable idx = new Hashtable(); > + ResultSet indexInfo = null; > + short indexType ; > + try > + { > + indexInfo = dbMeta.getIndexInfo(null, dbSchema, > tableName,false,true); > + while (indexInfo.next()) > + { > + indexType = indexInfo.getShort(7); > + if ( indexType == dbMeta.tableIndexStatistic ) > + continue; > + String ixName = indexInfo.getString(6); > + // if IX has no name - make it up (use tablename > instead) > + if (ixName == null) > + { > + ixName = indexInfo.getString(3); > + } > + Object[] ix = (Object[]) idx.get(ixName); > + List refs; > + if (ix == null) > + { > + ix = new Object[3]; > + ix[0] = indexInfo.getString(3); //table name > + refs = new ArrayList(); > + ix[1] = refs; > + ix[2] = new Boolean(indexInfo.getBoolean(4)); > + idx.put(ixName, ix); > + } > + else > + { > + refs = (ArrayList) ix[1]; > + } > + String ref = indexInfo.getString(9); //column > + refs.add(ref); > + } > + } > + finally > + { > + if (indexInfo != null) > + { > + indexInfo.close(); > + } > + } > + return idx.values(); > + } > + /** > + * Checks wether or not an index may be the primary key > + * > + * An index is probably the primary key if it contains the > + * same columns in the same order. > + * > + * @param cols Columns for the current index > + * @param pKeyCols Columns for the primary key > + * @return true if the index is the primary key > + */ > + private boolean checkPKey(List cols,List pKeyCols ) > + { > + if ( pKeyCols.size() != cols.size() ) > + return false; > + for ( int m = 0 ; m < cols.size() ; m++ ) > + if > (((String)cols.get(m)).compareTo((String)pKeyCols.get(m)) > != 0) > + return false; > + return true; > + } > } > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org > For additional commands, e-mail: torque-user-help@db.apache.org > > >