mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moved stuff around to be more Alfresco standard.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3658 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.AVMAspectName;
|
||||
import org.alfresco.repo.avm.AVMAspectNameDAO;
|
||||
import org.alfresco.repo.avm.AVMNode;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* Hibernate implementation of AVMAspectNameDAO.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMAspectNameDAOHibernate extends HibernateDaoSupport
|
||||
implements AVMAspectNameDAO
|
||||
{
|
||||
/**
|
||||
* Persist an aspect name.
|
||||
* @param aspectName The item to persist.
|
||||
*/
|
||||
public void save(AVMAspectName aspectName)
|
||||
{
|
||||
getSession().save(aspectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an Aspect Name.
|
||||
* @param aspectName The item to delete.
|
||||
*/
|
||||
public void delete(AVMAspectName aspectName)
|
||||
{
|
||||
getSession().delete(aspectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a single aspect name from a node.
|
||||
* @param node The node.
|
||||
* @param aspectName The aspect name.
|
||||
*/
|
||||
public void delete(AVMNode node, QName aspectName)
|
||||
{
|
||||
Query delete =
|
||||
getSession().createQuery(
|
||||
"delete from AVMAspectNameImpl aa where aa.node = :node and aa.name = :name");
|
||||
delete.setEntity("node", node);
|
||||
delete.setParameter("name", aspectName);
|
||||
delete.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all Aspect Names on a given node.
|
||||
* @param node The given node.
|
||||
*/
|
||||
public void delete(AVMNode node)
|
||||
{
|
||||
Query delete =
|
||||
getSession().createQuery("delete from AVMAspectNameImpl aa where aa.node = :node");
|
||||
delete.setEntity("node", node);
|
||||
delete.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Aspect Names for a given node.
|
||||
* @param node The AVM Node.
|
||||
* @return A List of AVMAspectNames.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AVMAspectName> get(AVMNode node)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery("from AVMAspectNameImpl aa where aa.node = :node");
|
||||
query.setEntity("node", node);
|
||||
return (List<AVMAspectName>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given node have the given asset.
|
||||
* @param node The AVM node.
|
||||
* @param name The QName of the Aspect.
|
||||
* @return Whether the aspect is there.
|
||||
*/
|
||||
public boolean exists(AVMNode node, QName name)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery(
|
||||
"from AVMAspectNameImpl aa where aa.node = :node and aa.name = :name");
|
||||
query.setEntity("node", node);
|
||||
query.setParameter("name", name);
|
||||
return query.uniqueResult() != null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.AVMNodeDAO;
|
||||
import org.alfresco.repo.avm.AVMNodeImpl;
|
||||
import org.alfresco.repo.avm.AVMNodeUnwrapper;
|
||||
import org.alfresco.repo.avm.AVMStore;
|
||||
import org.alfresco.repo.avm.DirectoryNode;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* @author britt
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 store The store we're querying.
|
||||
* @param version The version.
|
||||
* @return The VersionRoot or null.
|
||||
*/
|
||||
public DirectoryNode getAVMStoreRoot(AVMStore store, int version)
|
||||
{
|
||||
Query query =
|
||||
getSession().getNamedQuery("VersionRoot.GetVersionRoot");
|
||||
query.setEntity("store", store);
|
||||
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 content urls in he AVM Repository.
|
||||
* @return A List of URL Strings.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getContentUrls()
|
||||
{
|
||||
Query query = getSession().getNamedQuery("PlainFileNode.GetContentUrls");
|
||||
return (List<String>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inappropriate hack to get Hibernate to play nice.
|
||||
*/
|
||||
public void flush()
|
||||
{
|
||||
getSession().flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
package org.alfresco.repo.avm.hibernate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.avm.AVMNode;
|
||||
import org.alfresco.repo.avm.AVMNodeProperty;
|
||||
import org.alfresco.repo.avm.AVMNodePropertyDAO;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* Hibernate implemenation for DAO for AVMNodeProperties.
|
||||
* @author britt
|
||||
*/
|
||||
class AVMNodePropertyDAOHibernate extends HibernateDaoSupport
|
||||
implements AVMNodePropertyDAO
|
||||
{
|
||||
/**
|
||||
* Get a property by node and name.
|
||||
* @param node The AVMNode.
|
||||
* @param name The QName.
|
||||
* @return The found property or null.
|
||||
*/
|
||||
public AVMNodeProperty get(AVMNode node, QName name)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery(
|
||||
"from AVMNodePropertyImpl anp where anp.node = :node and anp.name = :name");
|
||||
query.setEntity("node", node);
|
||||
query.setParameter("name", name);
|
||||
query.setCacheable(true);
|
||||
query.setCacheRegion("Property.Lookup");
|
||||
return (AVMNodeProperty)query.uniqueResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all properties owned by the given node.
|
||||
* @param node The AVMNode.
|
||||
* @return A List of properties.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AVMNodeProperty> get(AVMNode node)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery(
|
||||
"from AVMNodePropertyImpl anp where anp.node = :node");
|
||||
query.setEntity("node", node);
|
||||
query.setCacheable(true);
|
||||
query.setCacheRegion("Properties.Lookup");
|
||||
return (List<AVMNodeProperty>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a property.
|
||||
* @param prop The property to save.
|
||||
*/
|
||||
public void save(AVMNodeProperty prop)
|
||||
{
|
||||
getSession().save(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a property entry.
|
||||
* @param prop The property.
|
||||
*/
|
||||
public void update(AVMNodeProperty prop)
|
||||
{
|
||||
// Do nothing for Hibernate.
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all properties associated with a node.
|
||||
* @param node The AVMNode whose properties should be deleted.
|
||||
*/
|
||||
public void deleteAll(AVMNode node)
|
||||
{
|
||||
Query delete =
|
||||
getSession().createQuery("delete from AVMNodePropertyImpl anp where anp.node = :node");
|
||||
delete.setEntity("node", node);
|
||||
delete.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given property from the given node.
|
||||
* @param node The node to delete the property to delete.
|
||||
* @param name The name of the property to delete.
|
||||
*/
|
||||
public void delete(AVMNode node, QName name)
|
||||
{
|
||||
Query delete =
|
||||
getSession().createQuery("delete from AVMNodePropertyImpl anp where anp.node = :node " +
|
||||
"and name = :name");
|
||||
delete.setEntity("node", node);
|
||||
delete.setParameter("name", name);
|
||||
delete.executeUpdate();
|
||||
}
|
||||
}
|
@@ -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.AVMStore;
|
||||
import org.alfresco.repo.avm.AVMStoreDAO;
|
||||
import org.alfresco.repo.avm.AVMStoreImpl;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* The Hibernate version for AVMStoreDAO
|
||||
* @author britt
|
||||
*/
|
||||
class AVMStoreDAOHibernate extends HibernateDaoSupport implements
|
||||
AVMStoreDAO
|
||||
{
|
||||
/**
|
||||
* Do nothing constructor.
|
||||
*/
|
||||
public AVMStoreDAOHibernate()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a store, never before saved.
|
||||
* @param store The store
|
||||
*/
|
||||
public void save(AVMStore store)
|
||||
{
|
||||
getSession().save(store);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given AVMStore.
|
||||
* @param store The AVMStore.
|
||||
*/
|
||||
public void delete(AVMStore store)
|
||||
{
|
||||
getSession().delete(store);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all stores.
|
||||
* @return A List of all the AVMStores.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AVMStore> getAll()
|
||||
{
|
||||
Query query = getSession().createQuery("from AVMStoreImpl r");
|
||||
return (List<AVMStore>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a store by name.
|
||||
* @param name The name of the store.
|
||||
* @return The store or null if not found.
|
||||
*/
|
||||
public AVMStore getByName(String name)
|
||||
{
|
||||
return (AVMStore)getSession().get(AVMStoreImpl.class, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the given AVMStore record.
|
||||
* @param store The dirty AVMStore.
|
||||
*/
|
||||
public void update(AVMStore store)
|
||||
{
|
||||
// No op in Hibernate.
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.AVMStore;
|
||||
import org.alfresco.repo.avm.AVMStoreProperty;
|
||||
import org.alfresco.repo.avm.AVMStorePropertyDAO;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* The Hibernate implementation of the DAO for AVMNodeProperties.
|
||||
* @author britt
|
||||
*/
|
||||
class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMStorePropertyDAO
|
||||
{
|
||||
/**
|
||||
* Persist a property.
|
||||
* @param prop The AVMStoreProperty to persist.
|
||||
*/
|
||||
public void save(AVMStoreProperty prop)
|
||||
{
|
||||
getSession().save(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a property by store and name.
|
||||
* @param store The AVMStore.
|
||||
* @param name The QName of the property.
|
||||
* @return The given AVMStoreProperty or null if not found.
|
||||
*/
|
||||
public AVMStoreProperty get(AVMStore store, QName name)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery("from AVMStorePropertyImpl asp where asp.store = :store and asp.name = :name");
|
||||
query.setEntity("store", store);
|
||||
query.setParameter("name", name);
|
||||
return (AVMStoreProperty)query.uniqueResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the properties associated with a store.
|
||||
* @param store The AVMStore whose properties should be fetched.
|
||||
* @return A List of properties associated with the store.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AVMStoreProperty> get(AVMStore store)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery("from AVMStorePropertyImpl asp where asp.store = :store");
|
||||
query.setEntity("store", store);
|
||||
return (List<AVMStoreProperty>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a modified property.
|
||||
* @param prop The AVMStoreProperty to update.
|
||||
*/
|
||||
public void update(AVMStoreProperty prop)
|
||||
{
|
||||
// This is a no op for hibernate.
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a property from a store by name.
|
||||
* @param store The AVMStore to delete from.
|
||||
* @param name The name of the property.
|
||||
*/
|
||||
public void delete(AVMStore store, QName name)
|
||||
{
|
||||
Query delete =
|
||||
getSession().createQuery("delete from AVMStorePropertyImpl asp " +
|
||||
"where asp.store = :store and asp.name = :name");
|
||||
delete.setEntity("store", store);
|
||||
delete.setParameter("name", name);
|
||||
delete.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all properties associated with a store.
|
||||
* @param store The AVMStore whose properties are to be deleted.
|
||||
*/
|
||||
public void delete(AVMStore store)
|
||||
{
|
||||
Query delete =
|
||||
getSession().createQuery("delete from AVMStorePropertyImpl asp where asp.store = :store");
|
||||
delete.setEntity("store", store);
|
||||
delete.executeUpdate();
|
||||
}
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.ChildEntry;
|
||||
import org.alfresco.repo.avm.ChildEntryDAO;
|
||||
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
|
||||
*/
|
||||
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)
|
||||
{
|
||||
Query query = getSession().createQuery(
|
||||
"from ChildEntryImpl ce where ce.name = :name and ce.parent = :parent");
|
||||
query.setString("name", name);
|
||||
query.setEntity("parent", parent);
|
||||
query.setCacheable(true);
|
||||
return (ChildEntry)query.uniqueResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 java.sql.SQLException;
|
||||
|
||||
import org.alfresco.repo.avm.RetryingTransactionCallback;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.orm.hibernate3.HibernateCallback;
|
||||
|
||||
/**
|
||||
* This is a wrapper around HibernateTxnCallback implementation.
|
||||
* @author britt
|
||||
*/
|
||||
class HibernateCallbackWrapper implements HibernateCallback
|
||||
{
|
||||
/**
|
||||
* The HibernateTxnCallback to execute.
|
||||
*/
|
||||
private RetryingTransactionCallback fCallback;
|
||||
|
||||
/**
|
||||
* Make one up.
|
||||
* @param callback
|
||||
*/
|
||||
public HibernateCallbackWrapper(RetryingTransactionCallback callback)
|
||||
{
|
||||
fCallback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the HibernateTxnCallback internally.
|
||||
* @param session The Hibernate Session.
|
||||
*/
|
||||
public Object doInHibernate(Session session) throws HibernateException,
|
||||
SQLException
|
||||
{
|
||||
fCallback.perform();
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,179 @@
|
||||
package org.alfresco.repo.avm.hibernate;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.alfresco.repo.avm.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.avm.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.avm.AVMException;
|
||||
import org.alfresco.service.cmr.avm.AVMNotFoundException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.dao.DeadlockLoserDataAccessException;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.orm.hibernate3.HibernateTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
/**
|
||||
* Helper for DAOs.
|
||||
* @author britt
|
||||
*/
|
||||
public class HibernateRetryingTransactionHelper extends HibernateTemplate implements RetryingTransactionHelper
|
||||
{
|
||||
private static Logger fgLogger = Logger.getLogger(HibernateRetryingTransactionHelper.class);
|
||||
|
||||
/**
|
||||
* The transaction manager.
|
||||
*/
|
||||
private PlatformTransactionManager fTransactionManager;
|
||||
|
||||
/**
|
||||
* The read transaction definition.
|
||||
*/
|
||||
private TransactionDefinition fReadDefinition;
|
||||
|
||||
/**
|
||||
* The write transaction definition.
|
||||
*/
|
||||
private TransactionDefinition fWriteDefinition;
|
||||
|
||||
/**
|
||||
* The random number generator for inter-retry sleep.
|
||||
*/
|
||||
private Random fRandom;
|
||||
|
||||
/**
|
||||
* Make one up.
|
||||
* @param sessionFactory The SessionFactory.
|
||||
*/
|
||||
public HibernateRetryingTransactionHelper()
|
||||
{
|
||||
fRandom = new Random();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an idempotent transaction, repeating invocations as necessary
|
||||
* for failures caused by deadlocks and lost races.
|
||||
* @param callback The callback containging the work to do.
|
||||
* @param write Whether this is a write transaction.
|
||||
*/
|
||||
public void perform(RetryingTransactionCallback callback, boolean write)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
TransactionStatus status = null;
|
||||
boolean newTxn = true;
|
||||
try
|
||||
{
|
||||
status =
|
||||
fTransactionManager.getTransaction(write ? fWriteDefinition : fReadDefinition);
|
||||
newTxn = status.isNewTransaction();
|
||||
execute(new HibernateCallbackWrapper(callback));
|
||||
if (newTxn)
|
||||
{
|
||||
fTransactionManager.commit(status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
if (status == null)
|
||||
{
|
||||
t.printStackTrace(System.err);
|
||||
throw new AVMException("Unrecoverable error.", t);
|
||||
}
|
||||
if (newTxn && !status.isCompleted())
|
||||
{
|
||||
fTransactionManager.rollback(status);
|
||||
}
|
||||
if (!newTxn)
|
||||
{
|
||||
if (t instanceof RuntimeException)
|
||||
{
|
||||
throw (RuntimeException)t;
|
||||
}
|
||||
throw new AVMException("Unrecoverable error.", t);
|
||||
}
|
||||
// If we've lost a race or we've deadlocked, retry.
|
||||
if (t instanceof DeadlockLoserDataAccessException)
|
||||
{
|
||||
fgLogger.info("Deadlock");
|
||||
try
|
||||
{
|
||||
long interval;
|
||||
synchronized (fRandom)
|
||||
{
|
||||
interval = fRandom.nextInt(1000);
|
||||
}
|
||||
Thread.sleep(interval);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t instanceof OptimisticLockingFailureException)
|
||||
{
|
||||
fgLogger.info("Lost Race");
|
||||
continue;
|
||||
}
|
||||
if (t instanceof AVMException)
|
||||
{
|
||||
throw (AVMException)t;
|
||||
}
|
||||
if (t instanceof DataRetrievalFailureException)
|
||||
{
|
||||
System.err.println("Data Retrieval Error.");
|
||||
throw new AVMNotFoundException("Object not found.", t);
|
||||
}
|
||||
throw new AVMException("Unrecoverable error.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the transaction manager we are operating under.
|
||||
* @param manager
|
||||
*/
|
||||
public void setTransactionManager(PlatformTransactionManager manager)
|
||||
{
|
||||
fTransactionManager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the read Transaction Definition.
|
||||
* @param def
|
||||
*/
|
||||
public void setReadTransactionDefinition(TransactionDefinition def)
|
||||
{
|
||||
fReadDefinition = def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the write Transaction Definition.
|
||||
* @param def
|
||||
*/
|
||||
public void setWriteTransactionDefinition(TransactionDefinition def)
|
||||
{
|
||||
fWriteDefinition = def;
|
||||
}
|
||||
}
|
@@ -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
|
||||
*/
|
||||
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,64 @@
|
||||
/*
|
||||
* 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.alfresco.service.cmr.avm.AVMException;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* DAO for Issuers. Hibernate version.
|
||||
* @author britt
|
||||
*/
|
||||
class IssuerDAOHibernate extends HibernateDaoSupport implements
|
||||
IssuerDAO
|
||||
{
|
||||
/**
|
||||
* Do nothing constructor.
|
||||
*/
|
||||
public IssuerDAOHibernate()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the largest issued id for the named issuer.
|
||||
* @param The name of the issuer.
|
||||
* @return The value or null if the issuer is brand new.
|
||||
* @throws AVMException on an invalid name.
|
||||
*/
|
||||
public Long getIssuerValue(String name)
|
||||
{
|
||||
if (name.equals("content"))
|
||||
{
|
||||
return (Long)getSession().
|
||||
createQuery("select max(fc.id) from FileContentImpl fc").uniqueResult();
|
||||
}
|
||||
else if (name.equals("layer"))
|
||||
{
|
||||
return (Long)getSession().
|
||||
createQuery("select max(an.layerID) from AVMNodeImpl an").uniqueResult();
|
||||
}
|
||||
else if (name.equals("node"))
|
||||
{
|
||||
return (Long)getSession().createQuery("select max(an.id) from AVMNodeImpl an").uniqueResult();
|
||||
}
|
||||
throw new AVMException("Unknown issuer type: " + name);
|
||||
}
|
||||
}
|
@@ -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
|
||||
*/
|
||||
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,78 @@
|
||||
/*
|
||||
* 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.AVMStore;
|
||||
import org.alfresco.repo.avm.NewInAVMStore;
|
||||
import org.alfresco.repo.avm.NewInAVMStoreDAO;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* Hibernate implementation of NewInAVMStore DAO.
|
||||
* @author britt
|
||||
*/
|
||||
class NewInAVMStoreDAOHibernate extends HibernateDaoSupport implements
|
||||
NewInAVMStoreDAO
|
||||
{
|
||||
/**
|
||||
* Save one.
|
||||
* @param newEntry The item to save.
|
||||
*/
|
||||
public void save(NewInAVMStore newEntry)
|
||||
{
|
||||
getSession().save(newEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one by Node.
|
||||
* @param node The node to lookup with.
|
||||
* @return The Entry or null if not found.
|
||||
*/
|
||||
public NewInAVMStore getByNode(AVMNode node)
|
||||
{
|
||||
Query query = getSession().createQuery("from NewInAVMStoreImpl nie where nie.node = :node");
|
||||
query.setEntity("node", node);
|
||||
return (NewInAVMStore)query.uniqueResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all that are in the given store.
|
||||
* @param store The AVMStore.
|
||||
* @return A List of NewInAVMStores.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<NewInAVMStore> getByAVMStore(AVMStore store)
|
||||
{
|
||||
Query query = getSession().createQuery("from NewInAVMStoreImpl nie where nie.avmStore = :store");
|
||||
query.setEntity("store", store);
|
||||
return (List<NewInAVMStore>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given entry.
|
||||
* @param newEntry The entry to delete.
|
||||
*/
|
||||
public void delete(NewInAVMStore newEntry)
|
||||
{
|
||||
getSession().delete(newEntry);
|
||||
}
|
||||
}
|
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.AVMStore;
|
||||
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
|
||||
*/
|
||||
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 store.
|
||||
* @param store The store.
|
||||
* @return A List of VersionRoots. In id order.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<VersionRoot> getAllInAVMStore(AVMStore store)
|
||||
{
|
||||
Query query = getSession().createQuery("from VersionRootImpl v where v.avmStore = :store order by v.versionID");
|
||||
query.setEntity("store", store);
|
||||
return (List<VersionRoot>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of a store by dates.
|
||||
* @param store The store.
|
||||
* @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(AVMStore store, Date from, Date to)
|
||||
{
|
||||
Query query;
|
||||
if (from == null)
|
||||
{
|
||||
query =
|
||||
getSession().createQuery("from VersionRootImpl vr where vr.createDate <= :to " +
|
||||
"and vr.avmStore = :store " +
|
||||
"order by vr.versionID");
|
||||
query.setLong("to", to.getTime());
|
||||
}
|
||||
else if (to == null)
|
||||
{
|
||||
query =
|
||||
getSession().createQuery("from VersionRootImpl vr " +
|
||||
"where vr.createDate >= :from " +
|
||||
"and vr.avmStore = :store " +
|
||||
"order by vr.versionID");
|
||||
query.setLong("from", from.getTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
query =
|
||||
getSession().createQuery("from VersionRootImpl vr "+
|
||||
"where vr.createDate between :from and :to " +
|
||||
"and vr.avmStore = :store " +
|
||||
"order by vr.versionID");
|
||||
query.setLong("from", from.getTime());
|
||||
query.setLong("to", to.getTime());
|
||||
}
|
||||
query.setEntity("store", store);
|
||||
return (List<VersionRoot>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the VersionRoot corresponding to the given id.
|
||||
* @param store The store
|
||||
* @param id The version id.
|
||||
* @return The VersionRoot or null if not found.
|
||||
*/
|
||||
public VersionRoot getByVersionID(AVMStore store, int id)
|
||||
{
|
||||
Query query = getSession().getNamedQuery("VersionRoot.VersionByID");
|
||||
query.setEntity("store", store);
|
||||
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(AVMStore 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