OK, here's the deal.

I am using MySQL 4 and the latest Connector drivers, but I get this
behaviour in all the drivers I tried.
The guys at MySQL seem to believe that the field "KEY_SEQ" in the resultset
returned by DatabaseMetaDAta.getExportedKeys
is the sequence of all key fields for all relationships for the table. As I
understand, is should be the sequence of the key in the current
relationship. The Middlegen code shares this understanding. Unfortunately,
the MySQL guys also see no use for the concept of of foreign key name. For
these two reasons, the following code in MiddleGenPopulator.addRelations
won't work on MySQL:

                                String pkColumnName = 
exportedKeyRs.getString("PKCOLUMN_NAME");
                                String fkColumnName = 
exportedKeyRs.getString("FKCOLUMN_NAME");
                                String fkName = exportedKeyRs.getString("FK_NAME");
                                short keySeq = exportedKeyRs.getShort("KEY_SEQ");
                                // Warn if there is a relation to a column which is 
not a pk

                                if (keySeq == 0) {
                                        bogusFkName++;
                                }
                                if (fkName == null) {
                                        fkName = String.valueOf(bogusFkName);
                                }

                                addCrossref(pkTable, pkColumnName, fkTableName, 
fkColumnName, fkName,
fkTables);


But I don't think it is worth while code for bugs in MySQL. What I have
found was that the MySQL JDBC drivers' metadata is not up to standard - they
lose all multi-keyed relationships - very bad! For my fellow MySQL-Middlegen
users I would recommend using the ODBC driver (which is much stronger on
metadata) and access it with the JDBC-ODBC bridge.
Unfortunately, here the "KEY_SEQ" field is 1 based as opposed to 0 based.
Since mySQL does not store foreign key names, all the "FK_NAME" values are
"NULL" (the string value "NULL"). I replaced (apologies!) the abovementioned
code with the following, and it seems to work:
                                String pkColumnName = 
exportedKeyRs.getString("PKCOLUMN_NAME");
                                String fkColumnName = 
exportedKeyRs.getString("FKCOLUMN_NAME");
                                short keySeq = exportedKeyRs.getShort("KEY_SEQ");
                                // Warn if there is a relation to a column which is 
not a pk

                                if (keySeq < lastKeySeq) {
                                        bogusFkName++;
                                }
                                lastKeySeq=keySeq;
                                fkName = String.valueOf(bogusFkName);//Just force it 
(ODBC-bridge has
the string value "NULL")

                                addCrossref(pkTable, pkColumnName, fkTableName, 
fkColumnName, fkName,
fkTables);

This works perfectly for the MySQL ODBC drivers as well as for the MySQL
JDBC drivers. But it does solve the absence of multi-keyed relationships in
the MySQL JDBC drivers.


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Ampie
Barnard
Sent: 17 September 2002 09:40
To: [EMAIL PROTECTED]
Subject: [Middlegen-user] Relationship roles merged


Hi!

In a case where I have 2 different foreign keys (fkX and fkY) from table A
to table B, a previous version of Middlegen would pick up two different
relationship roles in B: B.aByFkX and B.aByFkY. This was quite a cool
feature!

Since I have checked out the latest version from CVS though, it seems to
confuse these two different roles with a foreign key consisting of two
fields. In other word, it only sees one relationship role, but two column
maps.

Is this an intended change?

Regards

Ampie



-------------------------------------------------------
Sponsored by: AMD - Your access to the experts on Hammer Technology!
Open Source & Linux Developers, register now for the AMD Developer
Symposium. Code: EX8664 http://www.developwithamd.com/developerlab
_______________________________________________
middlegen-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/middlegen-user



-------------------------------------------------------
Sponsored by: AMD - Your access to the experts on Hammer Technology! 
Open Source & Linux Developers, register now for the AMD Developer 
Symposium. Code: EX8664 http://www.developwithamd.com/developerlab
_______________________________________________
middlegen-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/middlegen-user

Reply via email to