continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ri...@apache.org
Subject svn commit: r599779 - in /maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum: model/project/ store/api/ store/jpa/
Date Fri, 30 Nov 2007 11:16:49 GMT
Author: rinku
Date: Fri Nov 30 03:16:44 2007
New Revision: 599779

URL: http://svn.apache.org/viewvc?rev=599779&view=rev
Log:
o  Updates to Store<T> extension implementations.
o  minor refactorings.

Added:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
  (with props)
Modified:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/model/project/ProjectGroup.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/EntityNotFoundException.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/StoreException.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStore.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectStore.java

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/model/project/ProjectGroup.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/model/project/ProjectGroup.java?rev=599779&r1=599778&r2=599779&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/model/project/ProjectGroup.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/model/project/ProjectGroup.java
Fri Nov 30 03:16:44 2007
@@ -1,5 +1,6 @@
 package org.apache.maven.continuum.model.project;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.persistence.Basic;
@@ -114,6 +115,8 @@
      */
     public List<Project> getProjects()
     {
+        if ( null == this.projects )
+            this.projects = new ArrayList<Project>();
         return projects;
     }
 

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/EntityNotFoundException.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/EntityNotFoundException.java?rev=599779&r1=599778&r2=599779&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/EntityNotFoundException.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/EntityNotFoundException.java
Fri Nov 30 03:16:44 2007
@@ -25,6 +25,11 @@
  */
 public class EntityNotFoundException extends StoreException
 {
+    public EntityNotFoundException()
+    {
+        super();
+    }
+
     public EntityNotFoundException( String message )
     {
         super( message );

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/StoreException.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/StoreException.java?rev=599779&r1=599778&r2=599779&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/StoreException.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/StoreException.java
Fri Nov 30 03:16:44 2007
@@ -25,6 +25,13 @@
  */
 public class StoreException extends Exception
 {
+
+   
+    public StoreException()
+    {
+        super();
+    }
+
     public StoreException( String msg )
     {
         super( msg );

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStore.java?rev=599779&r1=599778&r2=599779&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStore.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStore.java
Fri Nov 30 03:16:44 2007
@@ -7,16 +7,17 @@
 
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.store.api.EntityNotFoundException;
-import org.apache.maven.continuum.store.api.StoreException;
 import org.apache.maven.continuum.store.api.Query;
 import org.apache.maven.continuum.store.api.Store;
+import org.apache.maven.continuum.store.api.StoreException;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  * @version $Id$
  * @since 1.2
  */
-public class JpaProjectGroupStore implements Store<ProjectGroup>
+public class JpaProjectGroupStore extends StoreSupport implements Store<ProjectGroup>
 {
 
     /**
@@ -24,10 +25,10 @@
      * 
      * @see org.apache.maven.continuum.store.api.Store#delete(java.lang.Object)
      */
+    @Transactional( readOnly = false )
     public void delete( ProjectGroup entity ) throws StoreException
     {
-        // TODO Auto-generated method stub
-
+        getJpaTemplate().remove( entity );
     }
 
     /**
@@ -37,9 +38,7 @@
      */
     public ProjectGroup lookup( Long id ) throws StoreException, EntityNotFoundException
     {
-        // TODO Auto-generated method stub
-
-        return null;
+        return lookup( ProjectGroup.class, id );
     }
 
     /**
@@ -47,20 +46,27 @@
      * 
      * @see org.apache.maven.continuum.store.api.Store#save(java.lang.Object)
      */
+    @Transactional( readOnly = false )
     public ProjectGroup save( ProjectGroup entity ) throws StoreException
     {
-        // TODO Auto-generated method stub
-        return null;
+        if ( null != entity )
+        {
+            if ( null == entity.getId() )
+                getJpaTemplate().persist( entity );
+            else
+                entity = getJpaTemplate().merge( entity );
+        }
+        return entity;
     }
 
-    /*
-     * (non-Javadoc)
+    /**
+     * {@inheritDoc}
      * 
      * @see org.apache.maven.continuum.store.api.Store#query(org.apache.maven.continuum.store.api.Query)
      */
     public List<ProjectGroup> query( Query query ) throws StoreException
     {
-        // TODO Auto-generated method stub
+        // TODO Implement!
         return null;
     }
 

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectStore.java?rev=599779&r1=599778&r2=599779&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectStore.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectStore.java
Fri Nov 30 03:16:44 2007
@@ -7,16 +7,17 @@
 
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.store.api.EntityNotFoundException;
-import org.apache.maven.continuum.store.api.StoreException;
 import org.apache.maven.continuum.store.api.Query;
 import org.apache.maven.continuum.store.api.Store;
+import org.apache.maven.continuum.store.api.StoreException;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  * @version $Id$
  * @since 1.2
  */
-public class JpaProjectStore implements Store<Project>
+public class JpaProjectStore extends StoreSupport implements Store<Project>
 {
 
     /**
@@ -24,10 +25,10 @@
      * 
      * @see org.apache.maven.continuum.store.api.Store#delete(java.lang.Object)
      */
+    @Transactional( readOnly = false )
     public void delete( Project entity ) throws StoreException
     {
-        // TODO Auto-generated method stub
-
+        getJpaTemplate().remove( entity );
     }
 
     /**
@@ -37,8 +38,7 @@
      */
     public Project lookup( Long id ) throws StoreException, EntityNotFoundException
     {
-        // TODO Auto-generated method stub
-        return null;
+        return lookup( Project.class, id );
     }
 
     /**
@@ -46,10 +46,17 @@
      * 
      * @see org.apache.maven.continuum.store.api.Store#save(java.lang.Object)
      */
+    @Transactional( readOnly = false )
     public Project save( Project entity ) throws StoreException
     {
-        // TODO Auto-generated method stub
-        return null;
+        if ( null != entity )
+        {
+            if ( null == entity.getId() )
+                getJpaTemplate().persist( entity );
+            else
+                entity = getJpaTemplate().merge( entity );
+        }
+        return entity;
     }
 
     /**
@@ -59,7 +66,7 @@
      */
     public List<Project> query( Query query ) throws StoreException
     {
-        // TODO Auto-generated method stub
+        // TODO Implement!
         return null;
     }
 

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java?rev=599779&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
Fri Nov 30 03:16:44 2007
@@ -0,0 +1,49 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.jpa;
+
+import org.apache.maven.continuum.model.CommonPersistableEntity;
+import org.apache.maven.continuum.store.api.EntityNotFoundException;
+import org.apache.maven.continuum.store.api.Store;
+import org.springframework.orm.jpa.JpaObjectRetrievalFailureException;
+import org.springframework.orm.jpa.support.JpaDaoSupport;
+
+/**
+ * Base class for concrete {@link Store} implementations that provides service methods for
Entity retrievals.
+ * 
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public abstract class StoreSupport extends JpaDaoSupport
+{
+
+    /**
+     * Service method to lookup matching entities.
+     * 
+     * @param <E>
+     * @param klass
+     * @param id
+     * @return
+     * @throws EntityNotFoundException
+     */
+    protected <E extends CommonPersistableEntity> E lookup( Class<E> klass, Long
id ) throws EntityNotFoundException
+    {
+        if ( id == null )
+            throw new EntityNotFoundException();
+        E entity = null;
+        try
+        {
+            entity = getJpaTemplate().find( klass, id );
+        }
+        catch ( JpaObjectRetrievalFailureException e )
+        {
+            throw new EntityNotFoundException();
+        }
+        if ( entity == null )
+            throw new EntityNotFoundException();
+        return entity;
+    }
+
+}

Propchange: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message