-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Trouble with boolean primitives in Example.PropertySelector
PostPosted: Fri Jul 30, 2004 7:59 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
Hi Folks,

I implemented a custom PropertySelector. Unfortunaly it does not care about boolean values. The convering fields are still in WHERE cause of the genrated SELECt. :-(

Any ideas? Attached you can find the code. As far as I can see the boolean values are handled correctly:

Code:
   private class ContactPropertyFilter implements Example.PropertySelector {

      /**
       * Filters out every boolean value
       *
       * @see net.sf.hibernate.expression.Example.PropertySelector#include(java.lang.Object,
       *      java.lang.String, net.sf.hibernate.type.Type)
       */
      public boolean include(Object propertyValue, String propertyName,
            Type type) {
         
         boolean keep = false;
         
         if (propertyValue != null) {
            if ( type.getReturnedClass().isAssignableFrom(String.class)) {
               keep = !(propertyValue.equals(""));
            } else {
               keep  = filterPrimitives(propertyValue, type);
            }                        
         }
                  

         return keep;
      }

      /**
       * @param propertyValue
       * @param type hibernate type
       * @return
       */
      private boolean filterPrimitives(Object propertyValue, Type type) {         
         if (propertyValue instanceof Float )
            return !(((Float) propertyValue).floatValue() == 0.0);
         if (propertyValue instanceof Double )
            return !(((Double) propertyValue).doubleValue() == 0.0);
         if (propertyValue instanceof Integer )
            return !(((Integer) propertyValue).intValue() == 0);
         if (propertyValue instanceof Long )
            return !(((Long) propertyValue).longValue() == 0);
         if (propertyValue instanceof Short)            
            return !(((Short) propertyValue).shortValue() == 0);         
         if (propertyValue instanceof Character)
            return !(((Character) propertyValue).charValue() == '\u0000');
         if (propertyValue instanceof Boolean ) {            
            return (((Boolean) propertyValue).booleanValue());
         }            
         if (propertyValue instanceof Enum ) {
            return !(((Enum) propertyValue).getName().equals(""));
         }         
         // let's pass components, collections and one-to-one relations
         return true;
      }

   }


A lot of thx.

Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject: Re: Trouble with boolean primitives in Example.PropertySelec
PostPosted: Fri Jul 30, 2004 8:13 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
tradem wrote:
Hi Folks,
I implemented a custom PropertySelector. Unfortunaly it does not care about boolean values.


It works now. There was a bug in building the criteria which seems to confuse hibernate in creating the query correclty. So now the PropertySelector rocks!

:-)

Thx
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.