You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Amine Bousta <ab...@lxsolutions.com> on 2003/11/05 17:33:37 UTC
Problem with jdbc 2 XML
Hello,
I'm experiencing a lot of problems by trying to generate an xml schema from
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table C, it
generates :
<foreign-key foreignTable="B">
<reference foreign="id" local="B_id"/>
<reference foreign="id" local="C_id"/>
</foreign-key>
instead of :
<foreign-key foreignTable="B">
<reference foreign="id" local="B_id"/>
</foreign-key>
<foreign-key foreignTable="C">
<reference foreign="id" local="C_id"/>
</foreign-key>
as expected.
If anybody knows a workaround I'd really appreciate :)
Thank you
Amine
PS : Is this the good place here to report Torque bugs or do I have to post
them in a bug database?
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Problem with jdbc 2 XML
Posted by Loïc Minier <lo...@via.ecp.fr>.
Amine Bousta <ab...@lxsolutions.com> - Wed, Nov 05, 2003:
> I'm experiencing a lot of problems by trying to generate an xml schema from
> a sql file.
> I'm using Mysql with InnoDB tables and foreign keys.
> I'm trying to launch ant on build-torque.xml with the "jdbc" option.
I'm new to Torque, but isn't the jdbc target reserved
to Oracle databases? (This is how I understand
the description of torque.database.schema at
<http://db.apache.org/torque/properties-reference.html>.)
Regards,
--
Loïc Minier <lo...@dooz.org>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
RE: Problem with jdbc 2 XML
Posted by Chiu Yee Weay <yw...@paradigm.com.my>.
Greetings,
I do not know how's mysql's behavior, but looking at the source file,
this might be caused by the following conditions :
- foreign keys' name is not null
- same foreign keys' name for different foreign tables
So, instead of using the foreign key name, I would recommend using the
foreign table name instead.
Here's my refined getForeignKeys method in TorqueJDBCTransformTask.java
:
/**
* Retrieves a list of foreign key columns for a given table.
*
* @param dbMeta JDBC metadata.
* @param tableName Table from which to retrieve FK information.
* @return A list of foreign keys in <code>tableName</code>.
* @throws SQLException
*/
public Collection getForeignKeys(DatabaseMetaData dbMeta, String
tableName)
throws SQLException
{
Hashtable fks = new Hashtable();
ResultSet foreignKeys = null;
try
{
foreignKeys = dbMeta.getImportedKeys(null, dbSchema,
tableName);
while (foreignKeys.next())
{
String refTableName = foreignKeys.getString(3);
//referenced table name
String refColumnName = foreignKeys.getString(4);
//foreign column
String localColumnName = foreignKeys.getString(8);
//local column
Object[] fk = (Object[]) fks.get(refTableName);
List refs;
if (fk == null)
{
fk = new Object[2];
fk[0] = refTableName;
refs = new ArrayList();
}
else
{
refs = (ArrayList) fk[1];
}
String[] ref = new String[2];
ref[0] = localColumnName;
ref[1] = refColumnName;
refs.add(ref);
fk[1] = refs;
fks.put(refTableName, fk);
}
}
finally
{
if (foreignKeys != null)
{
foreignKeys.close();
}
}
return fks.values();
}
Thanks.
Chiu Yee Weay
Systems Engineer
Paradigm Systems Sdn Bhd
-----Original Message-----
From: Amine Bousta [mailto:abousta@lxsolutions.com]
Sent: Thursday, November 06, 2003 12:34 AM
To: Apache Torque Users List
Subject: Problem with jdbc 2 XML
Hello,
I'm experiencing a lot of problems by trying to generate an xml schema
from
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table
C, it
generates :
<foreign-key foreignTable="B">
<reference foreign="id" local="B_id"/>
<reference foreign="id" local="C_id"/>
</foreign-key>
instead of :
<foreign-key foreignTable="B">
<reference foreign="id" local="B_id"/>
</foreign-key>
<foreign-key foreignTable="C">
<reference foreign="id" local="C_id"/>
</foreign-key>
as expected.
If anybody knows a workaround I'd really appreciate :)
Thank you
Amine
PS : Is this the good place here to report Torque bugs or do I have to
post
them in a bug database?
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
[ Scanned by JARING E-Mail Virus Scanner ( http://www.jaring.my ) ]
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org
RE: Problem with jdbc 2 XML
Posted by Chiu Yee Weay <yw...@paradigm.com.my>.
Greetings,
I do not know how's mysql's behavior, but looking at the source file,
this might be caused by the following conditions :
- foreign keys' name is not null
- same foreign keys' name for different foreign tables
So, instead of using the foreign key name, I would recommend using the
foreign table name instead.
Here's my refined getForeignKeys method in TorqueJDBCTransformTask.java
:
/**
* Retrieves a list of foreign key columns for a given table.
*
* @param dbMeta JDBC metadata.
* @param tableName Table from which to retrieve FK information.
* @return A list of foreign keys in <code>tableName</code>.
* @throws SQLException
*/
public Collection getForeignKeys(DatabaseMetaData dbMeta, String
tableName)
throws SQLException
{
Hashtable fks = new Hashtable();
ResultSet foreignKeys = null;
try
{
foreignKeys = dbMeta.getImportedKeys(null, dbSchema,
tableName);
while (foreignKeys.next())
{
String refTableName = foreignKeys.getString(3);
//referenced table name
String refColumnName = foreignKeys.getString(4);
//foreign column
String localColumnName = foreignKeys.getString(8);
//local column
Object[] fk = (Object[]) fks.get(refTableName);
List refs;
if (fk == null)
{
fk = new Object[2];
fk[0] = refTableName;
refs = new ArrayList();
}
else
{
refs = (ArrayList) fk[1];
}
String[] ref = new String[2];
ref[0] = localColumnName;
ref[1] = refColumnName;
refs.add(ref);
fk[1] = refs;
fks.put(refTableName, fk);
}
}
finally
{
if (foreignKeys != null)
{
foreignKeys.close();
}
}
return fks.values();
}
Thanks.
Chiu Yee Weay
Systems Engineer
Paradigm Systems Sdn Bhd
-----Original Message-----
From: Amine Bousta [mailto:abousta@lxsolutions.com]
Sent: Thursday, November 06, 2003 12:34 AM
To: Apache Torque Users List
Subject: Problem with jdbc 2 XML
Hello,
I'm experiencing a lot of problems by trying to generate an xml schema
from
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table
C, it
generates :
<foreign-key foreignTable="B">
<reference foreign="id" local="B_id"/>
<reference foreign="id" local="C_id"/>
</foreign-key>
instead of :
<foreign-key foreignTable="B">
<reference foreign="id" local="B_id"/>
</foreign-key>
<foreign-key foreignTable="C">
<reference foreign="id" local="C_id"/>
</foreign-key>
as expected.
If anybody knows a workaround I'd really appreciate :)
Thank you
Amine
PS : Is this the good place here to report Torque bugs or do I have to
post
them in a bug database?
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
[ Scanned by JARING E-Mail Virus Scanner ( http://www.jaring.my ) ]
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org