You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Dott. Christian OLIVIERI" <co...@gmail.com> on 2008/06/09 09:43:38 UTC

Transaction problem

Hi, I'm a newbie and the following is my problem:  I have a db MySQL 
managing personal information. That I would do is: everyone can READ 
single record. If someone open the record x to update/delete no one 
other can do the same (edit/update) till first user don't commit.

I was thinking Local Transaction was the answer but if user A open a 
record in update then user B open the same record, B is hanged untill 
timeout ends.

How to alter timeout value?

Thanks a lot.
Christian

Re: Transaction problem

Posted by Toby Thain <to...@smartgames.ca>.
On 9-Jun-08, at 3:43 AM, Dott. Christian OLIVIERI wrote:

> Hi, I'm a newbie and the following is my problem:  I have a db  
> MySQL managing personal information. That I would do is: everyone  
> can READ single record. If someone open the record x to update/ 
> delete no one other can do the same (edit/update) till first user  
> don't commit.
>
> I was thinking Local Transaction was the answer but if user A open  
> a record in update then user B open the same record, B is hanged  
> untill timeout ends.

Which is exactly what you asked for. :)

>
> How to alter timeout value?

It's a MySQL configuration setting (innodb_lock_wait_timeout).

--Toby

>
> Thanks a lot.
> Christian


Re: Dynamic Java SQL

Posted by EC...@nyiso.com.
Thanks Nathan.

I picked through the iBATIS source and think I see what's happening.
Roughly it looks like iBATIS pulls in the <include>s then the #param#s then
finally the $string$s.

I'll try to accomplish what I was trying to accomplish using <include>s and
see how far I can get, rather than turning my parameters into Strings and
generating the statement in Java and including it using $ in the iBATIS
statement.





                                                                           
             "Nathan Maves"                                                
             <nathan.maves@gma                                             
             il.com>                                                    To 
                                       user-java@ibatis.apache.org         
             06/09/2008 11:42                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re: Dynamic Java SQL                
             Please respond to                                             
             user-java@ibatis.                                             
                apache.org                                                 
                                                                           
                                                                           
                                                                           




You cannot quite do what you are trying to do.

You need to get the string fully ready to send to the map and then use the
$$ life you have in your example.

Be very weary about this approach because you might leave yourself open to
sql injection

On Mon, Jun 9, 2008 at 8:50 AM, <EC...@nyiso.com> wrote:
  Dangit, I didn't change the Subject to be unique. Sorry..



  Is there any way to generate an iBATIS statement in Java, including
  property references that reference attributes of the same object that you
  passed in the statement?

  Ok so I'd like to give iBATIS a map with 2 elements:

  Map<String, Object> mapToGiveIbatis;

  mapToGiveIbatis.put( "ibatisStatement", "SELECT * FROM user  WHERE userid
  =
  #useridInputParam#" );
  mapToGiveIbatis.put( "useridInputParam", 1257 );

  ......queryForObject( "javaGeneratedIbatisStatement", mapToGiveIbatis );

  And the ibatis looks like this:
   <select id="javaGeneratedIbatisStatement" ....>
     $ibatisStatement$
   </select>


  I get the feeling I misread the book, where it said that iBATIS did the $
  replacements before the prepared statement, but in my case it would have
  to
  do the $ replacements and then re-read the statement to do the #
  replacements, pulling the # replacements from the same map that I passed
  in
  the statement itself, which, after thinking about it more, doesn't seem
  like it would.


  -----------------------------------------
  *******************************************************************
  ***
  The information in this email is confidential and may be legally
  privileged against disclosure other than to the intended recipient.
  It is intended solely for the addressee. Access to this email by
  anyone else is unauthorized.

  If you are not the intended recipient, any disclosure, copying,
  distribution or any action taken or omitted to be taken in reliance
  on it, is prohibited and may be unlawful.  Please immediately
  delete this message and inform the sender of this error.
  *******************************************************************
  ***




-----------------------------------------
*******************************************************************
***
The information in this email is confidential and may be legally
privileged against disclosure other than to the intended recipient.
It is intended solely for the addressee. Access to this email by
anyone else is unauthorized.

If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.  Please immediately
delete this message and inform the sender of this error.
*******************************************************************
***


Re: Dynamic Java SQL

Posted by Nathan Maves <na...@gmail.com>.
You cannot quite do what you are trying to do.

You need to get the string fully ready to send to the map and then use the
$$ life you have in your example.

Be very weary about this approach because you might leave yourself open to
sql injection

On Mon, Jun 9, 2008 at 8:50 AM, <EC...@nyiso.com> wrote:

> Dangit, I didn't change the Subject to be unique. Sorry..
>
>
>
> Is there any way to generate an iBATIS statement in Java, including
> property references that reference attributes of the same object that you
> passed in the statement?
>
> Ok so I'd like to give iBATIS a map with 2 elements:
>
> Map<String, Object> mapToGiveIbatis;
>
> mapToGiveIbatis.put( "ibatisStatement", "SELECT * FROM user  WHERE userid =
> #useridInputParam#" );
> mapToGiveIbatis.put( "useridInputParam", 1257 );
>
> ......queryForObject( "javaGeneratedIbatisStatement", mapToGiveIbatis );
>
> And the ibatis looks like this:
>  <select id="javaGeneratedIbatisStatement" ....>
>    $ibatisStatement$
>  </select>
>
>
> I get the feeling I misread the book, where it said that iBATIS did the $
> replacements before the prepared statement, but in my case it would have to
> do the $ replacements and then re-read the statement to do the #
> replacements, pulling the # replacements from the same map that I passed in
> the statement itself, which, after thinking about it more, doesn't seem
> like it would.
>
>
> -----------------------------------------
> *******************************************************************
> ***
> The information in this email is confidential and may be legally
> privileged against disclosure other than to the intended recipient.
> It is intended solely for the addressee. Access to this email by
> anyone else is unauthorized.
>
> If you are not the intended recipient, any disclosure, copying,
> distribution or any action taken or omitted to be taken in reliance
> on it, is prohibited and may be unlawful.  Please immediately
> delete this message and inform the sender of this error.
> *******************************************************************
> ***
>
>

Dynamic Java SQL

Posted by EC...@nyiso.com.
Dangit, I didn't change the Subject to be unique. Sorry..



Is there any way to generate an iBATIS statement in Java, including
property references that reference attributes of the same object that you
passed in the statement?

Ok so I'd like to give iBATIS a map with 2 elements:

Map<String, Object> mapToGiveIbatis;

mapToGiveIbatis.put( "ibatisStatement", "SELECT * FROM user  WHERE userid =
#useridInputParam#" );
mapToGiveIbatis.put( "useridInputParam", 1257 );

......queryForObject( "javaGeneratedIbatisStatement", mapToGiveIbatis );

And the ibatis looks like this:
  <select id="javaGeneratedIbatisStatement" ....>
    $ibatisStatement$
  </select>


I get the feeling I misread the book, where it said that iBATIS did the $
replacements before the prepared statement, but in my case it would have to
do the $ replacements and then re-read the statement to do the #
replacements, pulling the # replacements from the same map that I passed in
the statement itself, which, after thinking about it more, doesn't seem
like it would.


-----------------------------------------
*******************************************************************
***
The information in this email is confidential and may be legally
privileged against disclosure other than to the intended recipient.
It is intended solely for the addressee. Access to this email by
anyone else is unauthorized.

If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.  Please immediately
delete this message and inform the sender of this error.
*******************************************************************
***


Re: Transaction problem

Posted by EC...@nyiso.com.
Is there any way to generate an iBATIS statement in Java, including
property references that reference attributes of the same object that you
passed in the statement?

Ok so I'd like to give iBATIS a map with 2 elements:

Map<String, Object> mapToGiveIbatis;

mapToGiveIbatis.put( "ibatisStatement", "SELECT * FROM user  WHERE userid =
#useridInputParam#" );
mapToGiveIbatis.put( "useridInputParam", 1257 );

......queryForObject( "javaGeneratedIbatisStatement", mapToGiveIbatis );

And the ibatis looks like this:
  <select id="javaGeneratedIbatisStatement" ....>
    $ibatisStatement$
  </select>


I get the feeling I misread the book, where it said that iBATIS did the $
replacements before the prepared statement, but in my case it would have to
do the $ replacements and then re-read the statement to do the #
replacements, pulling the # replacements from the same map that I passed in
the statement itself, which, after thinking about it more, doesn't seem
like it would.


-----------------------------------------
*******************************************************************
***
The information in this email is confidential and may be legally
privileged against disclosure other than to the intended recipient.
It is intended solely for the addressee. Access to this email by
anyone else is unauthorized.

If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.  Please immediately
delete this message and inform the sender of this error.
*******************************************************************
***


Re: Transaction problem

Posted by Toby Thain <to...@smartgames.ca>.
On 9-Jun-08, at 5:31 AM, Dott. Christian OLIVIERI wrote:

> Toby Thain ha scritto:
>>
>> On 9-Jun-08, at 3:43 AM, Dott. Christian OLIVIERI wrote:
>>
>>> Hi, I'm a newbie and the following is my problem:  I have a db  
>>> MySQL managing personal information. That I would do is: everyone  
>>> can READ single record. If someone open the record x to update/ 
>>> delete no one other can do the same (edit/update) till first user  
>>> don't commit.
>>>
>>> I was thinking Local Transaction was the answer but if user A  
>>> open a record in update then user B open the same record, B is  
>>> hanged untill timeout ends.
>>
>> Which is exactly what you asked for. :)
>>
>>>
>>> How to alter timeout value?
>>
>> It's a MySQL configuration setting (innodb_lock_wait_timeout).
>>
>> --Toby
>>
>>>
>>> Thanks a lot.
>>> Christian
>>
>>
> Hi Toby tnks for your help.
> I'll explain my problem:
> * All user may (always) views record data form db with SELECT  
> statement.
> * If User A wants edit/delete record xx, this must be locked for  
> update/delete operations. Other users can read (SELECT) always (If  
> dirty reading too) but they can't update/delete.
>   Only User A can edit/delete current record. When updated/deleted  
> the record will unlocked and  other users can edit/delete.
>
>
> Is possible change innodb_lock_wait_timeout at runtime at runtime,  
> or do you know a way to intercept hang status using transactions to  
> throw a messagebox to user to notify record locking?

OK, from your new description database-level locking isn't your  
answer. Instead you can set a flag (e.g. "locked by user id") at the  
application level and implement whatever user interface you need, in  
your client side application.

--Toby

>
> Tnks a lot