You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Nikolai Raitsev <ni...@gmail.com> on 2006/07/27 16:22:47 UTC

Objects stored in DB despite optimistic locking

Hello

How works optimistic locking?

I understand it such (see
http://cwiki.apache.org/CAY/optimistic-locking-explained.html):

if no data changed in the dataset, is this data record not updated in the
database.

i have following problem:
first run:
i have 20000 datarecords in a table 1. This dataset I copy with cayenne into
another table 2.
I use setProperty method, like this:

attrListParameter =
p_dataObjectInt.getObjEntity().getAttributes().toArray();

int nSizeAttrListParameter = attrListParameter.length;
ObjAttribute attr;
String sAttrName;

for(int i = 0; i<nSizeAttrListParameter; i++)
{
   attr = (ObjAttribute) attrListParameter[i];
   sAttrName = attr.getName();
   p_dataObject.writeProperty(sAttrName,
p_dataObjectInt.readProperty(sAttrName));
}

I make commit to the end, commit duratation is 11 sec.

second run:
i have 20000 datarecords in a table 1 and in table 2.
I copy this 20000 records once again into table 2 (the data is not changed!)
with code from above and commit changes, but commit duratation is also 11
sec.!!!! No data has changed!, optimistic locking is set in my
XXX.map.xmlfor class from p_dataObject and for all attributes.

in the second run is to be sent nevertheless update for all 20000
datarecords, or?

what i do wrong???

with thanks, nikolai

Re: Objects stored in DB despite optimistic locking

Posted by Nikolai Raitsev <ni...@gmail.com>.
Hello Mike,

Thank you for your answer and for the trouble!
And apologize for my English, is not really my language:)

Thanks once again for the tip...

best regards,

Nikolai


2006/7/27, Mike Kienenberger <mk...@gmail.com>:
>
> Nikolai,
>
> I'm not completely following what you're asking for.
>
> Perhaps you're asking how you can make an empty string into a null
> automatically?  Put this method into a BaseDataObject class (add this
> class between CayenneDataObject and your generated classes).
>
>     public void writeProperty(String propName, Object value)
>     {
>         // Oracle can't handle empty strings, so convert them into
> nulls automatically.
>         // We'll never use an empty string as a database value.
>         if ( (value instanceof String) && (0 == ((String)value).length())
> )
>         {
>             value = null;
>         }
>
>         super.writeProperty(propName, value);
>     }
>
>
>
> On 7/27/06, Nikolai Raitsev <ni...@gmail.com> wrote:
> > Escuse me, that is my and SQL Server problem, not from cayenne...
> >
> > a blank in SQL Server is no blank...
> >
> > best regards,
> >
> > Nikolai
> >
> > ps. but, is it possibility to build the examination that ' '== '' (blank
> > equals not blank) into cayenne?
> >
> > 2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
> > >
> > > I found the problem and probably a bug in cayenne...
> > >
> > > here is a part of my log:
> > >
> > > on first run, insert:
> > >
> > > INFO  QueryLogger: INSERT INTO WPTAB (WPTAB_AENKZ, WPTAB_ISIN,
> > > WPTAB_LOEKZ) VALUES (?, ?, ?)
> > > INFO  QueryLogger: [bind: ' ', 'DE0000044444', ' ']
> > >
> > > Attention, in ' ' is one blank!!!!
> > >
> > > on second run,  update:
> > >
> > > INFO  QueryLogger: UPDATE WPTAB SET WPTAB_AENKZ = ?, WPTAB_LOEKZ = ?
> WHERE
> > > WPTAB_ISIN = ?
> > > INFO  QueryLogger: [bind: ' ', ' ', 'DE0000044444']
> > >
> > > Attention, and here in ' ' is one blank!!!!
> > > The Fields WPTAB_AENKZ and WPTAB_LOEKZ has not changed, why cayenne
> does
> > > those update?
> > >
> > > Have everybody a tip for me, what can I do?
> > >
> > > thanks and best regards,
> > >
> > > Nikolai
> > >
> > >
> > >
> > > 2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
> > >
> > > > Hello
> > > >
> > > > How works optimistic locking?
> > > >
> > > > I understand it such (see
> > > > http://cwiki.apache.org/CAY/optimistic-locking-explained.html):
> > > >
> > > > if no data changed in the dataset, is this data record not updated
> in
> > > > the database.
> > > >
> > > > i have following problem:
> > > > first run:
> > > > i have 20000 datarecords in a table 1. This dataset I copy with
> cayenne
> > > > into another table 2.
> > > > I use setProperty method, like this:
> > > >
> > > > attrListParameter =
> > > > p_dataObjectInt.getObjEntity().getAttributes().toArray();
> > > >
> > > > int nSizeAttrListParameter = attrListParameter.length;
> > > > ObjAttribute attr;
> > > > String sAttrName;
> > > >
> > > > for(int i = 0; i<nSizeAttrListParameter; i++)
> > > > {
> > > >    attr = (ObjAttribute) attrListParameter[i];
> > > >    sAttrName = attr.getName();
> > > >    p_dataObject.writeProperty(sAttrName,
> > > > p_dataObjectInt.readProperty(sAttrName));
> > > > }
> > > >
> > > > I make commit to the end, commit duratation is 11 sec.
> > > >
> > > > second run:
> > > > i have 20000 datarecords in a table 1 and in table 2.
> > > > I copy this 20000 records once again into table 2 (the data is not
> > > > changed!) with code from above and commit changes, but commit
> duratation is
> > > > also 11 sec.!!!! No data has changed!, optimistic locking is set in
> my
> > > > XXX.map.xml for class from p_dataObject and for all attributes.
> > > >
> > > > in the second run is to be sent nevertheless update for all 20000
> > > > datarecords, or?
> > > >
> > > > what i do wrong???
> > > >
> > > > with thanks, nikolai
> > > >
> > > >
> > > >
> > >
> >
> >
>

Re: Objects stored in DB despite optimistic locking

Posted by Mike Kienenberger <mk...@gmail.com>.
Nikolai,

I'm not completely following what you're asking for.

Perhaps you're asking how you can make an empty string into a null
automatically?  Put this method into a BaseDataObject class (add this
class between CayenneDataObject and your generated classes).

    public void writeProperty(String propName, Object value)
    {
        // Oracle can't handle empty strings, so convert them into
nulls automatically.
        // We'll never use an empty string as a database value.
        if ( (value instanceof String) && (0 == ((String)value).length()) )
        {
            value = null;
        }

        super.writeProperty(propName, value);
    }



On 7/27/06, Nikolai Raitsev <ni...@gmail.com> wrote:
> Escuse me, that is my and SQL Server problem, not from cayenne...
>
> a blank in SQL Server is no blank...
>
> best regards,
>
> Nikolai
>
> ps. but, is it possibility to build the examination that ' '== '' (blank
> equals not blank) into cayenne?
>
> 2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
> >
> > I found the problem and probably a bug in cayenne...
> >
> > here is a part of my log:
> >
> > on first run, insert:
> >
> > INFO  QueryLogger: INSERT INTO WPTAB (WPTAB_AENKZ, WPTAB_ISIN,
> > WPTAB_LOEKZ) VALUES (?, ?, ?)
> > INFO  QueryLogger: [bind: ' ', 'DE0000044444', ' ']
> >
> > Attention, in ' ' is one blank!!!!
> >
> > on second run,  update:
> >
> > INFO  QueryLogger: UPDATE WPTAB SET WPTAB_AENKZ = ?, WPTAB_LOEKZ = ? WHERE
> > WPTAB_ISIN = ?
> > INFO  QueryLogger: [bind: ' ', ' ', 'DE0000044444']
> >
> > Attention, and here in ' ' is one blank!!!!
> > The Fields WPTAB_AENKZ and WPTAB_LOEKZ has not changed, why cayenne does
> > those update?
> >
> > Have everybody a tip for me, what can I do?
> >
> > thanks and best regards,
> >
> > Nikolai
> >
> >
> >
> > 2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
> >
> > > Hello
> > >
> > > How works optimistic locking?
> > >
> > > I understand it such (see
> > > http://cwiki.apache.org/CAY/optimistic-locking-explained.html):
> > >
> > > if no data changed in the dataset, is this data record not updated in
> > > the database.
> > >
> > > i have following problem:
> > > first run:
> > > i have 20000 datarecords in a table 1. This dataset I copy with cayenne
> > > into another table 2.
> > > I use setProperty method, like this:
> > >
> > > attrListParameter =
> > > p_dataObjectInt.getObjEntity().getAttributes().toArray();
> > >
> > > int nSizeAttrListParameter = attrListParameter.length;
> > > ObjAttribute attr;
> > > String sAttrName;
> > >
> > > for(int i = 0; i<nSizeAttrListParameter; i++)
> > > {
> > >    attr = (ObjAttribute) attrListParameter[i];
> > >    sAttrName = attr.getName();
> > >    p_dataObject.writeProperty(sAttrName,
> > > p_dataObjectInt.readProperty(sAttrName));
> > > }
> > >
> > > I make commit to the end, commit duratation is 11 sec.
> > >
> > > second run:
> > > i have 20000 datarecords in a table 1 and in table 2.
> > > I copy this 20000 records once again into table 2 (the data is not
> > > changed!) with code from above and commit changes, but commit duratation is
> > > also 11 sec.!!!! No data has changed!, optimistic locking is set in my
> > > XXX.map.xml for class from p_dataObject and for all attributes.
> > >
> > > in the second run is to be sent nevertheless update for all 20000
> > > datarecords, or?
> > >
> > > what i do wrong???
> > >
> > > with thanks, nikolai
> > >
> > >
> > >
> >
>
>

Re: Objects stored in DB despite optimistic locking

Posted by Nikolai Raitsev <ni...@gmail.com>.
Escuse me, that is my and SQL Server problem, not from cayenne...

a blank in SQL Server is no blank...

best regards,

Nikolai

ps. but, is it possibility to build the examination that ' '== '' (blank
equals not blank) into cayenne?

2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
>
> I found the problem and probably a bug in cayenne...
>
> here is a part of my log:
>
> on first run, insert:
>
> INFO  QueryLogger: INSERT INTO WPTAB (WPTAB_AENKZ, WPTAB_ISIN,
> WPTAB_LOEKZ) VALUES (?, ?, ?)
> INFO  QueryLogger: [bind: ' ', 'DE0000044444', ' ']
>
> Attention, in ' ' is one blank!!!!
>
> on second run,  update:
>
> INFO  QueryLogger: UPDATE WPTAB SET WPTAB_AENKZ = ?, WPTAB_LOEKZ = ? WHERE
> WPTAB_ISIN = ?
> INFO  QueryLogger: [bind: ' ', ' ', 'DE0000044444']
>
> Attention, and here in ' ' is one blank!!!!
> The Fields WPTAB_AENKZ and WPTAB_LOEKZ has not changed, why cayenne does
> those update?
>
> Have everybody a tip for me, what can I do?
>
> thanks and best regards,
>
> Nikolai
>
>
>
> 2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
>
> > Hello
> >
> > How works optimistic locking?
> >
> > I understand it such (see
> > http://cwiki.apache.org/CAY/optimistic-locking-explained.html):
> >
> > if no data changed in the dataset, is this data record not updated in
> > the database.
> >
> > i have following problem:
> > first run:
> > i have 20000 datarecords in a table 1. This dataset I copy with cayenne
> > into another table 2.
> > I use setProperty method, like this:
> >
> > attrListParameter =
> > p_dataObjectInt.getObjEntity().getAttributes().toArray();
> >
> > int nSizeAttrListParameter = attrListParameter.length;
> > ObjAttribute attr;
> > String sAttrName;
> >
> > for(int i = 0; i<nSizeAttrListParameter; i++)
> > {
> >    attr = (ObjAttribute) attrListParameter[i];
> >    sAttrName = attr.getName();
> >    p_dataObject.writeProperty(sAttrName,
> > p_dataObjectInt.readProperty(sAttrName));
> > }
> >
> > I make commit to the end, commit duratation is 11 sec.
> >
> > second run:
> > i have 20000 datarecords in a table 1 and in table 2.
> > I copy this 20000 records once again into table 2 (the data is not
> > changed!) with code from above and commit changes, but commit duratation is
> > also 11 sec.!!!! No data has changed!, optimistic locking is set in my
> > XXX.map.xml for class from p_dataObject and for all attributes.
> >
> > in the second run is to be sent nevertheless update for all 20000
> > datarecords, or?
> >
> > what i do wrong???
> >
> > with thanks, nikolai
> >
> >
> >
>

Re: Objects stored in DB despite optimistic locking

Posted by Nikolai Raitsev <ni...@gmail.com>.
I found the problem and probably a bug in cayenne...

here is a part of my log:

on first run, insert:

INFO  QueryLogger: INSERT INTO WPTAB (WPTAB_AENKZ, WPTAB_ISIN, WPTAB_LOEKZ)
VALUES (?, ?, ?)
INFO  QueryLogger: [bind: ' ', 'DE0000044444', ' ']

Attention, in ' ' is one blank!!!!

on second run,  update:

INFO  QueryLogger: UPDATE WPTAB SET WPTAB_AENKZ = ?, WPTAB_LOEKZ = ? WHERE
WPTAB_ISIN = ?
INFO  QueryLogger: [bind: ' ', ' ', 'DE0000044444']

Attention, and here in ' ' is one blank!!!!
The Fields WPTAB_AENKZ and WPTAB_LOEKZ has not changed, why cayenne does
those update?

Have everybody a tip for me, what can I do?

thanks and best regards,

Nikolai



2006/7/27, Nikolai Raitsev <ni...@gmail.com>:
>
> Hello
>
> How works optimistic locking?
>
> I understand it such (see
> http://cwiki.apache.org/CAY/optimistic-locking-explained.html):
>
> if no data changed in the dataset, is this data record not updated in the
> database.
>
> i have following problem:
> first run:
> i have 20000 datarecords in a table 1. This dataset I copy with cayenne
> into another table 2.
> I use setProperty method, like this:
>
> attrListParameter =
> p_dataObjectInt.getObjEntity().getAttributes().toArray();
>
> int nSizeAttrListParameter = attrListParameter.length;
> ObjAttribute attr;
> String sAttrName;
>
> for(int i = 0; i<nSizeAttrListParameter; i++)
> {
>    attr = (ObjAttribute) attrListParameter[i];
>    sAttrName = attr.getName();
>    p_dataObject.writeProperty(sAttrName,
> p_dataObjectInt.readProperty(sAttrName));
> }
>
> I make commit to the end, commit duratation is 11 sec.
>
> second run:
> i have 20000 datarecords in a table 1 and in table 2.
> I copy this 20000 records once again into table 2 (the data is not
> changed!) with code from above and commit changes, but commit duratation is
> also 11 sec.!!!! No data has changed!, optimistic locking is set in my
> XXX.map.xml for class from p_dataObject and for all attributes.
>
> in the second run is to be sent nevertheless update for all 20000
> datarecords, or?
>
> what i do wrong???
>
> with thanks, nikolai
>
>
>