You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by shivaken <sh...@e-can.ne.jp> on 2003/07/24 04:55:23 UTC

SequenceManager{Native|MySQL}Impl has a problem.

Hi,

I was started to use SequenceManagerNativeImpl to use autoincremented value.
# And I am evaluating both that and SequenceManagerMySQLImpl.

But, That has a problem. My app's junit test failed.
I couldn't understand the problem.

The cause seems to be afterStore(...) of them(MySQLImpl and NativeImpl) 
updates stored object's autoIncrement field.

When store(obj) inserted obj, That is proper.
But when store(obj) updates obj, That is not proper.
afterStore(...) should not update autoincrement field.

Anyway, I want to write a patch for this.

To fix this, SequenceManage has to update autoIncrement field only when
autoincremented by DB.
the value must be autoIncremented when inserted.

There are 2 way to know that.

1 .
boolean isAutoIncremented(Object obj, ClassDescriptor cld) {
    return isInserted(obj, cld);
}

boolean isInserted(Object obj, ClassDescriptor cld) {
    return  !(jdbcAccess.materializedObject(cld, oid)) != obj);
   // If so, obj must be inserted.
}

2.
boolean isAutoIncremented(Object obj, ClassDescriptor cld) {

   FieldDescriptor fd = cld.getAutoIncrementField();
   Object value = fd.getPersistentField().get(obj);

   return (value == getUniqueValue(fd));

   // If so, value must be autoincremented.
   // SequenceManageMySQLImpl getUniqueValue( int filed ) returns 0
   // SequenceManageNativeImpl getUniqueValue( int filed ) returns -1
}

-- 
-- shivaken
antshell: Ant command line front end
http://www.antshell.org


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: SequenceManager{Native|MySQL}Impl has a problem.

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi,

do you use attribute access="readonly" in the
field descriptor of your identity fields?

e.g.
<field-descriptor
        name="identifier"
        column="NATIVE_ID"
        jdbc-type="BIGINT"
        primarykey="true"
        autoincrement="true"
        access="readonly"
        />

regards,
Armin

----- Original Message -----
From: "shivaken" <sh...@e-can.ne.jp>
To: "'OJB Users List'" <oj...@db.apache.org>
Sent: Thursday, July 24, 2003 4:55 AM
Subject: SequenceManager{Native|MySQL}Impl has a problem.


> Hi,
>
> I was started to use SequenceManagerNativeImpl to use autoincremented
value.
> # And I am evaluating both that and SequenceManagerMySQLImpl.
>
> But, That has a problem. My app's junit test failed.
> I couldn't understand the problem.
>
> The cause seems to be afterStore(...) of them(MySQLImpl and
NativeImpl)
> updates stored object's autoIncrement field.
>
> When store(obj) inserted obj, That is proper.
> But when store(obj) updates obj, That is not proper.
> afterStore(...) should not update autoincrement field.
>
> Anyway, I want to write a patch for this.
>
> To fix this, SequenceManage has to update autoIncrement field only
when
> autoincremented by DB.
> the value must be autoIncremented when inserted.
>
> There are 2 way to know that.
>
> 1 .
> boolean isAutoIncremented(Object obj, ClassDescriptor cld) {
>     return isInserted(obj, cld);
> }
>
> boolean isInserted(Object obj, ClassDescriptor cld) {
>     return  !(jdbcAccess.materializedObject(cld, oid)) != obj);
>    // If so, obj must be inserted.
> }
>
> 2.
> boolean isAutoIncremented(Object obj, ClassDescriptor cld) {
>
>    FieldDescriptor fd = cld.getAutoIncrementField();
>    Object value = fd.getPersistentField().get(obj);
>
>    return (value == getUniqueValue(fd));
>
>    // If so, value must be autoincremented.
>    // SequenceManageMySQLImpl getUniqueValue( int filed ) returns 0
>    // SequenceManageNativeImpl getUniqueValue( int filed ) returns -1
> }
>
> --
> -- shivaken
> antshell: Ant command line front end
> http://www.antshell.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org