JPA Support for geocells API

141 views
Skip to first unread message

Ricardo Gladwell

unread,
Jan 24, 2011, 5:48:16 AM1/24/11
to javageomodel-discuss
Hi Guys

Just looking the through the code of javagemodel, and wanted to
congratulations on a great API.

I've just checked in some code changes for JPA support into a new
branch, JPA-SUPPORT. If someone (Alexandre?) could please review the
changes and let me know what they think and if it is OK to merge into
trunk?

There are some fundamental API changes:

* Deprecated the LocationCapable interface. Datanuclues 1.4 does
not seem to like JPA entities that implement interfaces. Instead
I have created:
* New @Geocells annotation indicating which property of an entity
bean will contain geocell data.
* New @Longitude and @Latitude annotations to indicate which
properties of an entity bean contain the longitude and latitude.
* Deprecated GeocellManager.proximityFetch methods and replaced
with new proximitySearch methods which take any entity bean
object.
* API now obtains key string by looking up @Id or @PrimaryKey
annotations using reflection (this code could be optimised to
cache reflection lookups).
* Additional unit tests.
* Added new GeocellQueryEngine hierarchy of classes to decorate
queries for proximity search. Support for additional ORMs can be
created by implementing this class.

Just had some thoughts for areas for improvement. Here are some areas
where I think the API might be a bit weak:

1. Static methods: these break the OCP[1], meaning that if a user
decides to use some other geo-location API they have to go into
all their calling class files and re-write them. Also makes
unit-testing harder.
2. Also, because these static methods have to have everything they
need has to be passed in as parameters, making the method
interfaces complex.

Another problem is the LocationCapable interface. This is problematic
for a number of reasons:

1. Couples your application domain model to the javageomodel. For
example, if you wanted to change your geo-search API you have to
also modify your JavaBeans, breaking the OCP[1].
2. The getKeyString() method maybe redundant: There already exists
a way to indicate which JavaBean properties uniquely identify
the entity, the JDO @PrimaryKey, or KPA @Id annotation.
3. While the LocationCapable interface does ensure that a bean has
a getGeocells() method, it can't ensure that this property is
persisted (i.e. annotated with @Persisted)

Solutions to the above might include:

* Re-write utility class methods (e.g. GeocellManager) as normal
POJOs with non-static service methods.
* Create interface for Geocell searcher (i.e. GeocellFinder) and
sub-class it for each type of ORM supported (JDOGeocellFinder,
JPAGeocellFinder, ObjectifyGeocellFinder, etc.)
* Similarly a @Location annotation could be created to mark
property getters instead of using the
LocationCapable.getLocation() method.

Regards...

[1] https://secure.wikimedia.org/wikipedia/en/wiki/Open/closed_principle

--
Ricardo Gladwell <ricardo....@gmail.com>
http://www.google.com/profiles/ricardo.gladwell
Twitter: @rgladwell - MSN: axo...@gmail.com

Gustavo Costa

unread,
Dec 12, 2012, 7:36:11 AM12/12/12
to javageomod...@googlegroups.com, ricardo....@gmail.com
Dear Ricardo,
       I'm develop the first app with geocell and I intend to using through JPA. But I couldn't understand the code below that I found in example code. In code below, there is a pm object. I couldn't identify the class of this pm object. Could you help me?


// Use this in a query
        // In Google App Engine, you'll have something like below. In hibernate (or whatever else), it might be a little bit different.
//              String queryString = "select from ObjectToSave where geocellsParameter.contains(geocells)";
//              Query query = pm.newQuery(queryString);
//          query.declareParameters("String geocellsParameter");
//          List<ObjectToSave> objects = (List<ObjectToSave>) query.execute(cells);

Kapil Pendse

unread,
Dec 13, 2012, 2:07:03 AM12/13/12
to javageomod...@googlegroups.com
Hello Gustavo,

//              Query query = pm.newQuery(queryString);

pm is probably an instance of javax.jdo.PersistenceManager. I my code I do something like this:

PersistenceManager pm = PMF.get().getPersistenceManager();

where PMF is:

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
            JDOHelper.getPersistenceManagerFactory("transactions-optional");

        private PMF() {}

        public static PersistenceManagerFactory get() {
            return pmfInstance;
        }
}

Hope this helps.

Kapil
--
"The Power to Imagine, is The Power to Create!"

Reply all
Reply to author
Forward
0 new messages