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
This commit is contained in:
Britt Park
2006-05-19 21:59:37 +00:00
parent f4980f8ddd
commit 72751fdedb
7 changed files with 121 additions and 12 deletions

View File

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

View File

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

View File

@@ -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.
*/