You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Daniel Larsson <de...@hotmail.com> on 2004/03/07 18:08:23 UTC

doUpdate(selectCritera, updateCriteria)

Noob-warning, first message ever.

I'm trying to change a bunch of (>250000 records) with
doUpdate(selectCriteria, updateCriteria)
like so:

     Criteria selectCriteria = new Criteria();
     selectCriteria.add(EntryPeer.SHOPID, 1000);
     selectCriteria.add(EntryPeer.SELECTED, 0);

      selectCriteria.addJoin(ItemPeer.ID, EntryPeer.ITEMID);
      selectCriteria.addJoin(CatPeer.ID, EntryPeer.CATID);
      selectCriteria.add(ItemPeer.ID, 0, Criteria.GREATER_EQUAL);

      Criteria updateCriteria = new Criteria();
      updateCriteria.add(EntryPeer.SELECTED, 1);

      try
      {
         String categorySet = Cat.getCat(catId).getSetString();
         selectCriteria.add(CatPeer.SETSTRING, (Object) (categorySet + "%"),
Criteria.LIKE);
         EntryPeer.doUpdate(selectCriteria, updateCriteria);
      } catch (TorqueException e)
      {
      }

The doUpdate-method throws an Exception: org.apache.torque.TorqueException:
No changes to save
when iterating through the tables trying to insertOrUpdateRecord with Cat,
which as you can see is
not what I want to do. I want do flip Entry.SELECTED from 0 to 1 for Items
with ID>0 and Cats with
a specified SETSTRING.
Debug output for BasePeer says:
[BasePeer] BasePeer.doUpdate: whereClause=SETSTRING LIKE 'OTHEML%'
.so it only takes into consideration the Cat-part of the select-clause and
finds no changes to save.

If I comment out the two last throwTorqueException(e); in
doUpdate(selectCriteria, updateCriteria)
it get stuck on the Item-table and selects half a billion Items in the db.

As a workaround I will select all the 2500000 records to a List and iterate
through them setting
SELECTED to 1 and save(), but as you all understand that will be slow
compared to a single
SQL-query so I really hope someone can help me getting this doSelect to
work.

best regards
Daniel Larsson



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


Re: doUpdate(selectCritera, updateCriteria)

Posted by Kostyantyn Shchekotykhin <Ko...@ifit.uni-klu.ac.at>.
Hi Daniel,
sorry that i cannot answer your question with a solution. All that i can
do is to point you where the problem can be.
Have a look at BasePeer.insertOrUpdateRecord(Record rec, String
tableName, Criteria criteria). It takes a table name from the peer, of
which you have called doUpdate. Then in gets all columns of this table
and tries to find them in updateCriteria calling
criteria.containsKey(String). If no keys were found then it throws
TorqueException("No changes to save").
You can try to see with your debugger what happens. Maybe the problem is
in your implementation of doUpdate, or something else.

Regards,
Kostya


Daniel Larsson wrote:
> Noob-warning, first message ever.
> 
> I'm trying to change a bunch of (>250000 records) with
> doUpdate(selectCriteria, updateCriteria)
> like so:
> 
>      Criteria selectCriteria = new Criteria();
>      selectCriteria.add(EntryPeer.SHOPID, 1000);
>      selectCriteria.add(EntryPeer.SELECTED, 0);
> 
>       selectCriteria.addJoin(ItemPeer.ID, EntryPeer.ITEMID);
>       selectCriteria.addJoin(CatPeer.ID, EntryPeer.CATID);
>       selectCriteria.add(ItemPeer.ID, 0, Criteria.GREATER_EQUAL);
> 
>       Criteria updateCriteria = new Criteria();
>       updateCriteria.add(EntryPeer.SELECTED, 1);
> 
>       try
>       {
>          String categorySet = Cat.getCat(catId).getSetString();
>          selectCriteria.add(CatPeer.SETSTRING, (Object) (categorySet + "%"),
> Criteria.LIKE);
>          EntryPeer.doUpdate(selectCriteria, updateCriteria);
>       } catch (TorqueException e)
>       {
>       }
> 
> The doUpdate-method throws an Exception: org.apache.torque.TorqueException:
> No changes to save
> when iterating through the tables trying to insertOrUpdateRecord with Cat,
> which as you can see is
> not what I want to do. I want do flip Entry.SELECTED from 0 to 1 for Items
> with ID>0 and Cats with
> a specified SETSTRING.
> Debug output for BasePeer says:
> [BasePeer] BasePeer.doUpdate: whereClause=SETSTRING LIKE 'OTHEML%'
> .so it only takes into consideration the Cat-part of the select-clause and
> finds no changes to save.
> 
> If I comment out the two last throwTorqueException(e); in
> doUpdate(selectCriteria, updateCriteria)
> it get stuck on the Item-table and selects half a billion Items in the db.
> 
> As a workaround I will select all the 2500000 records to a List and iterate
> through them setting
> SELECTED to 1 and save(), but as you all understand that will be slow
> compared to a single
> SQL-query so I really hope someone can help me getting this doSelect to
> work.
> 
> best regards
> Daniel Larsson
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 


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


Re: doUpdate(selectCritera, updateCriteria)

Posted by Daniel Larsson <de...@hotmail.com>.
Ok, thanks for the pointers Kostya!

I use the default doUpdate, so therefore I was debugging
insertOrUpdateRecord
inside BasePeer.doUpdate(selectCriteria, updateCriteria).

I just couldn't figure out what BasePeer.doUpdate(selectCriteria,
updateCriteria)
was doing, so...

.I have now solved the problem with a Criteria.CUSTOM like this:

String categorySet = Cat.getCat(catId).getSetString()+"%";
String query = Constants.EMPTY_STRING;
if (selected == 0)
    query = "UPDATE Entry, Item, Cat SET Entry.SELECTED=0 WHERE Item.ID>=0
AND Cat.SETSTRING LIKE '"+categorySet+"' AND Entry.SELECTED=1 AND
Entry.SHOPID="+data.getShopId()+" AND Item.ID=Entry.ITEMID AND
Cat.ID=Entry.CATID";
else
    query = "UPDATE Entry, Item, Cat SET Entry.SELECTED=1 WHERE Item.ID>=0
AND Cat.SETSTRING LIKE '"+categorySet+"' AND Entry.SELECTED=0 AND
Entry.SHOPID="+data.getShopId()+" AND Item.ID=Entry.ITEMID AND
Cat.ID=Entry.CATID";
BasePeer.executeStatement(query);

Which is fast, but schema-dependent, so if the schema changes
I have to check this snippet every time - so if someone could enlighten me
exactly how BasePeer.doUpdate(selectCriteria, updateCriteria) parses
the selectCriteria I would much appreciate it.

> Hi Daniel,
> sorry that i cannot answer your question with a solution. All that i can
> do is to point you where the problem can be.
> Have a look at BasePeer.insertOrUpdateRecord(Record rec, String
> tableName, Criteria criteria). It takes a table name from the peer, of
> which you have called doUpdate. Then in gets all columns of this table
> and tries to find them in updateCriteria calling
> criteria.containsKey(String). If no keys were found then it throws
> TorqueException("No changes to save").
> You can try to see with your debugger what happens. Maybe the problem is
> in your implementation of doUpdate, or something else.
>
> Regards,
> Kostya

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


Re: doUpdate(selectCritera, updateCriteria)

Posted by Kostyantyn Shchekotykhin <Ko...@ifit.uni-klu.ac.at>.
Hi Daniel,
sorry that i cannot answer your question with a solution. All that i can 
do is to point you where the problem can be.
Have a look at BasePeer.insertOrUpdateRecord(Record rec, String 
tableName, Criteria criteria). It takes a table name from the peer, of 
which you have called doUpdate. Then in gets all columns of this table 
and tries to find them in updateCriteria calling 
criteria.containsKey(String). If no keys were found then it throws 
TorqueException("No changes to save").
You can try to see with your debugger what happens. Maybe the problem is 
in your implementation of doUpdate, or something else.

Regards,
Kostya


Daniel Larsson wrote:
> Noob-warning, first message ever.
> 
> I'm trying to change a bunch of (>250000 records) with
> doUpdate(selectCriteria, updateCriteria)
> like so:
> 
>      Criteria selectCriteria = new Criteria();
>      selectCriteria.add(EntryPeer.SHOPID, 1000);
>      selectCriteria.add(EntryPeer.SELECTED, 0);
> 
>       selectCriteria.addJoin(ItemPeer.ID, EntryPeer.ITEMID);
>       selectCriteria.addJoin(CatPeer.ID, EntryPeer.CATID);
>       selectCriteria.add(ItemPeer.ID, 0, Criteria.GREATER_EQUAL);
> 
>       Criteria updateCriteria = new Criteria();
>       updateCriteria.add(EntryPeer.SELECTED, 1);
> 
>       try
>       {
>          String categorySet = Cat.getCat(catId).getSetString();
>          selectCriteria.add(CatPeer.SETSTRING, (Object) (categorySet + "%"),
> Criteria.LIKE);
>          EntryPeer.doUpdate(selectCriteria, updateCriteria);
>       } catch (TorqueException e)
>       {
>       }
> 
> The doUpdate-method throws an Exception: org.apache.torque.TorqueException:
> No changes to save
> when iterating through the tables trying to insertOrUpdateRecord with Cat,
> which as you can see is
> not what I want to do. I want do flip Entry.SELECTED from 0 to 1 for Items
> with ID>0 and Cats with
> a specified SETSTRING.
> Debug output for BasePeer says:
> [BasePeer] BasePeer.doUpdate: whereClause=SETSTRING LIKE 'OTHEML%'
> .so it only takes into consideration the Cat-part of the select-clause and
> finds no changes to save.
> 
> If I comment out the two last throwTorqueException(e); in
> doUpdate(selectCriteria, updateCriteria)
> it get stuck on the Item-table and selects half a billion Items in the db.
> 
> As a workaround I will select all the 2500000 records to a List and iterate
> through them setting
> SELECTED to 1 and save(), but as you all understand that will be slow
> compared to a single
> SQL-query so I really hope someone can help me getting this doSelect to
> work.
> 
> best regards
> Daniel Larsson
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 

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


Re: doUpdate(selectCritera, updateCriteria)

Posted by Kostyantyn Shchekotykhin <Ko...@ifit.uni-klu.ac.at>.
Hi Daniel,
sorry that i cannot answer your question with a solution. All that i can
do is to point you where the problem can be.
Have a look at BasePeer.insertOrUpdateRecord(Record rec, String
tableName, Criteria criteria). It takes a table name from the peer, of
which you have called doUpdate. Then in gets all columns of this table
and tries to find them in updateCriteria calling
criteria.containsKey(String). If no keys were found then it throws
TorqueException("No changes to save").
You can try to see with your debugger what happens. Maybe the problem is
in your implementation of doUpdate, or something else.

Regards,
Kostya


Daniel Larsson wrote:
> Noob-warning, first message ever.
> 
> I'm trying to change a bunch of (>250000 records) with
> doUpdate(selectCriteria, updateCriteria)
> like so:
> 
>      Criteria selectCriteria = new Criteria();
>      selectCriteria.add(EntryPeer.SHOPID, 1000);
>      selectCriteria.add(EntryPeer.SELECTED, 0);
> 
>       selectCriteria.addJoin(ItemPeer.ID, EntryPeer.ITEMID);
>       selectCriteria.addJoin(CatPeer.ID, EntryPeer.CATID);
>       selectCriteria.add(ItemPeer.ID, 0, Criteria.GREATER_EQUAL);
> 
>       Criteria updateCriteria = new Criteria();
>       updateCriteria.add(EntryPeer.SELECTED, 1);
> 
>       try
>       {
>          String categorySet = Cat.getCat(catId).getSetString();
>          selectCriteria.add(CatPeer.SETSTRING, (Object) (categorySet + "%"),
> Criteria.LIKE);
>          EntryPeer.doUpdate(selectCriteria, updateCriteria);
>       } catch (TorqueException e)
>       {
>       }
> 
> The doUpdate-method throws an Exception: org.apache.torque.TorqueException:
> No changes to save
> when iterating through the tables trying to insertOrUpdateRecord with Cat,
> which as you can see is
> not what I want to do. I want do flip Entry.SELECTED from 0 to 1 for Items
> with ID>0 and Cats with
> a specified SETSTRING.
> Debug output for BasePeer says:
> [BasePeer] BasePeer.doUpdate: whereClause=SETSTRING LIKE 'OTHEML%'
> .so it only takes into consideration the Cat-part of the select-clause and
> finds no changes to save.
> 
> If I comment out the two last throwTorqueException(e); in
> doUpdate(selectCriteria, updateCriteria)
> it get stuck on the Item-table and selects half a billion Items in the db.
> 
> As a workaround I will select all the 2500000 records to a List and iterate
> through them setting
> SELECTED to 1 and save(), but as you all understand that will be slow
> compared to a single
> SQL-query so I really hope someone can help me getting this doSelect to
> work.
> 
> best regards
> Daniel Larsson
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 



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