JPQL example queries

28 10 2008

Looking for JPQL queries, look no further. I use this as a reference page myself.

Search for Persons which all live in San Fransisco, New York or Frederikssund, traversal over single relation

SELECT p FROM Person WHERE p.city.id IN ("SF","NY", "FS")

Search for Persons with some of these tags(tags is a list of tags), traversal over list relations: Married, Divorced, OverTheHill

SELECT p FROM Person P JOIN p.tags t WHERE t.name IN ("married","divorced", "overthehill")

Above could be slow..
Search with enumerations:

SELECT p FROM Person WHERE p.enum = com.mypackage.enum.value
</code

Copy paste stuff:

public List searchForEvents(City city,
List eventTypeList,
List eventAdmittance,
List categoryTypeList)
{
List events = new ArrayList();
List categories = new ArrayList();
List admittanceTypes = new ArrayList();
if (eventTypeList.size() > 0 || categoryTypeList.size() > 0
|| eventAdmittance.size() > 0) {
for (EventType event : eventTypeList) {
events.add(EventType.class.getCanonicalName() + "."
+ event.name());
}

for (CategoryType categoryType : categoryTypeList) {
categories.add(CategoryType.class.getCanonicalName() + "."
+ categoryType.name());

}
for (EventAdmittanceType admittanceType : eventAdmittance) {
admittanceTypes.add(EventAdmittanceType.class
.getCanonicalName()
+ "." + admittanceType.name());

}

}
String jpql = "select e from Event e WHERE e.city.id='" + city.getId()
+ "'";
// types
List typesList = new ArrayList();

if (events.size() > 0) {
typesList.add("e.eventType IN ( " + buildJPQL(events, ",") + " ) ");
}
if (categories.size() > 0) {
typesList.add(" e.categoryType IN ( " + buildJPQL(categories, ",")
+ " )");
}
if (admittanceTypes.size() > 0) {
typesList.add(" e.eventAdmittanceType IN ( "
+ buildJPQL(admittanceTypes, ",") + " )");
}
if (typesList.size() > 0) {
jpql += " and " + buildJPQL(typesList, "and");
}

return getJpaTemplate().find(jpql);
}

private String buildJPQL(List sqlList, String delimiter) {
String constructedSQL = "";

for (String subSQL : sqlList) {
constructedSQL += subSQL + " " + delimiter;
}

if(sqlList.size()!=0){
constructedSQL = constructedSQL.substring(0, constructedSQL.length()
- delimiter.length());

}

return constructedSQL;
}





Stack page

7 10 2008

This is my stack page. Opensource tools that I use, find interesting or need to remember will be listed there:

In use (partial list):
http://wicket.apache.org/
http://wicketstuff.org/
http://sourceforge.net/projects/wicketopia/
http://mojo.codehaus.org/cobertura-maven-plugin/
jpa http://java.sun.com/javaee/5/docs/api/javax/persistence/package-summary.html
http://www.hibernate.org/
http://www.springframework.org/
http://browsershots.org/ (when I need to test cross platform browser)
http://geo-google.sourceforge.net/

https://simple-log.dev.java.net/
http://jbehave.org/
JTS / Hibernate spatial

Maven plugin:

http://maven.apache.org/plugin-developers/cookbook/add-svn-revision-to-manifest.html

Images / Art / Icons for applications free via creative commons or similar
http://tango.freedesktop.org/
http://www.everaldo.com/crystal/
http://www.famfamfam.com/lab/icons/silk/
http://www.deviantart.com/
http://www.iconfinder.net/

Tools to help your css:

http://www.cssjuice.com/tools/
http://www.roundz.net/

Interesting:

http://dev.eclipse.org/blogs/kmitov/2009/06/12/jpicus-the-tool-for-java-io-analysis/
http://sixrevisions.com/resources/40-beautiful-free-icon-sets/

http://picocontainer.org/

http://www.jdave.org

http://geoserver.org/
http://code.google.com/p/google-guice/
http://links.sourceforge.net/
http://www.dillo.org/
http://sourceforge.net/projects/protogen/
http://sourceforge.net/projects/qwick/

http://code.google.com/p/liquidform/
J2ME stuff:
https://meapplicationdevelopers.dev.java.net/mobileajax.html

Trouble shooting:

https://visualvm.dev.java.net

Desktop development:

http://publicobject.com/glazedlistsdeveloper/
https://appframework.dev.java.net/

funstuf

http://slick.cokeandcode.com/

jmoneyengine

documentation:

http://repo.exist.com/dist/maestro/1.7.0/BetterBuildsWithMaven.pdf
http://apollo.ucalgary.ca/tlcprojectswiki/index.php/Public/Subversion
http://apollo.ucalgary.ca/tlcprojectswiki/index.php/Public/Project_Versioning__Best_Practices#Build_Versioning

http://books.google.dk/books?id=zGgZ850Aw5gC&pg=PA1&lpg=PA1&dq=Beginning+Ubuntu+Server+Administration&source=bl&ots=6I0rezDNZY&sig=pAR-0kD7PxnlBAY5w0cw98ndWU0&hl=da&ei=SMB6SsPwA4OL-QaDvNVW&sa=X&oi=book_result&ct=result&resnum=4#v=onepage&q=&f=false

Project Stitching Spider

CI : https://hudson.dev.java.net/ / http://continuum.apache.org

Issue : http://jtrac.info/

WIKI: http://www.xwiki.org

SVN:http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91 / http://www.visualsvn.com/server/