Skip to main content

A Short Note About Properties And Politics

Posted by evanx on July 7, 2007 at 9:13 AM PDT

Another reason why we need properties in the language is ... for "native" database queries, e.g.

Person person = createQuery(new WhereLikePredicate(Person.name, "Homer Simpson"));

where Person.name is a property, ie. Person.class has an accessor getName().

In this case, our JPA queries are refactorable, yippee! If you have a real query, it's more obvious (no offense), eg.

      SelectQuery query = createSelectQuery();
      query.setTitle("Fido's in region %s", regionId);
      query.selectAll(dog);
      query.selectExclude(dog.address);
      query.select(organisation.organisationId, organisation.organisationName);
      query.join(dog, organisation, region);
      query.whereEquals(region.regionId, regionId);
      query.whereStartsWithIgnoreCase(dog.dogName, "fido");
      query.whereIsNotNull(organisation.organisationName);
      query.whereIs(organisation.active, true);
      query.orderBy(organisation.organisationId, dog.dogName);
      query.limit(100);

as presented in the The SQL precursor to the Jelly Bean series.

Having JPA queries in strings (and any references in strings) is something that i hope people cannot tolerate going forward!? ;)