Point checkin. Hibernate is currently beating me up by not doing

what I expect when trying to determine the concrete type of a polymorphic
type.  Some major surgery seems to be in order.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2927 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-05-20 15:34:17 +00:00
parent 72751fdedb
commit 2ee957f5e2
7 changed files with 164 additions and 70 deletions

View File

@@ -17,6 +17,8 @@
package org.alfresco.repo.avm;
import java.util.ArrayList;
import org.alfresco.repo.avm.hibernate.HibernateHelper;
import org.alfresco.repo.avm.impl.AVMServiceImpl;
import org.hibernate.cfg.Configuration;
@@ -56,6 +58,7 @@ public class AVMServiceTest extends TestCase
@Override
protected void tearDown() throws Exception
{
HibernateHelper.Reset();
}
/**
@@ -64,4 +67,43 @@ public class AVMServiceTest extends TestCase
public void testNothing()
{
}
/**
* Test making a simple directory.
*/
public void testCreateDirectory()
{
try
{
fService.createDirectory("main:/", "testdir");
ArrayList<String> toSnapshot = new ArrayList<String>();
toSnapshot.add("main");
fService.createSnapshot(toSnapshot);
}
catch (Exception e)
{
e.printStackTrace(System.err);
fail();
}
}
/**
* Test creating a file.
*/
public void testCreateFile()
{
try
{
testCreateDirectory();
fService.createFile("main:testdir", "testfile");
ArrayList<String> toSnapshot = new ArrayList<String>();
toSnapshot.add("main");
fService.createSnapshot(toSnapshot);
}
catch (Exception e)
{
e.printStackTrace(System.err);
fail();
}
}
}

View File

@@ -4,10 +4,10 @@
<!-- AVMNodeBean is the abstract base for filesystem like objects.
We're using the one table per class hierarchy strategy to implement
polymorphism. -->
<class table="avm_nodes" lazy="true" abstract="true"
<class table="avm_nodes" abstract="true"
name="AVMNodeBeanImpl"
proxy="AVMNodeBean"
optimistic-lock="version">
optimistic-lock="version" lazy="false">
<cache usage="read-write"/>
<!-- The id is set programmatically using an Issuer. See below. -->
<id name="id" column="id" type="long"/>
@@ -49,21 +49,24 @@
<!-- Directories, two flavors. -->
<subclass name="DirectoryNodeBeanImpl"
proxy="DirectoryNodeBean"
abstract="true">
abstract="true"
lazy="false">
<!-- A Layered Directory is our smart symlink thingy. -->
<subclass
name="LayeredDirectoryNodeBeanImpl"
proxy="LayeredDirectoryNodeBean" discriminator-value="layereddirectory">
<subclass name="LayeredDirectoryNodeBeanImpl"
proxy="LayeredDirectoryNodeBean"
discriminator-value="layereddirectory" lazy="false">
<!-- The layer id is an implementation trick to disambiguate
exactly what layer is being refered to in various circumstances. -->
<property name="layerID" column="layer_id" type="long" not-null="true"/>
<property name="layerID" column="layer_id" type="long"
not-null="true" />
<!-- The is the moral equivalent of the value of a symlink. -->
<property name="indirection" column="indirection" type="string"
length="511"/>
<property name="indirection" column="indirection"
type="string" length="511" />
<!-- This marks a layered directory as either knowing itself what
it points at (true) or inheriting what it points at from its
container (false). -->
<property name="primaryIndirection" column="primary_indirection" type="boolean"/>
<property name="primaryIndirection"
column="primary_indirection" type="boolean" />
<!-- Map of names to DirectoryEntries. -->
<map name="added" cascade="all">
<key column="directory_id" />
@@ -74,8 +77,8 @@
<property name="type" column="type_name"
type="string" length="30" not-null="true" />
<many-to-one name="child"
class="AVMNodeBeanImpl"
cascade="save-update" not-null="true">
class="AVMNodeBeanImpl" cascade="save-update"
not-null="true">
</many-to-one>
</composite-element>
</map>
@@ -89,7 +92,7 @@
</subclass>
<!-- Just plain directories. -->
<subclass name="PlainDirectoryNodeBeanImpl"
discriminator-value="plaindirectory" proxy="PlainDirectoryNodeBean">
discriminator-value="plaindirectory" proxy="PlainDirectoryNodeBean" lazy="false">
<!-- For reference count based garbage collection of purged nodes
to work we need to specially mark the root directory of
a Repository as special so that its absence of parents will
@@ -101,9 +104,10 @@
<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"/>
<composite-element
class="org.alfresco.repo.avm.hibernate.DirectoryEntry">
<property name="type" type="string"
not-null="true" length="30" column="type_name" />
<many-to-one name="child"
class="org.alfresco.repo.avm.hibernate.AVMNodeBeanImpl"
not-null="true" cascade="save-update">
@@ -115,19 +119,20 @@
<!-- There are two kinds of files, plain and symlinky. -->
<subclass name="FileNodeBeanImpl"
proxy="FileNodeBean"
abstract="true">
abstract="true"
lazy="false">
<!-- Plain files just have a reference to a Content object. -->
<subclass discriminator-value="plainfile"
name="PlainFileNodeBeanImpl"
proxy="PlainFileNodeBean">
name="PlainFileNodeBeanImpl" proxy="PlainFileNodeBean" lazy="false">
<many-to-one name="content" column="content_id"
class="ContentBeanImpl" fetch="join" cascade="save-update">
</many-to-one>
</subclass>
<!-- Layered files are almost exactly copy on write symlinks. -->
<subclass name="LayeredFileNodeBeanImpl"
discriminator-value="layeredfile" proxy="LayeredFileNodeBean">
<property name="indirection" type="string" length="511" column="indirection"/>
discriminator-value="layeredfile" proxy="LayeredFileNodeBean" lazy="false">
<property name="indirection" type="string" length="511"
column="indirection" />
</subclass>
</subclass>
</class>

View File

@@ -222,4 +222,39 @@ public class BasicAttributesBeanImpl implements BasicAttributesBean
{
return fAccessDate;
}
// TODO This is probably wrong.
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (fID == null)
{
return false;
}
if (!(obj instanceof BasicAttributesBean))
{
return false;
}
return fID == ((BasicAttributesBean)obj).getId();
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
if (fID == null)
{
return 0;
}
return fID.hashCode();
}
}

View File

@@ -30,6 +30,25 @@ public class HibernateHelper
static
{
Reset();
}
public static SessionFactory GetSessionFactory()
{
return fgFactory;
}
public static Configuration GetConfiguration()
{
return fgCfg;
}
public static void Reset()
{
if (fgFactory != null)
{
fgFactory.close();
}
try
{
fgCfg = new Configuration();
@@ -42,14 +61,4 @@ public class HibernateHelper
System.exit(1);
}
}
public static SessionFactory GetSessionFactory()
{
return fgFactory;
}
public static Configuration GetConfiguration()
{
return fgCfg;
}
}

View File

@@ -77,8 +77,8 @@ public class TestPopulate extends TestCase
{
// Set up issuers.
Issuer nodeIssuer = new Issuer("node", 0, session);
Issuer contentIssuer = new Issuer("content", 0, session);
Issuer repositoryIssuer = new Issuer("repository", 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",

View File

@@ -99,6 +99,7 @@ public class RepositoryImpl implements Repository
fData.setRoot(rootBean);
fData.getRoots().put(fData.getNextVersionID(), rootBean);
fData.setNextVersionID(fData.getNextVersionID());
fSuper.getSession().save(fData);
}
/**

View File

@@ -142,6 +142,8 @@ public class SuperRepositoryImpl implements SuperRepository
// Newing up the object causes it to be written to the db.
@SuppressWarnings("unused")
Repository rep = new RepositoryImpl(this, name);
// Special handling for repository creation.
rep.getDataBean().getRoot().setIsNew(false);
}
/* (non-Javadoc)
@@ -485,7 +487,7 @@ public class SuperRepositoryImpl implements SuperRepository
*/
private Repository getRepositoryByName(String name)
{
Query query = fSession.createQuery("from repositories r where r.name = :name");
Query query = fSession.createQuery("from RepositoryBeanImpl r where r.name = :name");
query.setString("name", name);
return new RepositoryImpl(this, (RepositoryBean)query.uniqueResult());
}