continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ri...@apache.org
Subject svn commit: r602031 - in /maven/continuum/branches/continuum-jpa/continuum-model-jpa/src: main/java/org/apache/maven/continuum/store/api/ main/java/org/apache/maven/continuum/store/jpa/ test/java/org/apache/maven/continuum/store/jpa/ test/resources/MET...
Date Fri, 07 Dec 2007 08:58:08 GMT
Author: rinku
Date: Fri Dec  7 00:58:07 2007
New Revision: 602031

URL: http://svn.apache.org/viewvc?rev=602031&view=rev
Log:
o  playing around with generics to implement a leaner JpaStore and drop specific extensions
for Project, ProjectGroup etc. 
o  added unit tests.
o  Some more unit tests required before earlier implementations can be deprecated. 

Added:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/ExtendedJpaProjectStore.java
  (with props)
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStore.java
  (with props)
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStoreFactory.java
  (with props)
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaStoreTest.java
  (with props)
Modified:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectQuery.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Query.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Store.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/JpaProjectNotifierStore.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectStore.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStoreTest.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/resources/META-INF/spring-config.xml

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectQuery.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectQuery.java?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectQuery.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectQuery.java
Fri Dec  7 00:58:07 2007
@@ -4,6 +4,7 @@
 package org.apache.maven.continuum.store.api;
 
 import java.util.Date;
+import java.util.Map;
 
 import org.apache.maven.continuum.model.project.Project;
 
@@ -14,7 +15,7 @@
  * @version $Id$
  * @since 1.2
  */
-public class ProjectQuery implements Query<Project>
+public class ProjectQuery<Project> implements Query<Project>
 {
 
     /**
@@ -319,6 +320,91 @@
     public void setVersion( String version )
     {
         this.version = version;
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Query#toString(java.util.Map)
+     */
+    public String toString( Map<String, Object> where )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        if ( this.hasId() )
+        {
+            where.put( "id", this.getId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.id =:id " );
+        }
+        if ( this.hasDateCreated() )
+        {
+            where.put( "dateCreated", this.getDateCreated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.dateCreated =:dateCreated " );
+        }
+        if ( this.hasDateUpdated() )
+        {
+            where.put( "dateUpdated", this.getDateUpdated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.dateUpdated =:dateUpdated " );
+        }
+        if ( this.hasDescription() )
+        {
+            where.put( "description", this.getDescription() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.description =:description " );
+        }
+        if ( this.hasGroupId() )
+        {
+            where.put( "groupId", this.getGroupId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.groupId =:groupId " );
+        }
+        if ( this.hasModelEncoding() )
+        {
+            where.put( "modelEncoding", this.getModelEncoding() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.modelEncoding =:modelEncoding " );
+        }
+        if ( this.hasName() )
+        {
+            where.put( "name", this.getName() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.name =:name " );
+        }
+        if ( this.hasArtifactId() )
+        {
+            where.put( "artifactId", this.getArtifactId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.artifactId =:artifactId" );
+        }
+        if ( this.hasBuildNumber() )
+        {
+            where.put( "buildNumber", this.getBuildNumber() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.buildNumber =:buildNumber" );
+        }
+        if ( this.hasVersion() )
+        {
+            where.put( "version", this.getVersion() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.version =:version" );
+        }
+
+        String whereClause = ( sb.length() > 0 ? " where " : "" ) + sb.toString();
+
+        return null;
     }
 
 }

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Query.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Query.java?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Query.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Query.java
Fri Dec  7 00:58:07 2007
@@ -3,8 +3,14 @@
  */
 package org.apache.maven.continuum.store.api;
 
+import java.util.Map;
+
 /**
  * Wraps up Type Query criteria to be used by store extensions to filter (and obtain) matching
type instances.
+ * <p>
+ * Implementations/extensions are expected to override {@link Object#toString()} method and
return a <b>JPQL</b>
+ * formatted string. The JPQL string is consumed by the {@link Store} implementation in {@link
Store#query(Query)}
+ * operations.
  * 
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  * @version $Id$
@@ -12,5 +18,16 @@
  */
 public interface Query<Q>
 {
-    // Marker interface
+
+    /**
+     * Returns this instance of {@link Query} as a JPQL String.
+     * 
+     * @param whereClause
+     *            {@link Map} containing the named parameters to be substituted in the JPQL
query. This is populated by
+     *            the {@link Query} implementation and subsequently used by the {@link Store}
implementation to
+     *            interpolate the parameters before the JPQL query is executed.
+     * 
+     * @return {@link Query} as a JPQL String
+     */
+    public String toString( Map<String, Object> whereClause );
 }

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Store.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Store.java?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Store.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/Store.java
Fri Dec  7 00:58:07 2007
@@ -6,6 +6,15 @@
 import java.util.List;
 
 /**
+ * Interface that Continuum store extensions/implementations are expected to implement to
allow operations on the
+ * underlying store.
+ * <ul>
+ * <li>Entity look ups</li>
+ * <li>Entity insert/updates</li>
+ * <li>Entity removal</li>
+ * <li>Querying one or more entity/entities based on specified criteria</li>
+ * </ul>
+ * 
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  * @version $Id$
  * @since 1.2
@@ -16,48 +25,51 @@
     /**
      * Looks up the underlying store and returns a {@link T} instance that matches the specified
id.
      * 
+     * @param klass
+     *            {@link Class} for type entity to lookup and return an instance of.
      * @param id
-     *            {@link T} id to match.
-     * @return matching {@link T} instance.
+     *            Entity Type {@link T}'s id to match.
+     * 
+     * @return matching entity type {@link T} instance.
      * @throws StoreException
      * @throws EntityNotFoundException
      *             if the entity specified by the identifier could be located in the system.
      * @throws EntityNotFoundException
      *             if the instance could not be looked up.
      */
-    public T lookup( Long id ) throws StoreException, EntityNotFoundException;
+    public T lookup( Class<T> klass, Long id ) throws StoreException, EntityNotFoundException;
 
     /**
-     * Persists the passed in {@link T} instance to the underlying store.
+     * Persists the passed in entity type {@link T} instance to the underlying store.
      * <p>
      * If the entity instance already exists in the database it is updated, else a new instance
is created and an
      * store-generated identifier assigned to it.
      * 
      * @param entity
-     *            {@link T} instance to be created/saved.
-     * @return updated {@link T} instance.
+     *            Type {@link T} instance to be created/saved.
+     * @return updated entity type {@link T} instance.
      * @throws StoreException
      *             if there was an error saving the entity.
      */
     public T save( T entity ) throws StoreException;
 
     /**
-     * Removes the passed {@link T} instance from the underlying store.
+     * Removes the passed entity type {@link T} instance from the underlying store.
      * 
      * @param entity
-     *            {@link T} instance to remove.
+     *            Type {@link T} instance to remove.
      * @throws StoreException
      *             if there was an error removing the entity.
      */
     public void delete( T entity ) throws StoreException;
 
     /**
-     * Obtains a {@link List} of instances of type {@link T} which match the criteria specified
by the passed in query
-     * instance.
+     * Obtains a {@link List} of instances of entity type {@link T} which match the criteria
specified by the passed in
+     * query instance.
      * 
      * @param query
      *            instance that wraps up the criteria for querying matching instances in
the system.
-     * @return {@link List} of instances of type {@link T} which match the specified query.
+     * @return {@link List} of instances of entity type {@link T} which match the specified
query.
      * @throws StoreException
      */
     public List<T> query( Q query ) throws StoreException;

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/ExtendedJpaProjectStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/ExtendedJpaProjectStore.java?rev=602031&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/ExtendedJpaProjectStore.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/ExtendedJpaProjectStore.java
Fri Dec  7 00:58:07 2007
@@ -0,0 +1,32 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.jpa;
+
+import java.util.List;
+
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.store.api.ProjectQuery;
+import org.apache.maven.continuum.store.api.StoreException;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @deprecated <em>experimental</em>
+ */
+public class ExtendedJpaProjectStore<T extends Project, Q extends ProjectQuery<Project>>
+    extends JpaStore<Project, ProjectQuery<Project>>
+{
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.jpa.JpaStore#query(org.apache.maven.continuum.store.api.Query)
+     */
+    @Override
+    public List<Project> query( ProjectQuery<Project> query ) throws StoreException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

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

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

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=602031&r1=602030&r2=602031&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 Dec  7 00:58:07 2007
@@ -40,6 +40,16 @@
      */
     public ProjectGroup lookup( Long id ) throws StoreException, EntityNotFoundException
     {
+        return lookup( null, id );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#lookup(Class, java.lang.Long)
+     */
+    public ProjectGroup lookup( Class<T> klass, Long id ) throws StoreException, EntityNotFoundException
+    {
         return lookup( ProjectGroup.class, id );
     }
 

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectNotifierStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectNotifierStore.java?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectNotifierStore.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaProjectNotifierStore.java
Fri Dec  7 00:58:07 2007
@@ -40,6 +40,16 @@
      */
     public ProjectNotifier lookup( Long id ) throws StoreException, EntityNotFoundException
     {
+        return lookup( null, id );
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#lookup(Class, java.lang.Long)
+     */
+    public ProjectNotifier lookup( Class<T> klass, Long id ) throws StoreException,
EntityNotFoundException
+    {
         return lookup( ProjectNotifier.class, id );
     }
 

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=602031&r1=602030&r2=602031&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 Dec  7 00:58:07 2007
@@ -19,7 +19,7 @@
  * @version $Id$
  * @since 1.2
  */
-public class JpaProjectStore extends StoreSupport implements Store<Project, ProjectQuery>
+public class JpaProjectStore extends StoreSupport implements Store<Project, ProjectQuery<Project>>
 {
 
     /**
@@ -39,6 +39,16 @@
      * @see org.apache.maven.continuum.store.api.Store#lookup(java.lang.Long)
      */
     public Project lookup( Long id ) throws StoreException, EntityNotFoundException
+    {
+        return lookup( null, id );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#lookup(Class, java.lang.Long)
+     */
+    public Project lookup( Class<T> klass, Long id ) throws StoreException, EntityNotFoundException
     {
         return lookup( Project.class, id );
     }

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStore.java?rev=602031&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStore.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStore.java
Fri Dec  7 00:58:07 2007
@@ -0,0 +1,87 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.jpa;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.store.api.EntityNotFoundException;
+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.orm.jpa.JpaObjectRetrievalFailureException;
+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 JpaStore<T, Q extends Query<T>> extends StoreSupport implements
Store<T, Q>
+{
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#delete(java.lang.Object)
+     */
+    @Transactional( readOnly = false )
+    public void delete( T entity ) throws StoreException
+    {
+        getJpaTemplate().remove( entity );
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#lookup(Class, java.lang.Long)
+     */
+    public T lookup( Class<T> klass, Long id ) throws StoreException, EntityNotFoundException
+    {
+        if ( id == null )
+            throw new EntityNotFoundException();
+        T entity = null;
+        try
+        {
+            entity = getJpaTemplate().find( klass, id );
+        }
+        catch ( JpaObjectRetrievalFailureException e )
+        {
+            throw new EntityNotFoundException();
+        }
+        if ( entity == null )
+            throw new EntityNotFoundException();
+        return entity;
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#query(org.apache.maven.continuum.store.api.Query)
+     */
+    public List<T> query( Q query ) throws StoreException
+    {
+        Map<String, Object> where = new HashMap<String, Object>();
+        String q = query.toString( where );
+
+        List<T> results = find( q, where, 0, 0 );
+
+        return results;
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.maven.continuum.store.api.Store#save(java.lang.Object)
+     */
+    @Transactional( readOnly = false )
+    public T save( T entity ) throws StoreException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

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

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

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStoreFactory.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStoreFactory.java?rev=602031&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStoreFactory.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/JpaStoreFactory.java
Fri Dec  7 00:58:07 2007
@@ -0,0 +1,26 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.jpa;
+
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.store.api.ProjectQuery;
+import org.apache.maven.continuum.store.api.Store;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public class JpaStoreFactory
+{
+
+    private final JpaStore<Project, ProjectQuery<Project>> JPA_PROJECT_STORE
=
+        new JpaStore<Project, ProjectQuery<Project>>();
+
+    public Store<Project, ProjectQuery<Project>> createProjectStoreInstance()
+    {
+        return JPA_PROJECT_STORE;
+    }
+
+}

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

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

Modified: 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=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java
Fri Dec  7 00:58:07 2007
@@ -30,33 +30,6 @@
 {
 
     /**
-     * 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;
-    }
-
-    /**
      * Prepares and executes a query using the 'where' criteria, a start index and a given
range of results to return.
      * 
      * @param queryString

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStoreTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStoreTest.java?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStoreTest.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectGroupStoreTest.java
Fri Dec  7 00:58:07 2007
@@ -81,7 +81,7 @@
     @Test
     public void testLookupProjectGroup() throws EntityNotFoundException, StoreException
     {
-        ProjectGroup projectGroup = getProjectGroupStore().lookup( 1000L );
+        ProjectGroup projectGroup = getProjectGroupStore().lookup( null, 1000L );
         Assert.assertNotNull( projectGroup );
         Assert.assertEquals( 1000L, projectGroup.getId().longValue() );
         Assert.assertEquals( "Continuum Projects", projectGroup.getName() );
@@ -93,7 +93,7 @@
     {
         try
         {
-            ProjectGroup projectGroup = getProjectGroupStore().lookup( 99999L );
+            ProjectGroup projectGroup = getProjectGroupStore().lookup( null, 99999L );
             Assert.fail( "Expected " + EntityNotFoundException.class.getSimpleName()
                             + " on account of an invalid ProjectGroup Id." );
         }

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
Fri Dec  7 00:58:07 2007
@@ -89,9 +89,9 @@
      * 
      * @return
      */
-    private Store<Project, ProjectQuery> getProjectStore()
+    private Store<Project, ProjectQuery<Project>> getProjectStore()
     {
-        Store<Project, ProjectQuery> store = getStore( BEAN_REF__PROJECT_STORE );
+        Store<Project, ProjectQuery<Project>> store = getStore( BEAN_REF__PROJECT_STORE
);
         return store;
     }
 

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaStoreTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaStoreTest.java?rev=602031&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaStoreTest.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaStoreTest.java
Fri Dec  7 00:58:07 2007
@@ -0,0 +1,75 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.jpa;
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.continuum.model.project.ProjectNotifier;
+import org.apache.maven.continuum.store.ApplicationContextAwareStoreTestCase;
+import org.apache.maven.continuum.store.api.ProjectNotifierQuery;
+import org.apache.maven.continuum.store.api.Store;
+import org.apache.maven.continuum.store.api.StoreException;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = "/META-INF/spring-config.xml" )
+public class JpaStoreTest extends ApplicationContextAwareStoreTestCase
+{
+    private static final String BEAN_REF__PROJECT_STORE = "projectStore";
+
+    @Override
+    @Before
+    public void setUp()
+    {
+        File testData = new File( "src/test/resources/sql/project-table-data.sql" );
+        Assert.assertTrue( "Unable to find test data resource: " + testData.getAbsolutePath(),
testData.exists() );
+        Properties propMap = new Properties();
+        setUp( propMap );
+
+        // load test data from SQL file.
+        setSqlSource( testData );
+    }
+
+    @Test
+    public void testOpenJPASetup()
+    {
+        OpenJPAQuery q = em.createQuery( "select p from Project p" );
+        String[] sql = q.getDataStoreActions( null );
+        Assert.assertEquals( 1, sql.length );
+        Assert.assertTrue( sql[0].startsWith( "SELECT" ) );
+        List results = q.getResultList();
+        Assert.assertNotNull( results );
+        Assert.assertEquals( 2, results.size() );
+    }
+
+    // @Test
+    public void testCreateProjectNotifier() throws StoreException
+    {
+        ProjectNotifier notifier = new ProjectNotifier();
+        notifier.setModelEncoding( "UTF-8" );
+        Assert.assertTrue( null == notifier.getId() );
+        notifier = getProjectNotifierStore().save( notifier );
+        Assert.assertTrue( null != notifier.getId() );
+        Assert.assertTrue( notifier.getId() > 0L );
+    }
+
+    private Store<ProjectNotifier, ProjectNotifierQuery> getProjectNotifierStore()
+    {
+        Store<ProjectNotifier, ProjectNotifierQuery> store = getStore( BEAN_REF__PROJECT_STORE
);
+        return store;
+    }
+}

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

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

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/resources/META-INF/spring-config.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/resources/META-INF/spring-config.xml?rev=602031&r1=602030&r2=602031&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/resources/META-INF/spring-config.xml
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/resources/META-INF/spring-config.xml
Fri Dec  7 00:58:07 2007
@@ -30,6 +30,7 @@
     </property>
   </bean>
 
+  <!-- 
   <bean id="projectStoreTarget"
     class="org.apache.maven.continuum.store.jpa.JpaProjectStore">
     <property name="entityManagerFactory" ref="entityManagerFactory" />
@@ -70,6 +71,19 @@
     <property name="interceptorNames">
       <idref local="transactionInterceptor" />
     </property>
+  </bean>
+  -->
+
+  <bean id="projectStoreFactory"
+    class="org.apache.maven.continuum.store.jpa.JpaStoreFactory">
+  </bean>
+  
+   <bean id="projectStore"
+    class="org.apache.maven.continuum.store.jpa.JpaStore"
+    factory-bean="projectStoreFactory"
+    factory-method="createProjectStoreInstance"    
+    >    
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
   </bean>
 
 </beans>



Mime
View raw message