Sample-vaadin-spring-hibernate » History » Revision 3
Revision 2 (Henning Blohm, 06.10.2012 15:28) → Revision 3/19 (Henning Blohm, 06.10.2012 16:00)
h1. A sample using Vaadin with Hibernate JPA and Spring on Z2
This sample is similar to [[Sample-spring-hibernate]] but differs (or rather extends) in that it show cases
the use of the "Vaadin":http://www.vaadin.com user interface toolkit in conjunction with Spring implemented annotation based
dependency injection over Z2 modularity.
As Spring is used throughout - in all modules - this is another practical application of [[How to Spring]].
This sample is stored in "z2-samples.vaadin-spring-hibernate":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-vaadin-spring-hibernate.
h2. Prerequisites
You need to run Java DB as network server on localhost. This is explained next.
The application will create a database "z2-samples"
{{include(How to run Java db)}}
h2. Run it
Like all samples, also this sample can be run as in [[How to run a sample]]. If you have the database, the fastest way to verify whether it runs is:
<pre><code class="ruby">
mkdir install
cd install
git clone -b master http://git.z2-environment.net/z2-base.core
git clone -b master http://git.z2-environment.net/z2-samples.vaadin-spring-hibernate
# on Linux / Mac OS:
cd z2-base.core/run/bin
./gui.sh
# on Windows:
cd z2-base.core\run\bin
gui.bat
</code></pre>
When running, go to http://localhost:8080/vaadin-spring-hibernate. You should see this:
!vaadin-spring-hibernate.png!
h2. Details
As in the other samples we have a re-use domain module. That is a recurring theme for many good reasons. In this case, the domain module "com.zfabrik.samples.vaadin-spring-hibernate.domain":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-vaadin-spring-hibernate/revisions/master/show/com.zfabrik.samples.vaadin-spring-hibernate.domain *com.zfabrik.samples.vaadin-spring-hibernate.domain* is essentially like the similarly named module of [[Sample-spring-hibernate]]. The only difference is some more data access methods in the "ThingyRepository":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-vaadin-spring-hibernate/revisions/master/entry/com.zfabrik.samples.vaadin-spring-hibernate.domain/java/src.api/com/zfabrik/samples/vaadin_spring_hibernate/thingies/ThingyRepository.java.
The Vaadin Web application is defined in the module "com.zfabrik.samples.vaadin-spring-hibernate.web":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-vaadin-spring-hibernate/revisions/master/show/com.zfabrik.samples.vaadin-spring-hibernate.web. It has the usual Spring application context in "web/WebContent/WEB-INF/applicationContext.xml":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-vaadin-spring-hibernate/revisions/master/entry/com.zfabrik.samples.vaadin-spring-hibernate.web/web/WebContent/WEB-INF/applicationContext.xml that imports the thingy repository:
<pre><code class="xml">
<!-- import external components -->
<bean id="thingyRepository" class="com.zfabrik.springframework.ComponentFactoryBean">
<property name="componentName" value="com.zfabrik.samples.vaadin-spring-hibernate.domain/repository" />
<property name="className" value="com.zfabrik.samples.vaadin_spring_hibernate.thingies.ThingyRepository" />
</bean>
...tbc
</code></pre>
The Vaadin application class "ApplicationImpl":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-vaadin-spring-hibernate/revisions/master/entry/com.zfabrik.samples.vaadin-spring-hibernate.web/java/src.impl/com/zfabrik/samples/impl/vaadin_spring_hibernate/ApplicationImpl.java constructs a simple view hierarchy that containes a table view based on a "lazy query container add-on":https://vaadin.com/directory#addon/lazy-query-container data model that is fed from the domain module. To do so the corresponding query implementation (in lazy query container speak) has the repository injected:
<pre><code class="java">
@Configurable
public class ThingiesQuery implements Query {
@Autowired
private ThingyRepository repository;
private Integer size;
private boolean asc;
// ...
}
</code></pre>
