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
This commit is contained in:
Britt Park
2006-07-26 13:47:40 +00:00
parent f7d9d83036
commit 6692c7a979
12 changed files with 401 additions and 10 deletions

View File

@@ -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;
}
}

View File

@@ -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();
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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<AVMStoreDescriptor> 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);
}
/**

View File

@@ -85,7 +85,7 @@ class Issuer
}
else
{
fNext = doit.value;
fNext = doit.value + 1;
}
}

View File

@@ -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 = "://";