From 72751fdedb70abaa6818b43a3884607feeeb9901 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Fri, 19 May 2006 21:59:37 +0000 Subject: [PATCH] First round trip. A unit test instantiates an AVMService and creates a new empty repository. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2926 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/avm/AVMServiceTest.java | 67 +++++++++++++++++++ .../org/alfresco/repo/avm/PlainFileNode.java | 2 - .../alfresco/repo/avm/hibernate/Issuer.java | 5 +- .../repo/avm/hibernate/TestPopulate.java | 9 +-- .../repo/avm/impl/AVMServiceImpl.java | 35 ++++++++++ .../repo/avm/impl/RepositoryImpl.java | 2 +- .../repo/avm/impl/SuperRepositoryImpl.java | 13 +++- 7 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 source/java/org/alfresco/repo/avm/AVMServiceTest.java diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java new file mode 100644 index 0000000000..757af66a0c --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2006 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * 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.alfresco.repo.avm; + +import org.alfresco.repo.avm.hibernate.HibernateHelper; +import org.alfresco.repo.avm.impl.AVMServiceImpl; +import org.hibernate.cfg.Configuration; +import org.hibernate.tool.hbm2ddl.SchemaExport; + +import junit.framework.TestCase; + +/** + * Big test of AVM behavior. + * @author britt + */ +public class AVMServiceTest extends TestCase +{ + /** + * The AVMService we are testing. + */ + private AVMService fService; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception + { + Configuration cfg = HibernateHelper.GetConfiguration(); + SchemaExport se = new SchemaExport(cfg); + se.drop(false, true); + AVMServiceImpl service = new AVMServiceImpl(); + service.setStorage("storage"); + service.init(true); + fService = service; + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception + { + } + + /** + * Test Nothing. Just make sure set up works. + */ + public void testNothing() + { + } +} diff --git a/source/java/org/alfresco/repo/avm/PlainFileNode.java b/source/java/org/alfresco/repo/avm/PlainFileNode.java index 6beedadfd4..8b05c84433 100644 --- a/source/java/org/alfresco/repo/avm/PlainFileNode.java +++ b/source/java/org/alfresco/repo/avm/PlainFileNode.java @@ -19,8 +19,6 @@ package org.alfresco.repo.avm; import org.alfresco.repo.avm.hibernate.BasicAttributesBean; import org.alfresco.repo.avm.hibernate.BasicAttributesBeanImpl; -import org.alfresco.repo.avm.hibernate.ContentBean; -import org.alfresco.repo.avm.hibernate.ContentBeanImpl; import org.alfresco.repo.avm.hibernate.PlainFileNodeBean; import org.alfresco.repo.avm.hibernate.PlainFileNodeBeanImpl; diff --git a/source/java/org/alfresco/repo/avm/hibernate/Issuer.java b/source/java/org/alfresco/repo/avm/hibernate/Issuer.java index 206ffdbcfe..02e1625fe0 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/Issuer.java +++ b/source/java/org/alfresco/repo/avm/hibernate/Issuer.java @@ -17,6 +17,8 @@ package org.alfresco.repo.avm.hibernate; +import org.hibernate.Session; + /** * This is a helper class that knows how to issue identifiers. * @author britt @@ -51,10 +53,11 @@ public class Issuer * @param name The name of this issuer. * @param next The next number to issue. */ - public Issuer(String name, long next) + public Issuer(String name, long next, Session session) { fName = name; fNext = next; + session.save(this); } // Bean methods. diff --git a/source/java/org/alfresco/repo/avm/hibernate/TestPopulate.java b/source/java/org/alfresco/repo/avm/hibernate/TestPopulate.java index f17eb08d80..00e833b976 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/TestPopulate.java +++ b/source/java/org/alfresco/repo/avm/hibernate/TestPopulate.java @@ -76,9 +76,9 @@ public class TestPopulate extends TestCase public void perform(Session session) { // Set up issuers. - Issuer nodeIssuer = new Issuer("node", 0); - Issuer contentIssuer = new Issuer("content", 0); - Issuer repositoryIssuer = new Issuer("repository", 0); + Issuer nodeIssuer = new Issuer("node", 0, session); + Issuer contentIssuer = new Issuer("content", 0, session); + Issuer repositoryIssuer = new Issuer("repository", 0, session); // Make the initial root directory. long time = System.currentTimeMillis(); BasicAttributesBean attrs = new BasicAttributesBeanImpl("britt", @@ -105,9 +105,6 @@ public class TestPopulate extends TestCase session.save(rep); rep.getRoots().put(rep.getNextVersionID(), root); rep.setNextVersionID(rep.getNextVersionID() + 1); - session.save(nodeIssuer); - session.save(contentIssuer); - session.save(repositoryIssuer); root.setIsNew(false); } }); diff --git a/source/java/org/alfresco/repo/avm/impl/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/impl/AVMServiceImpl.java index 44fd2a5c3a..ccfeafafa1 100644 --- a/source/java/org/alfresco/repo/avm/impl/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/impl/AVMServiceImpl.java @@ -30,8 +30,10 @@ import org.alfresco.repo.avm.SuperRepository; import org.alfresco.repo.avm.hibernate.HibernateHelper; import org.alfresco.repo.avm.hibernate.HibernateTxn; import org.alfresco.repo.avm.hibernate.HibernateTxnCallback; +import org.alfresco.repo.avm.hibernate.Issuer; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.hibernate.tool.hbm2ddl.SchemaExport; /** * Implements the AVMService. Stub. @@ -61,13 +63,46 @@ public class AVMServiceImpl implements AVMService /** * Basic constructor for the service. + * @param createTables Flag for whether tables should be created. */ public AVMServiceImpl() { + fSuperRepository = new ThreadLocal(); fSessionFactory = HibernateHelper.GetSessionFactory(); fTransaction = new HibernateTxn(fSessionFactory); } + /** + * Final initialization of the service. Must be called only on a + * fully initialized instance. + * @param createTables Whether we should create tables, and a default + * repository. + */ + public void init(boolean createTables) + { + if (createTables) + { + SchemaExport se = new SchemaExport(HibernateHelper.GetConfiguration()); + se.drop(false, true); + se.create(false, true); + class HTxnCallback implements HibernateTxnCallback + { + public InputStream in = null; + + public void perform(Session session) + { + new Issuer("node", 0L, session); + new Issuer("content", 0L, session); + new Issuer("branch", 0L, session); + new Issuer("layer", 0L, session); + } + }; + HTxnCallback doit = new HTxnCallback(); + fTransaction.perform(doit); + createRepository("main"); + } + } + /** * Set the location of file storage. * @param storage diff --git a/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java b/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java index e8a8f69fea..29e6c0b876 100644 --- a/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java +++ b/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java @@ -98,7 +98,7 @@ public class RepositoryImpl implements Repository fSuper.getSession().save(rootBean); fData.setRoot(rootBean); fData.getRoots().put(fData.getNextVersionID(), rootBean); - fData.setNextVersionID(fData.getNextVersionID() + 1); + fData.setNextVersionID(fData.getNextVersionID()); } /** diff --git a/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java b/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java index f69fefd7f0..aa1062def9 100644 --- a/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java +++ b/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java @@ -153,13 +153,16 @@ public class SuperRepositoryImpl implements SuperRepository String [] pathParts = SplitPath(srcPath); Repository srcRepo = getRepositoryByName(pathParts[0]); Lookup sPath = srcRepo.lookup(version, pathParts[1]); - // Lookup the destination direcctory. + // Lookup the destination directory. pathParts = SplitPath(dstPath); Repository dstRepo = getRepositoryByName(pathParts[0]); Lookup dPath = dstRepo.lookupDirectory(-1, pathParts[1]); DirectoryNode dirNode = (DirectoryNode)dPath.getCurrentNode(); AVMNode srcNode = sPath.getCurrentNode(); AVMNode dstNode = null; + // We do different things depending on what kind of thing we're + // branching from. I'd be considerably happier if we disallowed + // certain scenarios, but Jon won't let me :P (bhp). if (srcNode instanceof PlainDirectoryNode) { dstNode = new PlainDirectoryNode((PlainDirectoryNode)srcNode, dstRepo); @@ -200,6 +203,7 @@ public class SuperRepositoryImpl implements SuperRepository public void rename(String srcPath, String srcName, String dstPath, String dstName) { + // This is about as ugly as it gets. String [] pathParts = SplitPath(srcPath); Repository srcRepo = getRepositoryByName(pathParts[0]); Lookup sPath = srcRepo.lookupDirectory(-1, pathParts[1]); @@ -246,6 +250,8 @@ public class SuperRepositoryImpl implements SuperRepository } else if (srcNode instanceof LayeredDirectoryNode) { + // TODO I think I need to subdivide this logic again. + // based on whether the destination is a layer or not. if (!sPath.isLayered() || (sPath.isInThisLayer() && srcDir instanceof LayeredDirectoryNode && ((LayeredDirectoryNode)srcDir).directlyContains(srcNode))) @@ -295,6 +301,9 @@ public class SuperRepositoryImpl implements SuperRepository srcDir.removeChild(srcName, sPath); } + // TODO Should we allow cross-repository sliding. Tentatively no, because + // it serves no earthly purpose. God knows we need to trim the combinatorial + // tree of possibilities. /* (non-Javadoc) * @see org.alfresco.repo.avm.SuperRepository#slide(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -502,7 +511,7 @@ public class SuperRepositoryImpl implements SuperRepository } /** - * Utility to split a path, foo:/bar/baz into its repository and path parts. + * Utility to split a path, foo:bar/baz into its repository and path parts. * @param path The fully qualified path. * @return The repository name and the repository path. */