google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Builtin support for case insensitive queries #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Provides the ability to do case insensitive searching as described at 
http://gae-java-
persistence.blogspot.com/2009/11/case-insensitive-queries.html  

Original issue reported on code.google.com by brendanp...@gmail.com on 30 Jan 2010 at 1:02

GoogleCodeExporter commented 9 years ago

Original comment by lhori...@gmail.com on 30 Jan 2010 at 1:11

GoogleCodeExporter commented 9 years ago
I think this is the link you wanted:
http://gae-java-persistence.blogspot.com/2009/11/case-insensitive-queries.html

Also, instead of a function hook onSave, why not just create the annotation of
@CreateLowercaseIndex(Locale loc)

It would take the field name, append a ".lowercase" to the name, and store the
lowercase'd version in the entity. When the entity is read back to into the 
object,
it is ignored. You could then query for "fieldname.lowercase (=|<|>|etc.)"

Original comment by scotthernandez on 30 Jan 2010 at 3:02

GoogleCodeExporter commented 9 years ago
Resummarized the issue.

Original comment by lhori...@gmail.com on 30 Jan 2010 at 5:58

GoogleCodeExporter commented 9 years ago
Which locale would you pass to @CreateLowercaseIndex? In 
an application that supports i8n, won't it be neccessary to 
look up the locale of the current user?

@CreateLowercaseIndex is nice and simple, but I still think 
you'll need an @OnSave for more complex situations.

Original comment by brendanp...@gmail.com on 30 Jan 2010 at 11:58

GoogleCodeExporter commented 9 years ago
Which locale would you choose in your @OnSave?  The current user?  Then you'll 
have 
a wide variety of lowercase locales stored in your entities, and query results 
will be 
unpredictable.

At any rate, why is @OnSave (or @CreateLowerCaseIndex) better than implementing 
your own setter method which populates yourField and yourFieldLower?

class Foo {
    String lastName;
    String lastNameLower;

    public void setLastName(String value) {
        lastName = value;
        lastNameLower = value.toLowerCase(whaeverLocaleYouWant);
    }
}

Seems pretty elegant to me, and lets you perform other transmutations (maybe 
you 
want to normalize ñ,é,ü,etc to their non-accented equivalents).

Original comment by lhori...@gmail.com on 30 Jan 2010 at 6:14

GoogleCodeExporter commented 9 years ago
The way to go here might be a simple lifecycle interface (you can implement in 
your
POJO):

EntityLifecycle {

postGet(Entity ent) //allows you to read/hold-onto the actual entity
prePut(Enity ent) //allows you to add/remove stuff from the entity before 
DS.put()

}

Original comment by scotthernandez on 8 Feb 2010 at 6:31

GoogleCodeExporter commented 9 years ago
We should just recycle the JPA @PostLoad and @PrePersist annotations.

Original comment by lhori...@gmail.com on 8 Feb 2010 at 6:35

GoogleCodeExporter commented 9 years ago
Since we have @PostLoad and @PrePersist now, I'm marking this as fixed.

If something more is desired, open a new bug.

Original comment by lhori...@gmail.com on 18 Feb 2010 at 8:41