Retyped a counter so had to muck with many beans. Forced creation of layered directories

to work.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2930 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-05-21 21:59:41 +00:00
parent dd585adedf
commit df28c98983
30 changed files with 349 additions and 384 deletions

View File

@@ -34,7 +34,7 @@
won't cause violations in the db during saves. -->
<many-to-one name="repository" column="repository"
class="RepositoryBeanImpl" cascade="save-update"/>
<property name="versionID" type="long" column="version_id"
<property name="versionID" type="int" column="version_id"
not-null="true"/>
<!-- The branch id is always 0 for nodes that are not part of
a branch. -->
@@ -80,8 +80,8 @@
<!-- A DirectoryEntry is a (node)type AVMNode reference pair.
Should probably convert type into an integer code. -->
<composite-element class="DirectoryEntry">
<property name="type" column="type_name"
type="string" length="30" not-null="true" />
<property name="type" column="type_code"
type="int" not-null="true" />
<many-to-one name="child"
class="AVMNodeBeanImpl" cascade="save-update"
not-null="true">
@@ -106,14 +106,14 @@
this probably wants to be in the base class. -->
<property name="isRoot" column="is_root" type="boolean" />
<!-- A map of names to DirectoryEntries. In the AVM world, it makes sense
that nodes don't know there own names, only there containers do. -->
that nodes don't know there own names, only their containers do. -->
<map name="children" cascade="all">
<key column="directory_id" />
<map-key type="string" column="name" />
<composite-element
class="org.alfresco.repo.avm.hibernate.DirectoryEntry">
<property name="type" type="string"
not-null="true" length="30" column="type_name" />
<property name="type" type="int"
not-null="true" column="type_code" />
<many-to-one name="child"
class="org.alfresco.repo.avm.hibernate.AVMNodeBeanImpl"
not-null="true" cascade="save-update">
@@ -176,7 +176,7 @@
<cache usage="read-write" />
<id name="name" column="name" type="string"/>
<version name="vers" column="vers" type="long"/>
<property type="long" name="nextVersionID"
<property type="int" name="nextVersionID"
column="next_version_id" not-null="true"/>
<!-- Every Repository has a root directory that is the current root directory. -->
<!-- This should be not-null but hibernate (or my own idiocy) makes that difficult. -->
@@ -187,7 +187,7 @@
of versioned root directories. -->
<map name="roots" table="repository_roots">
<key column="repository_id"/>
<map-key type="long" column="version_id"/>
<map-key type="int" column="version_id"/>
<many-to-many class="DirectoryNodeBeanImpl"
column="directory_id"/>
</map>

View File

@@ -39,13 +39,13 @@ public interface AVMNodeBean
* Set the version id.
* @param id The version id of the node.
*/
public void setVersionID(long id);
public void setVersionID(int id);
/**
* Get the version id of this node.
* @return The version id.
*/
public long getVersionID();
public int getVersionID();
/**
* Set the parent of this node. This is only a canonical parent,

View File

@@ -31,7 +31,7 @@ public class AVMNodeBeanImpl implements AVMNodeBean
/**
* The Version ID
*/
private long fVersionID;
private int fVersionID;
/**
* The Branch ID
@@ -91,7 +91,7 @@ public class AVMNodeBeanImpl implements AVMNodeBean
* @param repository The repository.
*/
public AVMNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
@@ -155,7 +155,7 @@ public class AVMNodeBeanImpl implements AVMNodeBean
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setVersionID(int)
*/
public void setVersionID(long id)
public void setVersionID(int id)
{
fVersionID = id;
}
@@ -163,7 +163,7 @@ public class AVMNodeBeanImpl implements AVMNodeBean
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getVersionID()
*/
public long getVersionID()
public int getVersionID()
{
return fVersionID;
}

View File

@@ -28,7 +28,7 @@ public class DirectoryEntry
/**
* The type of entry a node is.
*/
private AVMNodeType fType;
private int fType;
/**
* This is the actual child Node.
@@ -47,31 +47,13 @@ public class DirectoryEntry
* @param type The type.
* @param child The child node.
*/
public DirectoryEntry(AVMNodeType type, AVMNodeBean child)
public DirectoryEntry(int type, AVMNodeBean child)
{
fType = type;
fChild = child;
}
/**
* Set the entry type.
* @param type The type to set.
*/
public void setEntryType(AVMNodeType type)
{
fType = type;
}
/**
* Get the entry type.
* @return The type.
*/
public AVMNodeType getEntryType()
{
return fType;
}
/**
/**
* Set the child.
* @param child The child to set.
*/
@@ -91,19 +73,19 @@ public class DirectoryEntry
/**
* Set the type by name.
* @param name The name of the type.
* @param type The type.
*/
public void setType(String name)
public void setType(int type)
{
fType = Enum.valueOf(AVMNodeType.class, name);
fType = type;
}
/**
* Get the type name.
* Get the type.
*/
public String getType()
public int getType()
{
return fType.name();
return fType;
}
/* (non-Javadoc)
@@ -138,6 +120,6 @@ public class DirectoryEntry
@Override
public String toString()
{
return "[" + fType.name() + "] " + fChild.getId();
return "[" + fType + "] " + fChild.getId();
}
}

View File

@@ -41,7 +41,7 @@ public class DirectoryNodeBeanImpl extends AVMNodeBeanImpl implements DirectoryN
* @param parent The parent.
*/
public DirectoryNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,

View File

@@ -42,7 +42,7 @@ public class FileNodeBeanImpl extends AVMNodeBeanImpl implements FileNodeBean
* @param parent The parent.
*/
public FileNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,

View File

@@ -72,10 +72,11 @@ public class LayeredDirectoryNodeBeanImpl extends DirectoryNodeBeanImpl implemen
* @param mergedFrom The node that merged into us.
* @param parent The parent node.
* @param layerID The layer id of this node.
* @param primary Whether this is a primary indirection node.
* @param indirection The indirection pointer of this.
*/
public LayeredDirectoryNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
@@ -83,10 +84,12 @@ public class LayeredDirectoryNodeBeanImpl extends DirectoryNodeBeanImpl implemen
RepositoryBean repository,
BasicAttributesBean attrs,
long layerID,
boolean primary,
String indirection)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository, attrs);
fLayerID = layerID;
fPrimaryIndirection = primary;
fIndirection = indirection;
fAdded = new HashMap<String, DirectoryEntry>();
fDeleted = new HashSet<String>();

View File

@@ -48,7 +48,7 @@ public class LayeredFileNodeBeanImpl extends FileNodeBeanImpl implements
* @param indirection The indirection pointer.
*/
public LayeredFileNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,

View File

@@ -55,7 +55,7 @@ public class PlainDirectoryNodeBeanImpl extends DirectoryNodeBeanImpl implements
* @param isRoot Whether this is a root node.
*/
public PlainDirectoryNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,

View File

@@ -48,7 +48,7 @@ public class PlainFileNodeBeanImpl extends FileNodeBeanImpl implements PlainFile
* @param content The content object.
*/
public PlainFileNodeBeanImpl(long id,
long versionID,
int versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,

View File

@@ -55,25 +55,25 @@ public interface RepositoryBean
* Set the roots map.
* @param roots The Map of version ids to roots.
*/
public void setRoots(Map<Long, DirectoryNodeBean> roots);
public void setRoots(Map<Integer, DirectoryNodeBean> roots);
/**
* Get the roots map.
* @return The roots map.
*/
public Map<Long, DirectoryNodeBean> getRoots();
public Map<Integer, DirectoryNodeBean> getRoots();
/**
* Set the next version id.
* @param nextVersionID The value to set.
*/
public void setNextVersionID(long nextVersionID);
public void setNextVersionID(int nextVersionID);
/**
* Get the next version id.
* @return The next version id.
*/
public long getNextVersionID();
public int getNextVersionID();
/**
* Set the new nodes.

View File

@@ -41,12 +41,12 @@ public class RepositoryBeanImpl implements RepositoryBean
/**
* The root directories for all versions.
*/
private Map<Long, DirectoryNodeBean> fRoots;
private Map<Integer, DirectoryNodeBean> fRoots;
/**
* The next version id.
*/
private long fNextVersionID;
private int fNextVersionID;
/**
* The nodes that are new since the last end operation.
@@ -76,7 +76,7 @@ public class RepositoryBeanImpl implements RepositoryBean
fName = name;
fNextVersionID = 0;
fRoot = root;
fRoots = new HashMap<Long, DirectoryNodeBean>();
fRoots = new HashMap<Integer, DirectoryNodeBean>();
fNewNodes = new HashSet<AVMNodeBean>();
}
@@ -115,7 +115,7 @@ public class RepositoryBeanImpl implements RepositoryBean
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#setRoots(java.util.Map)
*/
public void setRoots(Map<Long, DirectoryNodeBean> roots)
public void setRoots(Map<Integer, DirectoryNodeBean> roots)
{
fRoots = roots;
}
@@ -123,7 +123,7 @@ public class RepositoryBeanImpl implements RepositoryBean
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#getRoots()
*/
public Map<Long, DirectoryNodeBean> getRoots()
public Map<Integer, DirectoryNodeBean> getRoots()
{
return fRoots;
}
@@ -131,7 +131,7 @@ public class RepositoryBeanImpl implements RepositoryBean
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#setNextVersionID(int)
*/
public void setNextVersionID(long nextVersionID)
public void setNextVersionID(int nextVersionID)
{
fNextVersionID = nextVersionID;
}
@@ -139,7 +139,7 @@ public class RepositoryBeanImpl implements RepositoryBean
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#getNextVersionID()
*/
public long getNextVersionID()
public int getNextVersionID()
{
return fNextVersionID;
}

View File

@@ -1,233 +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.alfresco.repo.avm.AVMNodeType;
import org.alfresco.repo.avm.hibernate.ContentBean;
import org.alfresco.repo.avm.hibernate.ContentBeanImpl;
import org.alfresco.repo.avm.hibernate.HibernateHelper;
import org.alfresco.repo.avm.hibernate.HibernateTxn;
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
import org.alfresco.repo.avm.hibernate.Issuer;
import org.alfresco.repo.avm.hibernate.PlainDirectoryNodeBean;
import org.alfresco.repo.avm.hibernate.PlainDirectoryNodeBeanImpl;
import org.alfresco.repo.avm.hibernate.PlainFileNodeBean;
import org.alfresco.repo.avm.hibernate.PlainFileNodeBeanImpl;
import org.alfresco.repo.avm.hibernate.RepositoryBean;
import org.alfresco.repo.avm.hibernate.RepositoryBeanImpl;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import junit.framework.TestCase;
public class TestPopulate extends TestCase
{
/**
* The SessionFactory.
*/
private SessionFactory fSessionFactory;
public TestPopulate(String name)
{
super(name);
}
protected void setUp() throws Exception
{
fSessionFactory = HibernateHelper.GetSessionFactory();
Configuration cfg = HibernateHelper.GetConfiguration();
SchemaExport se = new SchemaExport(cfg);
se.drop(false, true);
se.create(false, true);
}
protected void tearDown() throws Exception
{
}
/**
* Add some data to persistent store.
*/
public void testPopulate()
{
try
{
HibernateTxn hTxn = new HibernateTxn(fSessionFactory);
boolean result = hTxn.perform(
new HibernateTxnCallback()
{
public void perform(Session session)
{
// Set up issuers.
Issuer nodeIssuer = new Issuer("node", 0, session);
new Issuer("content", 0, session);
new Issuer("repository", 0, session);
// Make the initial root directory.
long time = System.currentTimeMillis();
BasicAttributesBean attrs = new BasicAttributesBeanImpl("britt",
"britt",
"britt",
time,
time,
time);
session.save(attrs);
PlainDirectoryNodeBean root =
new PlainDirectoryNodeBeanImpl(nodeIssuer.issue(),
0,
0,
null,
null,
null,
null,
attrs,
true);
// Make a new repository.
RepositoryBean rep =
new RepositoryBeanImpl("main", root);
root.setRepository(rep);
session.save(rep);
rep.getRoots().put(rep.getNextVersionID(), root);
rep.setNextVersionID(rep.getNextVersionID() + 1);
root.setIsNew(false);
}
});
assertTrue(result);
System.out.println("--------------------------------------------");
result = hTxn.perform(
new HibernateTxnCallback()
{
public void perform(Session session)
{
// Now read some things back, and modify some stuff.
Issuer nodeIssuer = (Issuer)session.get(Issuer.class, "node");
Issuer contentIssuer = (Issuer)session.get(Issuer.class, "content");
RepositoryBean rep = (RepositoryBean)session.get(RepositoryBeanImpl.class, "main");
long version = rep.getNextVersionID();
rep.setNextVersionID(version + 1);
assertTrue(rep != null);
PlainDirectoryNodeBean root = (PlainDirectoryNodeBean)rep.getRoot();
long time = System.currentTimeMillis();
BasicAttributesBean attrs = new BasicAttributesBeanImpl("britt",
"britt",
"britt",
time,
time,
time);
session.save(attrs);
PlainDirectoryNodeBean newRoot = new PlainDirectoryNodeBeanImpl(nodeIssuer.issue(),
version,
0L,
root,
null,
null,
rep,
attrs,
true);
ContentBean content = new ContentBeanImpl(contentIssuer.issue());
attrs = new BasicAttributesBeanImpl(attrs);
session.save(attrs);
PlainFileNodeBean file = new PlainFileNodeBeanImpl(nodeIssuer.issue(),
version,
0L,
null,
null,
newRoot,
rep,
attrs,
content);
content.setRefCount(content.getRefCount() + 1);
newRoot.getChildren().put("foo", new DirectoryEntry(AVMNodeType.PLAIN_FILE, file));
session.save(content);
session.save(newRoot);
content = new ContentBeanImpl(contentIssuer.issue());
content.setRefCount(content.getRefCount() + 1);
file.setIsNew(false);
attrs = new BasicAttributesBeanImpl(attrs);
session.save(attrs);
file = new PlainFileNodeBeanImpl(nodeIssuer.issue(),
version,
0L,
null,
null,
newRoot,
rep,
attrs,
content);
session.save(content);
file.setIsNew(false);
newRoot.getChildren().put("bar", new DirectoryEntry(AVMNodeType.PLAIN_FILE, file));
rep.setRoot(newRoot);
rep.getRoots().put(version, newRoot);
newRoot.setIsNew(false);
}
});
assertTrue(result);
System.out.println("-----------------------------------------------");
result = hTxn.perform(
new HibernateTxnCallback()
{
public void perform(Session session)
{
Query query = session.createQuery("from RepositoryBeanImpl r where r.name = :name");
query.setString("name", "main");
RepositoryBean rep = (RepositoryBean)query.uniqueResult();
PlainDirectoryNodeBean root = (PlainDirectoryNodeBean)rep.getRoot();
assertEquals(2, root.getChildren().size());
for (String name : root.getChildren().keySet())
{
System.out.println(name);
}
for (DirectoryEntry entry : root.getChildren().values())
{
assertEquals(AVMNodeType.PLAIN_FILE, entry.getEntryType());
}
assertEquals("britt", root.getBasicAttributes().getCreator());
}
});
assertTrue(result);
System.out.println("----------------------------------------------");
// Just check cascading deletes for the children of a directory.
result = hTxn.perform(
new HibernateTxnCallback()
{
public void perform(Session session)
{
RepositoryBean rep = (RepositoryBean)session.get(RepositoryBeanImpl.class, "main");
PlainDirectoryNodeBean root = (PlainDirectoryNodeBean)rep.getRoot();
PlainDirectoryNodeBean prev = (PlainDirectoryNodeBean)root.getAncestor();
rep.getRoots().remove(rep.getRoot().getId());
rep.setRoot(prev);
for (String name : root.getChildren().keySet())
{
AVMNodeBean child = root.getChildren().get(name).getChild();
child.setParent(null);
}
session.delete(root);
}
});
assertTrue(result);
}
catch (Exception e)
{
e.printStackTrace(System.err);
fail();
}
}
}