continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r652556 [3/3] - in /continuum/branches/continuum-jpa-evenisse: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/continuum/ src/main/java/org/apache/continuum/dao/ src/main/java/org/apach...
Date Thu, 01 May 2008 15:19:55 GMT
Added: continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectNotifierQuery.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectNotifierQuery.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectNotifierQuery.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectNotifierQuery.java Thu May  1 08:19:53 2008
@@ -0,0 +1,247 @@
+/**
+ * 
+ */
+package org.apache.continuum.store.jpa;
+
+import java.util.Date;
+import java.util.Map;
+
+import org.apache.continuum.model.project.Project;
+import org.apache.continuum.model.project.ProjectGroup;
+import org.apache.continuum.store.api.Query;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public class ProjectNotifierQuery<ProjectNotifier> implements Query<ProjectNotifier>
+{
+
+    /**
+     * ProjectNotifier creation date criteria.
+     */
+    private Date dateCreated;
+
+    /**
+     * ProjectNotifier update date criteria.
+     */
+    private Date dateUpdated;
+
+    /**
+     * ProjectNotifier Id criteria.
+     */
+    private Long id;
+
+    /**
+     * Determines if a ProjectNotifier is set up on a {@link Project} or a {@link ProjectGroup}.
+     */
+    private boolean isDefinedOnProject = false;
+
+    /**
+     * Determines if a {@link ProjectNotifier} is defined by a user.
+     */
+    private boolean isUserDefined = false;
+
+    /**
+     * ProjectNotifier model encoding criteria.
+     */
+    private String modelEncoding;
+
+    /**
+     * @return
+     * 
+     */
+    public Date getDateCreated()
+    {
+        return this.dateCreated;
+    }
+
+    /**
+     * @return
+     * @see org.apache.continuum.model.CommonUpdatableEntity#getDateUpdated()
+     */
+    public Date getDateUpdated()
+    {
+        return this.dateUpdated;
+    }
+
+    /**
+     * @return
+     */
+    public Long getId()
+    {
+        return this.id;
+    }
+
+    /**
+     * @return
+     */
+    public String getModelEncoding()
+    {
+        return this.modelEncoding;
+    }
+
+    /**
+     * 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 );
+    }
+
+    /**
+     * 
+     * @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 );
+    }
+
+    /**
+     * @return the isDefinedOnProject
+     */
+    public boolean isDefinedOnProject()
+    {
+        return isDefinedOnProject;
+    }
+
+    /**
+     * @return the isUserDefined
+     */
+    public boolean isUserDefined()
+    {
+        return isUserDefined;
+    }
+
+    /**
+     * @param dateCreated
+     */
+    public void setDateCreated( Date dateCreated )
+    {
+        this.dateCreated = dateCreated;
+    }
+
+    /**
+     * @param dateUpdated
+     */
+    public void setDateUpdated( Date dateUpdated )
+    {
+        this.dateUpdated = dateUpdated;
+    }
+
+    /**
+     * @param isDefinedOnProject
+     *            the isDefinedOnProject to set
+     */
+    public void setDefinedOnProject( boolean isDefinedOnProject )
+    {
+        this.isDefinedOnProject = isDefinedOnProject;
+    }
+
+    /**
+     * @param id
+     */
+    public void setId( Long id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * @param modelEncoding
+     */
+    public void setModelEncoding( String modelEncoding )
+    {
+        this.modelEncoding = modelEncoding;
+    }
+
+    /**
+     * @param isUserDefined
+     *            the isUserDefined to set
+     */
+    public void setUserDefined( boolean isUserDefined )
+    {
+        this.isUserDefined = isUserDefined;
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.continuum.store.api.Query#toString(java.util.Map)
+     */
+    public String toString( Map<String, Object> whereClause )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        if ( this.hasId() )
+        {
+            whereClause.put( "id", this.getId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " notifier.id =:id " );
+        }
+        if ( this.hasDateCreated() )
+        {
+            whereClause.put( "dateCreated", this.getDateCreated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " notifier.dateCreated =:dateCreated " );
+        }
+        if ( this.hasDateUpdated() )
+        {
+            whereClause.put( "dateUpdated", this.getDateUpdated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " notifier.dateUpdated =:dateUpdated " );
+        }
+        if ( this.hasModelEncoding() )
+        {
+            whereClause.put( "modelEncoding", this.getModelEncoding() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " notifier.modelEncoding =:modelEncoding " );
+        }
+        if ( this.isDefinedOnProject() )
+        {
+            // TODO: Implement!
+            // Need to check what property is setup on the Notifier.
+            // May need to add a property ORM mapping to persist.
+        }
+        if ( this.isUserDefined() )
+        {
+            // TODO: Implement!
+            // Need to check what property is setup on the Notifier.
+            // May need to add a property ORM mapping to persist.
+        }
+
+        if ( sb.length() > 0 )
+            sb.insert( 0, " where " );
+        sb.insert( 0, "select project from Project as project " );
+
+        return sb.toString();
+    }
+
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectNotifierQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectQuery.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectQuery.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectQuery.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectQuery.java Thu May  1 08:19:53 2008
@@ -0,0 +1,403 @@
+/**
+ * 
+ */
+package org.apache.continuum.store.jpa;
+
+import java.util.Date;
+import java.util.Map;
+
+import org.apache.continuum.store.api.Query;
+
+/**
+ * Wraps up retrieval criteria for {@link Project}s.
+ * 
+ * @author <a href='mailto:rinku@apache.org'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public class ProjectQuery<Project> implements Query<Project>
+{
+
+    /**
+     * Project artifactId criteria.
+     */
+    private String artifactId;
+
+    /**
+     * Project groupId criteria.
+     */
+    private String groupId;
+
+    /**
+     * Project id criteria.
+     */
+    private Long id;
+
+    /**
+     * Project name criteria.
+     */
+    private String name;
+
+    /**
+     * Project Artifact version criteria.
+     */
+    private String version;
+
+    private int buildNumber;
+
+    private Date dateCreated;
+
+    private Date dateUpdated;
+
+    private String description;
+
+    private String modelEncoding;
+
+    /**
+     * @return the artifactId
+     */
+    public String getArtifactId()
+    {
+        return this.artifactId;
+    }
+
+    /**
+     * @return build number as query critera
+     */
+    public int getBuildNumber()
+    {
+        return this.buildNumber;
+    }
+
+    /**
+     * Determines if a build number criteria was specified in the Project query.
+     * 
+     * @return
+     */
+    public boolean hasBuildNumber()
+    {
+        return ( this.buildNumber > 0 );
+    }
+
+    /**
+     * @return creation date as query criteria
+     */
+    public Date getDateCreated()
+    {
+        return this.dateCreated;
+    }
+
+    /**
+     * Determines if there was a creation date criteria specified in the ProjectQuery.
+     * 
+     * @return <code>true</code> if a creation date was specified, else <code>false</code>.
+     */
+    public boolean hasDateCreated()
+    {
+        return ( null != this.dateCreated );
+    }
+
+    /**
+     * @return last update date from query criteria.
+     */
+    public Date getDateUpdated()
+    {
+        return this.dateUpdated;
+    }
+
+    /**
+     * Determine if there was a last update date criteria specified in the ProjectQuery.
+     * 
+     * @return <code>true</code> if there was a last update date criteria specified, else <code>false</code>.
+     */
+    public boolean hasDateUpdated()
+    {
+        return ( null != this.dateUpdated );
+    }
+
+    /**
+     * @return description criteria from the query.
+     */
+    public String getDescription()
+    {
+        return this.description;
+    }
+
+    /**
+     * Determines if there was description criteria specified in the ProjectQuery.
+     * 
+     * @return <code>true</code> if there was description criteria specified, else <code>false</code>.
+     */
+    public boolean hasDescription()
+    {
+        return ( null != this.description && this.description.length() > 0 );
+    }
+
+    /**
+     * @return the groupId
+     */
+    public String getGroupId()
+    {
+        return this.groupId;
+    }
+
+    /**
+     * @return the id
+     */
+    public Long getId()
+    {
+        return this.id;
+    }
+
+    /**
+     * @return model encoding criteria from the query.
+     */
+    public String getModelEncoding()
+    {
+        return this.modelEncoding;
+    }
+
+    /**
+     * Determine if there is a model encoding specified in the ProjectQuery.
+     * 
+     * @return <code>true</code> if there is a model encoding specified, else <code>false</code>.
+     */
+    public boolean hasModelEncoding()
+    {
+        return ( null != this.modelEncoding && this.modelEncoding.length() > 0 );
+    }
+
+    /**
+     * @return the name
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * @return the version
+     */
+    public String getVersion()
+    {
+        return this.version;
+    }
+
+    /**
+     * Determines if an artifact Id criteria was specified.
+     * 
+     * @return
+     */
+    public boolean hasArtifactId()
+    {
+        return ( null != this.artifactId );
+    }
+
+    /**
+     * Determines if a ProjectGroup Id criteria was specified.
+     * 
+     * @return
+     */
+    public boolean hasGroupId()
+    {
+        return ( null != this.groupId );
+    }
+
+    /**
+     * Determines if a Project id criteria was specified in the query.
+     * 
+     * @return
+     */
+    public boolean hasId()
+    {
+        return ( null != this.id && this.id >= 0 );
+    }
+
+    /**
+     * Determines if a project name criteria was specified.
+     * 
+     * @return
+     */
+    public boolean hasName()
+    {
+        return ( null != this.name );
+    }
+
+    /**
+     * Determines if a Version criteria was specified.
+     * 
+     * @return
+     */
+    public boolean hasVersion()
+    {
+        return ( null != this.version );
+    }
+
+    /**
+     * @param artifactId
+     *            the artifactId to set
+     */
+    public void setArtifactId( String artifactId )
+    {
+        this.artifactId = artifactId;
+    }
+
+    /**
+     * @param buildNumber
+     *            criteria to set in the ProjectQuery
+     */
+    public void setBuildNumber( int buildNumber )
+    {
+        this.buildNumber = buildNumber;
+    }
+
+    /**
+     * @param created
+     *            criteria to set in the Project Query.
+     */
+    public void setDateCreated( Date dateCreated )
+    {
+        this.dateCreated = dateCreated;
+    }
+
+    /**
+     * @param updated
+     *            date criteria to set in the Project Query.
+     */
+    public void setDateUpdated( Date dateUpdated )
+    {
+        this.dateUpdated = dateUpdated;
+    }
+
+    /**
+     * @param description
+     */
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    /**
+     * @param groupId
+     *            the groupId to set
+     */
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    /**
+     * @param id
+     *            the id to set
+     */
+    public void setId( Long id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * @param name
+     *            the name to set
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    /**
+     * @param version
+     *            the version to set
+     */
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.apache.continuum.store.api.Query#toString(java.util.Map)
+     */
+    public String toString( Map<String, Object> whereClause )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        if ( this.hasId() )
+        {
+            whereClause.put( "id", this.getId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.id =:id " );
+        }
+        if ( this.hasDateCreated() )
+        {
+            whereClause.put( "dateCreated", this.getDateCreated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.dateCreated =:dateCreated " );
+        }
+        if ( this.hasDateUpdated() )
+        {
+            whereClause.put( "dateUpdated", this.getDateUpdated() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.dateUpdated =:dateUpdated " );
+        }
+        if ( this.hasDescription() )
+        {
+            whereClause.put( "description", this.getDescription() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.description =:description " );
+        }
+        if ( this.hasGroupId() )
+        {
+            whereClause.put( "groupId", this.getGroupId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.groupId =:groupId " );
+        }
+        if ( this.hasModelEncoding() )
+        {
+            whereClause.put( "modelEncoding", this.getModelEncoding() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.modelEncoding =:modelEncoding " );
+        }
+        if ( this.hasName() )
+        {
+            whereClause.put( "name", this.getName() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.name =:name " );
+        }
+        if ( this.hasArtifactId() )
+        {
+            whereClause.put( "artifactId", this.getArtifactId() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.artifactId =:artifactId" );
+        }
+        if ( this.hasBuildNumber() )
+        {
+            whereClause.put( "buildNumber", this.getBuildNumber() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.buildNumber =:buildNumber" );
+        }
+        if ( this.hasVersion() )
+        {
+            whereClause.put( "version", this.getVersion() );
+            if ( sb.length() > 0 )
+                sb.append( "and" );
+            sb.append( " project.version =:version" );
+        }
+
+        if ( sb.length() > 0 )
+            sb.insert( 0, " where " );
+        sb.insert( 0, "select project from Project as project " );
+
+        return sb.toString();
+    }
+
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/ProjectQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/StoreSupport.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/StoreSupport.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/StoreSupport.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/main/java/org/apache/continuum/store/jpa/StoreSupport.java Thu May  1 08:19:53 2008
@@ -0,0 +1,68 @@
+/**
+ * 
+ */
+package org.apache.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.continuum.store.api.Store;
+import org.springframework.dao.DataAccessException;
+import org.springframework.orm.jpa.JpaCallback;
+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
+{
+
+    /**
+     * 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();
+            }
+        } );
+    }
+
+}

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

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

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/ApplicationContextAwareStoreTestCase.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/ApplicationContextAwareStoreTestCase.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/ApplicationContextAwareStoreTestCase.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/ApplicationContextAwareStoreTestCase.java Thu May  1 08:19:53 2008
@@ -0,0 +1,161 @@
+package org.apache.continuum.store;
+
+import org.apache.continuum.dao.api.GenericDao;
+import org.apache.continuum.model.CommonUpdatableEntity;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test Case support class that allows extensions to load test data from specified SQL files.
+ * <p/>
+ * This also implements Spring's {@link ApplicationContextAware} interface that allows the {@link ApplicationContext} to
+ * be made available to this test case's extensions.
+ *
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public abstract class ApplicationContextAwareStoreTestCase
+    extends SingleEMTestCase
+    implements ApplicationContextAware
+{
+    /**
+     * Continuum Store persistent unit defined in <code>persistence.xml</code> used by tests.
+     */
+    private static final String PERSISTENT_UNIT_CONTINUUM_STORE = "continuum-store";
+
+    /**
+     * Spring application context.
+     */
+    private ApplicationContext applicationContext;
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Spring IoC container injects the {@link ApplicationContext} through here.
+     *
+     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+     */
+    public void setApplicationContext( ApplicationContext applicationContext )
+        throws BeansException
+    {
+        this.applicationContext = applicationContext;
+    }
+
+    /**
+     * Imports sql from the specified file.
+     *
+     * @param sqlResource Resource containing sql
+     */
+    public void setSqlSource( File sqlResource )
+    {
+        try
+        {
+            // TODO: Use Logger!
+            // System.out.println( "Loading sql: " + sqlResource.getAbsolutePath() );
+            List<String> statements = new ArrayList<String>( 20 );
+            BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream( sqlResource ) ) );
+            String line;
+            StringBuffer currentStatement = new StringBuffer();
+            while ( ( line = br.readLine() ) != null )
+            {
+                if ( line.trim().length() == 0 )
+                {
+                    continue;
+                }
+                if ( line.trim().startsWith( "#" ) )
+                {
+                    continue;
+                }
+
+                currentStatement.append( line );
+                if ( line.endsWith( ";" ) )
+                {
+                    statements.add( currentStatement.toString() );
+                    currentStatement = new StringBuffer();
+                }
+            }
+            // append a line if missing a ';'
+            if ( currentStatement.length() > 0 )
+            {
+                statements.add( currentStatement.toString() );
+            }
+            runSQLStatements( statements );
+        }
+        catch ( Throwable e )
+        {
+            // TODO: User logger!
+            System.err.println( "Problem executing SQL!" );
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Run a bunch of SQL statements.
+     *
+     * @param statements Statements to run.
+     * @throws SQLException
+     */
+    public void runSQLStatements( final List<String> statements )
+        throws SQLException
+    {
+        for ( String qry : statements )
+        {
+            Connection con = (Connection) this.em.getConnection();
+            try
+            {
+                Statement stmt = con.createStatement();
+                System.out.println( qry );
+                stmt.execute( qry );
+                con.commit();
+            }
+            catch ( SQLException e )
+            {
+                try
+                {
+                    con.rollback();
+                }
+                catch ( SQLException e1 )
+                {
+                    // TODO: Use logger!
+                    System.err.println( "Unable to rollback transaction." );
+                    throw e1;
+                }
+                throw e;
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    protected <T extends CommonUpdatableEntity> GenericDao<T> getDao( String daoBeanReference )
+    {
+        return (GenericDao<T>) getObject( daoBeanReference );
+    }
+
+    protected Object getObject( String beanReference )
+    {
+        return applicationContext.getBean( beanReference );
+    }
+
+    /**
+     * Returns the name of the persistent-unit setup in <code>persistence.xml</code>.
+     */
+    @Override
+    protected String getPersistenceUnitName()
+    {
+        return PERSISTENT_UNIT_CONTINUUM_STORE;
+    }
+
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/ApplicationContextAwareStoreTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectGroupStoreTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectGroupStoreTest.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectGroupStoreTest.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectGroupStoreTest.java Thu May  1 08:19:53 2008
@@ -0,0 +1,92 @@
+/**
+ *
+ */
+package org.apache.continuum.store.jpa;
+
+import org.apache.continuum.model.project.ProjectGroup;
+import org.apache.continuum.service.api.ProjectGroupService;
+import org.apache.continuum.store.ApplicationContextAwareStoreTestCase;
+import org.apache.continuum.store.api.StoreException;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.junit.After;
+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;
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @see <a
+ *      href="http://mail-archives.apache.org/mod_mbox/openjpa-users/200706.mbox/%3CBF2B99E3-7EF3-4E99-91E1-8AEB940524C7@apache.org%3E">
+ *      http://mail-archives.apache.org/mod_mbox/openjpa-users/200706.mbox/%3CBF2B99E3-7EF3-4E99-91E1-8AEB940524C7@apache.org%3E
+ *      </a>
+ * @since 1.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "/META-INF/spring-config.xml")
+public class JpaProjectGroupStoreTest
+    extends ApplicationContextAwareStoreTestCase
+{
+    private static final String BEAN_REF__PROJECT_GROUP_STORE = "projectGroupStore";
+
+    @Override
+    @Before
+    public void setUp()
+    {
+        File testData = new File( "src/test/resources/sql/project-group-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 );
+    }
+
+    @Override
+    @After
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+    }
+
+    @Test
+    public void testOpenJPASetup()
+    {
+        OpenJPAQuery q = em.createQuery( "select pg from ProjectGroup pg" );
+        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( 1, results.size() );
+    }
+
+    @Test
+    public void testCreateProjectGroup()
+        throws StoreException
+    {
+        ProjectGroup group = new ProjectGroup();
+        group.setGroupId( "org.sample.group" );
+        group.setName( "Sample Project Group" );
+        group.setDescription( "A sample project group" );
+
+        Assert.assertTrue( null == group.getId() );
+        group = getService().saveOrUpdate( group );
+        Assert.assertTrue( null != group.getId() );
+        Assert.assertTrue( group.getId() > 0L );
+        Assert.assertEquals( 0, group.getProjects().size() );
+    }
+
+    private ProjectGroupService getService()
+    {
+        return (ProjectGroupService) getObject( "projectGroupService" );
+    }
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectGroupStoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectStoreTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectStoreTest.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectStoreTest.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectStoreTest.java Thu May  1 08:19:53 2008
@@ -0,0 +1,120 @@
+package org.apache.continuum.store.jpa;
+
+import org.apache.continuum.dao.api.GenericDao;
+import org.apache.continuum.model.project.Project;
+import org.apache.continuum.service.api.ProjectService;
+import org.apache.continuum.store.ApplicationContextAwareStoreTestCase;
+import org.apache.continuum.store.api.StoreException;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.junit.After;
+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;
+
+import javax.persistence.Query;
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @author <a href='mailto:evenisse@apache.org'>Emmanuel Venisse</a>
+ * @version $Id$
+ * @see <a
+ *      href="http://mail-archives.apache.org/mod_mbox/openjpa-users/200706.mbox/%3CBF2B99E3-7EF3-4E99-91E1-8AEB940524C7@apache.org%3E">
+ *      http://mail-archives.apache.org/mod_mbox/openjpa-users/200706.mbox/%3CBF2B99E3-7EF3-4E99-91E1-8AEB940524C7@apache.org%3E
+ *      </a>
+ * @since 1.2
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "/META-INF/spring-config.xml")
+public class JpaProjectStoreTest
+    extends ApplicationContextAwareStoreTestCase
+{
+    @Override
+    @Before
+    public void setUp()
+    {
+        File testData = new File( "src/test/resources/sql/project-table-data.sql" );
+        Properties propMap = new Properties();
+        setUp( propMap );
+        // load test data from SQL file.
+        setSqlSource( testData );
+    }
+
+    @Override
+    @After
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+    }
+
+    @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 testNamedQuery()
+    {
+        Query q = em.createNamedQuery( "Project.findAll" );
+        List<Project> projects = q.getResultList();
+        Assert.assertEquals( 2, projects.size() );
+        for ( Project p : projects )
+        {
+            System.out.println( p.getClass().getName() );
+            System.out.println( p );
+        }
+    }
+
+    @Test
+    public void testDao()
+    {
+        GenericDao<Project> dao = getDao( "projectDao" );
+        List<Project> projects = dao.findAll();
+        Assert.assertTrue( 2==projects.size() );
+    }
+
+    @Test
+    public void testCreateProject()
+        throws StoreException
+    {
+        Project project = new Project();
+        project.setArtifactId( "sample-project" );
+        project.setGroupId( "org.sample.group" );
+        project.setName( "Sample Project" );
+        project.setDescription( "A sample project" );
+        project.setScmUseCache( false );
+        project.setScmUrl( "https://localhost/svn/sample-project" );
+
+        Assert.assertTrue( null == project.getId() );
+
+        //store project
+        project = getService().saveOrUpdate( project );
+        Assert.assertTrue( "Identifier of the persisted new Entity should not be null.", null != project.getId() );
+        Assert.assertTrue( "Identifier of the persisted new Entity should be a valid positive value.",
+                           project.getId() > 0L );
+        long id = project.getId();
+
+        //search the project
+        Project p = getService().getProject( project.getGroupId(), project.getArtifactId(), project.getVersion() );
+        Assert.assertNotNull( p );
+        Assert.assertTrue( id == p.getId() );
+    }
+
+    private ProjectService getService()
+    {
+        return (ProjectService) getObject( "projectService" );
+    }
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/continuum/store/jpa/JpaProjectStoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java Thu May  1 08:19:53 2008
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.test;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.apache.openjpa.kernel.AbstractBrokerFactory;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.junit.Assert;
+
+/**
+ * Base test class providing persistence utilities.
+ */
+public abstract class PersistenceTestCase
+{
+
+    /**
+     * Marker object you an pass to {@link #setUp} to indicate that the database tables should be cleared.
+     */
+    protected static final Object CLEAR_TABLES = new Object();
+
+    /**
+     * Create an entity manager factory. Put {@link #CLEAR_TABLES} in this list to tell the test framework to delete all
+     * table contents before running the tests.
+     * 
+     * @param props
+     *            list of persistent types used in testing and/or configuration values in the form
+     *            key,value,key,value...
+     */
+    protected OpenJPAEntityManagerFactorySPI createEMF( Object... props )
+    {
+        return createNamedEMF( getPersistenceUnitName(), props );
+    }
+
+    /**
+     * The name of the persistence unit that this test class should use by default. This defaults to "test".
+     */
+    protected String getPersistenceUnitName()
+    {
+        return "test";
+    }
+
+    /**
+     * Create an entity manager factory for persistence unit <code>pu</code>. Put {@link #CLEAR_TABLES} in this list
+     * to tell the test framework to delete all table contents before running the tests.
+     * 
+     * @param props
+     *            list of persistent types used in testing and/or configuration values in the form
+     *            key,value,key,value...
+     */
+    protected OpenJPAEntityManagerFactorySPI createNamedEMF( String pu, Object... props )
+    {
+        Map map = new HashMap( System.getProperties() );
+        List<Class> types = new ArrayList<Class>();
+        boolean prop = false;
+        for ( int i = 0; i < props.length; i++ )
+        {
+            if ( prop )
+            {
+                map.put( props[i - 1], props[i] );
+                prop = false;
+            }
+            else if ( props[i] == CLEAR_TABLES )
+            {
+                map.put( "openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true,"
+                                + "SchemaAction='add,deleteTableContents')" );
+            }
+            else if ( props[i] instanceof Class )
+                types.add( (Class) props[i] );
+            else if ( props[i] != null )
+                prop = true;
+        }
+
+        if ( !types.isEmpty() )
+        {
+            StringBuffer buf = new StringBuffer();
+            for ( Class c : types )
+            {
+                if ( buf.length() > 0 )
+                    buf.append( ";" );
+                buf.append( c.getName() );
+            }
+            map.put( "openjpa.MetaDataFactory", "jpa(Types=" + buf.toString() + ")" );
+        }
+
+        return (OpenJPAEntityManagerFactorySPI) Persistence.createEntityManagerFactory( pu, map );
+    }
+
+    public void tearDown() throws Exception
+    {
+        // super.tearDown();
+    }
+
+    /**
+     * Safely close the given factory.
+     */
+    protected boolean closeEMF( EntityManagerFactory emf )
+    {
+        if ( emf == null )
+            return false;
+        if ( !emf.isOpen() )
+            return false;
+
+        for ( Iterator iter =
+            ( (AbstractBrokerFactory) JPAFacadeHelper.toBrokerFactory( emf ) ).getOpenBrokers().iterator(); iter.hasNext(); )
+        {
+            Broker b = (Broker) iter.next();
+            if ( b != null && !b.isClosed() )
+            {
+                EntityManager em = JPAFacadeHelper.toEntityManager( b );
+                if ( em.getTransaction().isActive() )
+                    em.getTransaction().rollback();
+                em.close();
+            }
+        }
+
+        emf.close();
+        return !emf.isOpen();
+    }
+
+    /**
+     * Delete all instances of the given types using bulk delete queries.
+     */
+    protected void clear( EntityManagerFactory emf, Class... types )
+    {
+        if ( emf == null || types.length == 0 )
+            return;
+
+        List<ClassMetaData> metas = new ArrayList<ClassMetaData>( types.length );
+        for ( Class c : types )
+        {
+            ClassMetaData meta = JPAFacadeHelper.getMetaData( emf, c );
+            if ( meta != null )
+                metas.add( meta );
+        }
+        clear( emf, metas.toArray( new ClassMetaData[metas.size()] ) );
+    }
+
+    /**
+     * Delete all instances of the persistent types registered with the given factory using bulk delete queries.
+     */
+    protected void clear( EntityManagerFactory emf )
+    {
+        if ( emf == null )
+            return;
+        clear(
+               emf,
+               ( (OpenJPAEntityManagerFactorySPI) emf ).getConfiguration().getMetaDataRepositoryInstance().getMetaDatas() );
+    }
+
+    /**
+     * Delete all instances of the given types using bulk delete queries.
+     */
+    private void clear( EntityManagerFactory emf, ClassMetaData... types )
+    {
+        if ( emf == null || types.length == 0 )
+            return;
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        for ( ClassMetaData meta : types )
+        {
+            if ( !meta.isMapped() || meta.isEmbeddedOnly()
+                            || Modifier.isAbstract( meta.getDescribedType().getModifiers() ) )
+                continue;
+            em.createQuery( "DELETE FROM " + meta.getTypeAlias() + " o" ).executeUpdate();
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    /**
+     * Return the entity name for the given type.
+     */
+    protected String entityName( EntityManagerFactory emf, Class c )
+    {
+        ClassMetaData meta = JPAFacadeHelper.getMetaData( emf, c );
+        return ( meta == null ) ? null : meta.getTypeAlias();
+    }
+
+    public static void assertNotEquals( Object o1, Object o2 )
+    {
+        if ( o1 == o2 )
+            Assert.fail( "expected args to be different; were the same instance." );
+        else if ( o1 == null || o2 == null )
+            return;
+        else if ( o1.equals( o2 ) )
+            Assert.fail( "expected args to be different; compared equal." );
+    }
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java Thu May  1 08:19:53 2008
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.junit.Assert;
+
+/**
+ * Base class for tests that need to check generated SQL.
+ * 
+ * @author Patrick Linskey
+ */
+public abstract class SQLListenerTestCase extends SingleEMFTestCase
+{
+
+    protected List<String> sql = new ArrayList<String>();
+
+    protected int sqlCount;
+
+    @Override
+    public void setUp( Object... props )
+    {
+        Object[] copy = new Object[props.length + 2];
+        System.arraycopy( props, 0, copy, 0, props.length );
+        copy[copy.length - 2] = "openjpa.jdbc.JDBCListeners";
+        copy[copy.length - 1] = new JDBCListener[] { new Listener() };
+        super.setUp( copy );
+    }
+
+    /**
+     * Confirm that the specified SQL has been executed.
+     * 
+     * @param sqlExp
+     *            the SQL expression. E.g., "SELECT FOO .*"
+     */
+    public void assertSQL( String sqlExp )
+    {
+        for ( String statement : sql )
+        {
+            if ( statement.matches( sqlExp ) )
+                return;
+        }
+
+        Assert.fail( "Expected regular expression <" + sqlExp + "> to have" + " existed in SQL statements: " + sql );
+    }
+
+    /**
+     * Confirm that the specified SQL has not been executed.
+     * 
+     * @param sqlExp
+     *            the SQL expression. E.g., "SELECT BADCOLUMN .*"
+     */
+    public void assertNotSQL( String sqlExp )
+    {
+        boolean failed = false;
+
+        for ( String statement : sql )
+        {
+            if ( statement.matches( sqlExp ) )
+                failed = true;
+        }
+
+        if ( failed )
+            Assert.fail( "Regular expression <" + sqlExp + ">" + " should not have been executed in SQL statements: "
+                            + sql );
+    }
+
+    /**
+     * Confirm that the executed SQL String contains the specified sqlExp.
+     * 
+     * @param sqlExp
+     *            the SQL expression. E.g., "SELECT BADCOLUMN .*"
+     */
+    public void assertContainsSQL( String sqlExp )
+    {
+        for ( String statement : sql )
+        {
+            if ( statement.contains( sqlExp ) )
+                return;
+        }
+
+        Assert.fail( "Expected regular expression <" + sqlExp + "> to be" + " contained in SQL statements: " + sql );
+    }
+
+    /**
+     * Gets the number of SQL issued since last reset.
+     */
+    public int getSQLCount()
+    {
+        return sqlCount;
+    }
+
+    /**
+     * Resets SQL count.
+     * 
+     * @return number of SQL counted since last reset.
+     */
+    public int resetSQLCount()
+    {
+        int tmp = sqlCount;
+        sqlCount = 0;
+        return tmp;
+    }
+
+    public class Listener extends AbstractJDBCListener
+    {
+
+        @Override
+        public void beforeExecuteStatement( JDBCEvent event )
+        {
+            if ( event.getSQL() != null && sql != null )
+            {
+                sql.add( event.getSQL() );
+                sqlCount++;
+            }
+        }
+    }
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java Thu May  1 08:19:53 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.test;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+public abstract class SingleEMFTestCase extends PersistenceTestCase
+{
+
+    protected OpenJPAEntityManagerFactorySPI emf;
+
+    /**
+     * Call {@link #setUp(Object...)} with no arguments so that the emf set-up happens even if <code>setUp()</code> is
+     * not called from the subclass.
+     */
+    public void setUp() throws Exception
+    {
+        setUp( new Object[0] );
+    }
+
+    /**
+     * Initialize entity manager factory. Put {@link #CLEAR_TABLES} in this list to tell the test framework to delete
+     * all table contents before running the tests.
+     * 
+     * @param props
+     *            list of persistent types used in testing and/or configuration values in the form
+     *            key,value,key,value...
+     */
+    protected void setUp( Object... props )
+    {
+        emf = createEMF( props );
+    }
+
+    /**
+     * Closes the entity manager factory.
+     */
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        if ( emf == null )
+            return;
+
+        try
+        {
+            clear( emf );
+        }
+        finally
+        {
+            closeEMF( emf );
+        }
+    }
+
+    protected ClassMapping getMapping( String name )
+    {
+        return (ClassMapping) emf.getConfiguration().getMetaDataRepositoryInstance().getMetaData(
+                                                                                                  name,
+                                                                                                  getClass().getClassLoader(),
+                                                                                                  true );
+    }
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java Thu May  1 08:19:53 2008
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.test;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.persistence.EntityTransaction;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+/**
+ * A base test case that can be used to easily test scenarios where there is only a single EntityManager at any given
+ * time.
+ * 
+ * @author Marc Prud'hommeaux
+ */
+public abstract class SingleEMTestCase extends SingleEMFTestCase
+{
+
+    protected OpenJPAEntityManager em;
+
+    @Override
+    public void setUp()
+    {
+        setUp( new Object[0] );
+    }
+
+    @Override
+    public void setUp( Object... props )
+    {
+        super.setUp( props );
+        em = emf.createEntityManager();
+    }
+
+    /**
+     * Clear the current EntityManager and re-initialize it.
+     */
+    protected void reset()
+    {
+        close();
+        em = emf.createEntityManager();
+    }
+
+    @Override
+    public void tearDown() throws Exception
+    {
+        rollback();
+        close();
+        super.tearDown();
+    }
+
+    /**
+     * Start a new transaction if there isn't currently one active.
+     * 
+     * @return true if a transaction was started, false if one already existed
+     */
+    protected boolean begin()
+    {
+        EntityTransaction tx = em.getTransaction();
+        if ( tx.isActive() )
+            return false;
+
+        tx.begin();
+        return true;
+    }
+
+    /**
+     * Commit the current transaction, if it is active.
+     * 
+     * @return true if the transaction was committed
+     */
+    protected boolean commit()
+    {
+        EntityTransaction tx = em.getTransaction();
+        if ( !tx.isActive() )
+            return false;
+
+        tx.commit();
+        return true;
+    }
+
+    /**
+     * Rollback the current transaction, if it is active.
+     * 
+     * @return true if the transaction was rolled back
+     */
+    protected boolean rollback()
+    {
+        EntityTransaction tx = em.getTransaction();
+        if ( !tx.isActive() )
+            return false;
+
+        tx.rollback();
+        return true;
+    }
+
+    /**
+     * Closes the current EntityManager if it is open.
+     * 
+     * @return false if the EntityManager was already closed.
+     */
+    protected boolean close()
+    {
+        if ( em == null )
+            return false;
+
+        rollback();
+
+        if ( !em.isOpen() )
+            return false;
+
+        em.close();
+        return !em.isOpen();
+    }
+
+    /**
+     * Delete all of the instances.
+     * 
+     * If no transaction is running, then one will be started and committed. Otherwise, the operation will take place in
+     * the current transaction.
+     */
+    protected void remove( Object... obs )
+    {
+        boolean tx = begin();
+        for ( Object ob : obs )
+            em.remove( ob );
+        if ( tx )
+            commit();
+    }
+
+    /**
+     * Persist all of the instances.
+     * 
+     * If no transaction is running, then one will be started and committed. Otherwise, the operation will take place in
+     * the current transaction.
+     */
+    protected void persist( Object... obs )
+    {
+        boolean tx = begin();
+        for ( Object ob : obs )
+            em.persist( ob );
+        if ( tx )
+            commit();
+    }
+
+    /**
+     * Creates a query in the current EntityManager with the specified string.
+     */
+    protected OpenJPAQuery query( String str )
+    {
+        return em.createQuery( str );
+    }
+
+    /**
+     * Create a query against the specified class, which will be aliased as "x". For example, query(Person.class, "where
+     * x.age = 21") will create the query "select x from Person x where x.age = 21".
+     * 
+     * @param c
+     *            the class to query against
+     * @param str
+     *            the query suffix
+     * @param params
+     *            the parameters, if any
+     * @return the Query object
+     */
+    protected OpenJPAQuery query( Class c, String str, Object... params )
+    {
+        String query = "select x from " + entityName( emf, c ) + " x " + ( str == null ? "" : str );
+        OpenJPAQuery q = em.createQuery( query );
+        for ( int i = 0; params != null && i < params.length; i++ )
+            q.setParameter( i + 1, params[i] );
+        return q;
+    }
+
+    /**
+     * Returns a list of all instances of the specific class in the database.
+     * 
+     * @param c
+     *            the class to find
+     * @param q
+     *            the query string suffix to use
+     * @param params
+     *            the positional parameter list value
+     * 
+     * @see #query(java.lang.Class,java.lang.String)
+     */
+    protected <E> List<E> find( Class<E> c, String q, Object... params )
+    {
+        return Collections.checkedList( query( c, q, params ).getResultList(), c );
+    }
+
+    /**
+     * Returns a list of all instances of the specific class in the database.
+     */
+    protected <E> List<E> find( Class<E> c )
+    {
+        return find( c, null );
+    }
+}

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/java/org/apache/openjpa/persistence/test/SingleEMTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/org.apache.openjpa.lib.conf.ProductDerivation
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/org.apache.openjpa.lib.conf.ProductDerivation?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/org.apache.openjpa.lib.conf.ProductDerivation (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/org.apache.openjpa.lib.conf.ProductDerivation Thu May  1 08:19:53 2008
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+org.apache.openjpa.persistence.jdbc.JDBCPersistenceProductDerivation

Added: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/persistence.xml?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/persistence.xml (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/persistence.xml Thu May  1 08:19:53 2008
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+  <persistence-unit name="continuum-store">    
+    <!-- provider>org.hibernate.ejb.HibernatePersistence</provider -->
+    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+    
+    <!-- Mapped superclasses -->
+    <class>org.apache.continuum.model.CommonPersistableEntity</class>
+    <class>org.apache.continuum.model.CommonCreatedEntity</class>
+    <class>org.apache.continuum.model.CommonUpdatableEntity</class>
+
+    <!-- Entities -->    
+    <class>org.apache.continuum.model.project.BuildDefinition</class>
+    <class>org.apache.continuum.model.project.BuildDefinitionTemplate</class>
+    <class>org.apache.continuum.model.project.BuildResult</class>
+    <class>org.apache.continuum.model.project.Project</class>
+    <class>org.apache.continuum.model.project.ProjectDependency</class>
+    <class>org.apache.continuum.model.project.ProjectDeveloper</class>
+    <class>org.apache.continuum.model.project.ProjectGroup</class>
+    <class>org.apache.continuum.model.project.ProjectNotifier</class>
+    <class>org.apache.continuum.model.project.Schedule</class>
+    
+    <class>org.apache.continuum.model.scm.ChangeFile</class>
+    <class>org.apache.continuum.model.scm.ChangeSet</class>
+    <class>org.apache.continuum.model.scm.ScmResult</class>
+    <class>org.apache.continuum.model.scm.SuiteResult</class>
+    <class>org.apache.continuum.model.scm.TestCaseFailure</class>
+    <class>org.apache.continuum.model.scm.TestResult</class>
+    
+    <class>org.apache.continuum.model.system.Installation</class>
+    <class>org.apache.continuum.model.system.NotificationAddress</class>
+    <class>org.apache.continuum.model.system.Profile</class>
+    <class>org.apache.continuum.model.system.SystemConfiguration</class>
+    
+    <properties>
+      <property name="openjpa.jdbc.DBDictionary" value="hsql" />
+      <property name="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:continuum_jpa;create=true,autoCommit=true"/>
+      <property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver"/>
+      <property name="openjpa.ConnectionUserName" value="sa"/>
+      <property name="openjpa.ConnectionPassword" value=""/>
+      <!--  Configure OpenJPA to automatically run the mapping tool at runtime and create schema on Unit Test setup -->
+      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> 
+      
+      <!-- Enable SQL logging in OpenJPA 
+      <property name="openjpa.Log" value="DefaultLevel=INFO,SQL=TRACE" />
+      -->
+      
+      <!-- Change default log level across OpenJPA --> 
+      <property name="openjpa.Log" value="DefaultLevel=WARN"/>
+      
+    </properties>
+    
+  </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/spring-config.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/spring-config.xml?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/spring-config.xml (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/spring-config.xml Thu May  1 08:19:53 2008
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:context="http://www.springframework.org/schema/context"
+  xmlns:tx="http://www.springframework.org/schema/tx"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+
+  <bean id="entityManagerFactory"
+    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
+    <property name="persistenceUnitName" value="continuum-store" />
+  </bean>
+
+  <!-- Setup the transaction manager -->
+  <bean id="transactionManager"
+    class="org.springframework.orm.jpa.JpaTransactionManager">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+  <bean id="transactionInterceptor"
+    class="org.springframework.transaction.interceptor.TransactionInterceptor">
+    <property name="transactionManager" ref="transactionManager" />
+    <property name="transactionAttributeSource">
+      <bean
+        class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
+    </property>
+  </bean>
+  
+  <!-- enable the configuration of transactional behavior based on annotations -->
+  <tx:annotation-driven transaction-manager="transactionManager" />
+
+  <bean id="storeFactory"
+    class="org.apache.continuum.store.jpa.JpaStoreFactory">
+  </bean>
+
+  <bean id="projectStore"
+    class="org.apache.continuum.store.jpa.JpaStore"
+    factory-bean="storeFactory"
+    factory-method="createProjectStoreInstance">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <bean id="projectGroupStore"
+    class="org.apache.continuum.store.jpa.JpaStore"
+    factory-bean="storeFactory"
+    factory-method="createProjectGroupStoreInstance">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <bean id="projectNotifierStore"
+    class="org.apache.continuum.store.jpa.JpaStore"
+    factory-bean="storeFactory"
+    factory-method="createProjectNotifierStoreInstance">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+
+  <!-- DAO -->
+
+  <bean id="daoFactory"
+    class="org.apache.continuum.dao.impl.DaoFactoryImpl">
+  </bean>
+
+  <bean id="projectGroupDao"
+    class="org.apache.continuum.dao.impl.GenericDaoJpa"
+    factory-bean="daoFactory"
+    factory-method="createProjectGroupDao">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <bean id="projectDao"
+    class="org.apache.continuum.dao.impl.GenericDaoJpa"
+    factory-bean="daoFactory"
+    factory-method="createProjectDao">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <bean id="notifierDao"
+    class="org.apache.continuum.dao.impl.GenericDaoJpa"
+    factory-bean="daoFactory"
+    factory-method="createNotifierDao">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <!-- SERVICES -->
+
+  <bean id="projectGroupService"
+    class="org.apache.continuum.service.impl.ProjectGroupServiceImpl">
+    <property name="projectGroupDao" ref="projectGroupDao"/>
+    <property name="projectDao" ref="projectDao"/>
+  </bean>
+
+  <bean id="projectService"
+    class="org.apache.continuum.service.impl.ProjectServiceImpl">
+    <property name="projectDao" ref="projectGroupDao"/>
+    <property name="notifierDao" ref="notifierDao"/>
+  </bean>
+
+</beans>
\ No newline at end of file

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/spring-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-jpa-evenisse/src/test/resources/META-INF/spring-config.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-group-table-data.sql
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-group-table-data.sql?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-group-table-data.sql (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-group-table-data.sql Thu May  1 08:19:53 2008
@@ -0,0 +1,5 @@
+# Test SQL to populate data here
+
+
+INSERT INTO PROJECT_GROUP ( ID, DATE_CREATED, DESCRIPTION, GROUP_ID, NAME)
+	VALUES ( 100, 2007-11-10, 'Group for Continuum sub-projects', 'org.apache.continuum', 'Continuum Projects')

Added: continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-notifier-table-data.sql
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-notifier-table-data.sql?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-notifier-table-data.sql (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-notifier-table-data.sql Thu May  1 08:19:53 2008
@@ -0,0 +1,5 @@
+# Test data for Project Notifier tests
+
+INSERT INTO PROJECT_NOTIFIER 
+  (ID, DATE_CREATED, DATE_UPDATED, FLG_ENABLED, NOTIFIER_ORIGIN, RECIPIENT_TYPE, FLG_SEND_ON_ERROR,FLG_SEND_ON_FAILURE, FLG_SEND_ON_SUCCESS, FLG_SEND_ON_WARNING)
+  VALUES (100, 2007-11-01, 2007-11-10, 1, 1, 1 , 1, 0, 0, 0 )
\ No newline at end of file

Added: continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-table-data.sql
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-table-data.sql?rev=652556&view=auto
==============================================================================
--- continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-table-data.sql (added)
+++ continuum/branches/continuum-jpa-evenisse/src/test/resources/sql/project-table-data.sql Thu May  1 08:19:53 2008
@@ -0,0 +1,7 @@
+# Test SQL to populate data here
+
+INSERT INTO PROJECT (ID, DATE_CREATED, DATE_UPDATED, ARTIFACT_ID, GROUP_ID, DESCRIPTION, NAME, FLG_SCM_USE_CACHE)
+  VALUES (100, 2007-11-01, 2007-11-10, 'continuum-jpa-model', 'org.apache.continuum', 'Model for Continuum using JPA', 'continuum-jpa-model', false);
+
+INSERT INTO PROJECT (ID, DATE_CREATED, DATE_UPDATED, ARTIFACT_ID, GROUP_ID, DESCRIPTION, NAME, FLG_SCM_USE_CACHE)
+  VALUES (101, 2007-11-02, 2007-11-11, 'continuum-jdo-model', 'org.apache.continuum', 'Legacy Model for Continuum using JDO', 'continuum-jdo-model', true);
\ No newline at end of file



Mime
View raw message