continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ri...@apache.org
Subject svn commit: r600081 - in /maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store: api/ jpa/
Date Sat, 01 Dec 2007 11:04:07 GMT
Author: rinku
Date: Sat Dec  1 03:04:03 2007
New Revision: 600081

URL: http://svn.apache.org/viewvc?rev=600081&view=rev
Log:
o  updated Query and Store interfaces. 
o  updated Project and ProjectGroup query implementations.

Added:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/QueryFactory.java
  (with props)
Modified:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectGroupQuery.java
    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/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/JpaProjectStore.java
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/jpa/StoreSupport.java

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectGroupQuery.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectGroupQuery.java?rev=600081&r1=600080&r2=600081&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectGroupQuery.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/ProjectGroupQuery.java
Sat Dec  1 03:04:03 2007
@@ -3,6 +3,8 @@
  */
 package org.apache.maven.continuum.store.api;
 
+import java.util.Date;
+
 import org.apache.maven.continuum.model.project.ProjectGroup;
 
 /**
@@ -12,8 +14,228 @@
  * @version $Id$
  * @since 1.2
  */
-public class ProjectGroupQuery
-    implements Query<ProjectGroup>
+public class ProjectGroupQuery implements Query<ProjectGroup>
 {
+
+    /**
+     * ProjectGroup creation date criteria.
+     */
+    private Date dateCreated;
+
+    /**
+     * ProjectGroup update date criteria.
+     */
+    private Date dateUpdated;
+
+    /**
+     * ProjectGroup description criteria.
+     */
+    private String description;
+
+    /**
+     * ProjectGroup groupId criteria.
+     */
+    private String groupId;
+
+    /**
+     * ProjectGroup Id criteria.
+     */
+    private Long id;
+
+    /**
+     * ProjectGroup model encoding criteria.
+     */
+    private String modelEncoding;
+
+    /**
+     * ProjectGroup name criteria.
+     */
+    private String name;
+
+    /**
+     * @return
+     * 
+     */
+    public Date getDateCreated()
+    {
+        return this.dateCreated;
+    }
+
+    /**
+     * @return
+     * @see org.apache.maven.continuum.model.CommonUpdatableEntity#getDateUpdated()
+     */
+    public Date getDateUpdated()
+    {
+        return this.dateUpdated;
+    }
+
+    /**
+     * @return
+     * 
+     */
+    public String getDescription()
+    {
+        return this.description;
+    }
+
+    /**
+     * @return
+     * 
+     */
+    public String getGroupId()
+    {
+        return this.groupId;
+    }
+
+    /**
+     * Determine if a date of creation was specified in the query.
+     * 
+     * @return <code>true</code> if a date of creation was specified, else <code>false</code>.
+     */
+    public boolean hasDateCreated()
+    {
+        return ( null != this.dateCreated );
+    }
+
+    /**
+     * Determine if an update date was specified in the query.
+     * 
+     * @return <code>true</code> if a date of update was specified, else <code>false</code>.
+     */
+    public boolean hasDateUpdated()
+    {
+        return ( null != this.dateUpdated );
+    }
+
+    /**
+     * Determine if there was a Project Group 'description' specified in the query.
+     * 
+     * @return <code>true</code> if there was a Project Group 'description' specified
, else <code>false</code>.
+     */
+    public boolean hasDescription()
+    {
+        return ( null != this.description && this.description.length() > 0 );
+    }
+
+    /**
+     * Determine if there was a Group Id for the {@link ProjectGroup} specified in the query.
+     * 
+     * @return <code>true</code> if there was a Group Id for the {@link ProjectGroup}
specified, else
+     *         <code>false</code>.
+     */
+    public boolean hasGroupId()
+    {
+        return ( null != this.groupId && this.groupId.length() > 0 );
+    }
+
+    /**
+     * 
+     * @return
+     */
+    public boolean hasId()
+    {
+        return ( null != this.id && this.id.longValue() > 0L );
+    }
+
+    /**
+     * Determine if there was a model encoding specified in the query.
+     * 
+     * @return <code>true</code> if there was a model encoding specified, else
<code>false</code>.
+     */
+    public boolean hasModelEncoding()
+    {
+        return ( null != this.modelEncoding && this.modelEncoding.length() > 0
);
+    }
+
+    /**
+     * Determine if there is a {@link ProjectGroup} name specified in the query.
+     * 
+     * @return <code>true</code> if there is a {@link ProjectGroup} name specified,
else <code>false</code>.
+     */
+    public boolean hasName()
+    {
+        return ( null != this.name && this.name.length() > 0 );
+    }
+
+    /**
+     * @return
+     */
+    public Long getId()
+    {
+        return this.id;
+    }
+
+    /**
+     * @return
+     */
+    public String getModelEncoding()
+    {
+        return this.modelEncoding;
+    }
+
+    /**
+     * @return
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * @param dateCreated
+     */
+    public void setDateCreated( Date dateCreated )
+    {
+        this.dateCreated = dateCreated;
+    }
+
+    /**
+     * @param dateUpdated
+     */
+    public void setDateUpdated( Date dateUpdated )
+    {
+        this.dateUpdated = dateUpdated;
+    }
+
+    /**
+     * @param description
+     */
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    /**
+     * @param groupId
+     */
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    /**
+     * @param id
+     */
+    public void setId( Long id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * @param modelEncoding
+     */
+    public void setModelEncoding( String modelEncoding )
+    {
+        this.modelEncoding = modelEncoding;
+    }
+
+    /**
+     * @param name
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
 
 }

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=600081&r1=600080&r2=600081&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
Sat Dec  1 03:04:03 2007
@@ -12,8 +12,7 @@
  * @version $Id$
  * @since 1.2
  */
-public class ProjectQuery
-    implements Query<Project>
+public class ProjectQuery implements Query<Project>
 {
 
     /**
@@ -48,7 +47,7 @@
      */
     public boolean hasId()
     {
-        return ( null != id && id >= 0 );
+        return ( null != this.id && this.id >= 0 );
     }
 
     /**
@@ -56,11 +55,12 @@
      */
     public Long getId()
     {
-        return id;
+        return this.id;
     }
 
     /**
-     * @param id the id to set
+     * @param id
+     *            the id to set
      */
     public void setId( Long id )
     {
@@ -74,7 +74,7 @@
      */
     public boolean hasGroupId()
     {
-        return ( null != groupId );
+        return ( null != this.groupId );
     }
 
     /**
@@ -82,11 +82,12 @@
      */
     public String getGroupId()
     {
-        return groupId;
+        return this.groupId;
     }
 
     /**
-     * @param groupId the groupId to set
+     * @param groupId
+     *            the groupId to set
      */
     public void setGroupId( String groupId )
     {
@@ -100,7 +101,7 @@
      */
     public boolean hasArtifactId()
     {
-        return ( null != artifactId );
+        return ( null != this.artifactId );
     }
 
     /**
@@ -108,11 +109,12 @@
      */
     public String getArtifactId()
     {
-        return artifactId;
+        return this.artifactId;
     }
 
     /**
-     * @param artifactId the artifactId to set
+     * @param artifactId
+     *            the artifactId to set
      */
     public void setArtifactId( String artifactId )
     {
@@ -126,7 +128,7 @@
      */
     public boolean hasVersion()
     {
-        return ( null != version );
+        return ( null != this.version );
     }
 
     /**
@@ -134,11 +136,12 @@
      */
     public String getVersion()
     {
-        return version;
+        return this.version;
     }
 
     /**
-     * @param version the version to set
+     * @param version
+     *            the version to set
      */
     public void setVersion( String version )
     {
@@ -152,7 +155,7 @@
      */
     public boolean hasName()
     {
-        return ( null != name );
+        return ( null != this.name );
     }
 
     /**
@@ -160,11 +163,12 @@
      */
     public String getName()
     {
-        return name;
+        return this.name;
     }
 
     /**
-     * @param name the name to set
+     * @param name
+     *            the name to set
      */
     public void setName( String name )
     {

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/QueryFactory.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/QueryFactory.java?rev=600081&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/QueryFactory.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/main/java/org/apache/maven/continuum/store/api/QueryFactory.java
Sat Dec  1 03:04:03 2007
@@ -0,0 +1,32 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.api;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public class QueryFactory
+{
+    public static <T, Q extends Query<T>> Q createQuery( Class<Q> klass
)
+    {
+        Q qry = null;
+        try
+        {
+            qry = klass.newInstance();
+        }
+        catch ( InstantiationException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( IllegalAccessException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return qry;
+    }
+}

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

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

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=600081&r1=600080&r2=600081&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
Sat Dec  1 03:04:03 2007
@@ -10,7 +10,7 @@
  * @version $Id$
  * @since 1.2
  */
-public interface Store<T>
+public interface Store<T, Q extends Query<T>>
 {
 
     /**
@@ -60,6 +60,6 @@
      * @return {@link List} of instances of type {@link T} which match the specified query.
      * @throws StoreException
      */
-    public List<T> query( Query query ) throws StoreException;
+    public List<T> query( Q query ) throws StoreException;
 
 }

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=600081&r1=600080&r2=600081&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
Sat Dec  1 03:04:03 2007
@@ -3,11 +3,13 @@
  */
 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.ProjectGroup;
 import org.apache.maven.continuum.store.api.EntityNotFoundException;
-import org.apache.maven.continuum.store.api.Query;
+import org.apache.maven.continuum.store.api.ProjectGroupQuery;
 import org.apache.maven.continuum.store.api.Store;
 import org.apache.maven.continuum.store.api.StoreException;
 import org.springframework.transaction.annotation.Transactional;
@@ -17,7 +19,7 @@
  * @version $Id$
  * @since 1.2
  */
-public class JpaProjectGroupStore extends StoreSupport implements Store<ProjectGroup>
+public class JpaProjectGroupStore extends StoreSupport implements Store<ProjectGroup,
ProjectGroupQuery>
 {
 
     /**
@@ -64,10 +66,66 @@
      * 
      * @see org.apache.maven.continuum.store.api.Store#query(org.apache.maven.continuum.store.api.Query)
      */
-    public List<ProjectGroup> query( Query query ) throws StoreException
+    public List<ProjectGroup> query( ProjectGroupQuery query ) throws StoreException
     {
-        // TODO Implement!
-        return null;
-    }
+        Map<String, Object> where = new HashMap<String, Object>();
+        StringBuffer sb = new StringBuffer();
 
+        if ( query.hasId() )
+        {
+            where.put( "id", query.getId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.id =:id " );
+        }
+        if ( query.hasDateCreated() )
+        {
+            where.put( "dateCreated", query.getDateCreated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.dateCreated =:dateCreated " );
+        }
+        if ( query.hasDateUpdated() )
+        {
+            where.put( "dateUpdated", query.getDateUpdated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.dateUpdated =:dateUpdated " );
+        }
+        if ( query.hasDescription() )
+        {
+            where.put( "description", query.getDescription() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.description =:description " );
+        }
+        if ( query.hasGroupId() )
+        {
+            where.put( "groupId", query.getGroupId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.groupId =:groupId " );
+        }
+        if ( query.hasModelEncoding() )
+        {
+            where.put( "modelEncoding", query.getModelEncoding() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.modelEncoding =:modelEncoding " );
+        }
+        if ( query.hasName() )
+        {
+            where.put( "name", query.getModelEncoding() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " projectGroup.name =:name " );
+        }
+
+        String whereClause = ( sb.length() > 0 ? " where " : "" ) + sb.toString();
+
+        List<ProjectGroup> results =
+            find( "select projectGroup from ProjectGroup as projectGroup " + whereClause,
where, 0, 0 );
+
+        return results;
+    }
 }

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=600081&r1=600080&r2=600081&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
Sat Dec  1 03:04:03 2007
@@ -7,7 +7,7 @@
 
 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.ProjectQuery;
 import org.apache.maven.continuum.store.api.Store;
 import org.apache.maven.continuum.store.api.StoreException;
 import org.springframework.transaction.annotation.Transactional;
@@ -17,7 +17,7 @@
  * @version $Id$
  * @since 1.2
  */
-public class JpaProjectStore extends StoreSupport implements Store<Project>
+public class JpaProjectStore extends StoreSupport implements Store<Project, ProjectQuery>
 {
 
     /**
@@ -64,9 +64,9 @@
      * 
      * @see org.apache.maven.continuum.store.api.Store#query(org.apache.maven.continuum.store.api.Query)
      */
-    public List<Project> query( Query query ) throws StoreException
+    public List<Project> query( ProjectQuery query ) throws StoreException
     {
-        // TODO Implement!
+        // TODO Auto-generated method stub
         return null;
     }
 

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=600081&r1=600080&r2=600081&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
Sat Dec  1 03:04:03 2007
@@ -3,9 +3,19 @@
  */
 package org.apache.maven.continuum.store.jpa;
 
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
+
 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.dao.DataAccessException;
+import org.springframework.orm.jpa.JpaCallback;
 import org.springframework.orm.jpa.JpaObjectRetrievalFailureException;
 import org.springframework.orm.jpa.support.JpaDaoSupport;
 
@@ -44,6 +54,45 @@
         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
+     * @param whereParams
+     * @param startIndex
+     * @param range
+     * @return
+     * @throws DataAccessException
+     */
+    protected List find( final String queryString, final Map<String, Object> whereParams,
final int startIndex,
+                         final int range ) throws DataAccessException
+    {
+        return getJpaTemplate().executeFind( new JpaCallback()
+        {
+            public Object doInJpa( EntityManager em ) throws PersistenceException
+            {
+                Query query = em.createQuery( queryString );
+                if ( whereParams != null )
+                {
+                    for ( Iterator it = whereParams.entrySet().iterator(); it.hasNext();
)
+                    {
+                        Map.Entry<String, Object> entry = (Map.Entry<String, Object>)
it.next();
+                        query.setParameter( entry.getKey(), entry.getValue() );
+                    }
+                }
+                if ( startIndex > 0 )
+                {
+                    query.setFirstResult( startIndex );
+                }
+                if ( range > 0 )
+                {
+                    query.setMaxResults( range );
+                }
+                return query.getResultList();
+            }
+        } );
     }
 
 }



Mime
View raw message