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 Luis Cruz <Lu...@ist.utl.pt> on 2004/08/18 17:50:44 UTC

Bug in org.apache.ojb.broker.metadata.DescriptorRepository

Hello,

We are working with OJB 1.0 release and we found a bug a few weeks ago.
Only now have we found time to determine the origin of the bug so here
goes.

In the DescriptorRepository class, in particular, in the method:

   getFieldDescriptorsForMultiMappedTable

the following snip of code is used to obtain the field descriptors of
the target class descriptor:

   synchronized (m_multiMappedTableMap)
   {
      retval =
getAllMappedColumns(getClassesMappedToSameTable(targetCld));
      m_multiMappedTableMap.put(targetCld.getClassNameOfObject(),
retval);
   }

Basically this code is retrieving all the field descriptors of all the
class descriptors mapped to the same table. This is a bug is it not? If
I'm missing something I would greatly appreciate an explanation.

As a result of this behavior, OJB latter materializes all the columns of
the table for objects which are mapped on the same table, even columns
that are not mapped to the object being materialized. A more detailed
description of the collateral damage induced by this behavior can be
found in a previous mail I submitted; the subject of the mail was:

   Possible bug Mapping All Classes on the Same Table

I think a simple fix for this bug can be simply getting all mapped
columns for the target class descriptor instead of getting all mapped
columns for all the classes mapped to the same table, but I'll leave
this up to you experts.

Best regards,
Luis Cruz


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


Re: Bug in org.apache.ojb.broker.metadata.DescriptorRepository

Posted by Armin Waibel <ar...@apache.org>.
Hi Luis,

Thanks for contribution.

Checked in your patch (in OJB_1_0_RELEASE branch). I made some 
modifications, now only RowReaderDefaultImpl was changed. Please check 
the new version (is it as smart as your original patch and avoid 
problems with field converters too?).

regards,
Armin


Luis Cruz wrote:

> Hello,
> 
> Here's the patch I cooked up. Sorry for not attaching the patch file,
> but every mail with attachment I sent was rejected by the mail servers.
> 
> As for the patch, when materializing a row from the database, we can
> just check the ojbConcreteClass whenever this is present and use it to
> determine the fields that need to be materialized. This helps
> performance whenever the ojbConcreteClass is present in the row of the
> resultSet and also avoids materializing every column of the table (which
> can lead to problems when field converters are used).
> 
> Best regards,
> Luis Cruz
> 
> ###### START OF PATCH ######
> Index: RowReaderDefaultImpl.java
> ===================================================================
> RCS file:
> /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
> retrieving revision 1.30.2.1
> diff -u -r1.30.2.1 RowReaderDefaultImpl.java
> --- RowReaderDefaultImpl.java   9 Aug 2004 07:51:26 -0000       1.30.2.1
> +++ RowReaderDefaultImpl.java   23 Aug 2004 14:46:50 -0000
> @@ -24,6 +24,7 @@
>  import org.apache.ojb.broker.PersistenceBrokerException;
>  import org.apache.ojb.broker.metadata.ClassDescriptor;
>  import org.apache.ojb.broker.metadata.FieldDescriptor;
> +import org.apache.ojb.broker.metadata.JdbcType;
>  import org.apache.ojb.broker.util.ClassHelper;
>  import org.apache.ojb.broker.util.logging.LoggerFactory;
>  
> @@ -171,7 +172,28 @@
>          }
>          else
>          {
> -            fields =
> m_cld.getRepository().getFieldDescriptorsForMultiMappedTable(m_cld);
> +               // If we know what concrete class to use, then we don't
> have to guess the fields.
> +            FieldDescriptor concreteClassFD =
> m_cld.getOjbConcreteClassField();
> +            ClassDescriptor classDescriptor = m_cld;
> +            if (concreteClassFD != null)
> +            {
> +               try
> +                               {
> +                       JdbcType jdbcType =
> concreteClassFD.getJdbcType();
> +                       String val = (String)
> jdbcType.getObjectFromColumn(rs, concreteClassFD.getColumnName());
> +                       classDescriptor =
> m_cld.getRepository().getDescriptorFor(val);
> +                       fields = classDescriptor.getFieldDescriptions();
> +                               }
> +               catch (SQLException e)
> +                               {
> +                       // I think this is never reached because
> (concreteClassFD != null)
> +                       // but let's play it on the safe side.
> +                       classDescriptor = m_cld;
> +                       fields =
> classDescriptor.getRepository().getFieldDescriptorsForMultiMappedTable(classDescriptor);
> +                               }
> +            } else {
> +               fields =
> classDescriptor.getRepository().getFieldDescriptorsForMultiMappedTable(classDescriptor);
> +            }
>          }
>          readValuesFrom(rs, row, fields);
>      }
> 
> ###### END OF PATCH ######
> 
> On Sat, 2004-08-21 at 11:21, Armin Waibel wrote:
> 
>>Hi Luis,
>>
>>I think this method returns all fields to support interfaces and 
>>abstract classes too. But I agree you are right, if the ClassDescritor 
>>belongs to a "normal" class only the associated fields should be 
>>returned. But I'm not familiar with this stuff (side-effects?), so did 
>>you write a patched version of DescriptorRepository? Do all junit tests 
>>pass?
>>
>>regards,
>>Armin
>>
>>Luis Cruz wrote:
>>
>>>Hello,
>>>
>>>We are working with OJB 1.0 release and we found a bug a few weeks ago.
>>>Only now have we found time to determine the origin of the bug so here
>>>goes.
>>>
>>>In the DescriptorRepository class, in particular, in the method:
>>>
>>>   getFieldDescriptorsForMultiMappedTable
>>>
>>>the following snip of code is used to obtain the field descriptors of
>>>the target class descriptor:
>>>
>>>   synchronized (m_multiMappedTableMap)
>>>   {
>>>      retval =
>>>getAllMappedColumns(getClassesMappedToSameTable(targetCld));
>>>      m_multiMappedTableMap.put(targetCld.getClassNameOfObject(),
>>>retval);
>>>   }
>>>
>>>Basically this code is retrieving all the field descriptors of all the
>>>class descriptors mapped to the same table. This is a bug is it not? If
>>>I'm missing something I would greatly appreciate an explanation.
>>>
>>>As a result of this behavior, OJB latter materializes all the columns of
>>>the table for objects which are mapped on the same table, even columns
>>>that are not mapped to the object being materialized. A more detailed
>>>description of the collateral damage induced by this behavior can be
>>>found in a previous mail I submitted; the subject of the mail was:
>>>
>>>   Possible bug Mapping All Classes on the Same Table
>>>
>>>I think a simple fix for this bug can be simply getting all mapped
>>>columns for the target class descriptor instead of getting all mapped
>>>columns for all the classes mapped to the same table, but I'll leave
>>>this up to you experts.
>>>
>>>Best regards,
>>>Luis Cruz
>>>
>>>
>>>---------------------------------------------------------------------
>>>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
>>
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Bug in org.apache.ojb.broker.metadata.DescriptorRepository

Posted by Luis Cruz <le...@netcabo.pt>.
Hello,

Here's the patch I cooked up. Sorry for not attaching the patch file,
but every mail with attachment I sent was rejected by the mail servers.

As for the patch, when materializing a row from the database, we can
just check the ojbConcreteClass whenever this is present and use it to
determine the fields that need to be materialized. This helps
performance whenever the ojbConcreteClass is present in the row of the
resultSet and also avoids materializing every column of the table (which
can lead to problems when field converters are used).

Best regards,
Luis Cruz

###### START OF PATCH ######
Index: RowReaderDefaultImpl.java
===================================================================
RCS file:
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
retrieving revision 1.30.2.1
diff -u -r1.30.2.1 RowReaderDefaultImpl.java
--- RowReaderDefaultImpl.java   9 Aug 2004 07:51:26 -0000       1.30.2.1
+++ RowReaderDefaultImpl.java   23 Aug 2004 14:46:50 -0000
@@ -24,6 +24,7 @@
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.JdbcType;
 import org.apache.ojb.broker.util.ClassHelper;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 
@@ -171,7 +172,28 @@
         }
         else
         {
-            fields =
m_cld.getRepository().getFieldDescriptorsForMultiMappedTable(m_cld);
+               // If we know what concrete class to use, then we don't
have to guess the fields.
+            FieldDescriptor concreteClassFD =
m_cld.getOjbConcreteClassField();
+            ClassDescriptor classDescriptor = m_cld;
+            if (concreteClassFD != null)
+            {
+               try
+                               {
+                       JdbcType jdbcType =
concreteClassFD.getJdbcType();
+                       String val = (String)
jdbcType.getObjectFromColumn(rs, concreteClassFD.getColumnName());
+                       classDescriptor =
m_cld.getRepository().getDescriptorFor(val);
+                       fields = classDescriptor.getFieldDescriptions();
+                               }
+               catch (SQLException e)
+                               {
+                       // I think this is never reached because
(concreteClassFD != null)
+                       // but let's play it on the safe side.
+                       classDescriptor = m_cld;
+                       fields =
classDescriptor.getRepository().getFieldDescriptorsForMultiMappedTable(classDescriptor);
+                               }
+            } else {
+               fields =
classDescriptor.getRepository().getFieldDescriptorsForMultiMappedTable(classDescriptor);
+            }
         }
         readValuesFrom(rs, row, fields);
     }

###### END OF PATCH ######

On Sat, 2004-08-21 at 11:21, Armin Waibel wrote:
> Hi Luis,
> 
> I think this method returns all fields to support interfaces and 
> abstract classes too. But I agree you are right, if the ClassDescritor 
> belongs to a "normal" class only the associated fields should be 
> returned. But I'm not familiar with this stuff (side-effects?), so did 
> you write a patched version of DescriptorRepository? Do all junit tests 
> pass?
> 
> regards,
> Armin
> 
> Luis Cruz wrote:
> > Hello,
> > 
> > We are working with OJB 1.0 release and we found a bug a few weeks ago.
> > Only now have we found time to determine the origin of the bug so here
> > goes.
> > 
> > In the DescriptorRepository class, in particular, in the method:
> > 
> >    getFieldDescriptorsForMultiMappedTable
> > 
> > the following snip of code is used to obtain the field descriptors of
> > the target class descriptor:
> > 
> >    synchronized (m_multiMappedTableMap)
> >    {
> >       retval =
> > getAllMappedColumns(getClassesMappedToSameTable(targetCld));
> >       m_multiMappedTableMap.put(targetCld.getClassNameOfObject(),
> > retval);
> >    }
> > 
> > Basically this code is retrieving all the field descriptors of all the
> > class descriptors mapped to the same table. This is a bug is it not? If
> > I'm missing something I would greatly appreciate an explanation.
> > 
> > As a result of this behavior, OJB latter materializes all the columns of
> > the table for objects which are mapped on the same table, even columns
> > that are not mapped to the object being materialized. A more detailed
> > description of the collateral damage induced by this behavior can be
> > found in a previous mail I submitted; the subject of the mail was:
> > 
> >    Possible bug Mapping All Classes on the Same Table
> > 
> > I think a simple fix for this bug can be simply getting all mapped
> > columns for the target class descriptor instead of getting all mapped
> > columns for all the classes mapped to the same table, but I'll leave
> > this up to you experts.
> > 
> > Best regards,
> > Luis Cruz
> > 
> > 
> > ---------------------------------------------------------------------
> > 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
> 

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


Re: Bug in org.apache.ojb.broker.metadata.DescriptorRepository

Posted by Armin Waibel <ar...@apache.org>.
Hi Luis,

I think this method returns all fields to support interfaces and 
abstract classes too. But I agree you are right, if the ClassDescritor 
belongs to a "normal" class only the associated fields should be 
returned. But I'm not familiar with this stuff (side-effects?), so did 
you write a patched version of DescriptorRepository? Do all junit tests 
pass?

regards,
Armin

Luis Cruz wrote:
> Hello,
> 
> We are working with OJB 1.0 release and we found a bug a few weeks ago.
> Only now have we found time to determine the origin of the bug so here
> goes.
> 
> In the DescriptorRepository class, in particular, in the method:
> 
>    getFieldDescriptorsForMultiMappedTable
> 
> the following snip of code is used to obtain the field descriptors of
> the target class descriptor:
> 
>    synchronized (m_multiMappedTableMap)
>    {
>       retval =
> getAllMappedColumns(getClassesMappedToSameTable(targetCld));
>       m_multiMappedTableMap.put(targetCld.getClassNameOfObject(),
> retval);
>    }
> 
> Basically this code is retrieving all the field descriptors of all the
> class descriptors mapped to the same table. This is a bug is it not? If
> I'm missing something I would greatly appreciate an explanation.
> 
> As a result of this behavior, OJB latter materializes all the columns of
> the table for objects which are mapped on the same table, even columns
> that are not mapped to the object being materialized. A more detailed
> description of the collateral damage induced by this behavior can be
> found in a previous mail I submitted; the subject of the mail was:
> 
>    Possible bug Mapping All Classes on the Same Table
> 
> I think a simple fix for this bug can be simply getting all mapped
> columns for the target class descriptor instead of getting all mapped
> columns for all the classes mapped to the same table, but I'll leave
> this up to you experts.
> 
> Best regards,
> Luis Cruz
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Bug in org.apache.ojb.broker.metadata.DescriptorRepository

Posted by Luis Cruz <Lu...@ist.utl.pt>.
Hello,

I'm sending the patch I cooked up in attachment. I hope you approve of
it. All the tests pass (at least all the ones that passed before the
patch was applied).

Basically, what this patch does is to lookup the concrete class before
materializing the corresponding object. This lookup avoids needing to
materialize each column in the method

   DescriptorRepository.getFieldDescriptorsForMultiMappedTable()

This is in my opinion a cleaner solution for materializing objects
(which avoids the issues I previously stated). However, when generating
the sql statements, all the fields must be known, so the original
behavior must be maintained for the SqlSelectStatement classes. 

Cheers,
Luis Cruz


On Sat, 2004-08-21 at 12:21, Armin Waibel wrote:
> Hi Luis,
>
> I think this method returns all fields to support interfaces and
> abstract classes too. But I agree you are right, if the ClassDescritor
> belongs to a "normal" class only the associated fields should be
> returned. But I'm not familiar with this stuff (side-effects?), so did
> you write a patched version of DescriptorRepository? Do all junit
> tests pass?
> 
> regards,
> Armin
>
> On Wed, 2004-08-18 at 16:50, Luis Cruz wrote:
> > Hello,
> > 
> > We are working with OJB 1.0 release and we found a bug a few weeks ago.
> > Only now have we found time to determine the origin of the bug so here
> > goes.
> > 
> > In the DescriptorRepository class, in particular, in the method:
> > 
> >    getFieldDescriptorsForMultiMappedTable
> > 
> > the following snip of code is used to obtain the field descriptors of
> > the target class descriptor:
> > 
> >    synchronized (m_multiMappedTableMap)
> >    {
> >       retval =
> > getAllMappedColumns(getClassesMappedToSameTable(targetCld));
> >       m_multiMappedTableMap.put(targetCld.getClassNameOfObject(),
> > retval);
> >    }
> > 
> > Basically this code is retrieving all the field descriptors of all the
> > class descriptors mapped to the same table. This is a bug is it not? If
> > I'm missing something I would greatly appreciate an explanation.
> > 
> > As a result of this behavior, OJB latter materializes all the columns of
> > the table for objects which are mapped on the same table, even columns
> > that are not mapped to the object being materialized. A more detailed
> > description of the collateral damage induced by this behavior can be
> > found in a previous mail I submitted; the subject of the mail was:
> > 
> >    Possible bug Mapping All Classes on the Same Table
> > 
> > I think a simple fix for this bug can be simply getting all mapped
> > columns for the target class descriptor instead of getting all mapped
> > columns for all the classes mapped to the same table, but I'll leave
> > this up to you experts.
> > 
> > Best regards,
> > Luis Cruz