Dev - findByLike

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Dev - findByLike

Hans Bakker
Anybody has a solution for this?

My code:
-------------
List topEntityList = delegator.findByLike("ProductStore",
        UtilMisc.toMap("productStoreId",prefix.concat("%")));

and I get i the log:
--------------
EntityExpr called with lhs as a String; consider recompiling
Exception: java.lang.Exception
Message: null

This is happening in the following code in EntityExpr.java around line 60:
-----------------------------------------------------------
public EntityExpr(Object lhs, EntityComparisonOperator operator, Object rhs) {
  if (lhs == null) {
        throw new IllegalArgumentException("The field value cannot be null");
        }


I am a bit surprised because findbylike requires the field and values to be in
a map with a fieldname(string) and value(string)

so why it is complaining about the string?

 
met vriendelijke groet,
Hans Bakker
A-NeT Internet Services (www.a-net.nl)

E-Mail public key can be downloaded from:
www.a-net.nl/hbakkerA-net.asc

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Hans Bakker
forgot to tell that 'prefix' is a String variable...

On Saturday 29 April 2006 14:19, Hans Bakker wrote:

> Anybody has a solution for this?
>
> My code:
> -------------
> List topEntityList = delegator.findByLike("ProductStore",
> UtilMisc.toMap("productStoreId",prefix.concat("%")));
>
> and I get i the log:
> --------------
> EntityExpr called with lhs as a String; consider recompiling
> Exception: java.lang.Exception
> Message: null
>
> This is happening in the following code in EntityExpr.java around line 60:
> -----------------------------------------------------------
> public EntityExpr(Object lhs, EntityComparisonOperator operator, Object
> rhs) { if (lhs == null) {
>         throw new IllegalArgumentException("The field value cannot be
> null"); }
>
>
> I am a bit surprised because findbylike requires the field and values to be
> in a map with a fieldname(string) and value(string)
>
> so why it is complaining about the string?
>
>
> met vriendelijke groet,
> Hans Bakker
> A-NeT Internet Services (www.a-net.nl)
>
> E-Mail public key can be downloaded from:
> www.a-net.nl/hbakkerA-net.asc
--
Regards,
Hans Bakker
ANT Websystems Co.,Ltd (http://www.antwebsystems.com)

If you want to verify that this message really originates from
from the above person, download the public key from:
http://www.antwebsystems.com/hbakkerAntwebsystems.asc

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Andrew Sykes
In reply to this post by Hans Bakker
Hans,

It looks to me like GenericDelegator.findByLike is calling the wrong
constructor method on EntityExpr. There are 2 similar constructors...

The one we should use is...
EntityExpr(java.lang.String lhs, EntityComparisonOperator operator,
java.lang.Object rhs)

The one that is actually being used is...
EntityExpr(EntityCondition lhs, EntityJoinOperator operator,
EntityCondition rhs)

The reason the wrong one is being called is that by default
Map.Entry.getKey() returns type Object. GenericDelegator.findByLike
should be casting this key to type String.

I've attached a patch below...


Index: /home/andrew/eclipse-
workspace/ofbiz/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
===================================================================
--- /home/andrew/eclipse-
workspace/ofbiz/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (revision 7443)
+++ /home/andrew/eclipse-
workspace/ofbiz/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (working copy)
@@ -1666,7 +1666,7 @@
             Iterator fieldEntries = fields.entrySet().iterator();
             while (fieldEntries.hasNext()) {
                 Map.Entry fieldEntry = (Map.Entry) fieldEntries.next();
-                likeExpressions.add(new EntityExpr(fieldEntry.getKey(),
EntityOperator.LIKE, fieldEntry.getValue()));
+                likeExpressions.add(new EntityExpr
((String)fieldEntry.getKey(), EntityOperator.LIKE, fieldEntry.getValue
()));
             }
         }
         EntityConditionList ecl = new EntityConditionList
(likeExpressions, EntityOperator.AND);


--
Kind Regards
Andrew Sykes <[hidden email]>
Sykes Development Ltd
http://www.sykesdevelopment.com

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Andrew Sykes
In reply to this post by Hans Bakker
I've created a Jira issue for this (OFBIZ-866), including the patch
--
Kind Regards
Andrew Sykes <[hidden email]>
Sykes Development Ltd
http://www.sykesdevelopment.com

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Hans Bakker
In reply to this post by Andrew Sykes
That is very quick reponse and it is working too.

Thanks very much for your help.
--
Regards,
Hans Bakker
ANT Websystems Co.,Ltd (http://www.antwebsystems.com)

If you want to verify that this message really originates from
from the above person, download the public key from:
http://www.antwebsystems.com/hbakkerAntwebsystems.asc

On Saturday 29 April 2006 15:17, Andrew Sykes wrote:

> Hans,
>
> It looks to me like GenericDelegator.findByLike is calling the wrong
> constructor method on EntityExpr. There are 2 similar constructors...
>
> The one we should use is...
> EntityExpr(java.lang.String lhs, EntityComparisonOperator operator,
> java.lang.Object rhs)
>
> The one that is actually being used is...
> EntityExpr(EntityCondition lhs, EntityJoinOperator operator,
> EntityCondition rhs)
>
> The reason the wrong one is being called is that by default
> Map.Entry.getKey() returns type Object. GenericDelegator.findByLike
> should be casting this key to type String.
>
> I've attached a patch below...
>
>
> Index: /home/andrew/eclipse-
> workspace/ofbiz/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
> ===================================================================
> --- /home/andrew/eclipse-
> workspace/ofbiz/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
> (revision 7443) +++ /home/andrew/eclipse-
> workspace/ofbiz/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
> (working copy) @@ -1666,7 +1666,7 @@
>              Iterator fieldEntries = fields.entrySet().iterator();
>              while (fieldEntries.hasNext()) {
>                  Map.Entry fieldEntry = (Map.Entry) fieldEntries.next();
> -                likeExpressions.add(new EntityExpr(fieldEntry.getKey(),
> EntityOperator.LIKE, fieldEntry.getValue()));
> +                likeExpressions.add(new EntityExpr
> ((String)fieldEntry.getKey(), EntityOperator.LIKE, fieldEntry.getValue
> ()));
>              }
>          }
>          EntityConditionList ecl = new EntityConditionList
> (likeExpressions, EntityOperator.AND);

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Andrew Sykes
You're welcome Hans

Do you have commit privileges for this?

On Sat, 2006-04-29 at 15:53 +0700, Hans Bakker wrote:
> That is very quick reponse and it is working too.
>
> Thanks very much for your help.
>  _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
--
Kind Regards
Andrew Sykes <[hidden email]>
Sykes Development Ltd
http://www.sykesdevelopment.com

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Hans Bakker
No I do not, but will talk with David to get this in.

On Saturday 29 April 2006 16:08, Andrew Sykes wrote:

> You're welcome Hans
>
> Do you have commit privileges for this?
>
> On Sat, 2006-04-29 at 15:53 +0700, Hans Bakker wrote:
> > That is very quick reponse and it is working too.
> >
> > Thanks very much for your help.
> >  _______________________________________________
> > Dev mailing list
> > [hidden email]
> > http://lists.ofbiz.org/mailman/listinfo/dev
--
Regards,
Hans Bakker
ANT Websystems Co.,Ltd (http://www.antwebsystems.com)

If you want to verify that this message really originates from
from the above person, download the public key from:
http://www.antwebsystems.com/hbakkerAntwebsystems.asc

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Hans Bakker
Thanks to David this is in now...

On Saturday 29 April 2006 17:19, Hans Bakker wrote:

> No I do not, but will talk with David to get this in.
>
> On Saturday 29 April 2006 16:08, Andrew Sykes wrote:
> > You're welcome Hans
> >
> > Do you have commit privileges for this?
> >
> > On Sat, 2006-04-29 at 15:53 +0700, Hans Bakker wrote:
> > > That is very quick reponse and it is working too.
> > >
> > > Thanks very much for your help.
> > >  _______________________________________________
> > > Dev mailing list
> > > [hidden email]
> > > http://lists.ofbiz.org/mailman/listinfo/dev
--
Regards,
Hans Bakker
ANT Websystems Co.,Ltd (http://www.antwebsystems.com)

If you want to verify that this message really originates from
from the above person, download the public key from:
http://www.antwebsystems.com/hbakkerAntwebsystems.asc

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dev - findByLike

Andrew Sykes
Hans,

Yes, I saw that. thanks.

On Mon, 2006-05-01 at 09:20 +0700, Hans Bakker wrote:

> Thanks to David this is in now...
>
> On Saturday 29 April 2006 17:19, Hans Bakker wrote:
> > No I do not, but will talk with David to get this in.
> >
> > On Saturday 29 April 2006 16:08, Andrew Sykes wrote:
> > > You're welcome Hans
> > >
> > > Do you have commit privileges for this?
> > >
> > > On Sat, 2006-04-29 at 15:53 +0700, Hans Bakker wrote:
> > > > That is very quick reponse and it is working too.
> > > >
> > > > Thanks very much for your help.
> > > >  _______________________________________________
> > > > Dev mailing list
> > > > [hidden email]
> > > > http://lists.ofbiz.org/mailman/listinfo/dev
>
>  _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
--
Kind Regards
Andrew Sykes <[hidden email]>
Sykes Development Ltd
http://www.sykesdevelopment.com

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev