mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Having managed to get WCM-DEV royally screwed up, I made a new branch,
WCM-DEV2 and added back my changes. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2804 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
421
source/java/org/alfresco/repo/avm/impl/AVMServiceImpl.java
Normal file
421
source/java/org/alfresco/repo/avm/impl/AVMServiceImpl.java
Normal file
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.avm.AVMNode;
|
||||
import org.alfresco.repo.avm.AVMService;
|
||||
import org.alfresco.repo.avm.FolderEntry;
|
||||
import org.alfresco.repo.avm.Lookup;
|
||||
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.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
/**
|
||||
* Implements the AVMService. Stub.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMServiceImpl implements AVMService
|
||||
{
|
||||
/**
|
||||
* The Hibernate SessionFactory.
|
||||
*/
|
||||
private SessionFactory fSessionFactory;
|
||||
|
||||
/**
|
||||
* The HibernateTxn.
|
||||
*/
|
||||
private HibernateTxn fTransaction;
|
||||
|
||||
/**
|
||||
* The SuperRepository for each service thread.
|
||||
*/
|
||||
private ThreadLocal<SuperRepository> fSuperRepository;
|
||||
|
||||
/**
|
||||
* Basic constructor for the service.
|
||||
*/
|
||||
public AVMServiceImpl()
|
||||
{
|
||||
fSessionFactory = HibernateHelper.GetSessionFactory();
|
||||
fTransaction = new HibernateTxn(fSessionFactory);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getFileInputStream(int, java.lang.String)
|
||||
*/
|
||||
public InputStream getFileInputStream(final int version, final String path)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public InputStream in = null;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
in = fSuperRepository.get().getInputStream(version, path);
|
||||
}
|
||||
};
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.in;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getFileOutputStream(java.lang.String)
|
||||
*/
|
||||
public OutputStream getFileOutputStream(final String path)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public OutputStream out = null;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
out = fSuperRepository.get().getOutputStream(path);
|
||||
}
|
||||
};
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.out;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getFolderListing(int, java.lang.String)
|
||||
*/
|
||||
public List<FolderEntry> getDirectoryListing(final int version, final String path)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public List<FolderEntry> listing;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
listing = fSuperRepository.get().getListing(version, path);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.listing;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createFile(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createFile(final String path, final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createFile(path, name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createFolder(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createDirectory(final String path, final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createDirectory(path, name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createLayeredFile(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createLayeredFile(final String srcPath, final String parent, final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createLayeredFile(srcPath, parent, name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createLayeredFolder(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createLayeredDirectory(final String srcPath, final String parent, final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createLayeredDirectory(srcPath, parent, name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createRepository(java.lang.String)
|
||||
*/
|
||||
public void createRepository(final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createRepository(name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createBranch(int, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createBranch(final int version, final String srcPath, final String dstPath,
|
||||
final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createBranch(version, srcPath, dstPath, name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#removeNode(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void removeNode(final String parent, final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().remove(parent, name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#rename(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void rename(final String srcParent, final String srcName, final String dstParent,
|
||||
final String dstName)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().rename(srcParent, srcName, dstParent, dstName);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#slide(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void slide(final String srcParent, final String srcName, final String dstParent,
|
||||
final String dstName)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().slide(srcParent, srcName, dstParent, dstName);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getLatestVersionID(java.lang.String)
|
||||
*/
|
||||
public long getLatestVersionID(final String repName)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public long latestVersionID;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
latestVersionID = fSuperRepository.get().getLatestVersionID(repName);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.latestVersionID;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#createSnapshot(java.util.List)
|
||||
*/
|
||||
public void createSnapshot(final List<String> repositories)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().createSnapshot(repositories);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#lookup(int, java.lang.String)
|
||||
*/
|
||||
public AVMNode lookup(final int version, final String path)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public Lookup lookup;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
lookup = fSuperRepository.get().lookup(version, path);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.lookup.getCurrentNode();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#destroyRepository(java.lang.String)
|
||||
*/
|
||||
public void destroyRepository(final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().destroyRepository(name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#purgeVersion(int, java.lang.String)
|
||||
*/
|
||||
public void purgeVersion(final int version, final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
fSuperRepository.get().purgeVersion(name, version);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getIndirectionPath(java.lang.String)
|
||||
*/
|
||||
public String getIndirectionPath(final int version, final String path)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public String indirectionPath;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
indirectionPath = fSuperRepository.get().getIndirectionPath(version, path);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.indirectionPath;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#getRepositoryVersions(java.lang.String)
|
||||
*/
|
||||
public Set<Integer> getRepositoryVersions(final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public Set<Integer> versions;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.set(new SuperRepositoryImpl(session));
|
||||
versions = fSuperRepository.get().getRepositoryVersions(name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
return doit.versions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.AVMService#retargetLayeredFolder(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void retargetLayeredFolder(String path, String target)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
291
source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java
Normal file
291
source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.avm.AVMNode;
|
||||
import org.alfresco.repo.avm.DirectoryNode;
|
||||
import org.alfresco.repo.avm.FolderEntry;
|
||||
import org.alfresco.repo.avm.LayeredDirectoryNode;
|
||||
import org.alfresco.repo.avm.Lookup;
|
||||
import org.alfresco.repo.avm.PlainDirectoryNode;
|
||||
import org.alfresco.repo.avm.Repository;
|
||||
import org.alfresco.repo.avm.SuperRepository;
|
||||
import org.alfresco.repo.avm.hibernate.AVMNodeBean;
|
||||
import org.alfresco.repo.avm.hibernate.DirectoryNodeBean;
|
||||
import org.alfresco.repo.avm.hibernate.PlainDirectoryNodeBean;
|
||||
import org.alfresco.repo.avm.hibernate.PlainDirectoryNodeBeanImpl;
|
||||
import org.alfresco.repo.avm.hibernate.RepositoryBean;
|
||||
import org.alfresco.repo.avm.hibernate.RepositoryBeanImpl;
|
||||
|
||||
/**
|
||||
* @author britt
|
||||
*
|
||||
*/
|
||||
public class RepositoryImpl implements Repository
|
||||
{
|
||||
/**
|
||||
* The data bean.
|
||||
*/
|
||||
private RepositoryBean fData;
|
||||
|
||||
/**
|
||||
* The super repository.
|
||||
*/
|
||||
private SuperRepository fSuper;
|
||||
|
||||
/**
|
||||
* Make a brand new repository.
|
||||
* @param superRepo The SuperRepository.
|
||||
* @param name The name of the Repository.
|
||||
*/
|
||||
public RepositoryImpl(SuperRepository superRepo, String name)
|
||||
{
|
||||
fSuper = superRepo;
|
||||
fData = new RepositoryBeanImpl(name, null);
|
||||
fSuper.getSession().save(fData);
|
||||
PlainDirectoryNodeBean rootBean =
|
||||
new PlainDirectoryNodeBeanImpl(fSuper.issueID(),
|
||||
fData.getNextVersionID(),
|
||||
0L,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
fData,
|
||||
true // is root
|
||||
);
|
||||
fSuper.getSession().save(rootBean);
|
||||
fData.setRoot(rootBean);
|
||||
fData.getRoots().put(fData.getNextVersionID(), rootBean);
|
||||
fData.setNextVersionID(fData.getNextVersionID() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make one from a data bean.
|
||||
* @param data The data.
|
||||
*/
|
||||
public RepositoryImpl(SuperRepository superRepo, RepositoryBean data)
|
||||
{
|
||||
fData = data;
|
||||
fSuper = superRepo;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#setNew(org.alfresco.repo.avm.AVMNode)
|
||||
*/
|
||||
public void setNew(AVMNode node)
|
||||
{
|
||||
fData.getNewNodes().add(node.getDataBean());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getLatestVersion()
|
||||
*/
|
||||
public long getLatestVersion()
|
||||
{
|
||||
return fData.getNextVersionID();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#setNewRoot(org.alfresco.repo.avm.DirectoryNode)
|
||||
*/
|
||||
public void setNewRoot(DirectoryNode root)
|
||||
{
|
||||
fData.setRoot((DirectoryNodeBean)root.getDataBean());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#createSnapshot()
|
||||
*/
|
||||
public void createSnapshot()
|
||||
{
|
||||
// Walk through the new nodes and mark them not new.
|
||||
for (AVMNodeBean newBean : fData.getNewNodes())
|
||||
{
|
||||
newBean.setIsNew(false);
|
||||
}
|
||||
// Clear out the new nodes.
|
||||
fData.getNewNodes().clear();
|
||||
// Add the current root to the root history.
|
||||
fData.getRoots().put(fData.getNextVersionID(), fData.getRoot());
|
||||
// Increment the version id.
|
||||
fData.setNextVersionID(fData.getNextVersionID() + 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#createDirectory(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createDirectory(String path, String name)
|
||||
{
|
||||
Lookup lPath = lookupDirectory(-1, path);
|
||||
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
|
||||
if (dir.lookupChild(lPath, name, -1) != null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Child exists: " + name);
|
||||
}
|
||||
DirectoryNode newDir = null;
|
||||
if (lPath.isLayered()) // Creating a directory in a layered context creates
|
||||
// a LayeredDirectoryNode that gets its indirection from
|
||||
// its parent.
|
||||
{
|
||||
newDir = new LayeredDirectoryNode((String)null, this);
|
||||
((LayeredDirectoryNode)newDir).setPrimaryIndirection(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
newDir = new PlainDirectoryNode(this);
|
||||
}
|
||||
// TODO Untangle when you are going to set a new version id.
|
||||
newDir.setVersion(fData.getNextVersionID());
|
||||
this.setNew(newDir);
|
||||
dir.addChild(name, newDir, lPath);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#createLayeredDirectory(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createLayeredDirectory(String srcPath, String dstPath,
|
||||
String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#createFile(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createFile(String path, String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#createLayeredFile(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createLayeredFile(String srcPath, String dstPath, String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getInputStream(int, java.lang.String)
|
||||
*/
|
||||
public InputStream getInputStream(int version, String path)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getListing(int, java.lang.String)
|
||||
*/
|
||||
public List<FolderEntry> getListing(int version, String path)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getOutputStream(java.lang.String)
|
||||
*/
|
||||
public OutputStream getOutputStream(String path)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#removeNode(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void removeNode(String path, String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#slide(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void slide(String srcPath, String srcName, String dstPath,
|
||||
String dstName)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getVersions()
|
||||
*/
|
||||
public Set<Integer> getVersions()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getDataBean()
|
||||
*/
|
||||
public RepositoryBean getDataBean()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getSuperRepository()
|
||||
*/
|
||||
public SuperRepository getSuperRepository()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#lookup(int, java.lang.String)
|
||||
*/
|
||||
public Lookup lookup(int version, String path)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#lookupDirectory(int, java.lang.String)
|
||||
*/
|
||||
public Lookup lookupDirectory(int version, String path)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.Repository#getIndirectionPath(int, java.lang.String)
|
||||
*/
|
||||
public String getIndirectionPath(int version, String path)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
501
source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java
Normal file
501
source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java
Normal file
@@ -0,0 +1,501 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.avm.AVMNode;
|
||||
import org.alfresco.repo.avm.DirectoryNode;
|
||||
import org.alfresco.repo.avm.FileNode;
|
||||
import org.alfresco.repo.avm.FolderEntry;
|
||||
import org.alfresco.repo.avm.LayeredDirectoryNode;
|
||||
import org.alfresco.repo.avm.LayeredFileNode;
|
||||
import org.alfresco.repo.avm.Lookup;
|
||||
import org.alfresco.repo.avm.PlainDirectoryNode;
|
||||
import org.alfresco.repo.avm.PlainFileNode;
|
||||
import org.alfresco.repo.avm.Repository;
|
||||
import org.alfresco.repo.avm.SuperRepository;
|
||||
import org.alfresco.repo.avm.hibernate.Issuer;
|
||||
import org.alfresco.repo.avm.hibernate.RepositoryBean;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Implementation of a SuperRepository. This is a per thread
|
||||
* class.
|
||||
* @author britt
|
||||
*/
|
||||
public class SuperRepositoryImpl implements SuperRepository
|
||||
{
|
||||
/**
|
||||
* The Hibernate Session associated with the current operation.
|
||||
*/
|
||||
private Session fSession;
|
||||
|
||||
/**
|
||||
* The node id issuer.
|
||||
*/
|
||||
private Issuer fNodeIssuer;
|
||||
|
||||
/**
|
||||
* The content id issuer;
|
||||
*/
|
||||
private Issuer fContentIssuer;
|
||||
|
||||
/**
|
||||
* The branch id issuer.
|
||||
*/
|
||||
private Issuer fBranchIssuer;
|
||||
|
||||
/**
|
||||
* The layer id issuer.
|
||||
*/
|
||||
private Issuer fLayerIssuer;
|
||||
|
||||
/**
|
||||
* Make a new one, initialized with the session.
|
||||
* @param session The session for this operation.
|
||||
*/
|
||||
public SuperRepositoryImpl(Session session)
|
||||
{
|
||||
fSession = session;
|
||||
fNodeIssuer = (Issuer)fSession.get(Issuer.class, "node");
|
||||
fContentIssuer = (Issuer)fSession.get(Issuer.class, "content");
|
||||
fBranchIssuer = (Issuer)fSession.get(Issuer.class, "branch");
|
||||
fLayerIssuer = (Issuer)fSession.get(Issuer.class, "layer");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createFile(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createFile(String path, String name)
|
||||
{
|
||||
String[] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
rep.createFile(pathParts[1], name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createDirectory(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createDirectory(String path, String name)
|
||||
{
|
||||
String[] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
rep.createDirectory(pathParts[1], name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createLayeredDirectory(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createLayeredDirectory(String srcPath, String dstPath,
|
||||
String name)
|
||||
{
|
||||
String[] pathParts = SplitPath(dstPath);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
rep.createLayeredDirectory(srcPath, pathParts[1], name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createLayerdFile(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createLayeredFile(String srcPath, String dstPath, String name)
|
||||
{
|
||||
String[] pathParts = SplitPath(dstPath);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
rep.createLayeredFile(srcPath, pathParts[1], name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createRepository(java.lang.String)
|
||||
*/
|
||||
public void createRepository(String name)
|
||||
{
|
||||
// Newing up the object causes it to be written to the db.
|
||||
@SuppressWarnings("unused")
|
||||
Repository rep = new RepositoryImpl(this, name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createBranch(int, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createBranch(int version, String srcPath, String dstPath, String name)
|
||||
{
|
||||
// Lookup the src node.
|
||||
String [] pathParts = SplitPath(srcPath);
|
||||
Repository srcRepo = getRepositoryByName(pathParts[0]);
|
||||
Lookup sPath = srcRepo.lookup(version, pathParts[1]);
|
||||
// Lookup the destination direcctory.
|
||||
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;
|
||||
if (srcNode instanceof PlainDirectoryNode)
|
||||
{
|
||||
dstNode = new PlainDirectoryNode((PlainDirectoryNode)srcNode, dstRepo);
|
||||
}
|
||||
else if (srcNode instanceof LayeredDirectoryNode)
|
||||
{
|
||||
dstNode =
|
||||
new LayeredDirectoryNode((LayeredDirectoryNode)srcNode, dstRepo);
|
||||
}
|
||||
else if (srcNode instanceof LayeredFileNode)
|
||||
{
|
||||
dstNode = new LayeredFileNode((LayeredFileNode)srcNode, dstRepo);
|
||||
}
|
||||
else // This is a plain file.
|
||||
{
|
||||
dstNode = new PlainFileNode((PlainFileNode)srcNode, dstRepo);
|
||||
}
|
||||
dstNode.setVersion(dstRepo.getLatestVersion() + 1);
|
||||
dstRepo.setNew(dstNode);
|
||||
dstNode.setAncestor(srcNode);
|
||||
dstNode.setBranchID(fBranchIssuer.issue());
|
||||
dirNode.addChild(name, dstNode, dPath);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getOutputStream(java.lang.String)
|
||||
*/
|
||||
public OutputStream getOutputStream(String path)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
return rep.getOutputStream(pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#rename(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void rename(String srcPath, String srcName, String dstPath,
|
||||
String dstName)
|
||||
{
|
||||
String [] pathParts = SplitPath(srcPath);
|
||||
Repository srcRepo = getRepositoryByName(pathParts[0]);
|
||||
Lookup sPath = srcRepo.lookupDirectory(-1, pathParts[1]);
|
||||
DirectoryNode srcDir = (DirectoryNode)sPath.getCurrentNode();
|
||||
AVMNode srcNode = srcDir.lookupChild(sPath, srcName, -1);
|
||||
if (srcNode == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Not found: " + srcName);
|
||||
}
|
||||
pathParts = SplitPath(dstPath);
|
||||
Repository dstRepo = getRepositoryByName(pathParts[0]);
|
||||
Lookup dPath = dstRepo.lookupDirectory(-1, dstPath);
|
||||
DirectoryNode dstDir = (DirectoryNode)dPath.getCurrentNode();
|
||||
AVMNode dstNode = dstDir.lookupChild(dPath, dstName, -1);
|
||||
if (dstNode != null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Node exists: " + dstName);
|
||||
}
|
||||
// We've passed the check, so we can go ahead and do the rename.
|
||||
if (srcNode instanceof PlainDirectoryNode)
|
||||
{
|
||||
// If the source is layered then the renamed thing needs to be layered also.
|
||||
if (sPath.isLayered())
|
||||
{
|
||||
// If this is a rename happening in the same layer we make a new
|
||||
// OverlayedDirectoryNode that is not a primary indirection layer.
|
||||
// Otherwise we do make the new OverlayedDirectoryNode a primary
|
||||
// Indirection layer. This complexity begs the question of whether
|
||||
// we should allow renames from within one layer to within another
|
||||
// layer. Allowing it makes the logic absurdly complex.
|
||||
if (dPath.isLayered() && dPath.getTopLayer() == sPath.getTopLayer())
|
||||
{
|
||||
dstNode = new LayeredDirectoryNode((PlainDirectoryNode)srcNode, dstRepo, sPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
dstNode = new LayeredDirectoryNode((DirectoryNode)srcNode, dstRepo, sPath, srcName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dstNode = new PlainDirectoryNode((PlainDirectoryNode)srcNode, dstRepo);
|
||||
}
|
||||
}
|
||||
else if (srcNode instanceof LayeredDirectoryNode)
|
||||
{
|
||||
if (!sPath.isLayered() || (sPath.isInThisLayer() &&
|
||||
srcDir instanceof LayeredDirectoryNode &&
|
||||
((LayeredDirectoryNode)srcDir).directlyContains(srcNode)))
|
||||
{
|
||||
// Use the simple 'copy' constructor.
|
||||
dstNode =
|
||||
new LayeredDirectoryNode((LayeredDirectoryNode)srcNode, dstRepo);
|
||||
((LayeredDirectoryNode)dstNode).setLayerID(((LayeredDirectoryNode)srcNode).getLayerID());
|
||||
}
|
||||
else
|
||||
{
|
||||
// The thing we are renaming does not belong to sPath's layer and therefore
|
||||
// we need to compute the indirection path for this layer after the rename.
|
||||
dstNode =
|
||||
new LayeredDirectoryNode((DirectoryNode)srcNode, dstRepo, sPath, srcName);
|
||||
((LayeredDirectoryNode)dstNode).setLayerID(fLayerIssuer.issue());
|
||||
}
|
||||
}
|
||||
else if (srcNode instanceof LayeredFileNode)
|
||||
{
|
||||
if (!sPath.isLayered() || (sPath.isInThisLayer() &&
|
||||
srcDir instanceof LayeredDirectoryNode &&
|
||||
((LayeredDirectoryNode)srcDir).directlyContains(srcNode)))
|
||||
{
|
||||
// Use the simple 'copy' constructor.
|
||||
dstNode =
|
||||
new LayeredFileNode((LayeredFileNode)srcNode, dstRepo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Calculate the indirection path, because srcNode was not in this layer.
|
||||
dstNode =
|
||||
new LayeredFileNode((FileNode)srcNode, dstRepo, sPath, srcName);
|
||||
}
|
||||
}
|
||||
else // This is a plain file node.
|
||||
{
|
||||
dstNode = new PlainFileNode((PlainFileNode)srcNode, dstRepo);
|
||||
}
|
||||
dstNode.setVersion(dstRepo.getLatestVersion() + 1);
|
||||
dstRepo.setNew(dstNode);
|
||||
dstDir.addChild(dstName, dstNode, dPath);
|
||||
dstNode.setAncestor(srcNode);
|
||||
pathParts = SplitPath(srcPath);
|
||||
sPath = srcRepo.lookup(-1, pathParts[1]);
|
||||
srcDir = (DirectoryNode)sPath.getCurrentNode();
|
||||
srcDir.removeChild(srcName, sPath);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#slide(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void slide(String srcPath, String srcName, String dstPath,
|
||||
String dstName)
|
||||
{
|
||||
String[] srcPathParts = SplitPath(srcPath);
|
||||
String[] dstPathParts = SplitPath(dstPath);
|
||||
if (!srcPathParts[0].equals(dstPathParts[0]))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Argument must be in same Repository: " + srcPathParts[0] + "!=" +
|
||||
dstPathParts[0]);
|
||||
}
|
||||
Repository repo = getRepositoryByName(srcPathParts[0]);
|
||||
repo.slide(srcPathParts[1], srcName, dstPathParts[1], dstName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createSnapshot(java.util.List)
|
||||
*/
|
||||
public void createSnapshot(List<String> repositories)
|
||||
{
|
||||
for (String repName : repositories)
|
||||
{
|
||||
Repository repo = getRepositoryByName(repName);
|
||||
repo.createSnapshot();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#remove(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void remove(String path, String name)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository repo = getRepositoryByName(pathParts[0]);
|
||||
repo.removeNode(pathParts[1], name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#purgeRepository(java.lang.String)
|
||||
*/
|
||||
public void purgeRepository(String name)
|
||||
{
|
||||
// TODO Leave until later. Need to set up GC thread to handle this.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#purgeVersion(java.lang.String, int)
|
||||
*/
|
||||
public void purgeVersion(String name, int version)
|
||||
{
|
||||
// TODO Leave until later. Need to set up GC thread to handle this.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getInputStream(java.lang.String)
|
||||
*/
|
||||
public InputStream getInputStream(int version, String path)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository repo = getRepositoryByName(pathParts[0]);
|
||||
return repo.getInputStream(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getListing(java.lang.String)
|
||||
*/
|
||||
public List<FolderEntry> getListing(int version, String path)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository repo = getRepositoryByName(pathParts[0]);
|
||||
return repo.getListing(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getRepositoryNames()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getRepositoryNames()
|
||||
{
|
||||
Query query = fSession.createQuery("select r.name from RepositoryBeanImpl r");
|
||||
return (List<String>)query.list();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getRepositoryVersions(java.lang.String)
|
||||
*/
|
||||
public Set<Integer> getRepositoryVersions(String name)
|
||||
{
|
||||
Repository rep = getRepositoryByName(name);
|
||||
return rep.getVersions();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#issueID()
|
||||
*/
|
||||
public long issueID()
|
||||
{
|
||||
return fNodeIssuer.issue();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#issueContentID()
|
||||
*/
|
||||
public long issueContentID()
|
||||
{
|
||||
return fContentIssuer.issue();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getSession()
|
||||
*/
|
||||
public Session getSession()
|
||||
{
|
||||
return fSession;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#createContentOutputStream(int)
|
||||
*/
|
||||
public OutputStream createContentOutputStream(String path)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
return rep.getOutputStream(pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getContentInputStream(int)
|
||||
*/
|
||||
public InputStream getContentInputStream(int version, String path)
|
||||
{
|
||||
String[] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
return rep.getInputStream(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#destroyRepository(java.lang.String)
|
||||
*/
|
||||
public void destroyRepository(String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
// Leave this until we have GC in place.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getIndirectionPath(int, java.lang.String)
|
||||
*/
|
||||
public String getIndirectionPath(int version, String path)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
return rep.getIndirectionPath(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#getLatestVersionID(java.lang.String)
|
||||
*/
|
||||
public long getLatestVersionID(String name)
|
||||
{
|
||||
Repository rep = getRepositoryByName(name);
|
||||
return rep.getLatestVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a repository by name.
|
||||
* @param name The name of the repository.
|
||||
* @return The Repository.
|
||||
*/
|
||||
private Repository getRepositoryByName(String name)
|
||||
{
|
||||
Query query = fSession.createQuery("from repositories r where r.name = :name");
|
||||
query.setString("name", name);
|
||||
return new RepositoryImpl(this, (RepositoryBean)query.uniqueResult());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#lookup(int, java.lang.String)
|
||||
*/
|
||||
public Lookup lookup(int version, String path)
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
return rep.lookup(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#lookupDirectory(int, java.lang.String)
|
||||
*/
|
||||
public Lookup lookupDirectory(int version, String path)
|
||||
{
|
||||
String[] pathParts = SplitPath(path);
|
||||
Repository rep = getRepositoryByName(pathParts[0]);
|
||||
return rep.lookupDirectory(version, pathParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private String[] SplitPath(String path)
|
||||
{
|
||||
String [] pathParts = path.split(":");
|
||||
if (pathParts.length != 2)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Invalid path: " + path);
|
||||
}
|
||||
return pathParts;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user