Having managed to get WCM-DEV royally screwed up, I made a new branch,

WCM-DEV2 and added back my changes.  


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2804 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-05-09 23:22:15 +00:00
parent 76740ffe1c
commit 8433c03ed0
51 changed files with 6385 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.alfresco.repo.avm.hibernate">
<class table="avm_nodes" lazy="true" abstract="true"
name="AVMNodeBeanImpl"
proxy="AVMNodeBean"
optimistic-lock="version">
<cache usage="read-write"/>
<id name="id" column="id" type="long">
</id>
<discriminator column="class_type" type="string" length="20"></discriminator>
<version column="vers" name="vers" type="long"></version>
<many-to-one name="ancestor" column="ancestor_id"
class="AVMNodeBeanImpl">
</many-to-one>
<many-to-one name="mergedFrom" column="merged_from"
class="AVMNodeBeanImpl">
</many-to-one>
<many-to-one name="parent" column="parent_id"
class="DirectoryNodeBeanImpl">
</many-to-one>
<!-- This should really be not null, but hibernate doesn't provide
a way of saving both a RepositoryBean and an AVMNodeBean,
that refer to new instances of each other. -->
<many-to-one name="repository" column="repository"
class="RepositoryBeanImpl" cascade="save-update">
</many-to-one>
<property name="versionID" type="long" column="version_id"
not-null="true">
</property>
<property name="branchID" type="long" column="branch_id"
not-null="true">
</property>
<property name="isNew" column="is_new" type="boolean"
not-null="true">
</property>
<subclass name="DirectoryNodeBeanImpl"
proxy="DirectoryNodeBean"
abstract="true">
<subclass
name="LayeredDirectoryNodeBeanImpl"
proxy="LayeredDirectoryNodeBean" discriminator-value="layereddirectory">
<property name="layerID" column="layer_id" type="long"></property>
<property name="indirection" column="indirection" type="string" length="511"></property>
<property name="primaryIndirection" column="primary_indirection" type="boolean"></property>
<map name="added" cascade="all">
<key column="directory_id"></key>
<map-key type="string" column="name"></map-key>
<composite-element class="org.alfresco.repo.avm.hibernate.DirectoryEntry">
<property name="type" column="type_name"
type="string" length="30" not-null="true">
</property>
<many-to-one name="child"
class="org.alfresco.repo.avm.hibernate.AVMNodeBeanImpl"
cascade="save-update" not-null="true">
</many-to-one>
</composite-element>
</map>
<set name="deleted" table="deleted_children"
fetch="join" cascade="all">
<key column="directory_id"></key>
<element type="string" column="name"></element>
</set>
</subclass>
<subclass name="PlainDirectoryNodeBeanImpl"
discriminator-value="plaindirectory" proxy="PlainDirectoryNodeBean">
<property name="isRoot" column="is_root" type="boolean"/>
<map name="children" cascade="all">
<key column="directory_id"></key>
<map-key type="string" column="name"></map-key>
<composite-element class="org.alfresco.repo.avm.hibernate.DirectoryEntry">
<property name="type" type="string" not-null="true" length="30" column="type_name">
</property>
<many-to-one name="child"
class="org.alfresco.repo.avm.hibernate.AVMNodeBeanImpl"
not-null="true" cascade="save-update">
</many-to-one>
</composite-element>
</map>
</subclass>
</subclass>
<subclass name="FileNodeBeanImpl"
proxy="FileNodeBean"
abstract="true">
<subclass discriminator-value="plainfile"
name="PlainFileNodeBeanImpl"
proxy="PlainFileNodeBean">
<many-to-one name="content" column="content_id"
class="ContentBeanImpl" fetch="join" cascade="save-update">
</many-to-one>
</subclass>
<subclass name="LayeredFileNodeBeanImpl"
discriminator-value="layeredfile" proxy="LayeredFileNodeBean">
<property name="indirection" type="string" length="511" column="indirection"></property>
</subclass>
</subclass>
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,134 @@
/*
* 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;
/**
* The base Node class for the new versioning model, at least for now.
* @author britt
*/
public interface AVMNodeBean
{
/**
* Set the object id of this node.
* @param id The Object ID.
*/
public void setId(long id);
/**
* Get the object id of this node.
* @return The Object ID of this node.
*/
public long getId();
/**
* Set the version id.
* @param id The version id of the node.
*/
public void setVersionID(long id);
/**
* Get the version id of this node.
* @return The version id.
*/
public long getVersionID();
/**
* Set the parent of this node. This is only a canonical parent,
* the one that this node had at the time of its creation.
* @param parent The id of the parent node.
*/
public void setParent(DirectoryNodeBean parent);
/**
* Get the parent of this node.
* @return The parent of this node.
*/
public DirectoryNodeBean getParent();
/**
* Set the node that is this node's direct ancestor.
* @param ancestor The id of the ancestor node.
*/
public void setAncestor(AVMNodeBean ancestor);
/**
* Get the direct ancestor of this node.
* @return The id of the direct ancestor of this node.
*/
public AVMNodeBean getAncestor();
/**
* Set the node that this node was merged from.
* @param mergedFrom The id of the node from which this was merged.
*/
public void setMergedFrom(AVMNodeBean mergedFrom);
/**
* Get the node that this was merged from.
* @return The id of the node this was merged from.
*/
public AVMNodeBean getMergedFrom();
/**
* Set the branch id.
* @param branchID The branch id to set.
*/
public void setBranchID(long branchID);
/**
* Get the branch id of this node.
* @return The branch id of this node.
*/
public long getBranchID();
/**
* Set the Repository that owns this node.
* @param repository The repository that owns this node.
*/
public void setRepository(RepositoryBean repository);
/**
* Get the Repository that owns this node.
* @return The Repository.
*/
public RepositoryBean getRepository();
/**
* Set is new.
* @param isNew
*/
public void setIsNew(boolean isNew);
/**
* Get is new.
* @return Whether this node is new.
*/
public boolean getIsNew();
/**
* Set the version (for concurrency management.)
* @param vers The version.
*/
public void setVers(long vers);
/**
* Get the version (for concurrency management.)
* @return The version.
*/
public long getVers();
}

View File

@@ -0,0 +1,275 @@
/*
* 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;
/**
* Base interface for versioned and layered node implementation data objects.
* @author britt
*/
public class AVMNodeBeanImpl implements AVMNodeBean
{
/**
* The Object ID (and Primary Key)
*/
private long fID;
/**
* The Version ID
*/
private long fVersionID;
/**
* The Branch ID
*/
private long fBranchID;
/**
* The ancestor of this.
*/
private AVMNodeBean fAncestor;
/**
* The node that was merged into this.
*/
private AVMNodeBean fMergedFrom;
/**
* The id of the parent of this.
*/
private DirectoryNodeBean fParent;
/**
* The Repository that owns this.
*/
private RepositoryBean fRepository;
/**
* Whether this node is new (and should therefore not be COWed).
*/
private boolean fIsNew;
/**
* The version number (for concurrency control).
*/
private long fVers;
/**
* Anonymous constructor.
*/
public AVMNodeBeanImpl()
{
}
/**
* Rich constructor.
* @param id The ID to set.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent.
* @param repository The repository.
*/
public AVMNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository)
{
fID = id;
fVersionID = versionID;
fBranchID = branchID;
fAncestor = ancestor;
fMergedFrom = mergedFrom;
fParent = parent;
fRepository = repository;
fIsNew = true;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof AVMNodeBean))
{
return false;
}
return fID == ((AVMNodeBean)obj).getId();
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return (int)fID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setId(int)
*/
public void setId(long id)
{
fID = id;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getId()
*/
public long getId()
{
return fID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setVersionID(int)
*/
public void setVersionID(long id)
{
fVersionID = id;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getVersionID()
*/
public long getVersionID()
{
return fVersionID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setParent(int)
*/
public void setParent(DirectoryNodeBean parent)
{
fParent = parent;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getParent()
*/
public DirectoryNodeBean getParent()
{
return fParent;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setAncestor(int)
*/
public void setAncestor(AVMNodeBean ancestor)
{
fAncestor = ancestor;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getAncestor()
*/
public AVMNodeBean getAncestor()
{
return fAncestor;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setMergedFrom(int)
*/
public void setMergedFrom(AVMNodeBean mergedFrom)
{
fMergedFrom = mergedFrom;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getMergedFrom()
*/
public AVMNodeBean getMergedFrom()
{
return fMergedFrom;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#setBranchID(int)
*/
public void setBranchID(long branchID)
{
fBranchID = branchID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNode#getBranchID()
*/
public long getBranchID()
{
return fBranchID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNodeBean#getRepository()
*/
public RepositoryBean getRepository()
{
return fRepository;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.AVMNodeBean#setRepository(org.alfresco.proto.avm.RepositoryBean)
*/
public void setRepository(RepositoryBean repository)
{
fRepository = repository;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.AVMNodeBean#getIsNew()
*/
public boolean getIsNew()
{
return fIsNew;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.AVMNodeBean#setIsNew(boolean)
*/
public void setIsNew(boolean isNew)
{
fIsNew = isNew;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.AVMNodeBean#getVers()
*/
public long getVers()
{
return fVers;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.AVMNodeBean#setVers(java.lang.int)
*/
public void setVers(long vers)
{
fVers = vers;
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.alfresco.repo.avm.hibernate">
<class table="contents" name="ContentBeanImpl" proxy="ContentBean"
optimistic-lock="version">
<cache usage="read-write" />
<id name="id" column="id" type="long">
</id>
<version name="vers" column="vers" type="long"></version>
<property name="refCount" column="ref_count" type="int"
not-null="true">
</property>
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,61 @@
/*
* 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;
/**
* This exists to share content across different versions.
* @author britt
*/
public interface ContentBean
{
/**
* Set the object id.
* @param id The object id.
*/
public void setId(long id);
/**
* Get the object id.
* @return The object id.
*/
public long getId();
/**
* Set the reference count on this.
* @param refCount The reference count to set.
*/
public void setRefCount(int refCount);
/**
* Get the reference count on this.
* @return The reference count.
*/
public int getRefCount();
/**
* Set the version (for concurrency control).
* @param vers The version.
*/
public void setVers(long vers);
/**
* Get the version (for concurrency control).
* @return The version.
*/
public long getVers();
}

View File

@@ -0,0 +1,124 @@
/*
* 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;
/**
* @author britt
*
*/
public class ContentBeanImpl implements ContentBean
{
/**
* The object id.
*/
private long fID;
/**
* The reference count of this id.
*/
private int fRefCount;
/**
* The version (for concurrency control).
*/
private long fVers;
/**
* Basic constructor with an id.
*/
public ContentBeanImpl(long id)
{
fID = id;
fRefCount = 0;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Content#setId(int)
*/
public void setId(long id)
{
fID = id;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Content#getID()
*/
public long getId()
{
return fID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Content#setRefCount(int)
*/
public void setRefCount(int refCount)
{
fRefCount = refCount;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Content#getRefCount()
*/
public int getRefCount()
{
return fRefCount;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof ContentBean))
{
return false;
}
return fID == ((ContentBean)obj).getId();
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return (int)fID;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.ContentBean#getVers()
*/
public long getVers()
{
return fVers;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.ContentBean#setVers(java.lang.int)
*/
public void setVers(long vers)
{
fVers = vers;
}
}

View File

@@ -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 org.alfresco.repo.avm.AVMNodeType;
/**
* This holds Directory Entries in directories.
* @author britt
*/
public class DirectoryEntry
{
/**
* The type of entry a node is.
*/
private AVMNodeType fType;
/**
* This is the actual child Node.
*/
private AVMNodeBean fChild;
/**
* Anonymous constructor.
*/
public DirectoryEntry()
{
}
/**
* Make one from scratch.
* @param type The type.
* @param child The child node.
*/
public DirectoryEntry(AVMNodeType 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.
*/
public void setChild(AVMNodeBean child)
{
fChild = child;
}
/**
* Get the child.
* @return The child.
*/
public AVMNodeBean getChild()
{
return fChild;
}
/**
* Set the type by name.
* @param name The name of the type.
*/
public void setType(String name)
{
fType = Enum.valueOf(AVMNodeType.class, name);
}
/**
* Get the type name.
*/
public String getType()
{
return fType.name();
}
}

View File

@@ -0,0 +1,22 @@
/*
* 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;
public interface DirectoryNodeBean extends AVMNodeBean
{
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.avm.hibernate;
/**
* Base for all for all directory data types.
* @author britt
*/
public class DirectoryNodeBeanImpl extends AVMNodeBeanImpl implements DirectoryNodeBean
{
/**
* Anonymous constructor.
*/
public DirectoryNodeBeanImpl()
{
super();
}
/**
* Rich constructor.
* @param id The id to assign it.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent.
*/
public DirectoryNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository);
}
}

View File

@@ -0,0 +1,27 @@
/*
* 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;
/**
* Doesn't do much.
* @author britt
*/
public interface FileNodeBean extends AVMNodeBean
{
}

View File

@@ -0,0 +1,54 @@
/*
* 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;
/**
* Doesn't do much.
* @author britt
*/
public class FileNodeBeanImpl extends AVMNodeBeanImpl implements FileNodeBean
{
/**
* Anonymous constructor.
*/
public FileNodeBeanImpl()
{
super();
}
/**
* Rich constructor.
* @param id The ID to set.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent.
*/
public FileNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository);
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* @author britt
*/
public class HibernateHelper
{
private static Configuration fgCfg = null;
private static SessionFactory fgFactory = null;
static
{
try
{
fgCfg = new Configuration();
fgCfg.configure();
fgFactory = fgCfg.buildSessionFactory();
}
catch (Throwable t)
{
t.printStackTrace(System.err);
System.exit(1);
}
}
public static SessionFactory GetSessionFactory()
{
return fgFactory;
}
public static Configuration GetConfiguration()
{
return fgCfg;
}
}

View File

@@ -0,0 +1,93 @@
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 org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
/**
* Helper for DAOs.
* @author britt
*/
public class HibernateTxn
{
/**
* The SessionFactory.
*/
private SessionFactory fSessionFactory;
/**
* Make one up.
* @param sessionFactory The SessionFactory.
*/
public HibernateTxn(SessionFactory sessionFactory)
{
fSessionFactory = sessionFactory;
}
/**
* Perform a set of operations under a single Hibernate transaction.
* @param callback The worker.
* @return Whether the operation finished with a commit.
*/
public boolean perform(HibernateTxnCallback callback)
{
Session sess = null;
Transaction txn = null;
try
{
sess = fSessionFactory.openSession();
txn = sess.beginTransaction();
callback.perform(sess);
txn.commit();
return true;
}
catch (Throwable t)
{
t.printStackTrace(System.err);
if (txn != null)
{
try
{
txn.rollback();
}
catch (HibernateException he)
{
// Do nothing.
}
}
return false;
}
finally
{
if (sess != null)
{
try
{
sess.close();
}
catch (HibernateException he)
{
// Do nothing.
}
}
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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);
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.alfresco.repo.avm.hibernate">
<class name="Issuer" table="issuers" lazy="false"
optimistic-lock="version">
<cache usage="read-write" />
<id name="name" column="name" type="string" length="20"></id>
<version name="vers" column="vers" type="long"></version>
<property name="next" column="next" type="long"
not-null="true">
</property>
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,122 @@
/*
* 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;
/**
* This is a helper class that knows how to issue identifiers.
* @author britt
*/
public class Issuer
{
/**
* The name of this issuer. Used as the primary key in it's
* mapping.
*/
private String fName;
/**
* The next number to issue.
*/
private long fNext;
/**
* The version (for concurrency control).
*/
private long fVers;
/**
* Anonymous constructor.
*/
public Issuer()
{
}
/**
* Rich constructor.
* @param name The name of this issuer.
* @param next The next number to issue.
*/
public Issuer(String name, long next)
{
fName = name;
fNext = next;
}
// Bean methods.
/**
* Set the name of this issuer.
* @param name The name to set.
*/
public void setName(String name)
{
fName = name;
}
/**
* Get the name of this issuer.
* @return The name of this issuer.
*/
public String getName()
{
return fName;
}
/**
* Set the next number.
* @param next The next number.
*/
public void setNext(long next)
{
fNext = next;
}
/**
* Get the next number.
* @return The next number.
*/
public long getNext()
{
return fNext;
}
/**
* Issue the next number.
* @return A serial number.
*/
public long issue()
{
return fNext++;
}
/**
* @return the vers
*/
public long getVers()
{
return fVers;
}
/**
* @param vers the vers to set
*/
public void setVers(long vers)
{
fVers = vers;
}
}

View File

@@ -0,0 +1,68 @@
package org.alfresco.repo.avm.hibernate;
import java.util.Map;
import java.util.Set;
public interface LayeredDirectoryNodeBean extends DirectoryNodeBean
{
/**
* Set the layer id.
* @param id The id to set.
*/
public void setLayerID(long id);
/**
* Get the layer id.
* @return The layer id.
*/
public long getLayerID();
/**
* Set the indirection.
* @param indirection The indirection to set.
*/
public void setIndirection(String indirection);
/**
* Get the indirection.
* @return The indirection.
*/
public String getIndirection();
/**
* Set the added map.
* @param added The added children.
*/
public void setAdded(Map<String, DirectoryEntry> added);
/**
* Get the added map.
* @return The map of added children.
*/
public Map<String, DirectoryEntry> getAdded();
/**
* Set the Set of deleted names.
* @param deleted The deleted names.
*/
public void setDeleted(Set<String> deleted);
/**
* Get the Set of deleted names.
* @return The Set of deleted names.
*/
public Set<String> getDeleted();
/**
* Set the primary indirection-ness of this.
* @param primary Whether this is a primary indirection node.
*/
public void setPrimaryIndirection(boolean primary);
/**
* Get the primary indirection-ness of this.
* @return Whether this is a primary indirection node.
*/
public boolean getPrimaryIndirection();
}

View File

@@ -0,0 +1,173 @@
/*
* 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.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Layered directories are semitransparent links to other directories.
* They maintain a delta of what has been changed relative to what they
* link to.
* @author britt
*/
public class LayeredDirectoryNodeBeanImpl extends DirectoryNodeBeanImpl implements LayeredDirectoryNodeBean
{
/**
* The Layer ID.
*/
private long fLayerID;
/**
* The link to the underlying directory.
*/
private String fIndirection;
/**
* The Map of nodes added in this layer.
*/
private Map<String, DirectoryEntry> fAdded;
/**
* The Set of names that have been deleted.
*/
private Set<String> fDeleted;
/**
* Whether this is a primary indirection node.
*/
private boolean fPrimaryIndirection;
/**
* Anonymous constructor.
*/
public LayeredDirectoryNodeBeanImpl()
{
super();
}
/**
* Rich constructor.
* @param id The id to assign.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent node.
* @param layerID The layer id of this node.
* @param indirection The indirection pointer of this.
*/
public LayeredDirectoryNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository,
long layerID,
String indirection)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository);
fLayerID = layerID;
fIndirection = indirection;
fAdded = new HashMap<String, DirectoryEntry>();
fDeleted = new HashSet<String>();
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#setLayerID(int)
*/
public void setLayerID(long id)
{
fLayerID = id;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#getLayerID()
*/
public long getLayerID()
{
return fLayerID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#setIndirection(java.lang.String)
*/
public void setIndirection(String indirection)
{
fIndirection = indirection;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#getIndirection()
*/
public String getIndirection()
{
return fIndirection;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#setAdded(java.util.Map)
*/
public void setAdded(Map<String, DirectoryEntry> added)
{
fAdded = added;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#getAdded()
*/
public Map<String, DirectoryEntry> getAdded()
{
return fAdded;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#setDeleted(java.util.Set)
*/
public void setDeleted(Set<String> deleted)
{
fDeleted = deleted;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.LayeredDirectoryNode#getDeleted()
*/
public Set<String> getDeleted()
{
return fDeleted;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.LayeredDirectoryNodeBean#getPrimaryIndirection()
*/
public boolean getPrimaryIndirection()
{
return fPrimaryIndirection;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.LayeredDirectoryNodeBean#setPrimaryIndirection(boolean)
*/
public void setPrimaryIndirection(boolean primary)
{
fPrimaryIndirection = primary;
}
}

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.hibernate;
/**
* Very much like a copy on write symlink.
* @author britt
*/
public interface LayeredFileNodeBean extends FileNodeBean
{
/**
* Set the indirection for this node.
* @param indirection The indirection to set.
*/
public void setIndirection(String indirection);
/**
* Get the indirection for this node.
* @return The indirection.
*/
public String getIndirection();
}

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;
/**
* @author britt
*/
public class LayeredFileNodeBeanImpl extends FileNodeBeanImpl implements
LayeredFileNodeBean
{
/**
* The indirection.
*/
private String fIndirection;
/**
* Anonymous constructor.
*/
public LayeredFileNodeBeanImpl()
{
super();
}
/**
* Rich constructor.
* @param id The ID to set.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent.
* @param indirection The indirection pointer.
*/
public LayeredFileNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository,
String indirection)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository);
fIndirection = indirection;
}
/**
* @see org.alfresco.repo.avm.hibernate.LayeredFileNodeBean#setIndirection(java.lang.String)
*/
public void setIndirection(String indirection)
{
fIndirection = indirection;
}
/**
* @see org.alfresco.repo.avm.hibernate.LayeredFileNodeBean#getIndirection()
*/
public String getIndirection()
{
return fIndirection;
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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.Map;
public interface PlainDirectoryNodeBean extends DirectoryNodeBean
{
/**
* Set the child map.
* @param children The Map to set.
*/
public void setChildren(Map<String, DirectoryEntry> children);
/**
* Get the child map.
* @return The map of child names to IDs.
*/
public Map<String, DirectoryEntry> getChildren();
/**
* Set whether this node is a root directory.
* @param isRoot
*/
public void setIsRoot(boolean isRoot);
/**
* Get whether this node is a root directory.
* @return Whether it is.
*/
public boolean getIsRoot();
}

View File

@@ -0,0 +1,102 @@
/*
* 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.HashMap;
import java.util.Map;
/**
* A plain directory node is just a map of names to AVMNodes.
* @author britt
*/
public class PlainDirectoryNodeBeanImpl extends DirectoryNodeBeanImpl implements PlainDirectoryNodeBean
{
/**
* The child map.
*/
private Map<String, DirectoryEntry> fChildren;
/**
* Whether this is a root node.
*/
private boolean fIsRoot;
/**
* Anonymous constructor.
*/
public PlainDirectoryNodeBeanImpl()
{
super();
}
/**
* Rich constructor.
* @param id The id to assign it.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent.
* @param isRoot Whether this is a root node.
*/
public PlainDirectoryNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository,
boolean isRoot)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository);
fChildren = new HashMap<String, DirectoryEntry>();
fIsRoot = isRoot;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.PlainDirectoryNode#setChildren(java.util.Map)
*/
public void setChildren(Map<String, DirectoryEntry> children)
{
fChildren = children;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.PlainDirectoryNode#getChildren()
*/
public Map<String, DirectoryEntry> getChildren()
{
return fChildren;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.PlainDirectoryNodeBean#getIsRoot()
*/
public boolean getIsRoot()
{
return fIsRoot;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.PlainDirectoryNodeBean#setIsRoot(boolean)
*/
public void setIsRoot(boolean isRoot)
{
fIsRoot = isRoot;
}
}

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.hibernate;
/**
* A Plain File Node. Contains a possibly shared Content object.
* @author britt
*/
public interface PlainFileNodeBean extends FileNodeBean
{
/**
* Set the Content object for this.
*/
public void setContent(ContentBean content);
/**
* Get the Content object for this.
* @return The Content object.
*/
public ContentBean getContent();
}

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;
/**
* @author britt
*
*/
public class PlainFileNodeBeanImpl extends FileNodeBeanImpl implements PlainFileNodeBean
{
/**
* The Content object.
*/
private ContentBean fContent;
/**
* Anonymous constructor.
*/
public PlainFileNodeBeanImpl()
{
super();
}
/**
* Rich constructor.
* @param id The ID to set.
* @param versionID The version id.
* @param branchID The branch id.
* @param ancestor The ancestor.
* @param mergedFrom The node that merged into us.
* @param parent The parent.
* @param content The content object.
*/
public PlainFileNodeBeanImpl(long id,
long versionID,
long branchID,
AVMNodeBean ancestor,
AVMNodeBean mergedFrom,
DirectoryNodeBean parent,
RepositoryBean repository,
ContentBean content)
{
super(id, versionID, branchID, ancestor, mergedFrom, parent, repository);
fContent = content;
}
/**
* @see org.alfresco.repo.avm.hibernate.PlainFileNodeBean#setContent(org.alfresco.repo.avm.hibernate.ContentBean)
*/
public void setContent(ContentBean content)
{
fContent = content;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.PlainFileNode#getContent()
*/
public ContentBean getContent()
{
return fContent;
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.alfresco.repo.avm.hibernate">
<class table="repositories" name="RepositoryBeanImpl"
proxy="RepositoryBean" optimistic-lock="version">
<cache usage="read-write" />
<id name="name" column="name" type="string"></id>
<version name="vers" column="vers" type="long"></version>
<property type="long" name="nextVersionID"
column="next_version_id" not-null="true">
</property>
<!-- This should be not-null but hibernate makes that difficult. -->
<many-to-one name="root" class="DirectoryNodeBeanImpl"
column="current_root_id" unique="true" cascade="save-update">
</many-to-one>
<map name="roots" table="repository_roots">
<key column="repository_id"></key>
<map-key type="long" column="version_id"></map-key>
<many-to-many class="DirectoryNodeBeanImpl"
column="directory_id">
</many-to-many>
</map>
<set table="new_nodes" name="newNodes" cascade="all">
<key column="repository_id"></key>
<many-to-many class="AVMNodeBeanImpl"
column="new_node_id">
</many-to-many>
</set>
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,101 @@
/*
* 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.Map;
import java.util.Set;
/**
* This is responsible for keeping track of the root
* directories for different versions.
* @author britt
*/
public interface RepositoryBean
{
/**
* Set the name of this Repository.
* @param name The name of the respository.
*/
public void setName(String name);
/**
* Get the name of this Repository.
* @return The name.
*/
public String getName();
/**
* Set the current root.
* @param root The root to set.
*/
public void setRoot(DirectoryNodeBean root);
/**
* Get the current root.
* @return The current root.
*/
public DirectoryNodeBean getRoot();
/**
* Set the roots map.
* @param roots The Map of version ids to roots.
*/
public void setRoots(Map<Long, DirectoryNodeBean> roots);
/**
* Get the roots map.
* @return The roots map.
*/
public Map<Long, DirectoryNodeBean> getRoots();
/**
* Set the next version id.
* @param nextVersionID The value to set.
*/
public void setNextVersionID(long nextVersionID);
/**
* Get the next version id.
* @return The next version id.
*/
public long getNextVersionID();
/**
* Set the new nodes.
* @param newNodes The new nodes Set to set.
*/
public void setNewNodes(Set<AVMNodeBean> newNodes);
/**
* Get the new nodes.
* @return The new nodes associated with this Repository.
*/
public Set<AVMNodeBean> getNewNodes();
/**
* Set the version (for concurrency control).
* @param vers The version to set.
*/
public void setVers(long vers);
/**
* Get the version (for concurrency control).
* @return The version.
*/
public long getVers();
}

View File

@@ -0,0 +1,204 @@
/*
* 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.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author britt
*
*/
public class RepositoryBeanImpl implements RepositoryBean
{
/**
* The name of this repository.
*/
private String fName;
/**
* The current root directory.
*/
private DirectoryNodeBean fRoot;
/**
* The root directories for all versions.
*/
private Map<Long, DirectoryNodeBean> fRoots;
/**
* The next version id.
*/
private long fNextVersionID;
/**
* The nodes that are new since the last end operation.
*/
private Set<AVMNodeBean> fNewNodes;
/**
* The version (for concurrency control).
*/
private long fVers;
/**
* Anonymous constructor.
*/
public RepositoryBeanImpl()
{
}
/**
* Rich constructor
* @param name The name of the Repository.
* @param root The current root node.
*/
public RepositoryBeanImpl(String name,
DirectoryNodeBean root)
{
fName = name;
fNextVersionID = 0;
fRoot = root;
fRoots = new HashMap<Long, DirectoryNodeBean>();
fNewNodes = new HashSet<AVMNodeBean>();
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RepositoryBean#getName()
*/
public String getName()
{
return fName;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RepositoryBean#setName(java.lang.String)
*/
public void setName(String name)
{
fName = name;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#setRoot(org.alfresco.proto.avm.DirectoryNode)
*/
public void setRoot(DirectoryNodeBean root)
{
fRoot = root;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#getRoot()
*/
public DirectoryNodeBean getRoot()
{
return fRoot;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#setRoots(java.util.Map)
*/
public void setRoots(Map<Long, DirectoryNodeBean> roots)
{
fRoots = roots;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#getRoots()
*/
public Map<Long, DirectoryNodeBean> getRoots()
{
return fRoots;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#setNextVersionID(int)
*/
public void setNextVersionID(long nextVersionID)
{
fNextVersionID = nextVersionID;
}
/* (non-Javadoc)
* @see org.alfresco.proto.avm.Repository#getNextVersionID()
*/
public long getNextVersionID()
{
return fNextVersionID;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof RepositoryBean))
{
return false;
}
return fName.equals(((RepositoryBean)obj).getName());
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return fName.hashCode();
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RepositoryBean#getNewNodes()
*/
public Set<AVMNodeBean> getNewNodes()
{
return fNewNodes;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RepositoryBean#setNewNodes(java.util.Set)
*/
public void setNewNodes(Set<AVMNodeBean> newNodes)
{
fNewNodes = newNodes;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RepositoryBean#getVers()
*/
public long getVers()
{
return fVers;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.hibernate.RepositoryBean#setVers(java.lang.int)
*/
public void setVers(long vers)
{
fVers = vers;
}
}

View File

@@ -0,0 +1,211 @@
/*
* 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);
Issuer contentIssuer = new Issuer("content", 0);
Issuer repositoryIssuer = new Issuer("repository", 0);
// Make the initial root directory.
PlainDirectoryNodeBean root =
new PlainDirectoryNodeBeanImpl(nodeIssuer.issue(),
0,
0,
null,
null,
null,
null,
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);
session.save(nodeIssuer);
session.save(contentIssuer);
session.save(repositoryIssuer);
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, 0L);
long version = rep.getNextVersionID();
rep.setNextVersionID(version + 1);
assertTrue(rep != null);
PlainDirectoryNodeBean root = (PlainDirectoryNodeBean)rep.getRoot();
PlainDirectoryNodeBean newRoot = new PlainDirectoryNodeBeanImpl(nodeIssuer.issue(),
version,
0L,
root,
null,
null,
rep,
true);
ContentBean content = new ContentBeanImpl(contentIssuer.issue());
PlainFileNodeBean file = new PlainFileNodeBeanImpl(nodeIssuer.issue(),
version,
0L,
null,
null,
newRoot,
rep,
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);
file = new PlainFileNodeBeanImpl(nodeIssuer.issue(),
version,
0L,
null,
null,
newRoot,
rep,
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());
}
}
});
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, 0L);
PlainDirectoryNodeBean root = (PlainDirectoryNodeBean)rep.getRoot();
PlainDirectoryNodeBean prev = (PlainDirectoryNodeBean)root.getAncestor();
rep.setRoot(prev);
rep.getRoots().remove(1);
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();
}
}
}