Hi,

Hope it could be useful:

I have some code that generates a new  (java long) key using the HIGH / 
LOW approach described by this Scott Ambler's paper:
http://www.ambysoft.com/mappingObjects.pdf

See:

http://sourceforge.net/projects/pow2toolkit

The class is:
com.pow2.dao.IdGenerator

the code uses the following rdbms table:

[postgresql 7.x ddl]

CREATE TABLE "app_identifier" (
    "id" integer NOT NULL,
    "high" integer,
    Constraint "app_identifier_pkey" Primary Key ("id")
);

CREATE UNIQUE INDEX "app_user_pkey" on "app_user" using btree ( 
"user_id" "int4_ops" );

INSERT INTO "app_identifier" VALUES (0,0);


You can retrieve a new (long) key value using this statement:

import com.pow2.dao.IdGenerator;

...

long myNewKey = IdGenerator.instance().getNextHighValue();

Tell me if you think this class can be useful to DbForms, the current 
toolkit version (not yet released) has got better transaction management..

Regards,
Luca



Dirk Kraemer wrote:

>Hi Alex!
>
>My guess:
>
>The error does not seem to come from the code inserting the new row
>but from the code that tries to show the row to you afterwards.
>The problem is that you are using an autoinc field, so the value
>of field OI is not set by user and is not known by dbforms. 
>
>I think after inserting the new row dbforms tries to navigate
>to the new row by using the key of the inserted row. But that
>value is currently not know to dbforms but a null value, so the 
>error appears. 
>
>What has to be done? Dbforms has to try to get the values of the
>new keys. Unfortunately this functionality seems to be missing in JDBC2,
>will (when?) come once with implementations of JDBC 3. Apache project 
>Torque has similar problems and uses DB Adapters with dbms 
>specific SQL queries to get this
>information from the underlying dbms. Have a look at:
>
>  http://jakarta.apache.org/turbine/torque/db-adapters.html
>
>and sources of db adapters at
>
>  
>http://cvs.apache.org/viewcvs/jakarta-turbine-torque/src/java/org/apache/torque/adapter/
>
>
>Responsible code within dbforms is within InsertEvent.java, lines 338 etc:
>
>    //Show the last record inserted
>    String firstPosition = null;
>    Vector key = table.getKey();
>    FieldValue[] fvEqual = new FieldValue[key.size()];
>    for (int i = 0; i < key.size(); i++) {
>         Field field = (Field) key.elementAt(i);
>         String value = (String) fieldValues.get(new Integer(field.getId()));
>         FieldValue keyFieldValue = new FieldValue(field, value, false);
>         fvEqual[i] = keyFieldValue;
>    }
>         // here could be a good place to get the key values
>         // generated by dbms
>
>    ResultSetVector resultSetVector =
>         table.doConstrainedSelect(...);
>
>Maybe the best way would be to try to integrate the existing Torque Adapters
>into dbforms and then use their functionality to get the id of the inserted 
>row from them. Why reinvent the wheel? 
>
>Don't we have some Torque professionals among us with some time?
>
>Well, just a quick guess, maybe I'm wrong....comments?
>
>Regards
>
>Dirk
>
>_______________________________________________________________
>
>Don't miss the 2002 Sprint PCS Application Developer's Conference
>August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
>
>_______________________________________________
>DbForms Mailing List
>
>http://www.wap-force.net/dbforms
>
>
>
>  
>




_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
DbForms Mailing List

http://www.wap-force.net/dbforms

Reply via email to