Archive

Archive for the ‘Spring DM’ Category

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…

Publicité

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 [step4]

avril 10, 2012 3 commentaires

In [step3] we have developed a Simple Client bundle which consumes the UserService from the OSGi services registry to display a list of User in the console. So we have seen how to:

  • consume service with Spring DM <osgi:reference.
  • publish service with Spring DM <osgi:service.

At this step we have a service layer. Now we can add Dao layer (Some people prefer merge services/dao layer, but in our case I prefer do that to have a facade and it will help us when remoting with REST will be done) to retrieve User data from Database. To do that we will use :

Before doing that, I would like show you an idea that we have done in our Eclipse RCP/RAP XDocReport application. We are 2 developers and when we wanted to integrate JPA as Dao implementation we would like continue to work together on 2 tasks :

  • one developer integrates Dao JPA implementation with EclipseLink and Spring Data JPA (an hard task when you don’t know very well those technologies).
  • one developer continues to develop the application: business services, UI components, etc…

The idea was been to integrate DAO API (very easy task) in our services layer and uses Mock Dao. So we have :

  • a Mock Dao implementation layer: which works with Java Map.
  • a JPA Dao implementation layer: which works with EclipseLink and Spring Data JPA.

Mock Dao was easy to develop (you will see that in this article) and once time UserDao API was finished, we can work on our own task (one task for JPA and one task for continue the development of the application) without disturb. You can tell me, yes it’s a classic mean to use Mock object.

But the second problem was Data. To inject data (ex: in our case User data) :

  • for Mock Dao, Data is managed with Java.
  • for JPA Dao, Data is managed with SQL scripts…

However JPA gives you the capability to generate Database by using the JPA annotation of the Domain classes (without SQL scripts). What is about data? So we tell us, why we cannot use ours services save method to inject data? For instance in our case we could call UserService#saveUser(User user) which uses Dao (Mock or JPA) somewhere to inject our users :

  • it will work for Mock Dao.
  • it will work for JPA Dao.

But where can we do that? The idea is very simple. We have created a new bundle « datainjector » with a DataInjector class which consumes service to inject Data. For instance in our case we could have that :

public class DataInjector {

	private UserService userService;

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void inject() {
          userService.saveUser(new User("Angelo", "Zerr"));
          ...
        }
}

In this article we will do that :

  • add API Dao layer used in the Services Implementation.
  • implement DAo with Mock (Java Map).
  • inject User data in a « datainjector » bundle which will use the UserService.

Lire la suite…

Catégories :Spring, Spring DM

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

avril 10, 2012 3 commentaires

In [step2] we have seen how to use Spring DM to load/unload in OSGi context Spring file (stored in META-INF/spring folder) from an OSGi bundle. In this article we will see how to:

  • publish service to OSGi services registry with declaration mean with Spring DM <osgi:service.
  • >S

  • consume service from OSGi services registry with declaration mean (to avoid using OSGi ServiceTracker) with Spring DM <osgi:reference .

We will modify our thread client FindAllUsersThread to consume a UserService which returns a list of User :

public interface UserService {

	Collection<User> findAll();

}

and displays on console this User list.

  • On consumer side (Simple Client), The UserService will be retrieved from the OSGi services registry with <osgi:reference:
    <osgi:reference id="userService" interface="fr.opensagres.services.UserService"
      cardinality="0..1" timeout="1000" />
    

    This service instance will be injected (Dependency Injection) in the FindAllUsersThread :

    <bean id="FindAllUsersThread" class="fr.opensagres.simpleclient.FindAllUsersThread"
      init-method="start" destroy-method="interrupt">
      <property name="userService" ref="userService"></property>
    </bean>
    

    and UserService will be used in the thread :

    public class FindAllUsersThread extends Thread {
    
    	private UserService userService;
    
    	public void setUserService(UserService userService) {
    		this.userService = userService;
    	}
            
            @Override
    	public void run() {
              // Consume UserService and display user list here...
            }
    }
    
  • On publish side (Services Implementation), the UserService implementation instance will be declared in Spring file as bean:
    <bean id="userService" class="fr.opensagres.services.impl.UserServiceImpl" />
    

    and this bean will be registered in the OSGi references with Spring DM <osgi:service:

    <osgi:service ref="userService" interface="fr.opensagres.services.UserService" />
    

Lire la suite…

Catégories :Spring, Spring DM

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

avril 6, 2012 10 commentaires

In [step1], we have initialized Spring DM. At this step we can start using Spring DM features. One of goal of Spring DM is to give the capability to any OSGi bundles, to declare Spring bean in XML Spring file stored in their META-INF/spring folder. Spring DM provides a Spring Extender bundle which :

  1. load XML Spring file for each OSGi bundles which starts. We will check that in the Start Simple Client bundle section.
  2. unload XML Spring file for each OSGi bundles which stops.We will check that in the Stop Simple Client bundle section.

We will check this feature in this article by developing a Simple OSGi Bundle which uses Spring fr.opensagres.simpleclient to create an instance of a Thread :

  • the bundle hosts a Thread class which display in the System Out console a message :
    public class FindAllUsersThread extends Thread {	
    	
      @Override
      public void run() {
        while (!super.isInterrupted()) {				
          System.out.println("Call FindAllUsersThread#run()");				
        }
      }
    }
  • this Thread class will be declared in a Spring bean in the META-INF/spring/module-context.xml Spring file of the bundle. The start/interrupt of the Thread will be managed by the Spring:
    <bean id="FindAllUsersThread" class="fr.opensagres.simpleclient.FindAllUsersThread"
    	init-method="start" destroy-method="interrupt" />
    

Lire la suite…

Catégories :Spring DM

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

avril 6, 2012 16 commentaires

In [step0] we have seen that I will explain step by step how to develop « Eclipse RCP/RAP with Spring DM, Spring Data JPA and Remoting ». In my articles, I will use Spring DM instead of using Eclipse Gemini Blueprint because today CXF DOSGi supports only Spring DM. However I have created the patch DOSGI-115 to support Eclipse Gemini Blueprint with DOSGi.

In this article we will just initialize Spring DM :

But what is Spring DM? Spring DM gives you the capability to use Spring on OSGi context:

  1. any OSGi bundles can declare Spring bean in XML Spring file stored in their META-INF/spring folder. Spring DM provides a Spring Extender bundle which :
    1. load XML Spring file for each OSGi bundles which starts.
    2. unload XML Spring file for each OSGi bundles which stops.
  2. it’s possible to declare in Spring bean, services to publish/consume in the OSGi registry services.

Lire la suite…

Catégories :Spring, Spring DM Étiquettes :

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.

Load-Time Weaving for Spring-DM with JPA/EclipseLink [step2]

avril 30, 2010 4 commentaires

Into the previous [step1], I have introduced Springweaver 0.1.2 to use it with JPA/EclipseLink. In this article I will explain how launch the Springweaver- EclipseLink sample which use Springweaver 0.1.2 with JPA/EclipseLink. I assume you know Spring DM (Spring extender…). This sample was developed and tested with Eclipse Galileo.

Lire la suite…

Load-Time Weaving for Spring-DM with JPA/EclipseLink [step1]

avril 30, 2010 11 commentaires

Martin Lippert has created org.eclipse.equinox.weaving.springweaver (version 0.1.1) bundle to manage Spring LoadTimeWeaver into OSGi context (Equinox only) which is based on Equinox Aspects.

I have tried to use org.eclipse.equinox.weaving.springweaver (version 0.1.1) into JPA context with EclipseLink, but weaving doesn’t work very well ( see SpringWeaver (0.1.1) -JPA problem for more information). I think (but not sure) that Martin Lippert has tested org.eclipse.equinox.weaving.springweaver only with Spring @Configurable.

So I decided to create a new version of org.eclipse.equinox.weaving.springweaver (version 0.1.2) to manage LoadTimeWeaver into JPA context, that you can find on Dynaresume SVN – SpringWeaver.

Lire la suite…

Conception d’un client Eclipse RCP et serveur OSGI avec Spring DM [step19]

avril 27, 2010 10 commentaires

Dans le billet précédant [step18] nous avons mis en place JPA avec LocalContainerEntityManagerFactoryBean en utilisant JPA/Hibernate et JPA/EclipseLink avec les 2 bases de données H2 et Derby dans un contexte NON OSGi. Dans ce billet nous allons mettre en place JPA dans un contexte OSGi avec LocalContainerEntityManagerFactoryBean en utilisant JPA/Hibernate et JPA/EclipseLink avec les 2 bases de données H2 et Derby.

Notre classe UserServiceImpl du bundle org.dynaresume.services.impl utilisera une interface DAO UserDAO qui dans notre cas est implémenté en JPA. L’implémentation de la DAO UserDAO est renseigné à la classe UserServiceImpl via le mécanisme d’injection de Dépendances en utilisant le registre de services OSGi :

Lire la suite…