jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r744774 - in /incubator/jspwiki/trunk: src/java/org/apache/wiki/content/ContentManager.java tests/java/org/apache/wiki/content/ContentManagerTest.java
Date Sun, 15 Feb 2009 22:50:26 GMT
Author: jalkanen
Date: Sun Feb 15 22:50:25 2009
New Revision: 744774

URL: http://svn.apache.org/viewvc?rev=744774&view=rev
Log:
Minor mucking about to make ContentManagerTest to actually run.

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=744774&r1=744773&r2=744774&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Sun Feb 15
22:50:25 2009
@@ -87,6 +87,9 @@
 
 public class ContentManager
 {
+    /**
+     *  The name of the default WikiSpace.
+     */
     public static final String DEFAULT_SPACE = "Main";
     
     private static final String JCR_DEFAULT_SPACE = "pages/"+DEFAULT_SPACE;
@@ -197,6 +200,8 @@
             {
                 try
                 {
+                    // FIXME: Should really use reflection to find this class - this requires
+                    //        an unnecessary compile-time presence of priha.jar.
                     m_repository = RepositoryManager.getRepository();
                 }
                 catch( ConfigurationException e1 )
@@ -233,7 +238,9 @@
         
         try
         {
+            Object foo = acquire();
             initialize();
+            release(foo);
         }
         catch( RepositoryException e )
         {
@@ -248,47 +255,54 @@
      */
     private void initialize() throws LoginException, RepositoryException 
     {
-        Object id = null;
-        
-        try
-        {
-            id = m_sessionManager.createSession();
-            
-            Session session = m_sessionManager.getSession();
+        Session session = m_sessionManager.getSession();
             
-            //
-            //  Create the proper namespaces
-            //
+        //
+        //  Create the proper namespaces
+        //
             
-            session.getWorkspace().getNamespaceRegistry().registerNamespace( "wiki", NS_JSPWIKI
);
+        session.getWorkspace().getNamespaceRegistry().registerNamespace( "wiki", NS_JSPWIKI
);
             
-            Node root = session.getRootNode();
+        Node root = session.getRootNode();
         
-            //
-            // Create main page directory
-            //
-            if( !root.hasNode( JCR_PAGES_NODE ) )
-            {
-                root.addNode( JCR_PAGES_NODE );
-            }
+        //
+        // Create main page directory
+        //
+        if( !root.hasNode( JCR_PAGES_NODE ) )
+        {
+            root.addNode( JCR_PAGES_NODE );
+        }
         
-            //
-            //  Make sure at least the default "Main" wikispace exists.
-            //
+        //
+        //  Make sure at least the default "Main" wikispace exists.
+        //
             
-            if( !root.hasNode( JCR_DEFAULT_SPACE ) )
-            {
-                root.addNode( JCR_DEFAULT_SPACE );
-            }
+        if( !root.hasNode( JCR_DEFAULT_SPACE ) )
+        {
+            root.addNode( JCR_DEFAULT_SPACE );
+        }
             
-            session.save();
+        session.save();
+
+    }
+    
+    public Object acquire() throws ProviderException
+    {
+        try
+        {
+            return m_sessionManager.createSession();
         }
-        finally
+        catch( Exception e )
         {
-            m_sessionManager.destroySession( id );
+            throw new ProviderException( "Unable to create a JCR session", e );
         }
     }
     
+    public void release( Object id )
+    {
+        m_sessionManager.destroySession( id );
+    }
+    
     /**
      *  Returns all pages in some random order.  If you need just the page names, 
      *  please see {@link ReferenceManager#findCreated()}, which is probably a lot
@@ -303,11 +317,9 @@
     public Collection<WikiPage> getAllPages( String space )
         throws ProviderException
     {
-        Object id = null;
         ArrayList<WikiPage> result = new ArrayList<WikiPage>();
         try
         {
-            id = m_sessionManager.createSession();
             Session session = m_sessionManager.getSession();
         
             QueryManager mgr = session.getWorkspace().getQueryManager();
@@ -333,10 +345,6 @@
         {
             throw new ProviderException("getAllPages()",e);
         }
-        finally
-        {
-            m_sessionManager.destroySession(id);
-        }
         
         return result;
     }
@@ -620,11 +628,8 @@
             throw new ProviderException("Illegal page name");
         }
 
-        Object id = null;
-        
         try
         {
-            id = m_sessionManager.createSession();
             Session session = m_sessionManager.getSession();
             
             String jcrPath = getJCRPath( wikiPath ); 
@@ -635,10 +640,6 @@
         {
             throw new ProviderException( "Unable to check for page existence", e );
         }
-        finally
-        {
-            m_sessionManager.destroySession( id );
-        }
     }
     
     /**
@@ -659,11 +660,8 @@
             throw new WikiException("Illegal page name");
         }
 
-        Object id = null;
         try
         {
-            id = m_sessionManager.createSession();
-            
             Session session = m_sessionManager.getSession();
             
             return session.itemExists( getJCRPath( wikiPath ) );
@@ -672,10 +670,6 @@
         {
             throw new WikiException("Unable to check for page existence",e);
         }
-        finally
-        {
-            m_sessionManager.destroySession( id );
-        }
     }
 
     /**
@@ -981,11 +975,8 @@
      */
     public JCRWikiPage addPage( WikiName path, String contentType ) throws WikiException
     {
-        Object id = null;
-        
         try
         {
-            id = m_sessionManager.createSession();
             Session session = m_sessionManager.getSession();
         
             Node nd = session.getRootNode().addNode( getJCRPath(path) );
@@ -998,10 +989,6 @@
         {
             throw new WikiException( "Unable to add a page", e );
         }
-        finally
-        {
-            m_sessionManager.destroySession(id);
-        }
     }
 
     /**
@@ -1014,10 +1001,8 @@
      */
     public JCRWikiPage getPage( WikiName path ) throws ProviderException
     {
-        Object id = null;
         try
         {
-            id = m_sessionManager.createSession();
             Session session = m_sessionManager.getSession();
         
             Node nd = session.getRootNode().getNode( getJCRPath(path) );
@@ -1037,20 +1022,12 @@
         {
             throw new ProviderException("Unable to get a  page",e);
         }
-        finally
-        {
-            m_sessionManager.destroySession( id );
-        }
     }
 
     public JCRWikiPage getPage( WikiName path, int version ) throws WikiException
     {
-        Object id = null;
-        
         try
         {
-            id = m_sessionManager.createSession();
-            
             Session session = m_sessionManager.getSession();
         
             Node nd = session.getRootNode().getNode( getJCRPath(path) );
@@ -1067,10 +1044,6 @@
         {
             throw new WikiException( "Unable to get a page", e );
         }
-        finally
-        {
-            m_sessionManager.destroySession( id );
-        }
     }
     
     /**
@@ -1188,11 +1161,8 @@
 
     public WikiPage getDummyPage() throws WikiException
     {
-        Object id = null;
         try
         {
-            id = m_sessionManager.createSession();
-            
             Session session = m_sessionManager.getSession();
             Node nd = session.getRootNode().addNode( "/pages/Main/Dummy" );
             return new JCRWikiPage( m_engine, nd );
@@ -1201,10 +1171,6 @@
         {
             throw new WikiException("Unable to get dummy page",e);
         }
-        finally
-        {
-            m_sessionManager.destroySession( id );
-        }
     }
 
     /**
@@ -1258,13 +1224,18 @@
  
         /**
          *  Between createSession() and destroySession() you may get the Session object
-         *  with this call. Otherwise the end result is undefined.
+         *  with this call.
          *  
          *  @return A valid Session object, if called between createSession and destroySession().
+         *  @throws IllegalStateException If the object has not been acquired with createSession()
          */
-        public Session getSession() 
+        public Session getSession() throws IllegalStateException
         {
-            return m_currentSession.get();
+            Session s = m_currentSession.get();
+            
+            if( s == null ) throw new IllegalStateException("You have not yet opened a Session");
+            
+            return s;
         } 
 
     }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java?rev=744774&r1=744773&r2=744774&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java Sun
Feb 15 22:50:25 2009
@@ -17,6 +17,8 @@
 {
     ContentManager m_mgr;
     TestEngine     m_engine;
+    Object         m_owner;
+    
     @Override
     protected void setUp() throws Exception
     {
@@ -28,6 +30,7 @@
         m_engine = new TestEngine(props);
         
         m_mgr = m_engine.getContentManager();
+        m_owner = m_mgr.acquire();
     }
 
     @Override
@@ -37,6 +40,7 @@
         
         if( p != null ) m_mgr.deletePage( p );
         
+        m_mgr.release( m_owner );
         super.tearDown();
     }
 



Mime
View raw message