Making Freeform Queries

    Getting started with the FreeformQuery may be done as shown in the following. The connection pool initialization is similar to the TableQuery example so it is omitted here. Note that the name(s) of the primary key column(s) must be provided to the FreeformQuery manually. This is required because depending on the query the result set may or may not contain data about primary key columns. In this example, there is one primary key column with a name ‘ID’.

    The FreeformStatementDelegate interface is an extension of the FreeformQueryDelegate interface, which returns StatementHelper objects instead of pure query String#s. This enables the developer to use prepared statetemens instead of regular statements. It is highly recommended to use the [classname]#FreeformStatementDelegate in all implementations. From this chapter onwards, we will only refer to the FreeformStatementDelegate in cases where FreeformQueryDelegate could also be applied.

    1. public StatementHelper getCountStatement()
    2. public StatementHelper getContainsRowQueryStatement(Object... keys)
    3. // Filtering and sorting
    4. public void setFilters(List<Filter> filters)
    5. public void setFilters(List<Filter> filters,
    6. public void setOrderBy(List<OrderBy> orderBys)
    7. // Write support
    8. public boolean removeRow(Connection conn, RowItem row)

    A simple demo implementation of this interface can be found in the SQLContainer package, more specifically in the class com.vaadin.addon.sqlcontainer.demo.DemoFreeformQueryDelegate.