From 6692c7a97949cc59bcbd9f6554213e1858d9ee67 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Wed, 26 Jul 2006 13:47:40 +0000 Subject: [PATCH] Merged AVMService into the rest of Alfresco. It all comes up in the same ApplicationContext. Some adjustments to tests needed, but everything is passing. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3414 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/application-context.xml | 1 + config/alfresco/avm-services-context.xml | 228 ++++++++++++++++++ config/alfresco/avm-test-context.xml | 5 +- config/alfresco/hibernate-context.xml | 1 + config/alfresco/public-services-context.xml | 17 ++ config/alfresco/repository.properties | 3 + .../alfresco/repo/avm/AVMPathConverter.java | 71 ++++++ .../repo/avm/AVMPathConverterTest.java | 55 +++++ .../org/alfresco/repo/avm/AVMServiceImpl.java | 11 +- .../alfresco/repo/avm/AVMServiceTestBase.java | 16 +- source/java/org/alfresco/repo/avm/Issuer.java | 2 +- .../service/cmr/repository/StoreRef.java | 1 + 12 files changed, 401 insertions(+), 10 deletions(-) create mode 100644 config/alfresco/avm-services-context.xml create mode 100644 source/java/org/alfresco/repo/avm/AVMPathConverter.java create mode 100644 source/java/org/alfresco/repo/avm/AVMPathConverterTest.java diff --git a/config/alfresco/application-context.xml b/config/alfresco/application-context.xml index 5cb650346c..5b142fcc65 100644 --- a/config/alfresco/application-context.xml +++ b/config/alfresco/application-context.xml @@ -24,6 +24,7 @@ + diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml new file mode 100644 index 0000000000..0a99e7594f --- /dev/null +++ b/config/alfresco/avm-services-context.xml @@ -0,0 +1,228 @@ + + + + + + + + + + node + + + + + + + + + content + + + + + + + + + layer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PROPAGATION_REQUIRED + + + true + + + + + + + PROPAGATION_REQUIRED + + + false + + + + + + + + + + + + + + + + + + + + + + 4000 + + + 1000 + + + 50 + + + + + + + + + ${avm.storage} + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/avm-test-context.xml b/config/alfresco/avm-test-context.xml index a9c03c3397..febaa0501f 100644 --- a/config/alfresco/avm-test-context.xml +++ b/config/alfresco/avm-test-context.xml @@ -4,6 +4,7 @@ + + diff --git a/config/alfresco/hibernate-context.xml b/config/alfresco/hibernate-context.xml index 12564b8c0a..22087d3b06 100644 --- a/config/alfresco/hibernate-context.xml +++ b/config/alfresco/hibernate-context.xml @@ -41,6 +41,7 @@ org/alfresco/repo/domain/hibernate/VersionCount.hbm.xml org/alfresco/repo/domain/hibernate/AppliedPatch.hbm.xml org/alfresco/repo/domain/hibernate/Permission.hbm.xml + org/alfresco/repo/avm/hibernate/AVM.hbm.xml diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index e536595323..7a8ca4d6a9 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -935,4 +935,21 @@ + + + + + ${avm.storage} + + + ${avm.initialize} + + + + + + + + + diff --git a/config/alfresco/repository.properties b/config/alfresco/repository.properties index 736fe5d4ee..78a6f896e8 100644 --- a/config/alfresco/repository.properties +++ b/config/alfresco/repository.properties @@ -108,4 +108,7 @@ system.people_container.childname=sys:people user.name.caseSensitive=false +# AVM Specific properties. +avm.storage=build/test-results/storage +avm.initialize=true diff --git a/source/java/org/alfresco/repo/avm/AVMPathConverter.java b/source/java/org/alfresco/repo/avm/AVMPathConverter.java new file mode 100644 index 0000000000..2e9fa0311f --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMPathConverter.java @@ -0,0 +1,71 @@ +/* + * 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; + +/** + * Utility class with static methods to convert between + * a NodeRef style id string and an ordinary AVM path. + * @author britt + */ +public class AVMPathConverter +{ + /** + * Converts to a string to stuff into a NodeRef. Version = 3 + * of main:/snot/efluvium/biggle would be converted into + * 3/main/snot/efluvium/biggle + * @param version The version id. + * @param avmPath The full AVM path. + * @return A mangled string appropriate for stuffing into a NodeRef. + */ + public static String toNodeRefStyle(int version, String avmPath) + { + String [] pathParts = avmPath.split(":"); + if (pathParts.length != 2) + { + throw new AVMException("Malformed path."); + } + return version + "/" + pathParts[0] + pathParts[1]; + } + + /** + * Convert from a NodeRef packed form to a version number + * and standard AVM path. + * @param nrID The NodeRef packed for of an AVM path. + * @return The version number and the standard AVM path. + */ + public static Object[] toAVMStyle(String nrID) + { + Object [] result = new Object[2]; + String [] pathParts = nrID.split("/"); + result[0] = new Integer(pathParts[0]); + StringBuilder builder = new StringBuilder(); + builder.append(pathParts[1]); + builder.append(':'); + for (int i = 2; i < pathParts.length; i++) + { + builder.append('/'); + builder.append(pathParts[i]); + } + if (pathParts.length == 2) + { + builder.append('/'); + } + result[1] = builder.toString(); + return result; + } +} diff --git a/source/java/org/alfresco/repo/avm/AVMPathConverterTest.java b/source/java/org/alfresco/repo/avm/AVMPathConverterTest.java new file mode 100644 index 0000000000..cb7b76478c --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMPathConverterTest.java @@ -0,0 +1,55 @@ +/* + * 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 junit.framework.TestCase; + +/** + * Test of AVMPathConverter. + * @author britt + */ +public class AVMPathConverterTest extends TestCase +{ + /** + * Test conversions. + */ + public void testConversions() + { + try + { + String start = "main:/"; + String nrRep = AVMPathConverter.toNodeRefStyle(-1, start); + assertEquals("-1/main/", nrRep); + Object[] back = AVMPathConverter.toAVMStyle(nrRep); + assertEquals(((Integer)back[0]).intValue(), -1); + assertEquals((String)back[1], "main:/"); + start = "main:/foo/bar/baz"; + nrRep = AVMPathConverter.toNodeRefStyle(2, start); + assertEquals("2/main/foo/bar/baz", nrRep); + back = AVMPathConverter.toAVMStyle(nrRep); + assertEquals(((Integer)back[0]).intValue(), 2); + assertEquals((String)back[1], "main:/foo/bar/baz"); + + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } +} diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index 54b2e05a6d..83f7ca4c9c 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -85,8 +85,15 @@ class AVMServiceImpl implements AVMService { if (fInitialize) { - createAVMStore("main"); - fgLogger.info("Created new main AVMStore"); + try + { + createAVMStore("main"); + fgLogger.info("Created new main AVMStore"); + } + catch (AVMExistsException e) + { + fgLogger.info("AVMStore main already exists"); + } } } diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java b/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java index 8de965e8c8..491bedab79 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java @@ -19,7 +19,9 @@ package org.alfresco.repo.avm; import java.io.IOException; import java.io.PrintStream; +import java.io.File; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -59,9 +61,8 @@ public class AVMServiceTestBase extends TestCase @Override protected void setUp() throws Exception { -// HibernateHelper.GetSessionFactory().getStatistics().setStatisticsEnabled(true); fContext = new FileSystemXmlApplicationContext("config/alfresco/avm-test-context.xml"); - fService = (AVMService)fContext.getBean("avmService"); + fService = (AVMService)fContext.getBean("AVMService"); fReaper = (OrphanReaper)fContext.getBean("orphanReaper"); fStartTime = System.currentTimeMillis(); } @@ -74,10 +75,15 @@ public class AVMServiceTestBase extends TestCase { long now = System.currentTimeMillis(); System.out.println("Timing: " + (now - fStartTime) + "ms"); -// Statistics stats = HibernateHelper.GetSessionFactory().getStatistics(); -// stats.logSummary(); -// stats.clear(); + List descriptors = fService.getAVMStores(); + for (AVMStoreDescriptor desc : descriptors) + { + fService.purgeAVMStore(desc.getName()); + } fContext.close(); + File alfData = new File("alf_data"); + File target = new File("alf_data" + now); + alfData.renameTo(target); } /** diff --git a/source/java/org/alfresco/repo/avm/Issuer.java b/source/java/org/alfresco/repo/avm/Issuer.java index d53fb252f4..d207e2a744 100644 --- a/source/java/org/alfresco/repo/avm/Issuer.java +++ b/source/java/org/alfresco/repo/avm/Issuer.java @@ -85,7 +85,7 @@ class Issuer } else { - fNext = doit.value; + fNext = doit.value + 1; } } diff --git a/source/java/org/alfresco/service/cmr/repository/StoreRef.java b/source/java/org/alfresco/service/cmr/repository/StoreRef.java index b9b2faba13..302d89e84a 100644 --- a/source/java/org/alfresco/service/cmr/repository/StoreRef.java +++ b/source/java/org/alfresco/service/cmr/repository/StoreRef.java @@ -30,6 +30,7 @@ public final class StoreRef implements EntityRef, Serializable private static final long serialVersionUID = 3905808565129394486L; public static final String PROTOCOL_WORKSPACE = "workspace"; + public static final String PROTOCOL_AVM = "avm"; public static final String URI_FILLER = "://";