Just wanted to let you know that we just released
Vaadin SQLContainer v0.3. This is the first preview of the SQLContainer, which should replace QueryContainer in Vaadin 7. This container can be used when JPA feels like overkill for your small app.
It currently supports freeform queries, and version 0.5, to be released in a couple of weeks, will support table queries as well. Table queries will automatically support writing, sorting, filtering and lazy loading for the following database engines: HSQLDB, MySQL, MSSQL, Oracle and PostgreSQL. With freeform queries, you must implement some of the functionality yourself by implementing the FreeformQueryDelegate interface.
Unfortunately documentation is very sparse in this first experimental release, but before 1.0 we will have a full manual for you. While this is the case, I would very much appreciate your help in testing and reporting any bugs or issues you find!
A simple demo can be found
here and the source code to the demo can be found
here . The demo contains a simple example implementation of the FreeformQueryDelegate interface that you can use as a stepping stone.
Hope you like this first taste, there’s more to come!
/Jonatan
A short update on the SQLContainer: The feature complete version 0.8 was just released. Please download it from
the directory page and try it out. If you find bugs, please report them at
dev.vaadin.com .
A stable version 1.0 will be released in a couple of weeks with fixes for the bugs found in this version.
I’m just trying to implement a table based on
SQLContainer addon with a
J2EEConnectionPool connection. Unfortunately I got some errors. Maybe someone can help me.
If I use “Approach 1” then I got this error message:
Cause: java.lang.RuntimeException: Failed to fetch property id’s.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507)
…
Caused by: java.lang.RuntimeException: Failed to fetch property id’s.
at com.vaadin.addon.sqlcontainer.SQLContainer.getPropertyIds(Unknown Source)
…
Incorrect syntax near ‘LIMIT’.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
If I use “Approach 2” then I got this:
Cause: java.lang.IllegalStateException: A transaction is already active!
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
…
Caused by: java.lang.IllegalStateException: A transaction is already active!
at com.vaadin.addon.sqlcontainer.query.FreeformQuery.beginTransaction(Unknown Source)
at com.vaadin.addon.sqlcontainer.SQLContainer.getPage(Unknown Source)
…
java.lang.IllegalStateException: A transaction is already active!
at com.vaadin.addon.sqlcontainer.query.FreeformQuery.beginTransaction(Unknown Source)
at com.vaadin.addon.sqlcontainer.SQLContainer.getPage(Unknown Source)
Any ideas? I use SQL Server 2005 and the DB table MYTABLE has a primary key called “id”.
Thanks, Thorsten
••••••••••
Eclipse 3.5.1 • Vaadin 6.4.7 • Vaadin Eclipse Integration 1.2.0 • JRE 6
Windows XP • IE7 (7.0.5730) • Tomcat 5.5.28 • SQL Server 2005
For the first case, you need to use the public
TableQuery(String tableName, JDBCConnectionPool connectionPool, SQLGenerator sqlGenerator)
constructor, and specify MSSQLGenerator as the sqlGenerator. Using the other constructor will create a DefaultSQLGenerator that supports HSQLDB, MySQL and PostgreSQL. For Oracle and MSSQL you need to use the specialized implementations.
As for the second issue, this is a (very bad) bug that somehow got released. It is fixed in the SVN and a version containing this fix ought to be released sometime this week.
Version 1.0.pre1 can now be found from
here . This should fix the problem that Thorsten had with FreeformQuery and also allow for using FreeformQuery without specifying any ID columns.
Hi. I’m using SqlContainer with Mysql and would like to know if Is it possible to use a view or a stored procedure instead of a table and in that case, how to do it.
Thanks in adavance and congratulations for you great product.
I’m sorry to say that currently there is no support for views or stored procedures in the SQLContainer. It does, however sound like a good thing to add support for in the next version, so could you please file an enhancement ticket on
dev.vaadin.com ? (component = SQLContainer add-on)
Unfortunately there’s no ready made example using MySQL. However, the only changes you need to make to the code in the demo applications should be the initialization of the SimpleJDBCConnectionPool and fix the table creation SQL statements to work for your chosen DB.
As for which DB is “the best”, this is very subjective. It’s all a matter of personal preference. I’ve had success with MySQL, PostgreSQL and others as well.
I just uploaded a major update to the add-on
JPA 2.0 Criteria LazyQueryContainer that allows you to dynamically build the query you want without writing any SQL: JPA 2.0 has an API that allows you to specify your query dynamically as Java objects (i.e there is a CriteriaBuilder that can create the from, where, select, group, etc.), without maniplating textual query language (which is extremely error-prone and not type-safe)
I wrote two containers on top of LazyQueryContainer that use this approach. One manages entities (i.e. it returns objects from one class). The other returns a Tuple, that is, the set of objects that are connected together by a join or some other arbitrarily complex conditions. Vaadin’s JPA Container has some notion of joining queries, but this approach allows just about anything you might think of. The containers allow computed expressions in the SQL, and support sorting on any property that is Comparable.
If you look at the sample applications, I’ve created five variations on how to create queries and perform filtering.
If you need lazy loading while using FreeFormQuery you must implement FreeformStatementDelegate (and use it by calling myFreeFormQuery.setDelegate(myFreeformStatementDelegate)). It is not feasible to generically implement lazyloading, etc for any type of SQL query, so this is left up to you to implement for your specific cases.
A simple example of a FreeformStatementDelegate implementation can be found in the demo application source
here .
In my opinion, this is the best solution for data lazy loading. I’ve just create that to use direct query and the result is fantastic: performance are very very very fast!
Thanks a lot for this component:
Vaadin SQLContainer rulez!