Archive

Archive for the ‘Spring Data’ Category

Eclipse RCP/RAP and Remoting with JAX-RS, Spring Data JPA and CXF DOSGi [step3]

juin 6, 2012 4 commentaires

In [step2] we have implemented the JAX-RS Client which consumes the UserService#findAll() with JAX-RS:

@Path("/user")
public interface UserService {

	@GET
	@Path("/findAll")
	@Produces(MediaType.APPLICATION_JSON)
	Collection<User> findAll();
...
}

We have seen that JAX-RS Client fails when UserService#findAll(Pageable pageable) is called, because we have not annoted this method with JAX-RS:

1031 [Thread-5] ERROR org.apache.cxf.jaxrs.client.ClientProxyImpl  - Method fr.opensagres.services.UserService.findAll is not a valid resource method
	at org.apache.cxf.jaxrs.client.ClientProxyImpl.reportInvalidResourceMethod(ClientProxyImpl.java:546)

In this article we wish to export and import with JAX-RS the UserService#findAll(Pageable pageable) which returns the paginated list of the User which uses Spring Data – Commons structures :

  • Pageable : this parameter is the pagination request.
  • Page: the findAll method returns this structure which is the result of the pagination.

On other words we will annotate the UserService#findAll(Pageable pageable) like this :

@POST
@Path("/findAllPage")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
Page<User> findAll(Pageable pageable);

However when I have managed JAX-RS with Spring Data structure, I had 2 big problems coming from :

  • Spring Data – Commons: Spring Data Page and Pageable are interfaces and not Pojo. JAX-RS works with Pojo which are annotated with JAXB annotations. How do manage Spring Data Page and Pageable interfaces with JAX-RS? Fortunately, JAXB 2.0 provides XmlJavaTypeAdapter (please read Using JAXB 2.0’s XmlJavaTypeAdapter) which gives the capability to serialize Page and Pageable interfaces with JAXB. I have suggested this idea to Oliver Gierke, the lead of the Spring Data and he is developing JAXB Adapter with SpringDataJaxb.java. However in this article we will not use this class (because this class is not finished) but we will create our own JAXB adapter which will be more simply to understand how to work the JAXB Adapter.
  • Apache CXF: on server side when CXF tries to serialize the Page class with JAXB, it fails because the JAXBContext doesn’t know the User class. This problem comes from that CXF is not able to populate the JAXBContext automaticly with Parameterized class (in our case , we have Page<T> and T=User, the JAXBContext is filled just with Page but not with User). You can fix the problem by setting extra class to the JSONProvider :
    <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider">
    	<property name="singleJaxbContext" value="true" />
    	<property name="extraClass">
    		<list>
    			<value>fr.opensagres.domain.User</value>
    		</list>
    	</property>
    </bean>
    

    We will do that in this article, but I have created the patch CXF-4359 which fixes the explained problem below to avoid declaring extra classes for JSONProvider.

Lire la suite…

Catégories :Apache CXF, DOSGi, Spring Data JPA

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step9]

avril 16, 2012 7 commentaires

In [step8] we have developed a Rich Client with RCP Application to display User list in a SWT Table by consuming the UserService by using Spring DM by using the SpringExtensionFactory from Martin Lippert.

In this article we will display the User List with pagination by using Nebula Pagination Control.

The sort of column will be done by the UserService by using Spring Data Sort Structure:

Lire la suite…

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step8]

avril 15, 2012 2 commentaires

In [step7] we have seen how to use Spring Data JPA to add custom methods to the Dao to manage criteria and pagination.

In this article we will implement a Rich Client with RCP Application to display User list in a SWT Table :

We will see how to we can consume the UserService by using Spring DM by using the SpringExtensionFactory from Martin Lippert.

Lire la suite…

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step7]

avril 13, 2012 2 commentaires

In [step6] we have implemented the API Dao UserDao with JPA by using Spring Data JPA :

  • the API Dao fr.opensagres.dao.UserDao extends the Spring Data org.springframework.data.repository.PagingAndSortingRepository.
  • the JPA User Dao implementation is created on runtime by Spring Data JPA by declaring a jpa:repository:
    <!-- Spring Data JPA-->
    <jpa:repositories base-package="fr.opensagres.dao">
      <jpa:repository id="userDao" />
    </jpa:repositories>
    

At this step the UserDao provides the CRUD methods and pagination methods for User entity like :

  • Iterable findAll(): to find all entity.
  • T save(T model): to save an entity.
  • Page findAll(Pageable pageable): to find all entity with pagination.

With Spring Data JPA, it’s possible to add your own method to manage search entities by criteria : to do that the method name of the UserDao must just follow some convention name (see Query creation for more information). In this article we will add the 2 following methods to the UserDao :

  • findByFirstNameLikeAndLastNameLike to retrieve a list of User by first name (like) and last name (like):
    List<User> findByFirstNameLikeAndLastNameLike(String firstName,	String lastName);
    
  • findByFirstNameLikeAndLastNameLike to retrieve a list of User by first name (like) and last name (like) with pagination:
    Page<User> findByFirstNameLikeAndLastNameLike(String firstName,	String lastName, Pageable pageable);
    

Just add those 2 methods to UserDao API and Spring Data JPA will manage for you the JPA implementation!

Lire la suite…

Catégories :Spring Data JPA

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step6]

avril 12, 2012 13 commentaires

In [step5] we have prepared the Target Platform with:

The API Dao fr.opensagres.dao.UserDao extends the Spring Data org.springframework.data.repository.PagingAndSortingRepository interface which is the first step to use Spring Data JPA.

In this article we will create several bundles/fragment to retrieves User list from a Database Derby with EclipseLink JPA. The JPA Dao implementation will be done with Spring Data JPA, on other words, you will do nothing (no need to code a JPAUserDao class). We will create 2 bundles and 1 fragment :

Lire la suite…

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step5]

avril 11, 2012 2 commentaires

In [step4] we have created DAO layer with Mock implementation. In this article we will start to explains how to implement DAO with JPA to use Database. We will use:

  • EclipseLink as JPA Implementation
  • Derby as Database.
  • Spring Data JPA to implement our DAO with JPA. Spring Data gives some DAO interface like org.springframework.data.repository.PagingAndSortingRepository which provides several CRUD methods like :
    • Iterable findAll(): to find all entity.
    • T save(T model): to save an entity.
    • Page findAll(Pageable pageable): to find all entity with pagination.

    The basic idea of Spring Data JPA is extends this interface in your DAO, and you not need to implements this methods with JPA query. It’s the goal of Spring Data JPA.

But it’s very long to explain how to configure and creates bundles to do that. So I decided to split the explanation into 2 articles :

  1. [step5]: explains how to download Spring Data JPA, use Java Spring Data Structure in our Mock and API DAO, and configure the OSGi launch.
  2. [step6]: explains how to create and configure bundles to use Spring Data JPA with EclipseLink and Derby.

Lire la suite…

Catégories :Spring, Spring Data, Spring DM

Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting [step0]

avril 5, 2012 3 commentaires

XDocReport project provides a modular Eclipse RCP/RAP XDocReport application where you can develop your own module with Eclipse Plugin to manage your domain with CRUD Form and generates some reporting. The online RAP demo provides for instance a Resume module to manage resume (create/update/search resume and generate report resume):

This application is based on :

  • Eclipse RCP to provide Fat Rich Client.
  • Eclipse RAP to provide the same application in WEB mode
  • Eclipse Gemini Blueprint to use Spring on OSGi context. This project is the donation of the Spring DM project to Eclipse
  • Spring Data JPA is used to implement our DAO with JPA. This Spring project is very impressive because you need not code your JPA Query. You must just follow some convention name with your methode DAO interface and that’s all! Spring Data JPA implements (at runtime) for you the JPA DAO.
  • Eclipselink used as JPA Implementation.

You can find sources from this Eclipse RCP/RAP application on Git.

Our 2 next goals is :

  • manage remoting to provide too Client (RCP Client) and Server (Services on server side) architecture. To do that we have several solutions like :
  • use Eclipse E4 instead of Eclipse RCP as soon as Eclipse RAP will support Eclipse E4.

We spent much time to study how to manage those technologies together but today we like this architecture. Goal of my « Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting » articles is to explain step by step how to develop a simple Eclipse RCP/RAP with those Spring technologies, shares several rules that we have discovered with Spring on OSGi context, and manages 2 architectures :

To follow those articles, you must know OSGi, Eclipse RCP:

You can read the next article [step1] which explains how to initialize Spring DM.

Eclipse Nebula Pagination Control

janvier 6, 2012 13 commentaires

In business application with large data, display data in a table with navigation page can be really helpful. In our XDocReport project, we need this feature in our Eclipse RCP/RAP XDocReport application for instance to select resumes to open in the Search Resume Dialog :

This last screenshot is the resume search dialog in WEB context (Eclipse RAP). Here a screenshot in fat client context (Eclipse RCP) :

After several search, it seems that there is no project which provides a SWT pagination control, which works with Eclipse RCP and RAP. So we decided to develop this control and give our code to Eclipse Nebula Project. Today Nebula Team are voting if the project will be accepted or not. Pagination control was accepted by Nebula and today it is stored on Eclipse Nebula Git.

If you are intersted you can read the original bug 367064.

Lire la suite…