mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -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();
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Worker object for Hibernate Transactions.
|
||||
* @author britt
|
||||
*/
|
||||
public interface HibernateTxnCallback
|
||||
{
|
||||
/**
|
||||
* Do our work.
|
||||
* @param sess The Hibernate session.
|
||||
*/
|
||||
public void perform(Session sess);
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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.
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user