Moved the tracking of newly introduced nodes into its own table. Simplifies things a bit.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3320 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-07-13 15:48:10 +00:00
parent fae76d7896
commit 6ac87efa5a
20 changed files with 342 additions and 129 deletions

View File

@@ -65,6 +65,11 @@ public class AVMContext
*/
public DeletedChildDAO fDeletedChildDAO;
/**
* The NewInRepositoryDAO
*/
public NewInRepositoryDAO fNewInRepositoryDAO;
/**
* @param nodeDAO the fAVMNodeDAO to set
*/
@@ -136,4 +141,12 @@ public class AVMContext
{
fIssuerDAO = issuerDAO;
}
/**
* @param newInRepositoryDAO The DAO to set.
*/
public void setNewInRepositoryDAO(NewInRepositoryDAO newInRepositoryDAO)
{
fNewInRepositoryDAO = newInRepositoryDAO;
}
}

View File

@@ -65,12 +65,6 @@ public interface AVMNode
*/
public AVMNode copy(Lookup lPath);
/**
* Set the repository for a node.
* @param repo The Repository to set.
*/
public void setRepository(Repository repo);
/**
* Get the type of this node.
*/
@@ -106,12 +100,6 @@ public interface AVMNode
*/
public long getId();
/**
* Set this node's newness.
* @param isNew The newness.
*/
public void setIsNew(boolean isNew);
/**
* Get the newnews.
* @return Whether the node is new.

View File

@@ -30,13 +30,6 @@ public interface AVMNodeDAO
*/
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 unreferenceRepository(Repository rep);
/**
* Delete a single node.
* @param node The node to delete.
@@ -57,13 +50,6 @@ public interface AVMNodeDAO
*/
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.

View File

@@ -35,21 +35,11 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
*/
private int fVersionID;
/**
* The Repository that owns this.
*/
private Repository fRepository;
/**
* The basic attributes of this. Owner, creator, mod time, etc.
*/
private BasicAttributes fBasicAttributes;
/**
* Whether this node is new (and should therefore not be COWed).
*/
private boolean fIsNew;
/**
* The version number (for concurrency control).
*/
@@ -77,16 +67,14 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
{
fID = id;
fVersionID = -1;
fRepository = repo;
fIsRoot = false;
long time = System.currentTimeMillis();
fBasicAttributes = new BasicAttributesImpl("britt",
"britt",
"britt",
time,
time,
time);
fIsNew = true;
"britt",
"britt",
time,
time,
time);
}
/**
@@ -139,24 +127,6 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
return AVMContext.fgInstance.fAVMNodeDAO.getMergedFrom(this);
}
/**
* Set the owning repository for this.
* @param repo The owning repository.
*/
public void setRepository(Repository repo)
{
fRepository = repo;
}
/**
* Get the repository that owns this.
* @return The repository.
*/
public Repository getRepository()
{
return fRepository;
}
/**
* Equality based on object ids.
* @param obj The thing to compare against.
@@ -241,22 +211,13 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
return fBasicAttributes;
}
/**
* Set whether this is new.
* @param isNew Whether this is new.
*/
public void setIsNew(boolean isNew)
{
fIsNew = isNew;
}
/**
* Get whether this is a new node.
* @return Whether this is new.
*/
public boolean getIsNew()
{
return fIsNew;
return AVMContext.fgInstance.fNewInRepositoryDAO.getByNode(this) != null;
}
/**

View File

@@ -75,6 +75,8 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fPrimaryIndirection = true;
fOpacity = false;
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**
@@ -105,6 +107,8 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
this);
AVMContext.fgInstance.fDeletedChildDAO.save(newDel);
}
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**
@@ -136,6 +140,8 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
AVMContext.fgInstance.fChildEntryDAO.save(newChild);
}
}
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**
@@ -157,6 +163,8 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fLayerID = -1;
fOpacity = false;
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repo, this));
}
/**

View File

@@ -48,6 +48,8 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
super(repo.getSuperRepository().issueID(), repo);
fIndirection = other.getIndirection();
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repo, this));
}
/**
@@ -60,6 +62,8 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
super(repo.getSuperRepository().issueID(), repo);
fIndirection = indirection;
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repo, this));
}
/**

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;
/**
* Eensy-weensy interface for tracking nodes that are new in a repository.
* @author britt
*/
public interface NewInRepository
{
/**
* Get the Repository part.
* @return The Repository
*/
public Repository getRepository();
/**
* Get the node part.
* @return The AVMNode.
*/
public AVMNode getNode();
}

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 NewInRepository markers.
* @author britt
*/
public interface NewInRepositoryDAO
{
/**
* Save one.
* @param newEntry The item to save.
*/
public void save(NewInRepository newEntry);
/**
* Get one by Node.
* @param node The node to lookup with.
* @return The Entry or null if not found.
*/
public NewInRepository getByNode(AVMNode node);
/**
* Get all that are in the given repository.
* @param repository The Repository.
* @return A List of NewInRepositorys.
*/
public List<NewInRepository> getByRepository(Repository repository);
/**
* Delete the given entry.
* @param newEntry The entry to delete.
*/
public void delete(NewInRepository newEntry);
}

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;
import java.io.Serializable;
/**
* A record of a node that is new and in which repository it resides.
* @author britt
*/
public class NewInRepositoryImpl implements NewInRepository, Serializable
{
private static final long serialVersionUID = 1905996612150732182L;
/**
* The Repository.
*/
private Repository fRepository;
/**
* The Node.
*/
private AVMNode fNode;
/**
* Default constructor.
*/
public NewInRepositoryImpl()
{
}
/**
* Make a new one.
* @param repository The repository.
* @param node The AVMNode that is new.
*/
public NewInRepositoryImpl(Repository repository, AVMNode node)
{
fRepository = repository;
fNode = node;
}
/**
* @return the fNode
*/
public AVMNode getNode()
{
return fNode;
}
/**
* @param node the fNode to set
*/
public void setNode(AVMNode node)
{
fNode = node;
}
/**
* @return the fRepository
*/
public Repository getRepository()
{
return fRepository;
}
/**
* @param repository the fRepository to set
*/
public void setRepository(Repository repository)
{
fRepository = repository;
}
}

View File

@@ -209,6 +209,7 @@ public class OrphanReaper implements Runnable
mergedFrom = mlink.getMfrom();
AVMContext.fgInstance.fMergeLinkDAO.delete(mlink);
}
AVMContext.fgInstance.fAVMNodeDAO.flush();
// Get all the nodes that have this node as ancestor.
List<HistoryLink> links = AVMContext.fgInstance.fHistoryLinkDAO.getByAncestor(node);
for (HistoryLink link : links)
@@ -228,6 +229,11 @@ public class OrphanReaper implements Runnable
link.getMto().setMergedFrom(ancestor);
AVMContext.fgInstance.fMergeLinkDAO.delete(link);
}
NewInRepository newInRep = AVMContext.fgInstance.fNewInRepositoryDAO.getByNode(node);
if (newInRep != null)
{
AVMContext.fgInstance.fNewInRepositoryDAO.delete(newInRep);
}
// TODO What to do about such Hibernate wackiness: session.flush();
// TODO More of the same: node = AVMNodeUnwrapper.Unwrap(node);
// Extra work for directories.

View File

@@ -38,6 +38,8 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
{
super(repo.getSuperRepository().issueID(), repo);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repo, this));
}
/**
@@ -58,15 +60,15 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
{
super(repos.getSuperRepository().issueID(), repos);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
// TODO Something about this. sess.flush();
for (ChildEntry child : AVMContext.fgInstance.fChildEntryDAO.getByParent(other))
{
ChildEntry newChild = new ChildEntryImpl(child.getName(),
this,
child.getChild());
AVMContext.fgInstance.fChildEntryDAO.save(newChild);
// TODO Something about this: sess.flush();
}
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**

View File

@@ -50,6 +50,8 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
super(repos.getSuperRepository().issueID(), repos);
fContent = new FileContentImpl(SuperRepository.GetInstance().issueContentID());
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**
@@ -62,6 +64,8 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
super(repos.getSuperRepository().issueID(), repos);
fContent = new FileContentImpl(SuperRepository.GetInstance().issueContentID(), content);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**
@@ -76,6 +80,8 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
fContent = other.getContent();
fContent.setRefCount(fContent.getRefCount() + 1);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**
@@ -91,6 +97,8 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
fContent = content;
fContent.setRefCount(fContent.getRefCount() + 1);
AVMContext.fgInstance.fAVMNodeDAO.save(this);
AVMContext.fgInstance.fAVMNodeDAO.flush();
AVMContext.fgInstance.fNewInRepositoryDAO.save(new NewInRepositoryImpl(repos, this));
}
/**

View File

@@ -100,7 +100,6 @@ public class RepositoryImpl implements Repository, Serializable
// Make up the initial version record and save.
long time = System.currentTimeMillis();
fRoot = new PlainDirectoryNodeImpl(this);
fRoot.setIsNew(false);
fRoot.setIsRoot(true);
AVMContext.fgInstance.fAVMNodeDAO.save(fRoot);
VersionRoot versionRoot = new VersionRootImpl(this,
@@ -135,13 +134,11 @@ public class RepositoryImpl implements Repository, Serializable
throw new AVMExistsException("Already snapshotted.");
}
// Clear out the new nodes.
AVMNodeDAO anDAO = AVMContext.fgInstance.fAVMNodeDAO;
for (AVMNode newNode : anDAO.getNewInRepo(this))
List<NewInRepository> newInRep = AVMContext.fgInstance.fNewInRepositoryDAO.getByRepository(this);
for (NewInRepository newGuy : newInRep)
{
newNode.setIsNew(false);
AVMContext.fgInstance.fNewInRepositoryDAO.delete(newGuy);
}
// TODO: This is a grotesque hack to deal with hibernate.
anDAO.flush();
// Make up a new version record.
VersionRoot versionRoot = new VersionRootImpl(this,
fRoot,

View File

@@ -33,7 +33,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
try
{
int n = 8;
int m = 2;
int m = 1;
fReaper.setInactiveBaseSleep(60000);
for (int i = 0; i < n; i++)
{

View File

@@ -23,7 +23,6 @@ import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
@@ -178,8 +177,8 @@ class SuperRepository
@SuppressWarnings("unused")
Repository rep = new RepositoryImpl(this, name);
// Special handling for repository creation.
// TODO is this needed.
rep.getRoot().setIsNew(false);
NewInRepository newInRep = AVMContext.fgInstance.fNewInRepositoryDAO.getByNode(rep.getRoot());
AVMContext.fgInstance.fNewInRepositoryDAO.delete(newInRep);
}
/**
@@ -456,12 +455,10 @@ class SuperRepository
node.setIsRoot(false);
vrDAO.delete(vr);
}
Iterator<AVMNode> iter = AVMContext.fgInstance.fAVMNodeDAO.getByRepository(rep);
while (iter.hasNext())
List<NewInRepository> newGuys = AVMContext.fgInstance.fNewInRepositoryDAO.getByRepository(rep);
for (NewInRepository newGuy : newGuys)
{
AVMNode node = iter.next();
node.setRepository(null);
AVMContext.fgInstance.fAVMNodeDAO.update(node);
AVMContext.fgInstance.fNewInRepositoryDAO.delete(newGuy);
}
AVMContext.fgInstance.fRepositoryDAO.delete(rep);
}

View File

@@ -27,12 +27,8 @@
<!-- This should really be not null, but I haven't figured out
the right way to build the relation so that nullability constraints
won't cause violations in the db during saves. -->
<many-to-one name="repository" column="repository"
class="RepositoryImpl"/>
<property name="versionID" type="int" column="version_id"
not-null="true"/>
<property name="isNew" column="is_new" type="boolean"
not-null="true"/>
<component name="basicAttributes" class="BasicAttributesImpl">
<property name="creator" type="string" not-null="true"/>
<property name="owner" type="string" not-null="true"/>
@@ -175,6 +171,12 @@
<key-many-to-one name="mto" class="AVMNodeImpl" column="mto"/>
</composite-id>
</class>
<class name="NewInRepositoryImpl" proxy="NewInRepository" table="new_in_repository_nodes">
<composite-id>
<key-many-to-one name="repository" class="RepositoryImpl" column="repository_id"/>
<key-many-to-one name="node" class="AVMNodeImpl" column="node_id"/>
</composite-id>
</class>
<query name="ChildEntry.ByNameParent">
<![CDATA[
from ChildEntryImpl ce
@@ -204,9 +206,8 @@
</query>
<query name="AVMNode.ByNewInRepo">
<![CDATA[
from AVMNodeImpl a
where
a.repository = :repo and a.isNew = true
from NewInRepositoryImpl nie
where nie.repository = :rep
]]>
</query>
<query name="AVMNode.GetDescendents">

View File

@@ -53,26 +53,6 @@ public class AVMNodeDAOHibernate extends HibernateDaoSupport implements
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 unreferenceRepository(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.
@@ -91,20 +71,6 @@ public class AVMNodeDAOHibernate extends HibernateDaoSupport implements
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.

View File

@@ -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.NewInRepository;
import org.alfresco.repo.avm.NewInRepositoryDAO;
import org.alfresco.repo.avm.Repository;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Hibernate implementation of NewInRepository DAO.
* @author britt
*/
public class NewInRepositoryDAOHibernate extends HibernateDaoSupport implements
NewInRepositoryDAO
{
/**
* Save one.
* @param newEntry The item to save.
*/
public void save(NewInRepository newEntry)
{
getSession().save(newEntry);
}
/**
* Get one by Node.
* @param node The node to lookup with.
* @return The Entry or null if not found.
*/
public NewInRepository getByNode(AVMNode node)
{
Query query = getSession().createQuery("from NewInRepositoryImpl nie where nie.node = :node");
query.setEntity("node", node);
return (NewInRepository)query.uniqueResult();
}
/**
* Get all that are in the given repository.
* @param repository The Repository.
* @return A List of NewInRepositorys.
*/
@SuppressWarnings("unchecked")
public List<NewInRepository> getByRepository(Repository repository)
{
Query query = getSession().createQuery("from NewInRepositoryImpl nie where nie.repository = :rep");
query.setEntity("rep", repository);
return (List<NewInRepository>)query.list();
}
/**
* Delete the given entry.
* @param newEntry The entry to delete.
*/
public void delete(NewInRepository newEntry)
{
getSession().delete(newEntry);
}
}