Refactored persistence for AVM. I'm guessing because I dropped a number of

unnecessary flushes seems about 20% snappier.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3296 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-07-11 09:32:13 +00:00
parent a58a3c4f53
commit d0b5b14af1
46 changed files with 2172 additions and 506 deletions

View File

@@ -0,0 +1,139 @@
/**
*
*/
package org.alfresco.repo.avm;
/**
* This is the (shudder) global context for AVM. It a rendezvous
* point for access to needed global instances.
* @author britt
*/
public class AVMContext
{
/**
* The single instance of an AVMContext.
*/
public static AVMContext fgInstance;
public AVMContext()
{
fgInstance = this;
}
/**
* The IssuerDAO.
*/
public IssuerDAO fIssuerDAO;
/**
* The AVMNodeDAO.
*/
public AVMNodeDAO fAVMNodeDAO;
/**
* The Repository DAO.
*/
public RepositoryDAO fRepositoryDAO;
/**
* The VersionRootDAO.
*/
public VersionRootDAO fVersionRootDAO;
/**
* The FileContentDAO.
*/
public FileContentDAO fFileContentDAO;
/**
* The ChildEntryDAO.
*/
public ChildEntryDAO fChildEntryDAO;
/**
* The HistoryLinkDAO.
*/
public HistoryLinkDAO fHistoryLinkDAO;
/**
* The MergeLinkDAO.
*/
public MergeLinkDAO fMergeLinkDAO;
/**
* The DeletedChildDAO.
*/
public DeletedChildDAO fDeletedChildDAO;
/**
* @param nodeDAO the fAVMNodeDAO to set
*/
public void setNodeDAO(AVMNodeDAO nodeDAO)
{
fAVMNodeDAO = nodeDAO;
}
/**
* @param childEntryDAO the fChildEntryDAO to set
*/
public void setChildEntryDAO(ChildEntryDAO childEntryDAO)
{
fChildEntryDAO = childEntryDAO;
}
/**
* @param deletedChildDAO the fDeletedChildDAO to set
*/
public void setDeletedChildDAO(DeletedChildDAO deletedChildDAO)
{
fDeletedChildDAO = deletedChildDAO;
}
/**
* @param fileContentDAO the fFileContentDAO to set
*/
public void setFileContentDAO(FileContentDAO fileContentDAO)
{
fFileContentDAO = fileContentDAO;
}
/**
* @param historyLinkDAO the fHistoryLinkDAO to set
*/
public void setHistoryLinkDAO(HistoryLinkDAO historyLinkDAO)
{
fHistoryLinkDAO = historyLinkDAO;
}
/**
* @param mergeLinkDAO the fMergeLinkDAO to set
*/
public void setMergeLinkDAO(MergeLinkDAO mergeLinkDAO)
{
fMergeLinkDAO = mergeLinkDAO;
}
/**
* @param repositoryDAO the fRepositoryDAO to set
*/
public void setRepositoryDAO(RepositoryDAO repositoryDAO)
{
fRepositoryDAO = repositoryDAO;
}
/**
* @param versionRootDAO the fVersionRootDAO to set
*/
public void setVersionRootDAO(VersionRootDAO versionRootDAO)
{
fVersionRootDAO = versionRootDAO;
}
/**
* @param issuerDAO the fIssuerDAO to set
*/
public void setIssuerDAO(IssuerDAO issuerDAO)
{
fIssuerDAO = issuerDAO;
}
}

View File

@@ -35,8 +35,8 @@ public class AVMCrawlTest extends AVMServiceTestBase
*/
public void testCrawl()
{
int n = 8; // Number of Threads.
int m = 16; // How many multiples of content to start with.
int n = 2; // Number of Threads.
int m = 4; // How many multiples of content to start with.
long runTime = 1200000; // Ten minutes
fService.purgeRepository("main");
fReaper.setInactiveBaseSleep(60000);

View File

@@ -20,7 +20,7 @@ package org.alfresco.repo.avm;
* The Interface for versionable objects.
* @author britt
*/
interface AVMNode
public interface AVMNode
{
/**
* Set the ancestor of this node.

View File

@@ -0,0 +1,105 @@
/*
* 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 java.util.Iterator;
import java.util.List;
/**
* DAO for AVMNodes interface.
* @author britt
*/
public interface AVMNodeDAO
{
/**
* Save the given node, having never been saved before.
*/
public void save(AVMNode node);
/**
* Make all the nodes owned by a repository no longer
* point to that repository.
* @param rep The Repository.
*/
public void dereferenceNodesInRepository(Repository rep);
/**
* Delete a single node.
* @param node The node to delete.
*/
public void delete(AVMNode node);
/**
* Get by ID.
* @param id The id to get.
*/
public AVMNode getByID(long id);
/**
* Get the root of a particular version.
* @param rep The repository we're querying.
* @param version The version.
* @return The VersionRoot or null.
*/
public DirectoryNode getRepositoryRoot(Repository rep, int version);
/**
* Get those nodes which are new in the given repository.
* @param repo The repository.
* @return A List of AVMNodes.
*/
public List<AVMNode> getNewInRepo(Repository repo);
/**
* Update a node that has been dirtied.
* @param node The node.
*/
public void update(AVMNode node);
/**
* Get the ancestor of a node.
* @param node The node whose ancestor is desired.
* @return The ancestor or null.
*/
public AVMNode getAncestor(AVMNode node);
/**
* Get the node the given node was merged from.
* @param node The node whose merged from is desired.
* @return The merged from node or null.
*/
public AVMNode getMergedFrom(AVMNode node);
/**
* Get up to batchSize orphans.
* @param batchSize Get no more than this number.
* @return A List of orphaned AVMNodes.
*/
public List<AVMNode> getOrphans(int batchSize);
/**
* Get all nodes that have the given repository as their owning repository.
* @param rep The Repository.
* @return An Iterator over the matching nodes.
*/
public Iterator<AVMNode> getByRepository(Repository rep);
/**
* Inappropriate hack to get Hibernate to play nice.
*/
public void flush();
}

View File

@@ -26,7 +26,7 @@ import org.hibernate.Session;
* Base class for all repository file system like objects.
* @author britt
*/
abstract class AVMNodeImpl implements AVMNode, Serializable
public abstract class AVMNodeImpl implements AVMNode, Serializable
{
/**
* The Object ID.
@@ -105,7 +105,7 @@ abstract class AVMNodeImpl implements AVMNode, Serializable
HistoryLinkImpl link = new HistoryLinkImpl();
link.setAncestor(ancestor);
link.setDescendent(this);
SuperRepository.GetInstance().getSession().save(link);
AVMContext.fgInstance.fHistoryLinkDAO.save(link);
}
/**
@@ -114,10 +114,7 @@ abstract class AVMNodeImpl implements AVMNode, Serializable
*/
public AVMNode getAncestor()
{
Session sess = SuperRepository.GetInstance().getSession();
Query query = sess.createQuery("select hl.ancestor from HistoryLinkImpl hl where hl.descendent = :desc");
query.setEntity("desc", this);
return (AVMNode)query.uniqueResult();
return AVMContext.fgInstance.fAVMNodeDAO.getAncestor(this);
}
/**
@@ -133,7 +130,7 @@ abstract class AVMNodeImpl implements AVMNode, Serializable
MergeLinkImpl link = new MergeLinkImpl();
link.setMfrom(mergedFrom);
link.setMto(this);
SuperRepository.GetInstance().getSession().save(link);
AVMContext.fgInstance.fMergeLinkDAO.save(link);
}
/**
@@ -142,10 +139,7 @@ abstract class AVMNodeImpl implements AVMNode, Serializable
*/
public AVMNode getMergedFrom()
{
Session sess = SuperRepository.GetInstance().getSession();
Query query = sess.createQuery("select ml.mfrom from MergeLinkImpl ml where ml.mto = :to");
query.setEntity("to", this);
return (AVMNode)query.uniqueResult();
return AVMContext.fgInstance.fAVMNodeDAO.getMergedFrom(this);
}
/**

View File

@@ -26,7 +26,7 @@ import org.hibernate.proxy.HibernateProxy;
* The CGLIB villains dither unintelligibly.
* @author britt
*/
class AVMNodeUnwrapper
public class AVMNodeUnwrapper
{
public static AVMNode Unwrap(AVMNode node)
{

View File

@@ -28,10 +28,6 @@ import java.util.List;
import java.util.SortedMap;
import org.alfresco.repo.avm.SuperRepository;
import org.alfresco.repo.avm.hibernate.HibernateTxn;
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
import org.hibernate.Query;
import org.hibernate.Session;
/**
* Implements the AVMService. Stub.
@@ -40,9 +36,9 @@ import org.hibernate.Session;
public class AVMServiceImpl implements AVMService
{
/**
* The HibernateTxn.
* The RetryingTransaction.
*/
private HibernateTxn fTransaction;
private RetryingTransaction fTransaction;
/**
* The SuperRepository for each service thread.
@@ -90,18 +86,16 @@ public class AVMServiceImpl implements AVMService
try
{
fTransaction.perform(
new HibernateTxnCallback()
new RetryingTransactionCallback()
{
public void perform(Session sess)
public void perform()
{
Query query = sess.createQuery("select max(an.id) from AVMNodeImpl an");
Long val = (Long)query.uniqueResult();
IssuerDAO dao = AVMContext.fgInstance.fIssuerDAO;
Long val = dao.getNodeIssuerValue();
fNodeIssuer = new Issuer(val == null ? 0L : val + 1L);
query = sess.createQuery("select max(fc.id) from FileContentImpl fc");
val = (Long)query.uniqueResult();
val = dao.getContentIssuerValue();
fContentIssuer = new Issuer(val == null ? 0L : val + 1L);
query = sess.createQuery("select max(an.layerID) from AVMNodeImpl an");
val = (Long)query.uniqueResult();
val = dao.getLayerIssuerValue();
fLayerIssuer = new Issuer(val == null ? 0L : val + 1L);
}
}, false);
@@ -122,10 +116,10 @@ public class AVMServiceImpl implements AVMService
}
/**
* Set the Hibernate Transaction wrapper.
* Set the Retrying Transaction wrapper.
* @param txn
*/
public void setHibernateTxn(HibernateTxn txn)
public void setRetryingTransaction(RetryingTransaction txn)
{
fTransaction = txn;
}
@@ -161,17 +155,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null path.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public InputStream in = null;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
in = fSuperRepository.getInputStream(version, path);
}
};
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.in;
}
@@ -187,23 +180,22 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public InputStream in = null;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
in = fSuperRepository.getInputStream(desc);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.in;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#getFileOutputStream(java.lang.String)
/**
* Get an output stream to a file. Triggers versioning.
*/
public OutputStream getFileOutputStream(final String path)
{
@@ -211,17 +203,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null path.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public OutputStream out = null;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
out = fSuperRepository.getOutputStream(path);
}
};
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
return doit.out;
}
@@ -239,23 +230,25 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public RandomAccessFile file;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
file = fSuperRepository.getRandomAccess(version, path, access);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
return doit.file;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#getFolderListing(int, java.lang.String)
/**
* Get a directory listing.
* @param version The version id to lookup.
* @param path The path to lookup.
*/
public SortedMap<String, AVMNodeDescriptor> getDirectoryListing(final int version, final String path)
{
@@ -263,17 +256,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null path.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public SortedMap<String, AVMNodeDescriptor> listing;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
listing = fSuperRepository.getListing(version, path);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.listing;
}
@@ -289,23 +281,25 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null descriptor.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public SortedMap<String, AVMNodeDescriptor> listing;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
listing = fSuperRepository.getListing(dir);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.listing;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createFile(java.lang.String, java.lang.String)
/**
* Create a new file. The file must not exist.
* @param path The path to the containing directory.
* @param name The name of the file.
* @return An output stream to the file.
*/
public OutputStream createFile(final String path, final String name)
{
@@ -313,17 +307,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public OutputStream out;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
out = fSuperRepository.createFile(path, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
return doit.out;
}
@@ -361,15 +354,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMException("I/O Error.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.createFile(path, name, temp);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
try
{
fTransaction.perform(doit, true);
@@ -380,8 +372,10 @@ public class AVMServiceImpl implements AVMService
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createFolder(java.lang.String, java.lang.String)
/**
* Create a directory. The directory must not exist.
* @param path The path to the containing directory.
* @param name The name of the new directory.
*/
public void createDirectory(final String path, final String name)
{
@@ -389,20 +383,22 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.createDirectory(path, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createLayeredFile(java.lang.String, java.lang.String, java.lang.String)
/**
* Create a new layered file. It must not exist.
* @param srcPath The src path. Ie the target for the layering.
* @param parent The path to the parent directory.
* @param name The name to give the new file.
*/
public void createLayeredFile(final String srcPath, final String parent, final String name)
{
@@ -410,20 +406,22 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.createLayeredFile(srcPath, parent, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createLayeredFolder(java.lang.String, java.lang.String, java.lang.String)
/**
* Create a new layered directory. It must not exist.
* @param srcPath The src path. Ie the target for layering.
* @param parent The path to the parent directory.
* @param name The name for the new directory.
*/
public void createLayeredDirectory(final String srcPath, final String parent, final String name)
{
@@ -431,20 +429,20 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.createLayeredDirectory(srcPath, parent, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createRepository(java.lang.String)
/**
* Create a repository with the given name. It must not exist.
* @param name The name to give the repository.
*/
public void createRepository(final String name)
{
@@ -452,20 +450,23 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Name is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.createRepository(name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createBranch(int, java.lang.String, java.lang.String, java.lang.String)
/**
* Create a branch.
* @param version The version to branch from.
* @param srcPath The path to the thing to branch from.
* @param dstPath The path to the destination containing directory.
* @param name The name of the new branch.
*/
public void createBranch(final int version, final String srcPath, final String dstPath,
final String name)
@@ -474,20 +475,22 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.createBranch(version, srcPath, dstPath, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#removeNode(java.lang.String, java.lang.String)
/**
* Remove a node. Beware, the node can be a directory and
* this acts recursively.
* @param parent The path to the parent.
* @param name The name of the node to remove.
*/
public void removeNode(final String parent, final String name)
{
@@ -495,20 +498,23 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.remove(parent, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#rename(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
/**
* Rename a node.
* @param srcParent The path to the source parent.
* @param srcName The name of the source node.
* @param dstParent The path to the destination parent.
* @param dstName The name to give the renamed node.
*/
public void rename(final String srcParent, final String srcName, final String dstParent,
final String dstName)
@@ -517,15 +523,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.rename(srcParent, srcName, dstParent, dstName);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
@@ -540,20 +545,21 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.uncover(dirPath, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#getLatestVersionID(java.lang.String)
/**
* Get the Latest Version ID for a repository.
* @param repName The name of the repository.
* @return The Latest Version ID.
*/
public int getLatestVersionID(final String repName)
{
@@ -561,23 +567,24 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public int latestVersionID;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
latestVersionID = fSuperRepository.getLatestVersionID(repName);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.latestVersionID;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createSnapshot(java.util.List)
/**
* Create snapshots of a group of repositories.
* @param repositories A List of repository name.
* @return A List of the new version ids.
*/
public List<Integer> createSnapshot(final List<String> repositories)
{
@@ -585,23 +592,24 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Repositories is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public List<Integer> versionIDs;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
versionIDs = fSuperRepository.createSnapshot(repositories);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
return doit.versionIDs;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#createSnapshot(java.lang.String)
/**
* Snapshot a repository.
* @param repository The name of the repository.
* @return The id of the new version.
*/
public int createSnapshot(final String repository)
{
@@ -609,23 +617,25 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Repository is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public int versionID;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
versionID = fSuperRepository.createSnapshot(repository);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
return doit.versionID;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#lookup(int, java.lang.String)
/**
* Look up information about a node.
* @param version The version to look up.
* @param path The path to look up.
* @return A Descriptor.
*/
public AVMNodeDescriptor lookup(final int version, final String path)
{
@@ -633,18 +643,17 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Path is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public AVMNodeDescriptor descriptor;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
Lookup lookup = fSuperRepository.lookup(version, path);
descriptor = lookup.getCurrentNode().getDescriptor(lookup);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.descriptor;
}
@@ -661,23 +670,24 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public AVMNodeDescriptor child;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
child = fSuperRepository.lookup(dir, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.child;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#destroyRepository(java.lang.String)
/**
* Purge a repository. Permanently delete everything that
* is only referenced in that repository.
* @param name The name of the repository to purge.
*/
public void purgeRepository(final String name)
{
@@ -685,20 +695,21 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Name is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.purgeRepository(name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#purgeVersion(int, java.lang.String)
/**
* Purge a particular version from a repository.
* @param version The id of the version to purge.
* @param name The name of the repository.
*/
public void purgeVersion(final int version, final String name)
{
@@ -706,20 +717,22 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Name is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.purgeVersion(name, version);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#getIndirectionPath(java.lang.String)
/**
* Get the indirection path of a layered node.
* @param version The version to lookup.
* @param path The path to lookup.
* @return The indirection path (target) of the layered node.
*/
public String getIndirectionPath(final int version, final String path)
{
@@ -727,23 +740,24 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Path is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public String indirectionPath;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
indirectionPath = fSuperRepository.getIndirectionPath(version, path);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.indirectionPath;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMService#getRepositoryVersions(java.lang.String)
/**
* Get the extant version ids for a repository.
* @param name The name of the repository.
* @return A List of VersionDescriptors.
*/
public List<VersionDescriptor> getRepositoryVersions(final String name)
{
@@ -751,17 +765,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Name is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public List<VersionDescriptor> versions;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
versions = fSuperRepository.getRepositoryVersions(name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.versions;
}
@@ -780,23 +793,23 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public List<VersionDescriptor> versions;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
versions = fSuperRepository.getRepositoryVersions(name, from, to);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.versions;
}
/**
* Change what a layered directory points to.
* @param path The path to the layered directory.
*/
public void retargetLayeredDirectory(final String path, final String target)
{
@@ -804,15 +817,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.retargetLayeredDirectory(path, target);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
@@ -826,15 +838,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Path is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.makePrimary(path);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
@@ -844,17 +855,16 @@ public class AVMServiceImpl implements AVMService
*/
public List<RepositoryDescriptor> getRepositories()
{
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public List<RepositoryDescriptor> reps;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
reps = fSuperRepository.getRepositories();
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.reps;
}
@@ -866,17 +876,16 @@ public class AVMServiceImpl implements AVMService
*/
public RepositoryDescriptor getRepository(final String name)
{
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public RepositoryDescriptor desc;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
desc = fSuperRepository.getRepository(name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.desc;
}
@@ -893,17 +902,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Name is null.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public AVMNodeDescriptor root;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
root = fSuperRepository.getRepositoryRoot(version, name);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.root;
}
@@ -920,17 +928,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null descriptor.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public List<AVMNodeDescriptor> history;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
history = fSuperRepository.getHistory(desc, count);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.history;
}
@@ -947,15 +954,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null path.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
fSuperRepository.setOpacity(path, opacity);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
@@ -976,17 +982,16 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null node descriptor.");
}
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public AVMNodeDescriptor ancestor;
public void perform(Session session)
public void perform()
{
fSuperRepository.setSession(session);
ancestor = fSuperRepository.getCommonAncestor(left, right);
}
}
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.ancestor;
}

View File

@@ -0,0 +1,74 @@
/*
* 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 java.util.List;
/**
* DAO for ChildEntries.
* @author britt
*/
public interface ChildEntryDAO
{
/**
* Save an unsaved ChildEntry.
* @param entry The entry to save.
*/
public void save(ChildEntry entry);
/**
* Get an entry by name and parent.
* @param name The name of the child to find.
* @param parent The parent to look in.
* @return The ChildEntry or null if not foun.
*/
public ChildEntry getByNameParent(String name, DirectoryNode parent);
/**
* Get all the children of a given parent.
* @param parent The parent.
* @return A List of ChildEntries.
*/
public List<ChildEntry> getByParent(DirectoryNode parent);
/**
* Get the entry for a given child in a given parent.
* @param parent The parent.
* @param child The child.
* @return The ChildEntry or null.
*/
public ChildEntry getByParentChild(DirectoryNode parent, AVMNode child);
/**
* Update a dirty ChildEntry.
* @param child The dirty entry.
*/
public void update(ChildEntry child);
/**
* Delete one.
* @param child The one to delete.
*/
public void delete(ChildEntry child);
/**
* Delete all children of the given parent.
* @param parent The parent.
*/
public void deleteByParent(AVMNode parent);
}

View File

@@ -0,0 +1,60 @@
/*
* 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 java.util.List;
/**
* DAO for DeletedChildren.
* @author britt
*/
public interface DeletedChildDAO
{
/**
* Save an unsaved DeletedChild.
* @param child The DeletedChild to be saved.
*/
public void save(DeletedChild child);
/**
* Delete one.
* @param child The one to delete.
*/
public void delete(DeletedChild child);
/**
* Delete all belonging to the given parent.
* @param parent The parent.
*/
public void deleteByParent(AVMNode parent);
/**
* Get by name and parent.
* @param name The name of the deleted entry.
* @param parent The parent.
* @return A DeletedChild or null if not found.
*/
public DeletedChild getByNameParent(String name, LayeredDirectoryNode parent);
/**
* Get all the deleted children of a given parent.
* @param parent The parent.
* @return A List of DeletedChildren.
*/
public List<DeletedChild> getByParent(LayeredDirectoryNode parent);
}

View File

@@ -24,7 +24,7 @@ import java.util.SortedMap;
* The interface for Directory Nodes.
* @author britt
*/
interface DirectoryNode extends AVMNode
public interface DirectoryNode extends AVMNode
{
/**
* Does this directory directly contain the specified node.

View File

@@ -19,9 +19,6 @@ package org.alfresco.repo.avm;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
/**
* Base class for Directories.
* @author britt
@@ -52,14 +49,9 @@ abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode
* @param write Whether the child should be looked up for writing.
* @return The ChildEntry or null if not found.
*/
@SuppressWarnings("unchecked")
protected ChildEntry getChild(String name, boolean write)
{
// TODO This may be very Dangerous!
Session sess = SuperRepository.GetInstance().getSession();
ChildEntry entry = (ChildEntry)sess.get(ChildEntryImpl.class, new ChildEntryImpl(name, this, null));
// (write && getIsNew()) ? LockMode.UPGRADE : LockMode.READ);
return entry;
return AVMContext.fgInstance.fChildEntryDAO.getByNameParent(name, this);
}
/**
@@ -68,16 +60,9 @@ abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode
* exposed through the interface.
* @return A List of ChildEntries.
*/
@SuppressWarnings("unchecked")
public List<ChildEntry> getChildren()
{
Session sess = SuperRepository.GetInstance().getSession();
Query query = sess.getNamedQuery("ChildEntry.ByParent");
query.setEntity("parent", this);
query.setCacheable(true);
query.setCacheRegion("ChildEntry.ByParent");
List<ChildEntry> found = (List<ChildEntry>)query.list();
return found;
return AVMContext.fgInstance.fChildEntryDAO.getByParent(this);
}
/**
@@ -85,20 +70,8 @@ abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode
* @param child The child node to look for.
* @return The ChildEntry or null if not found.
*/
@SuppressWarnings("unchecked")
protected ChildEntry getChild(AVMNode child)
{
Session sess = SuperRepository.GetInstance().getSession();
Query query = sess.getNamedQuery("ChildEntry.ByParentChild");
query.setEntity("parent", this);
query.setEntity("child", child);
query.setCacheable(true);
query.setCacheRegion("ChildEntry.ByParentChild");
List<ChildEntry> found = (List<ChildEntry>)query.list();
if (found.size() == 0)
{
return null;
}
return found.get(0);
return AVMContext.fgInstance.fChildEntryDAO.getByParentChild(this, child);
}
}

View File

@@ -24,7 +24,7 @@ import java.io.RandomAccessFile;
* Interface for file content. FileContent can be shared between files.
* @author britt
*/
interface FileContent
public interface FileContent
{
/**
* Get the number of files that refer to this content.

View File

@@ -0,0 +1,37 @@
/*
* 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;
/**
* DAO for FileContent objects.
* @author britt
*/
public interface FileContentDAO
{
/**
* Save one.
* @param content To be saved.
*/
public void save(FileContent content);
/**
* Delete one.
* @param content To be deleted.
*/
public void delete(FileContent content);
}

View File

@@ -89,7 +89,7 @@ class FileContentImpl implements FileContent, Serializable
{
throw new AVMException("File data error.", ie);
}
SuperRepository.GetInstance().getSession().save(this);
AVMContext.fgInstance.fFileContentDAO.save(this);
}
/**
@@ -119,7 +119,7 @@ class FileContentImpl implements FileContent, Serializable
{
throw new AVMException("I/O Error.", ie);
}
SuperRepository.GetInstance().getSession().save(this);
AVMContext.fgInstance.fFileContentDAO.save(this);
}
/**
@@ -150,7 +150,7 @@ class FileContentImpl implements FileContent, Serializable
{
throw new AVMException("I/O failure in Copy on Write.", ie);
}
SuperRepository.GetInstance().getSession().save(this);
AVMContext.fgInstance.fFileContentDAO.save(this);
}
/**

View File

@@ -21,7 +21,7 @@ package org.alfresco.repo.avm;
* Interface for the ancestor-descendent relationship.
* @author britt
*/
interface HistoryLink
public interface HistoryLink
{
/**
* Set the ancestor part of this.

View File

@@ -0,0 +1,53 @@
/*
* 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 java.util.List;
/**
* DAO for history links.
* @author britt
*/
public interface HistoryLinkDAO
{
/**
* Save and unsaved HistoryLink.
* @param link
*/
public void save(HistoryLink link);
/**
* Get the history link with the given descendent.
* @param descendent The descendent.
* @return The HistoryLink or null if not found.
*/
public HistoryLink getByDescendent(AVMNode descendent);
/**
* Get all the descendents of a node.
* @param ancestor The ancestor node.
* @return A List of AVMNode descendents.
*/
public List<HistoryLink> getByAncestor(AVMNode ancestor);
/**
* Delete a HistoryLink
* @param link The link to delete.
*/
public void delete(HistoryLink link);
}

View File

@@ -0,0 +1,40 @@
/*
* 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;
/**
* DAO for Issuers.
* @author britt
*/
public interface IssuerDAO
{
/**
* Get the node Issuer value.
*/
public Long getNodeIssuerValue();
/**
* Get the content Issuer value.
*/
public Long getContentIssuerValue();
/**
* Get the layer Issuer value.
*/
public Long getLayerIssuerValue();
}

View File

@@ -6,7 +6,7 @@ import java.util.List;
* Interface for Layered Directories.
* @author britt
*/
interface LayeredDirectoryNode extends DirectoryNode, Layered
public interface LayeredDirectoryNode extends DirectoryNode, Layered
{
/**
* Does this node have a primary indirection.

View File

@@ -17,16 +17,12 @@
package org.alfresco.repo.avm;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.hibernate.Query;
import org.hibernate.Session;
/**
* A layered directory node. A layered directory node points at
* an underlying directory, which may or may not exist. The visible
@@ -78,7 +74,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fIndirection = indirection;
fPrimaryIndirection = true;
fOpacity = false;
repos.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -91,24 +87,23 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
Repository repos)
{
super(repos.getSuperRepository().issueID(), repos);
Session sess = repos.getSuperRepository().getSession();
fIndirection = other.getUnderlying();
fPrimaryIndirection = other.getPrimaryIndirection();
fLayerID = -1;
fOpacity = false;
sess.save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
for (ChildEntry child : other.getChildren())
{
ChildEntryImpl newChild = new ChildEntryImpl(child.getName(),
this,
child.getChild());
repos.getSuperRepository().getSession().save(newChild);
AVMContext.fgInstance.fChildEntryDAO.save(newChild);
}
for (DeletedChild dc : other.getDeleted())
{
DeletedChild newDel = new DeletedChildImpl(dc.getName(),
this);
sess.save(newDel);
AVMContext.fgInstance.fDeletedChildDAO.save(newDel);
}
}
@@ -130,8 +125,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fPrimaryIndirection = false;
fLayerID = -1;
fOpacity = false;
Session sess = repos.getSuperRepository().getSession();
sess.save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
if (copyContents)
{
for (ChildEntry child : other.getChildren())
@@ -139,7 +133,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
ChildEntryImpl newChild = new ChildEntryImpl(child.getName(),
this,
child.getChild());
sess.save(newChild);
AVMContext.fgInstance.fChildEntryDAO.save(newChild);
}
}
}
@@ -162,7 +156,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fPrimaryIndirection = true;
fLayerID = -1;
fOpacity = false;
repo.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -266,22 +260,21 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
*/
public void putChild(String name, AVMNode node)
{
Session sess = SuperRepository.GetInstance().getSession();
// sess.lock(this, LockMode.UPGRADE);
ChildEntry entry = new ChildEntryImpl(name, this, node);
ChildEntry existing = (ChildEntry)sess.get(ChildEntryImpl.class, (Serializable)entry);
ChildEntry existing = getChild(name, true);
if (existing != null)
{
existing.setChild(node);
AVMContext.fgInstance.fChildEntryDAO.update(existing);
}
else
{
sess.save(entry);
ChildEntry entry = new ChildEntryImpl(name, this, node);
AVMContext.fgInstance.fChildEntryDAO.save(entry);
}
DeletedChild dc = getDeleted("name");
DeletedChild dc = getDeleted(name);
if (dc != null)
{
sess.delete(dc);
AVMContext.fgInstance.fDeletedChildDAO.delete(dc);
}
}
@@ -499,11 +492,11 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
ChildEntry entry = getChild(name, true);
if (entry != null)
{
SuperRepository.GetInstance().getSession().delete(entry);
AVMContext.fgInstance.fChildEntryDAO.delete(entry);
}
DeletedChild dc = new DeletedChildImpl(name,
this);
SuperRepository.GetInstance().getSession().save(dc);
AVMContext.fgInstance.fDeletedChildDAO.save(dc);
}
/**
@@ -564,7 +557,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
DeletedChild dc = getDeleted(name);
if (dc != null)
{
SuperRepository.GetInstance().getSession().delete(dc);
AVMContext.fgInstance.fDeletedChildDAO.delete(dc);
}
}
@@ -687,31 +680,16 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
@SuppressWarnings("unchecked")
private DeletedChild getDeleted(String name)
{
Query query = SuperRepository.GetInstance().getSession().getNamedQuery("DeletedChild.ByNameParent");
query.setString("name", name);
query.setEntity("parent", this);
query.setCacheable(true);
query.setCacheRegion("DeletedChild.ByNameParent");
List<DeletedChild> dc = (List<DeletedChild>)query.list();
if (dc.size() == 0)
{
return null;
}
return dc.get(0);
return AVMContext.fgInstance.fDeletedChildDAO.getByNameParent(name, this);
}
/**
* Get all the deleted entries in this directory.
* @return A List of DeletedEntry objects.
*/
@SuppressWarnings("unchecked")
public List<DeletedChild> getDeleted()
{
Query query = SuperRepository.GetInstance().getSession().getNamedQuery("DeletedChild.ByParent");
query.setEntity("parent", this);
query.setCacheable(true);
query.setCacheRegion("DeletedChild.ByParent");
return (List<DeletedChild>)query.list();
return AVMContext.fgInstance.fDeletedChildDAO.getByParent(this);
}
/**

View File

@@ -47,7 +47,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
{
super(repo.getSuperRepository().issueID(), repo);
fIndirection = other.getIndirection();
repo.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -59,7 +59,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
{
super(repo.getSuperRepository().issueID(), repo);
fIndirection = indirection;
repo.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**

View File

@@ -185,7 +185,8 @@ class Lookup
{
// Inform the repository of a new root.
fRepository.setNewRoot((DirectoryNode)node);
SuperRepository.GetInstance().getSession().flush();
AVMContext.fgInstance.fRepositoryDAO.update(fRepository);
// TODO More Hibernate weirdness to figure out: SuperRepository.GetInstance().getSession().flush();
return;
}
// Not the root. Check if we are the top layer and insert this into it's parent.
@@ -194,7 +195,7 @@ class Lookup
fTopLayer = (LayeredDirectoryNode)node;
}
((DirectoryNode)fComponents.get(fPosition - 1).getNode()).putChild(name, node);
SuperRepository.GetInstance().getSession().flush();
// TODO More Hibernate hijinx: SuperRepository.GetInstance().getSession().flush();
}
}

View File

@@ -21,7 +21,7 @@ package org.alfresco.repo.avm;
* This is the interface for the merged from - to relationship.
* @author britt
*/
interface MergeLink
public interface MergeLink
{
/**
* Set the from part.

View File

@@ -0,0 +1,53 @@
/*
* 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 java.util.List;
/**
* DAO for MergeLinks.
* @author britt
*/
public interface MergeLinkDAO
{
/**
* Save an unsaved MergeLink.
* @param link The link to save.
*/
public void save(MergeLink link);
/**
* Get a link from the merged to node.
* @param to The node merged to.
* @return An AVMNode or null if not found.
*/
public MergeLink getByTo(AVMNode to);
/**
* Get all the link that the given node was merged to.
* @param from The node that was merged from
* @return A List of MergeLinks.
*/
public List<MergeLink> getByFrom(AVMNode from);
/**
* Delete a link.
* @param link The link to delete.
*/
public void delete(MergeLink link);
}

View File

@@ -19,11 +19,6 @@ package org.alfresco.repo.avm;
import java.util.List;
import org.alfresco.repo.avm.hibernate.HibernateTxn;
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
import org.hibernate.Query;
import org.hibernate.Session;
/**
* This is the background thread for reaping no longer referenced nodes
* in the AVM repository. These orphans arise from purge operations.
@@ -34,7 +29,7 @@ public class OrphanReaper implements Runnable
/**
* The HibernateTxn instance.
*/
private HibernateTxn fTransaction;
private RetryingTransaction fTransaction;
/**
* Inactive base sleep interval.
@@ -112,7 +107,7 @@ public class OrphanReaper implements Runnable
* Set the Hibernate Transaction Wrapper.
* @param transaction
*/
public void setHibernateTxn(HibernateTxn transaction)
public void setRetryingTransaction(RetryingTransaction transaction)
{
fTransaction = transaction;
}
@@ -184,17 +179,13 @@ public class OrphanReaper implements Runnable
/**
* Do a batch of cleanup work.
*/
@SuppressWarnings("unchecked")
public void doBatch()
{
class HTxnCallback implements HibernateTxnCallback
class TxnCallback implements RetryingTransactionCallback
{
public void perform(Session session)
public void perform()
{
SuperRepository.GetInstance().setSession(session);
Query query = session.getNamedQuery("FindOrphans");
query.setMaxResults(fBatchSize);
List<AVMNode> nodes = (List<AVMNode>)query.list();
List<AVMNode> nodes = AVMContext.fgInstance.fAVMNodeDAO.getOrphans(fBatchSize);
if (nodes.size() == 0)
{
fActive = false;
@@ -204,28 +195,22 @@ public class OrphanReaper implements Runnable
for (AVMNode node : nodes)
{
// Save away the ancestor and merged from fields from this node.
query = session.createQuery("from HistoryLinkImpl hl where hl.descendent = :desc");
query.setEntity("desc", node);
HistoryLink hlink = (HistoryLink)query.uniqueResult();
HistoryLink hlink = AVMContext.fgInstance.fHistoryLinkDAO.getByDescendent(node);
AVMNode ancestor = null;
if (hlink != null)
{
ancestor = hlink.getAncestor();
session.delete(hlink);
AVMContext.fgInstance.fHistoryLinkDAO.delete(hlink);
}
query = session.createQuery("from MergeLinkImpl ml where ml.mto = :to");
query.setEntity("to", node);
MergeLink mlink = (MergeLink)query.uniqueResult();
MergeLink mlink = AVMContext.fgInstance.fMergeLinkDAO.getByTo(node);
AVMNode mergedFrom = null;
if (mlink != null)
{
mergedFrom = mlink.getMfrom();
session.delete(mlink);
AVMContext.fgInstance.fMergeLinkDAO.delete(mlink);
}
// Get all the nodes that have this node as ancestor.
query = session.getNamedQuery("HistoryLink.ByAncestor");
query.setEntity("node", node);
List<HistoryLink> links = (List<HistoryLink>)query.list();
List<HistoryLink> links = AVMContext.fgInstance.fHistoryLinkDAO.getByAncestor(node);
for (HistoryLink link : links)
{
AVMNode desc = link.getDescendent();
@@ -234,56 +219,51 @@ public class OrphanReaper implements Runnable
{
desc.setMergedFrom(mergedFrom);
}
session.delete(link);
AVMContext.fgInstance.fHistoryLinkDAO.delete(link);
}
// Get all the nodes that have this node as mergedFrom
query = session.getNamedQuery("MergeLink.ByFrom");
query.setEntity("merged", node);
List<MergeLink> mlinks = (List<MergeLink>)query.list();
List<MergeLink> mlinks = AVMContext.fgInstance.fMergeLinkDAO.getByFrom(node);
for (MergeLink link : mlinks)
{
link.getMto().setMergedFrom(ancestor);
session.delete(link);
AVMContext.fgInstance.fMergeLinkDAO.delete(link);
}
session.flush();
node = AVMNodeUnwrapper.Unwrap(node);
// TODO What to do about such Hibernate wackiness: session.flush();
// TODO More of the same: node = AVMNodeUnwrapper.Unwrap(node);
// Extra work for directories.
if (node instanceof DirectoryNode)
if (node.getType() == AVMNodeType.PLAIN_DIRECTORY ||
node.getType() == AVMNodeType.LAYERED_DIRECTORY)
{
// First get rid of all child entries for the node.
Query delete = session.getNamedQuery("ChildEntry.DeleteByParent");
delete.setEntity("parent", node);
delete.executeUpdate();
if (node instanceof LayeredDirectoryNode)
AVMContext.fgInstance.fChildEntryDAO.deleteByParent(node);
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY)
{
// More special work for layered directories.
delete = session.getNamedQuery("DeletedChild.DeleteByParent");
delete.setEntity("parent", node);
delete.executeUpdate();
AVMContext.fgInstance.fDeletedChildDAO.deleteByParent(node);
}
session.delete(node);
AVMContext.fgInstance.fAVMNodeDAO.delete(node);
}
else if (node instanceof PlainFileNode)
{
session.delete(node);
AVMContext.fgInstance.fAVMNodeDAO.delete(node);
// FileContent should be purged if nobody else references it.
FileContent content = ((PlainFileNode)node).getContent();
if (content.getRefCount() == 1)
{
content.delete();
session.delete(content);
AVMContext.fgInstance.fFileContentDAO.delete(content);
}
}
else
{
session.delete(node);
AVMContext.fgInstance.fAVMNodeDAO.delete(node);
}
}
}
}
try
{
HTxnCallback doit = new HTxnCallback();
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
catch (Exception e)

View File

@@ -17,14 +17,11 @@
package org.alfresco.repo.avm;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.hibernate.Session;
/**
* A plain directory. No monkey tricks except for possiblyCopy.
* @author britt
@@ -40,7 +37,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
public PlainDirectoryNodeImpl(Repository repo)
{
super(repo.getSuperRepository().issueID(), repo);
repo.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -60,16 +57,15 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
Repository repos)
{
super(repos.getSuperRepository().issueID(), repos);
Session sess = repos.getSuperRepository().getSession();
sess.save(this);
sess.flush();
AVMContext.fgInstance.fAVMNodeDAO.save(this);
// TODO Something about this. sess.flush();
for (ChildEntry child : other.getChildren())
{
ChildEntry newChild = new ChildEntryImpl(child.getName(),
this,
child.getChild());
sess.save(newChild);
sess.flush();
AVMContext.fgInstance.fChildEntryDAO.save(newChild);
// TODO Something about this: sess.flush();
}
}
@@ -172,7 +168,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
ChildEntry entry = getChild(name, true);
if (entry != null)
{
SuperRepository.GetInstance().getSession().delete(entry);
AVMContext.fgInstance.fChildEntryDAO.delete(entry);
}
}
@@ -183,18 +179,16 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
*/
public void putChild(String name, AVMNode node)
{
Session sess = SuperRepository.GetInstance().getSession();
// sess.lock(this, LockMode.UPGRADE);
ChildEntry entry = new ChildEntryImpl(name, this, node);
ChildEntry existing = (ChildEntry)sess.get(ChildEntryImpl.class, (Serializable)entry);
ChildEntry existing = AVMContext.fgInstance.fChildEntryDAO.getByNameParent(name, this);
if (existing != null)
{
existing.setChild(node);
sess.flush(); // TODO Should we or shouldn't we?
AVMContext.fgInstance.fChildEntryDAO.update(existing);
}
else
{
sess.save(entry);
ChildEntry entry = new ChildEntryImpl(name, this, node);
AVMContext.fgInstance.fChildEntryDAO.save(entry);
}
}

View File

@@ -49,7 +49,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
{
super(repos.getSuperRepository().issueID(), repos);
fContent = new FileContentImpl(SuperRepository.GetInstance().issueContentID());
repos.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -61,7 +61,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
{
super(repos.getSuperRepository().issueID(), repos);
fContent = new FileContentImpl(SuperRepository.GetInstance().issueContentID(), content);
repos.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -75,7 +75,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
super(repos.getSuperRepository().issueID(), repos);
fContent = other.getContent();
fContent.setRefCount(fContent.getRefCount() + 1);
repos.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**
@@ -90,7 +90,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
super(repos.getSuperRepository().issueID(), repos);
fContent = content;
fContent.setRefCount(fContent.getRefCount() + 1);
repos.getSuperRepository().getSession().save(this);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
}
/**

View File

@@ -29,7 +29,7 @@ import java.util.SortedMap;
* and layering operations.
* @author britt
*/
interface Repository
public interface Repository
{
/**
* This returns the next version in this repository that will be snapshotted.

View File

@@ -0,0 +1,58 @@
/*
* 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 java.util.List;
/**
* DAO for Repositories.
* @author britt
*/
public interface RepositoryDAO
{
/**
* Save a repository, never before saved.
* @param rep The repository
*/
public void save(Repository rep);
/**
* Delete the given Repository.
* @param rep The Repository.
*/
public void delete(Repository rep);
/**
* Get all repositories.
* @return A List of all the Repositories.
*/
public List<Repository> getAll();
/**
* Get a repository by name.
* @param name The name of the repository.
* @return The repository or null if not found.
*/
public Repository getByName(String name);
/**
* Update the given Repository record.
* @param rep The dirty Repository.
*/
public void update(Repository rep);
}

View File

@@ -37,7 +37,7 @@ import org.hibernate.Query;
* operation.
* @author britt
*/
class RepositoryImpl implements Repository, Serializable
public class RepositoryImpl implements Repository, Serializable
{
static final long serialVersionUID = -1485972568675732904L;
@@ -98,20 +98,20 @@ class RepositoryImpl implements Repository, Serializable
fRoot = null;
fCreator = "britt";
fCreateDate = System.currentTimeMillis();
fSuper.getSession().save(this);
AVMContext.fgInstance.fRepositoryDAO.save(this);
// Make up the initial version record and save.
long time = System.currentTimeMillis();
fRoot = new PlainDirectoryNodeImpl(this);
fRoot.setIsNew(false);
fRoot.setIsRoot(true);
fSuper.getSession().save(fRoot);
AVMContext.fgInstance.fAVMNodeDAO.save(fRoot);
VersionRoot versionRoot = new VersionRootImpl(this,
fRoot,
fNextVersionID,
time,
"britt");
fNextVersionID++;
fSuper.getSession().save(versionRoot);
AVMContext.fgInstance.fVersionRootDAO.save(versionRoot);
}
/**
@@ -137,20 +137,21 @@ class RepositoryImpl implements Repository, Serializable
throw new AVMExistsException("Already snapshotted.");
}
// Clear out the new nodes.
Query query =
fSuper.getSession().getNamedQuery("AVMNode.ByNewInRepo");
query.setEntity("repo", this);
for (AVMNode newNode : (List<AVMNode>)query.list())
AVMNodeDAO anDAO = AVMContext.fgInstance.fAVMNodeDAO;
for (AVMNode newNode : anDAO.getNewInRepo(this))
{
newNode.setIsNew(false);
// anDAO.update(newNode);
}
// TODO: This is a grotesque hack to deal with hibernate.
anDAO.flush();
// Make up a new version record.
VersionRoot versionRoot = new VersionRootImpl(this,
fRoot,
fNextVersionID,
System.currentTimeMillis(),
"britt");
fSuper.getSession().save(versionRoot);
AVMContext.fgInstance.fVersionRootDAO.save(versionRoot);
// Increment the version id.
fNextVersionID++;
return fNextVersionID - 1;
@@ -438,9 +439,7 @@ class RepositoryImpl implements Repository, Serializable
@SuppressWarnings("unchecked")
public List<VersionDescriptor> getVersions()
{
Query query = fSuper.getSession().createQuery("from VersionRootImpl v where v.repository = :rep order by v.versionID");
query.setEntity("rep", this);
List<VersionRoot> versions = (List<VersionRoot>)query.list();
List<VersionRoot> versions = AVMContext.fgInstance.fVersionRootDAO.getAllInRepository(this);
List<VersionDescriptor> descs = new ArrayList<VersionDescriptor>();
for (VersionRoot vr : versions)
{
@@ -464,32 +463,7 @@ class RepositoryImpl implements Repository, Serializable
@SuppressWarnings("unchecked")
public List<VersionDescriptor> getVersions(Date from, Date to)
{
Query query;
if (from == null)
{
query =
fSuper.getSession().createQuery("from VersionRootImpl vr where vr.createDate <= :to " +
"order by vr.versionID");
query.setLong("to", to.getTime());
}
else if (to == null)
{
query =
fSuper.getSession().createQuery("from VersionRootImpl vr " +
"where vr.createDate >= :from " +
"order by vr.versionID");
query.setLong("from", from.getTime());
}
else
{
query =
fSuper.getSession().createQuery("from VersionRootImpl vr "+
"where vr.createDate between :from and :to " +
"order by vr.versionID");
query.setLong("from", from.getTime());
query.setLong("to", to.getTime());
}
List<VersionRoot> versions = (List<VersionRoot>)query.list();
List<VersionRoot> versions = AVMContext.fgInstance.fVersionRootDAO.getByDates(this, from, to);
List<VersionDescriptor> descs = new ArrayList<VersionDescriptor>();
for (VersionRoot vr : versions)
{
@@ -537,17 +511,13 @@ class RepositoryImpl implements Repository, Serializable
// Versions less than 0 mean get current.
if (version < 0)
{
dir = (DirectoryNode)AVMNodeUnwrapper.Unwrap(fRoot);
dir = fRoot; // TODO How to factor out this kind of Hibernate goofiness.
// (DirectoryNode)AVMNodeUnwrapper.Unwrap(fRoot);
}
else
{
Query query =
fSuper.getSession().getNamedQuery("VersionRoot.GetVersionRoot");
query.setEntity("rep", this);
query.setInteger("version", version);
dir = (DirectoryNode)AVMNodeUnwrapper.Unwrap((AVMNode)query.uniqueResult());
dir = AVMContext.fgInstance.fAVMNodeDAO.getRepositoryRoot(this, version);
}
// fSuper.getSession().lock(dir, LockMode.READ);
// Add an entry for the root.
result.add(dir, "", write);
dir = (DirectoryNode)result.getCurrentNode();
@@ -599,15 +569,7 @@ class RepositoryImpl implements Repository, Serializable
}
else
{
Query query =
fSuper.getSession().getNamedQuery("VersionRoot.GetVersionRoot");
query.setEntity("rep", this);
query.setInteger("version", version);
root = (AVMNode)query.uniqueResult();
if (root == null)
{
throw new AVMException("Invalid version: " + version);
}
root = AVMContext.fgInstance.fAVMNodeDAO.getRepositoryRoot(this, version);
}
return root.getDescriptor("main:", "", null);
}
@@ -800,28 +762,22 @@ class RepositoryImpl implements Repository, Serializable
{
throw new AVMBadArgumentException("Cannot purge initial version");
}
Query query = fSuper.getSession().getNamedQuery("VersionRoot.VersionByID");
query.setEntity("rep", this);
query.setInteger("version", version);
VersionRoot vRoot = (VersionRoot)query.uniqueResult();
AVMNode root = vRoot.getRoot();
if (root == null)
VersionRoot vRoot = AVMContext.fgInstance.fVersionRootDAO.getByVersionID(this, version);
if (vRoot == null)
{
throw new AVMNotFoundException("Version not found.");
}
AVMNode root = vRoot.getRoot();
root.setIsRoot(false);
fSuper.getSession().delete(vRoot);
AVMContext.fgInstance.fAVMNodeDAO.update(root);
AVMContext.fgInstance.fVersionRootDAO.delete(vRoot);
if (root.equals(fRoot))
{
// We have to set a new current root.
fSuper.getSession().flush();
query = fSuper.getSession().createQuery("select max(vr.versionID) from VersionRootImpl vr");
int latest = (Integer)query.uniqueResult();
query = fSuper.getSession().getNamedQuery("VersionRoot.VersionByID");
query.setEntity("rep", this);
query.setInteger("version", latest);
vRoot = (VersionRoot)query.uniqueResult();
// TODO More hibernate goofiness to compensate for: fSuper.getSession().flush();
vRoot = AVMContext.fgInstance.fVersionRootDAO.getMaxVersion(this);
fRoot = vRoot.getRoot();
AVMContext.fgInstance.fRepositoryDAO.update(this);
}
}

View File

@@ -0,0 +1,15 @@
package org.alfresco.repo.avm;
public interface RetryingTransaction
{
/**
* Perform a set of operations under a single transaction.
* Keep trying if the operation fails because of a concurrency issue.
* @param callback The worker.
* @param write Whether this is a write operation.
*/
public void perform(RetryingTransactionCallback callback, boolean write);
}

View File

@@ -15,19 +15,16 @@
* License.
*/
package org.alfresco.repo.avm.hibernate;
import org.hibernate.Session;
package org.alfresco.repo.avm;
/**
* Worker object for Hibernate Transactions.
* Worker object for AVM Retrying Transactions.
* @author britt
*/
public interface HibernateTxnCallback
public interface RetryingTransactionCallback
{
/**
* Do our work.
* @param sess The Hibernate session.
*/
public void perform(Session sess);
public void perform();
}

View File

@@ -27,10 +27,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
/**
* This or Repository are
* the implementors of the operations specified by AVMService.
@@ -43,11 +39,6 @@ class SuperRepository
*/
private static SuperRepository fgInstance;
/**
* The Hibernate Session associated with the current operation.
*/
private ThreadLocal<Session> fSession;
/**
* The current lookup count.
*/
@@ -89,21 +80,10 @@ class SuperRepository
fNodeIssuer = nodeIssuer;
fContentIssuer = contentIssuer;
fLayerIssuer = layerIssuer;
fSession = new ThreadLocal<Session>();
fLookupCount = new ThreadLocal<Integer>();
fgInstance = this;
}
/**
* Set the (thread local) Hibernate session.
* @param session The Session to set.
*/
public void setSession(Session session)
{
fSession.set(session);
fLookupCount.set(0);
}
/**
* Create a file.
* @param path The path to the containing directory.
@@ -485,25 +465,24 @@ class SuperRepository
// fSession.get().lock(rep, LockMode.UPGRADE);
AVMNode root = rep.getRoot();
root.setIsRoot(false);
Query query = fSession.get().createQuery("from VersionRootImpl vr where vr.repository = :rep");
query.setEntity("rep", rep);
List<VersionRoot> vRoots = (List<VersionRoot>)query.list();
// AVMContext.fgInstance.fAVMNodeDAO.update(root);
VersionRootDAO vrDAO = AVMContext.fgInstance.fVersionRootDAO;
List<VersionRoot> vRoots = vrDAO.getAllInRepository(rep);
for (VersionRoot vr : vRoots)
{
AVMNode node = vr.getRoot();
node.setIsRoot(false);
fSession.get().delete(vr);
// AVMContext.fgInstance.fAVMNodeDAO.update(node);
vrDAO.delete(vr);
}
query = fSession.get().createQuery("from AVMNodeImpl an where an.repository = :rep");
query.setEntity("rep", rep);
Iterator<AVMNode> iter = (Iterator<AVMNode>)query.iterate();
Iterator<AVMNode> iter = AVMContext.fgInstance.fAVMNodeDAO.getByRepository(rep);
while (iter.hasNext())
{
AVMNode node = iter.next();
node.setRepository(null);
AVMContext.fgInstance.fAVMNodeDAO.update(node);
}
fSession.get().flush();
fSession.get().delete(rep);
AVMContext.fgInstance.fRepositoryDAO.delete(rep);
}
/**
@@ -541,7 +520,7 @@ class SuperRepository
public InputStream getInputStream(AVMNodeDescriptor desc)
{
fLookupCount.set(1);
AVMNode node = (AVMNode)fSession.get().get(AVMNodeImpl.class, desc.getId());
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(desc.getId());
if (node == null)
{
throw new AVMNotFoundException("Not found.");
@@ -578,7 +557,7 @@ class SuperRepository
public SortedMap<String, AVMNodeDescriptor> getListing(AVMNodeDescriptor dir)
{
fLookupCount.set(1);
AVMNode node = (AVMNode)fSession.get().get(AVMNodeImpl.class, dir.getId());
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(dir.getId());
if (node.getType() != AVMNodeType.LAYERED_DIRECTORY &&
node.getType() != AVMNodeType.PLAIN_DIRECTORY)
{
@@ -595,8 +574,7 @@ class SuperRepository
@SuppressWarnings("unchecked")
public List<RepositoryDescriptor> getRepositories()
{
Query query = fSession.get().createQuery("from RepositoryImpl r");
List<Repository> l = (List<Repository>)query.list();
List<Repository> l = AVMContext.fgInstance.fRepositoryDAO.getAll();
List<RepositoryDescriptor> result = new ArrayList<RepositoryDescriptor>();
for (Repository rep : l)
{
@@ -670,15 +648,6 @@ class SuperRepository
return fLayerIssuer.issue();
}
/**
* Get the (thread local) Hibernate session.
* @return The Session.
*/
public Session getSession()
{
return fSession.get();
}
/**
* Get the indirection path for a layered node.
* @param version The version to look under.
@@ -714,17 +683,11 @@ class SuperRepository
*/
private Repository getRepositoryByName(String name, boolean write)
{
Repository rep = (Repository)fSession.get().get(RepositoryImpl.class,
name); /* LockMode.READ ,
write ? LockMode.UPGRADE : LockMode.READ); */
Repository rep = AVMContext.fgInstance.fRepositoryDAO.getByName(name);
if (rep == null)
{
throw new AVMNotFoundException("Repository not found: " + name);
}
// if (write && !rep.getRoot().getIsNew())
// {
// fSession.get().lock(rep, LockMode.UPGRADE);
// }
return rep;
}
@@ -744,7 +707,8 @@ class SuperRepository
// fSession.get().lock(rep, LockMode.READ);
return rep.getRoot(version);
}
// TODO Fix this awful mess regarding cycle detection.
/**
* Lookup a node.
* @param version The version to look under.
@@ -753,15 +717,27 @@ class SuperRepository
*/
public Lookup lookup(int version, String path)
{
fLookupCount.set(fLookupCount.get() + 1);
if (fLookupCount.get() > 10)
Integer count = fLookupCount.get();
if (count == null)
{
fLookupCount.set(1);
}
else
{
fLookupCount.set(count + 1);
}
if (fLookupCount.get() > 50)
{
throw new AVMCycleException("Cycle in lookup.");
}
String [] pathParts = SplitPath(path);
Repository rep = getRepositoryByName(pathParts[0], false);
// fSession.get().lock(rep, LockMode.READ);
return rep.lookup(version, pathParts[1], false);
Lookup result = rep.lookup(version, pathParts[1], false);
if (count == null)
{
fLookupCount.set(null);
}
return result;
}
/**
@@ -773,7 +749,7 @@ class SuperRepository
public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name)
{
fLookupCount.set(0);
AVMNode node = (AVMNode)fSession.get().get(AVMNodeImpl.class, dir.getId());
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(dir.getId());
if (node == null)
{
throw new AVMNotFoundException("Not found: " + dir.getId());
@@ -865,7 +841,7 @@ class SuperRepository
*/
public List<AVMNodeDescriptor> getHistory(AVMNodeDescriptor desc, int count)
{
AVMNode node = (AVMNode)fSession.get().get(AVMNodeImpl.class, desc.getId());
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(desc.getId());
if (node == null)
{
throw new AVMNotFoundException("Not found.");
@@ -926,8 +902,8 @@ class SuperRepository
public AVMNodeDescriptor getCommonAncestor(AVMNodeDescriptor left,
AVMNodeDescriptor right)
{
AVMNode lNode = (AVMNode)fSession.get().get(AVMNodeImpl.class, left.getId());
AVMNode rNode = (AVMNode)fSession.get().get(AVMNodeImpl.class, right.getId());
AVMNode lNode = AVMContext.fgInstance.fAVMNodeDAO.getByID(left.getId());
AVMNode rNode = AVMContext.fgInstance.fAVMNodeDAO.getByID(right.getId());
if (lNode == null || rNode == null)
{
throw new AVMNotFoundException("Node not found.");

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;
import java.util.Date;
import java.util.List;
/**
* DAO for VersionRoot objects.
* @author britt
*/
public interface VersionRootDAO
{
/**
* Save an unsaved VersionRoot.
* @param vr The VersionRoot to save.
*/
public void save(VersionRoot vr);
/**
* Delete a VersionRoot.
* @param vr The VersionRoot to delete.
*/
public void delete(VersionRoot vr);
/**
* Get all the version roots in a given repository.
* @param rep The repository.
* @return A List of VersionRoots. In id order.
*/
public List<VersionRoot> getAllInRepository(Repository rep);
/**
* Get the VersionRoot corresponding to the given id.
* @param rep The repository
* @param id The version id.
* @return The VersionRoot or null if not found.
*/
public VersionRoot getByVersionID(Repository rep, int id);
/**
* Get the version of a repository by dates.
* @param rep The repository.
* @param from The starting date. May be null but not with to null also.
* @param to The ending date. May be null but not with from null also.
* @return A List of VersionRoots.
*/
public List<VersionRoot> getByDates(Repository rep, Date from, Date to);
/**
* Get the highest numbered version in a repository.
* @param rep The repository.
* @return The highest numbered version.
*/
public VersionRoot getMaxVersion(Repository rep);
}

View File

@@ -0,0 +1,194 @@
/*
* 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.hibernate;
import java.util.Iterator;
import java.util.List;
import org.alfresco.repo.avm.AVMNode;
import org.alfresco.repo.avm.AVMNodeDAO;
import org.alfresco.repo.avm.AVMNodeImpl;
import org.alfresco.repo.avm.AVMNodeUnwrapper;
import org.alfresco.repo.avm.DirectoryNode;
import org.alfresco.repo.avm.Repository;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* @author britt
*
*/
public class AVMNodeDAOHibernate extends HibernateDaoSupport implements
AVMNodeDAO
{
/**
* Do nothing constructor.
*/
public AVMNodeDAOHibernate()
{
super();
}
/**
* Save the given node, having never been saved before.
*/
public void save(AVMNode node)
{
getSession().save(node);
}
/**
* Get all the nodes owned by a Repository and make
* them no longer point at that Repository.
* @param rep The Repository.
*/
@SuppressWarnings("unchecked")
public void dereferenceNodesInRepository(Repository rep)
{
Session sess = getSession();
Query query = sess.createQuery("from AVMNodeImpl an where an.repository = :rep");
query.setEntity("rep", rep);
Iterator<AVMNode> iter = (Iterator<AVMNode>)query.iterate();
while (iter.hasNext())
{
AVMNode node = iter.next();
node.setRepository(null);
}
sess.flush();
}
/**
* Delete a single node.
* @param node The node to delete.
*/
public void delete(AVMNode node)
{
getSession().delete(node);
}
/**
* Get by ID.
* @param id The id to get.
*/
public AVMNode getByID(long id)
{
return AVMNodeUnwrapper.Unwrap((AVMNode)getSession().get(AVMNodeImpl.class, id));
}
/**
* Get those nodes which are new in the given repository.
* @param repo The repository.
* @return A List of AVMNodes.
*/
@SuppressWarnings("unchecked")
public List<AVMNode> getNewInRepo(Repository repo)
{
Query query =
getSession().getNamedQuery("AVMNode.ByNewInRepo");
query.setEntity("repo", repo);
return (List<AVMNode>)query.list();
}
/**
* Update a node that has been dirtied.
* @param node The node.
*/
public void update(AVMNode node)
{
getSession().flush();
}
/**
* Get the root of a particular version.
* @param rep The repository we're querying.
* @param version The version.
* @return The VersionRoot or null.
*/
public DirectoryNode getRepositoryRoot(Repository rep, int version)
{
Query query =
getSession().getNamedQuery("VersionRoot.GetVersionRoot");
query.setEntity("rep", rep);
query.setInteger("version", version);
AVMNode root = (AVMNode)query.uniqueResult();
if (root == null)
{
return null;
}
return (DirectoryNode)AVMNodeUnwrapper.Unwrap(root);
}
/**
* Get the ancestor of a node.
* @param node The node whose ancestor is desired.
* @return The ancestor or null.
*/
public AVMNode getAncestor(AVMNode node)
{
Query query = getSession().createQuery("select hl.ancestor from HistoryLinkImpl hl where hl.descendent = :desc");
query.setEntity("desc", node);
return (AVMNode)query.uniqueResult();
}
/**
* Get the node the given node was merged from.
* @param node The node whose merged from is desired.
* @return The merged from node or null.
*/
public AVMNode getMergedFrom(AVMNode node)
{
Query query = getSession().createQuery("select ml.mfrom from MergeLinkImpl ml where ml.mto = :to");
query.setEntity("to", node);
return (AVMNode)query.uniqueResult();
}
/**
* Get up to batchSize orphans.
* @param batchSize Get no more than this number.
* @return A List of orphaned AVMNodes.
*/
@SuppressWarnings("unchecked")
public List<AVMNode> getOrphans(int batchSize)
{
Query query = getSession().getNamedQuery("FindOrphans");
query.setMaxResults(batchSize);
return (List<AVMNode>)query.list();
}
/**
* Get all nodes that have the given repository as their owning repository.
* @param rep The Repository.
* @return An Iterator over the matching nodes.
*/
@SuppressWarnings("unchecked")
public Iterator<AVMNode> getByRepository(Repository rep)
{
Query query = getSession().createQuery("from AVMNodeImpl an where an.repository = :rep");
query.setEntity("rep", rep);
return (Iterator<AVMNode>)query.iterate();
}
/**
* Inappropriate hack to get Hibernate to play nice.
*/
public void flush()
{
getSession().flush();
}
}

View File

@@ -0,0 +1,126 @@
/*
* 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.hibernate;
import java.io.Serializable;
import java.util.List;
import org.alfresco.repo.avm.AVMNode;
import org.alfresco.repo.avm.ChildEntry;
import org.alfresco.repo.avm.ChildEntryDAO;
import org.alfresco.repo.avm.ChildEntryImpl;
import org.alfresco.repo.avm.DirectoryNode;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The Hibernate version of the ChildEntry DAO.
* @author britt
*/
public class ChildEntryDAOHibernate extends HibernateDaoSupport implements
ChildEntryDAO
{
/**
* Do nothing constructor.
*/
public ChildEntryDAOHibernate()
{
super();
}
/**
* Save an unsaved ChildEntry.
* @param entry The entry to save.
*/
public void save(ChildEntry entry)
{
getSession().save(entry);
}
/**
* Get an entry by name and parent.
* @param name The name of the child to find.
* @param parent The parent to look in.
* @return The ChildEntry or null if not foun.
*/
public ChildEntry getByNameParent(String name, DirectoryNode parent)
{
ChildEntry query = new ChildEntryImpl(name, parent, null);
return (ChildEntry)getSession().get(ChildEntryImpl.class, (Serializable)query);
}
/**
* Get all the children of a given parent.
* @param parent The parent.
* @return A List of ChildEntries.
*/
@SuppressWarnings("unchecked")
public List<ChildEntry> getByParent(DirectoryNode parent)
{
Query query = getSession().getNamedQuery("ChildEntry.ByParent");
query.setEntity("parent", parent);
query.setCacheable(true);
query.setCacheRegion("ChildEntry.ByParent");
return (List<ChildEntry>)query.list();
}
/**
* Get the entry for a given child in a given parent.
* @param parent The parent.
* @param child The child.
* @return The ChildEntry or null.
*/
public ChildEntry getByParentChild(DirectoryNode parent, AVMNode child)
{
Query query = getSession().getNamedQuery("ChildEntry.ByParentChild");
query.setEntity("parent", parent);
query.setEntity("child", child);
query.setCacheable(true);
query.setCacheRegion("ChildEntry.ByParentChild");
return (ChildEntry)query.uniqueResult();
}
/**
* Update a dirty ChildEntry.
* @param child The dirty entry.
*/
public void update(ChildEntry child)
{
// NO OP in Hibernate.
}
/**
* Delete one.
* @param child The one to delete.
*/
public void delete(ChildEntry child)
{
getSession().delete(child);
}
/**
* Delete all children of the given parent.
* @param parent The parent.
*/
public void deleteByParent(AVMNode parent)
{
Query delete = getSession().getNamedQuery("ChildEntry.DeleteByParent");
delete.setEntity("parent", parent);
delete.executeUpdate();
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.hibernate;
import java.util.List;
import org.alfresco.repo.avm.AVMNode;
import org.alfresco.repo.avm.DeletedChild;
import org.alfresco.repo.avm.DeletedChildDAO;
import org.alfresco.repo.avm.LayeredDirectoryNode;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Hibernate implementation of DAO for DeletedChildren.
* @author britt
*/
public class DeletedChildDAOHibernate extends HibernateDaoSupport implements
DeletedChildDAO
{
/**
* Do nothing constructor.
*/
public DeletedChildDAOHibernate()
{
super();
}
/**
* Save an unsaved DeletedChild.
* @param child The DeletedChild to be saved.
*/
public void save(DeletedChild child)
{
getSession().save(child);
}
/**
* Delete one.
* @param child The one to delete.
*/
public void delete(DeletedChild child)
{
getSession().delete(child);
}
/**
* Delete all belonging to the given parent.
* @param parent The parent.
*/
public void deleteByParent(AVMNode parent)
{
Query delete = getSession().getNamedQuery("DeletedChild.DeleteByParent");
delete.setEntity("parent", parent);
delete.executeUpdate();
}
/**
* Get by name and parent.
* @param name The name of the deleted entry.
* @param parent The parent.
* @return A DeletedChild or null if not found.
*/
public DeletedChild getByNameParent(String name, LayeredDirectoryNode parent)
{
Query query = getSession().getNamedQuery("DeletedChild.ByNameParent");
query.setString("name", name);
query.setEntity("parent", parent);
query.setCacheable(true);
query.setCacheRegion("DeletedChild.ByNameParent");
return (DeletedChild)query.uniqueResult();
}
/**
* Get all the deleted children of a given parent.
* @param parent The parent.
* @return A List of DeletedChildren.
*/
@SuppressWarnings("unchecked")
public List<DeletedChild> getByParent(LayeredDirectoryNode parent)
{
Query query = getSession().getNamedQuery("DeletedChild.ByParent");
query.setEntity("parent", parent);
query.setCacheable(true);
query.setCacheRegion("DeletedChild.ByParent");
return (List<DeletedChild>)query.list();
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.hibernate;
import org.alfresco.repo.avm.FileContent;
import org.alfresco.repo.avm.FileContentDAO;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* @author britt
*
*/
public class FileContentDAOHibernate extends HibernateDaoSupport implements
FileContentDAO
{
/**
* Do nothing constructor.
*/
public FileContentDAOHibernate()
{
super();
}
/**
* Save one.
* @param content The one to save.
*/
public void save(FileContent content)
{
getSession().save(content);
}
/**
* Delete one.
* @param content To be deleted.
*/
public void delete(FileContent content)
{
getSession().delete(content);
}
}

View File

@@ -5,6 +5,7 @@ package org.alfresco.repo.avm.hibernate;
import java.sql.SQLException;
import org.alfresco.repo.avm.RetryingTransactionCallback;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
@@ -18,13 +19,13 @@ public class HibernateCallbackWrapper implements HibernateCallback
/**
* The HibernateTxnCallback to execute.
*/
private HibernateTxnCallback fCallback;
private RetryingTransactionCallback fCallback;
/**
* Make one up.
* @param callback
*/
public HibernateCallbackWrapper(HibernateTxnCallback callback)
public HibernateCallbackWrapper(RetryingTransactionCallback callback)
{
fCallback = callback;
}
@@ -36,7 +37,7 @@ public class HibernateCallbackWrapper implements HibernateCallback
public Object doInHibernate(Session session) throws HibernateException,
SQLException
{
fCallback.perform(session);
fCallback.perform();
return null;
}
}

View File

@@ -21,6 +21,8 @@ import java.util.Random;
import org.alfresco.repo.avm.AVMException;
import org.alfresco.repo.avm.AVMNotFoundException;
import org.alfresco.repo.avm.RetryingTransactionCallback;
import org.alfresco.repo.avm.RetryingTransaction;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.dao.OptimisticLockingFailureException;
@@ -34,7 +36,7 @@ import org.springframework.transaction.TransactionStatus;
* Helper for DAOs.
* @author britt
*/
public class HibernateTxn extends HibernateTemplate
public class HibernateTxn extends HibernateTemplate implements RetryingTransaction
{
/**
* The transaction manager.
@@ -65,13 +67,10 @@ public class HibernateTxn extends HibernateTemplate
fRandom = new Random();
}
/**
* Perform a set of operations under a single transaction.
* Keep trying if the operation fails because of a concurrency issue.
* @param callback The worker.
* @param write Whether this is a write operation.
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RetryingTransaction#perform(org.alfresco.repo.avm.hibernate.HibernateTxnCallback, boolean)
*/
public void perform(HibernateTxnCallback callback, boolean write)
public void perform(RetryingTransactionCallback callback, boolean write)
{
while (true)
{

View File

@@ -0,0 +1,85 @@
/*
* 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.hibernate;
import java.util.List;
import org.alfresco.repo.avm.AVMNode;
import org.alfresco.repo.avm.HistoryLink;
import org.alfresco.repo.avm.HistoryLinkDAO;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The Hibernate implementation of the DAO for HistoryLinks.
* @author britt
*/
public class HistoryLinkDAOHibernate extends HibernateDaoSupport implements
HistoryLinkDAO
{
/**
* Do nothing constructor.
*/
public HistoryLinkDAOHibernate()
{
super();
}
/**
* Save an unsaved HistoryLink.
* @param link
*/
public void save(HistoryLink link)
{
getSession().save(link);
}
/**
* Get the history link with the given descendent.
* @param descendent The descendent.
* @return The HistoryLink or null if not found.
*/
public HistoryLink getByDescendent(AVMNode descendent)
{
Query query = getSession().createQuery("from HistoryLinkImpl hl where hl.descendent = :desc");
query.setEntity("desc", descendent);
return (HistoryLink)query.uniqueResult();
}
/**
* Get all the descendents of a node.
* @param ancestor The ancestor node.
* @return A List of AVMNode descendents.
*/
@SuppressWarnings("unchecked")
public List<HistoryLink> getByAncestor(AVMNode ancestor)
{
Query query = getSession().getNamedQuery("HistoryLink.ByAncestor");
query.setEntity("node", ancestor);
return (List<HistoryLink>)query.list();
}
/**
* Delete a HistoryLink
* @param link The link to delete.
*/
public void delete(HistoryLink link)
{
getSession().delete(link);
}
}

View File

@@ -0,0 +1,53 @@
/*
* 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.hibernate;
import org.alfresco.repo.avm.IssuerDAO;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* DAO for Issuers. Hibernate version.
* @author britt
*/
public class IssuerDAOHibernate extends HibernateDaoSupport implements
IssuerDAO
{
/**
* Do nothing constructor.
*/
public IssuerDAOHibernate()
{
super();
}
public Long getContentIssuerValue()
{
return (Long)getSession().createQuery("select max(fc.id) from FileContentImpl fc").uniqueResult();
}
public Long getLayerIssuerValue()
{
return (Long)getSession().createQuery("select max(an.layerID) from AVMNodeImpl an").uniqueResult();
}
public Long getNodeIssuerValue()
{
return (Long)getSession().createQuery("select max(an.id) from AVMNodeImpl an").uniqueResult();
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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.hibernate;
import java.util.List;
import org.alfresco.repo.avm.AVMNode;
import org.alfresco.repo.avm.MergeLink;
import org.alfresco.repo.avm.MergeLinkDAO;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The Hibernate implementation of the DAO for a MergeLink
* @author britt
*/
public class MergeLinkDAOHibernate extends HibernateDaoSupport implements
MergeLinkDAO
{
/**
* Do nothing constructor.
*/
public MergeLinkDAOHibernate()
{
super();
}
/**
* Save an unsaved MergeLink.
* @param link The link to save.
*/
public void save(MergeLink link)
{
getSession().save(link);
}
/**
* Get a link from the merged to node.
* @param to The node merged to.
* @return An AVMNode or null if not found.
*/
public MergeLink getByTo(AVMNode to)
{
Query query = getSession().createQuery("from MergeLinkImpl ml where ml.mto = :to");
query.setEntity("to", to);
return (MergeLink)query.uniqueResult();
}
/**
* Get all the link that the given node was merged to.
* @param from The node that was merged from
* @return A List of MergeLinks.
*/
@SuppressWarnings("unchecked")
public List<MergeLink> getByFrom(AVMNode from)
{
Query query = getSession().getNamedQuery("MergeLink.ByFrom");
query.setEntity("merged", from);
return (List<MergeLink>)query.list();
}
/**
* Delete a link.
* @param link The link to delete.
*/
public void delete(MergeLink link)
{
getSession().delete(link);
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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.hibernate;
import java.util.List;
import org.alfresco.repo.avm.Repository;
import org.alfresco.repo.avm.RepositoryDAO;
import org.alfresco.repo.avm.RepositoryImpl;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The Hibernate version for RepositoryDAO
* @author britt
*/
public class RepositoryDAOHibernate extends HibernateDaoSupport implements
RepositoryDAO
{
/**
* Do nothing constructor.
*/
public RepositoryDAOHibernate()
{
super();
}
/**
* Save a repository, never before saved.
* @param rep The repository
*/
public void save(Repository rep)
{
getSession().save(rep);
}
/**
* Delete the given Repository.
* @param rep The Repository.
*/
public void delete(Repository rep)
{
getSession().delete(rep);
}
/**
* Get all repositories.
* @return A List of all the Repositories.
*/
@SuppressWarnings("unchecked")
public List<Repository> getAll()
{
Query query = getSession().createQuery("from RepositoryImpl r");
return (List<Repository>)query.list();
}
/**
* Get a repository by name.
* @param name The name of the repository.
* @return The repository or null if not found.
*/
public Repository getByName(String name)
{
return (Repository)getSession().get(RepositoryImpl.class, name);
}
/**
* Update the given Repository record.
* @param rep The dirty Repository.
*/
public void update(Repository rep)
{
// No op in Hibernate.
}
}

View File

@@ -0,0 +1,147 @@
/*
* 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.hibernate;
import java.util.Date;
import java.util.List;
import org.alfresco.repo.avm.Repository;
import org.alfresco.repo.avm.VersionRoot;
import org.alfresco.repo.avm.VersionRootDAO;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* This is the Hibernate version of the DAO for version roots.
* @author britt
*/
public class VersionRootDAOHibernate extends HibernateDaoSupport implements
VersionRootDAO
{
/**
* Do nothing constructor.
*/
public VersionRootDAOHibernate()
{
super();
}
/**
* Save an unsaved VersionRoot.
* @param vr The VersionRoot to save.
*/
public void save(VersionRoot vr)
{
getSession().save(vr);
}
/**
* Delete a VersionRoot.
* @param vr The VersionRoot to delete.
*/
public void delete(VersionRoot vr)
{
getSession().delete(vr);
getSession().flush();
}
/**
* Get all the version roots in a given repository.
* @param rep The repository.
* @return A List of VersionRoots. In id order.
*/
@SuppressWarnings("unchecked")
public List<VersionRoot> getAllInRepository(Repository rep)
{
Query query = getSession().createQuery("from VersionRootImpl v where v.repository = :rep order by v.versionID");
query.setEntity("rep", rep);
return (List<VersionRoot>)query.list();
}
/**
* Get the version of a repository by dates.
* @param rep The repository.
* @param from The starting date. May be null but not with to null also.
* @param to The ending date. May be null but not with from null also.
* @return A List of VersionRoots.
*/
@SuppressWarnings("unchecked")
public List<VersionRoot> getByDates(Repository rep, Date from, Date to)
{
Query query;
if (from == null)
{
query =
getSession().createQuery("from VersionRootImpl vr where vr.createDate <= :to " +
"and vr.repository = :rep " +
"order by vr.versionID");
query.setLong("to", to.getTime());
query.setEntity("rep", rep);
}
else if (to == null)
{
query =
getSession().createQuery("from VersionRootImpl vr " +
"where vr.createDate >= :from " +
"and vr.repository = :rep " +
"order by vr.versionID");
query.setLong("from", from.getTime());
query.setEntity("rep", rep);
}
else
{
query =
getSession().createQuery("from VersionRootImpl vr "+
"where vr.createDate between :from and :to " +
"and vr.repository = :rep " +
"order by vr.versionID");
query.setLong("from", from.getTime());
query.setLong("to", to.getTime());
query.setEntity("rep", rep);
}
query.setEntity("rep", rep);
return (List<VersionRoot>)query.list();
}
/**
* Get the VersionRoot corresponding to the given id.
* @param rep The repository
* @param id The version id.
* @return The VersionRoot or null if not found.
*/
public VersionRoot getByVersionID(Repository rep, int id)
{
Query query = getSession().getNamedQuery("VersionRoot.VersionByID");
query.setEntity("rep", rep);
query.setInteger("version", id);
return (VersionRoot)query.uniqueResult();
}
/**
* Get the highest numbered version in a repository.
* @param rep The repository.
* @return The highest numbered version.
*/
public VersionRoot getMaxVersion(Repository rep)
{
Query query = getSession().createQuery("from VersionRootImpl vr " +
"where vr.versionID = " +
"(select max(v.versionID) from VersionRootImpl v)");
return (VersionRoot)query.uniqueResult();
}
}