Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote a GPL'd solution for OMERO which you could easily build suited to your situation.</p> <ul> <li>Source: <a href="http://trac.openmicroscopy.org.uk/omero/browser/trunk/components/server/src/ome/tools/hibernate/QueryBuilder.java" rel="nofollow noreferrer">QueryBuilder.java</a></li> <li>Test: <a href="http://trac.openmicroscopy.org.uk/omero/browser/trunk/components/server/test/ome/server/utests/QueryBuilderMockTest.java" rel="nofollow noreferrer">QueryBuilderMockTest</a></li> </ul> <p>Usage:</p> <pre><code>QueryBuilder qb = new QueryBuilder(); qb.select("img"); qb.from("Image", "img"); qb.join("img.pixels", "pix", true, false); // Can't join anymore after this qb.where(); // First qb.append("("); qb.and("pt.details.creationTime &gt; :time"); qb.param("time", new Date()); qb.append(")"); qb.and("img.id in (:ids)"); qb.paramList("ids", new HashSet()); qb.order("img.id", true); qb.order("this.details.creationEvent.time", false); </code></pre> <p>It functions as a state machine "select->from->join->where->order", etc. and keeps up with optional parameters. There were several queries which the Criteria API could not perform (see <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-879" rel="nofollow noreferrer">HHH-879</a>), so in the end it was simpler to write this small class to wrap StringBuilder. (Note: there is a ticket <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-2407" rel="nofollow noreferrer">HHH-2407</a> describing a Hibernate branch which should unify the two. After that, it would probably make sense to re-visit the Criteria API)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload