db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Rau <ra...@gmx.de>
Subject Re: obtaining native primary keys problem
Date Sat, 01 Mar 2003 18:45:55 GMT

>>Depends on ... I think it does not work with any DBxxxAdapter implementing
>>public String getIDMethodType()
>>    {
>>        return NO_ID_METHOD;
>>    }
> sorry . rest of the message was lost (a lot !) gonna reply again in a few
> hours from at home)

Ok. Once again.

DBDB2NET Adapter uses NO_ID_METHOD as IdMethodType. I think several 
other database adapters do so as well.

This implies that there will be no IDGenererator instance created ) as 
beside the normal IDBroker only AutoIncrementIDGenerator and 
SequenceIdGernerator exist.

Here's the code snippet:

public class IDGeneratorFactory
{ ....

     public static IdGenerator create(DB dbAdapter)
         String idMethod = dbAdapter.getIDMethodType();
         if (IDMethod.AUTO_INCREMENT.equals(idMethod)) {
		return new AutoIncrementIdGenerator(dbAdapter);
         else if (IDMethod.SEQUENCE.equals(idMethod)) {
		return new SequenceIdGenerator(dbAdapter);
         else { return null; }     // DBDB2NET Adapter is handled here !



Now the BasePeer.java class:

public static ObjectKey doInsert(Criteria criteria, Connection con) {

// pk will be null if there is no primary key defined for the table
// we're inserting into.
if (pk != null && !criteria.containsKey(pk.getFullyQualifiedName())) {

	if (keyGen == null) {
	throw new TorqueException("IdGenerator for table '" + tableName + "' is 

keygen is the earlier assign ((IdGenerator) null) from 
IdGeneratorFactory.create(DBDB2NET-Adapter). As you can see you'll get a 
TorqueException because the keygen is null. Actually it's somehow 
logically correct because the Database should generate our new primary 
keys. However the code does not catch that at all.

So the conclusion is: all DBAdapters using ID_METHOD_NONE will fail as 
soon as the standard IDBroker won't be used anymore.

Oracle (IDMethod = Sequence) and Mysql (IDMethod = AutoIncrement) users 
are lucky here as this ID retrieval method works.

This is a list of Databases which use ID_METHOD_NONE:
- Axion
- DB2App/Net
- Informix
- InstantDB
- Interbase
- Weblogic

Personally I'm going to try to patch the DBDB2NET adapter to use 
Sequences as DB2 supports this since V7.2 AFAIK.

Has anyone any idea how to replace the oracle sql string ?

public String getIDMethodSQL(Object sequenceName) {
     return ("select " + sequenceName + ".nextval from dual");

I think it's something like 'SELECT NEXTVAL FOR sequencename FROM 
tablename WHERE entry_receiving_new_pk'

dunno. trying to find that out this weekend.

Regards, Alex

View raw message