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 "Janssen, Roger" <Ro...@ibanx.nl> on 2003/06/06 10:01:09 UTC

[Reminder] optimistic locking bug

hi,

i noticed some questions being asked by some people who want to use
optimistic locking.

in the current release, optimistic locking will not work (only by luck, you
have the chance to avoid any problems), you will not be able to update your
objects.

i did send a patch to this list, and thomas said he would check it in (if
nobody else had already done that).

however, viewing the head in CVS, the bug is still there.

so anyone using current release or the head, be aware that optimistic
locking might not work (with high probability) persisting your objects.

Roger Janssen



*************************************************************************
The information contained in this communication is confidential and is
intended solely for the use of the individual or entity to  whom it is
addressed.You should not copy, disclose or distribute this communication 
without the authority of iBanx bv. iBanx bv is neither liable for 
the proper and complete transmission of the information has been maintained
nor that the communication is free of viruses, interceptions or interference.

If you are not the intended recipient of this communication please return
the communication to the sender and delete and destroy all copies.

Re: [Reminder] optimistic locking bug

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi roger,

i just checked it in.
thanks for the patch.

jakob

Janssen, Roger wrote:

>hi,
>
>i noticed some questions being asked by some people who want to use
>optimistic locking.
>
>in the current release, optimistic locking will not work (only by luck, you
>have the chance to avoid any problems), you will not be able to update your
>objects.
>
>i did send a patch to this list, and thomas said he would check it in (if
>nobody else had already done that).
>
>however, viewing the head in CVS, the bug is still there.
>
>so anyone using current release or the head, be aware that optimistic
>locking might not work (with high probability) persisting your objects.
>
>Roger Janssen
>
>
>
>*************************************************************************
>The information contained in this communication is confidential and is
>intended solely for the use of the individual or entity to  whom it is
>addressed.You should not copy, disclose or distribute this communication 
>without the authority of iBanx bv. iBanx bv is neither liable for 
>the proper and complete transmission of the information has been maintained
>nor that the communication is free of viruses, interceptions or interference.
>
>If you are not the intended recipient of this communication please return
>the communication to the sender and delete and destroy all copies.
>  
>
>
> ------------------------------------------------------------------------
>
> Subject:
> [BUG + PATCH, rc3] StatementManager causes wrong update queries to be 
> created, when optimistic locking is used
> From:
> "Janssen, Roger" <Ro...@ibanx.nl>
> Date:
> Fri, 23 May 2003 09:23:32 +0200
> To:
> 'OJB Users List' <oj...@db.apache.org>
>
>
>hi,
>
>the StatementManager binds the fields/attributes used for optimistic
>locking in in incorrect way. it uses the wrong 'view' of field-descriptors
>for these fields. it uses the 'view' of 'all non PK fields' where it should
>use the view of 'all locking fields'. currently, in binding the locking
>field, it uses the positional-index of the field within the 'all locking
>fields'
>view to retrieve the field-descriptor from the 'all non PK fields' view.
>obviously they do not need to match, so it retrieves the wrong field
>descriptor
>which is used to calculate the datatype of the field.
>
>so if you are lucky, if the datatypes match, you won't notice anything,
>but if you're unlucky, wrongfull SQL is being generated and an
>java.sql.SQLException
>is being thrown.
>
>For instance, the current implementation of the HiLow sequence manager only
>works
>by 'luck' (the version-locking fields has the same datatype as the first non
>PK
>field in the 'all non PK fields' view).
>
>this bug results in not being able to use optimistic locking, you will be
>unable to
>update you're objects.
>
>
>below is a patch (which imho fixes the bug) for 
>org.apache.ojb.broker.accesslayer.StatementManager.
>changed code is marked with 'iBanx patch', only two lines!
>
>______________________ patch _________________________________
>
>/**
> * binds the values of the object obj to the statements parameters
> */
>public void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object
>obj) throws java.sql.SQLException
>{
>	int index = 1;
>	Object[] values, currentLockingValues;
>
>	currentLockingValues = cld.getCurrentLockingValues(obj);
>	cld.updateLockingValues(obj); // BRJ
>	values = getNonKeyValues(m_broker, cld, obj);
>
>	// parameters for SET-clause
>	for (int i = 0; i < values.length; i++)
>	{
>		Object val = values[i];
>		if (val != null)
>			m_platform.setObjectForStatement(stmt, index, val,
>SqlHelper.getSqlTypeRwNonPk(cld, i));
>		else
>			m_platform.setNullForStatement(stmt, index,
>SqlHelper.getSqlTypeRwNonPk(cld, i));
>		index++;
>	}
>	// parameters for WHERE-clause pk
>	values = getKeyValues(m_broker, cld, obj);
>	for (int i = 0; i < values.length; i++)
>	{
>		Object val = values[i];
>		if (val != null)
>		{
>			stmt.setObject(index, values[i],
>SqlHelper.getSqlTypePk(cld, i));
>		}
>		else
>		{
>			stmt.setNull(index, SqlHelper.getSqlTypePk(cld, i));
>		}
>
>		index++;
>	}
>	// parameters for WHERE-clause locking
>	values = currentLockingValues;
>	for (int i = 0; i < values.length; i++)
>	{
>		Object val = values[i];
>		if (val != null)
>		{
>			// iBanx patch
>			stmt.setObject(index, values[i],
>SqlHelper.getSqlTypeLocking(cld, i));
>			//stmt.setObject(index, values[i],
>SqlHelper.getSqlTypeRwNonPk(cld, i));
>			// end patch
>		}
>		else
>		{
>			// iBanx patch
>			stmt.setNull(index, SqlHelper.getSqlTypeLocking(cld,
>i));
>			//stmt.setNull(index,
>SqlHelper.getSqlTypeRwNonPk(cld, i));
>			// end patch
>		}
>
>		index++;
>	}
>}
>
>________________________ end patch __________________________________
>
>
>can any ojb developer please apply this patch in CVS.
>
>(since i use optimistic locking, to check whether objects have been
>modified, througout my whole application, this is a showstopper for me!)
>
>
>thanx,
>
>roger janssen
>
>
>*************************************************************************
>The information contained in this communication is confidential and is
>intended solely for the use of the individual or entity to  whom it is
>addressed.You should not copy, disclose or distribute this communication 
>without the authority of iBanx bv. iBanx bv is neither liable for 
>the proper and complete transmission of the information has been maintained
>nor that the communication is free of viruses, interceptions or
>interference.
>
>If you are not the intended recipient of this communication please return
>the communication to the sender and delete and destroy all copies.
>
>---------------------------------------------------------------------
>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
>