Added the opacity bit to layered directories, and a method to set it. The opacity

status is returned in AVMNodeDescriptors now. Basic test added.  Also restored
a bunch of commented out checks in a number of tests.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3257 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-27 21:26:39 +00:00
parent 72f2ff989d
commit 39728a6f86
13 changed files with 340 additions and 102 deletions

View File

@@ -101,6 +101,11 @@ public class AVMNodeDescriptor
*/ */
private long fLength; private long fLength;
/**
* The opacity for layered directories.
*/
private boolean fOpacity;
/** /**
* Make one up. * Make one up.
* @param path The looked up path. * @param path The looked up path.
@@ -132,6 +137,7 @@ public class AVMNodeDescriptor
String indirection, String indirection,
boolean isPrimary, boolean isPrimary,
long layerID, long layerID,
boolean opacity,
long length) long length)
{ {
fPath = path; fPath = path;
@@ -149,6 +155,7 @@ public class AVMNodeDescriptor
fIsPrimary = isPrimary; fIsPrimary = isPrimary;
fLayerID = layerID; fLayerID = layerID;
fLength = length; fLength = length;
fOpacity = opacity;
} }
/** /**
@@ -357,6 +364,14 @@ public class AVMNodeDescriptor
return fName; return fName;
} }
/**
* @return the opacity
*/
public boolean getOpacity()
{
return fOpacity;
}
/** /**
* Get a debuggable string representation of this. * Get a debuggable string representation of this.
* @return A string representation of this. * @return A string representation of this.

View File

@@ -270,4 +270,11 @@ public interface AVMService
* @return A List of ancestors starting with the most recent. * @return A List of ancestors starting with the most recent.
*/ */
public List<AVMNodeDescriptor> getHistory(AVMNodeDescriptor desc, int count); public List<AVMNodeDescriptor> getHistory(AVMNodeDescriptor desc, int count);
/**
* Set the opacity of a layered directory. An opaque layered directory
* hides the contents of its indirection.
* @param path The path to the layered directory.
*/
public void setOpacity(String path, boolean opacity);
} }

View File

@@ -860,4 +860,28 @@ public class AVMServiceImpl implements AVMService
fTransaction.perform(doit, false); fTransaction.perform(doit, false);
return doit.history; return doit.history;
} }
/**
* Set the opacity of a layered directory. An opaque layer hides what
* its indirection points to.
* @param path The path to the layered directory.
* @param opacity True is opaque false is not.
*/
public void setOpacity(final String path, final boolean opacity)
{
if (path == null)
{
throw new AVMBadArgumentException("Null path.");
}
class HTxnCallback implements HibernateTxnCallback
{
public void perform(Session session)
{
fSuperRepository.setSession(session);
fSuperRepository.setOpacity(path, opacity);
}
}
HTxnCallback doit = new HTxnCallback();
fTransaction.perform(doit, false);
}
} }

View File

@@ -70,16 +70,19 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b should contain fao and bar // /layer/b should contain fao and bar
listing = fService.getDirectoryListing(-1, "main:/layer/b"); listing = fService.getDirectoryListing(-1, "main:/layer/b");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("bar", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("foo", listing.get(1).getName()); assertEquals("bar", list.get(0));
assertEquals("foo", list.get(1));
// /a/b should contain foo. // /a/b should contain foo.
listing = fService.getDirectoryListing(-1, "main:/a/b"); listing = fService.getDirectoryListing(-1, "main:/a/b");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("foo", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("foo", list.get(0));
// /a/c should contain bar. // /a/c should contain bar.
listing = fService.getDirectoryListing(-1, "main:/a/c"); listing = fService.getDirectoryListing(-1, "main:/a/c");
// assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("bar", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("bar", list.get(0));
// Now make a file in /a/b // Now make a file in /a/b
fService.createFile("main:/a/b", "baz").close(); fService.createFile("main:/a/b", "baz").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -88,15 +91,17 @@ public class AVMServiceTest extends AVMServiceTestBase
// /a/b should contain baz and foo. // /a/b should contain baz and foo.
listing = fService.getDirectoryListing(-1, "main:/a/b"); listing = fService.getDirectoryListing(-1, "main:/a/b");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("baz", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("foo", listing.get(1).getName()); assertEquals("baz", list.get(0));
assertEquals("foo", list.get(1));
// /layer/b should contain foo, bar, and baz. // /layer/b should contain foo, bar, and baz.
listing = fService.getDirectoryListing(-1, "main:/layer/b"); listing = fService.getDirectoryListing(-1, "main:/layer/b");
System.out.println(recursiveList("main", -1, true)); System.out.println(recursiveList("main", -1, true));
assertEquals(3, listing.size()); assertEquals(3, listing.size());
// assertEquals("bar", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("baz", listing.get(1).getName()); assertEquals("bar", list.get(0));
// assertEquals("foo", listing.get(2).getName()); assertEquals("baz", list.get(1));
assertEquals("foo", list.get(2));
// Remove baz from /layer/b // Remove baz from /layer/b
fService.removeNode("main:/layer/b", "baz"); fService.removeNode("main:/layer/b", "baz");
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -106,13 +111,15 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b should have bar and foo. // /layer/b should have bar and foo.
listing = fService.getDirectoryListing(-1, "main:/layer/b"); listing = fService.getDirectoryListing(-1, "main:/layer/b");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("bar", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("foo", listing.get(1).getName()); assertEquals("bar", list.get(0));
assertEquals("foo", list.get(1));
// /a/b should contain baz and foo as before. // /a/b should contain baz and foo as before.
listing = fService.getDirectoryListing(-1, "main:/a/b"); listing = fService.getDirectoryListing(-1, "main:/a/b");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("baz", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("foo", listing.get(1).getName()); assertEquals("baz", list.get(0));
assertEquals("foo", list.get(1));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -163,8 +170,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/d should no contain baz and figs. // /layer/d should no contain baz and figs.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/d"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/d");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("baz", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("figs", listing.get(1).getName()); assertEquals("baz", list.get(0));
assertEquals("figs", list.get(1));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -219,8 +227,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/d should now contain baz and figs. // /layer/d should now contain baz and figs.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/d"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/d");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("baz", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("figs", listing.get(1).getName()); assertEquals("baz", list.get(0));
assertEquals("figs", list.get(1));
// Rename /layer/d to /layer/e and uncover /layer/d // Rename /layer/d to /layer/e and uncover /layer/d
fService.rename("main:/layer", "d", "main:/layer", "e"); fService.rename("main:/layer", "d", "main:/layer", "e");
fService.uncover("main:/layer", "d"); fService.uncover("main:/layer", "d");
@@ -230,11 +239,13 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/d contains figs. // /layer/d contains figs.
listing = fService.getDirectoryListing(-1, "main:/layer/d"); listing = fService.getDirectoryListing(-1, "main:/layer/d");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("figs", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("figs", list.get(0));
// /layer/e contains baz. // /layer/e contains baz.
listing = fService.getDirectoryListing(-1, "main:/layer/e"); listing = fService.getDirectoryListing(-1, "main:/layer/e");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("baz", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("baz", list.get(0));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -283,9 +294,10 @@ public class AVMServiceTest extends AVMServiceTestBase
// /b should have foo and bar and baz. // /b should have foo and bar and baz.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/b"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/b");
assertEquals(3, listing.size()); assertEquals(3, listing.size());
// assertEquals("bar", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("baz", listing.get(1).getName()); assertEquals("bar", list.get(0));
// assertEquals("foo", listing.get(2).getName()); assertEquals("baz", list.get(1));
assertEquals("foo", list.get(2));
// Add something to /a and it will show up in /layer. // Add something to /a and it will show up in /layer.
fService.createFile("main:/a", "figs").close(); fService.createFile("main:/a", "figs").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -293,8 +305,9 @@ public class AVMServiceTest extends AVMServiceTestBase
checkHistory(history, "main"); checkHistory(history, "main");
// /layer should have figs in it. // /layer should have figs in it.
listing = fService.getDirectoryListing(-1, "main:/layer"); listing = fService.getDirectoryListing(-1, "main:/layer");
// assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("figs", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("figs", list.get(0));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -403,8 +416,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/under/e should contain bow and f. // /layer/under/e should contain bow and f.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/under/e"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/under/e");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("bow", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("f", listing.get(1).getName()); assertEquals("bow", list.get(0));
assertEquals("f", list.get(1));
// Put a new set of dirs in to be made into a layering under d. // Put a new set of dirs in to be made into a layering under d.
fService.createDirectory("main:/", "g"); fService.createDirectory("main:/", "g");
fService.createDirectory("main:/g", "h"); fService.createDirectory("main:/g", "h");
@@ -444,8 +458,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/under/gover/h/i shows both moo and cow. // /layer/under/gover/h/i shows both moo and cow.
listing = fService.getDirectoryListing(-1, "main:/layer/under/gover/h/i"); listing = fService.getDirectoryListing(-1, "main:/layer/under/gover/h/i");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("cow", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("moo", listing.get(1).getName()); assertEquals("cow", list.get(0));
assertEquals("moo", list.get(1));
// Rename /layer/under/gover to /layer/b/gover and see what happens. // Rename /layer/under/gover to /layer/b/gover and see what happens.
fService.rename("main:/layer/under", "gover", "main:/layer/b", "gover"); fService.rename("main:/layer/under", "gover", "main:/layer/b", "gover");
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -454,7 +469,8 @@ public class AVMServiceTest extends AVMServiceTestBase
// moo should be in /layer/b/gover/h/i // moo should be in /layer/b/gover/h/i
listing = fService.getDirectoryListing(-1, "main:/layer/b/gover/h/i"); listing = fService.getDirectoryListing(-1, "main:/layer/b/gover/h/i");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("moo", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("moo", list.get(0));
// Add a new file to /layer/b/gover/h/i // Add a new file to /layer/b/gover/h/i
fService.createFile("main:/layer/b/gover/h/i", "oink").close(); fService.createFile("main:/layer/b/gover/h/i", "oink").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -463,8 +479,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b/gover/h/i should contain moo, oink. // /layer/b/gover/h/i should contain moo, oink.
listing = fService.getDirectoryListing(-1, "main:/layer/b/gover/h/i"); listing = fService.getDirectoryListing(-1, "main:/layer/b/gover/h/i");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("moo", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("oink", listing.get(1).getName()); assertEquals("moo", list.get(0));
assertEquals("oink", list.get(1));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -969,7 +986,8 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.createSnapshot("main"); fService.createSnapshot("main");
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/a"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/a");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("b", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
assertEquals("b", list.get(0));
fService.createLayeredDirectory("main:/a", "main:/", "c"); fService.createLayeredDirectory("main:/a", "main:/", "c");
fService.createLayeredDirectory("main:/c", "main:/", "d"); fService.createLayeredDirectory("main:/c", "main:/", "d");
fService.createFile("main:/d/b", "foo.txt").close(); fService.createFile("main:/d/b", "foo.txt").close();
@@ -977,23 +995,27 @@ public class AVMServiceTest extends AVMServiceTestBase
System.out.println(recursiveList("main", -1, true)); System.out.println(recursiveList("main", -1, true));
listing = fService.getDirectoryListing(-1, "main:/d/b"); listing = fService.getDirectoryListing(-1, "main:/d/b");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("foo.txt", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("foo.txt", list.get(0));
fService.createFile("main:/c/b", "bar.txt").close(); fService.createFile("main:/c/b", "bar.txt").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
System.out.println(recursiveList("main", -1, true)); System.out.println(recursiveList("main", -1, true));
listing = fService.getDirectoryListing(-1, "main:/c/b"); listing = fService.getDirectoryListing(-1, "main:/c/b");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("bar.txt", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("bar.txt", list.get(0));
listing = fService.getDirectoryListing(-1, "main:/d/b"); listing = fService.getDirectoryListing(-1, "main:/d/b");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("bar.txt", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("foo.txt", listing.get(1).getName()); assertEquals("bar.txt", list.get(0));
assertEquals("foo.txt", list.get(1));
fService.rename("main:/", "c", "main:/", "e"); fService.rename("main:/", "c", "main:/", "e");
fService.createSnapshot("main"); fService.createSnapshot("main");
System.out.println(recursiveList("main", -1, true)); System.out.println(recursiveList("main", -1, true));
listing = fService.getDirectoryListing(-1, "main:/d/b"); listing = fService.getDirectoryListing(-1, "main:/d/b");
// assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("foo.txt", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("foo.txt", list.get(0));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -1088,28 +1110,32 @@ public class AVMServiceTest extends AVMServiceTestBase
// /g/b/c/d should contain foo and bar. // /g/b/c/d should contain foo and bar.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/g/b/c/d"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/g/b/c/d");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("bar", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("foo", listing.get(1).getName()); assertEquals("bar", list.get(0));
assertEquals("foo", list.get(1));
// /f/b/c/d should contain just bar. // /f/b/c/d should contain just bar.
listing = fService.getDirectoryListing(-1, "main:/f/b/c/d"); listing = fService.getDirectoryListing(-1, "main:/f/b/c/d");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("bar", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
assertEquals("bar", list.get(0));
// Now do something in the bottom layer. // Now do something in the bottom layer.
fService.createFile("main:/a/b/c", "baz").close(); fService.createFile("main:/a/b/c", "baz").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
// /e/b/c should contain baz and d // /e/b/c should contain baz and d
listing = fService.getDirectoryListing(-1, "main:/e/b/c"); listing = fService.getDirectoryListing(-1, "main:/e/b/c");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("baz", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("d", listing.get(1).getName()); assertEquals("baz", list.get(0));
assertEquals("d", list.get(1));
// Now add something in the e layer. // Now add something in the e layer.
fService.createFile("main:/e/b/c/d", "bing").close(); fService.createFile("main:/e/b/c/d", "bing").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
// /f/b/c/d should now contain bar and bing. // /f/b/c/d should now contain bar and bing.
listing = fService.getDirectoryListing(-1, "main:/f/b/c/d"); listing = fService.getDirectoryListing(-1, "main:/f/b/c/d");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("bar", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("bing", listing.get(1).getName()); assertEquals("bar", list.get(0));
assertEquals("bing", list.get(1));
System.out.println(recursiveList("main", -1, true)); System.out.println(recursiveList("main", -1, true));
} }
catch (Exception e) catch (Exception e)
@@ -1144,16 +1170,18 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer should contain b and moved // /layer should contain b and moved
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("b", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("moved", listing.get(1).getName()); assertEquals("b", list.get(0));
assertEquals("moved", list.get(1));
// Now rename moved back to d. // Now rename moved back to d.
fService.rename("main:/layer", "moved", "main:/layer", "d"); fService.rename("main:/layer", "moved", "main:/layer", "d");
fService.createSnapshot("main"); fService.createSnapshot("main");
// /layer should contain b and d. // /layer should contain b and d.
listing = fService.getDirectoryListing(-1, "main:/layer"); listing = fService.getDirectoryListing(-1, "main:/layer");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("b", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("d", listing.get(1).getName()); assertEquals("b", list.get(0));
assertEquals("d", list.get(1));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -1252,9 +1280,10 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer2/c should contain foo bar and baz. // /layer2/c should contain foo bar and baz.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer2/c"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer2/c");
assertEquals(3, listing.size()); assertEquals(3, listing.size());
// assertEquals("bar", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("baz", listing.get(1).getName()); assertEquals("bar", list.get(0));
// assertEquals("foo", listing.get(2).getName()); assertEquals("baz", list.get(1));
assertEquals("foo", list.get(2));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -1291,7 +1320,8 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b/c should contain e. // /layer/b/c should contain e.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/c"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/c");
assertEquals(1, listing.size()); assertEquals(1, listing.size());
// assertEquals("e", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
assertEquals("e", list.get(0));
// Rename /layer/b/c to /layer/c // Rename /layer/b/c to /layer/c
fService.rename("main:/layer/b", "c", "main:/layer", "c"); fService.rename("main:/layer/b", "c", "main:/layer", "c");
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -1314,8 +1344,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer2/c should have baz and e in it. // /layer2/c should have baz and e in it.
listing = fService.getDirectoryListing(-1, "main:/layer2/c"); listing = fService.getDirectoryListing(-1, "main:/layer2/c");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("baz", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("e", listing.get(1).getName()); assertEquals("baz", list.get(0));
assertEquals("e", list.get(1));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -1431,8 +1462,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b/branch/e/f should contain moo and cow. // /layer/b/branch/e/f should contain moo and cow.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/branch/e/f"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/branch/e/f");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("cow", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("moo", listing.get(1).getName()); assertEquals("cow", list.get(0));
assertEquals("moo", list.get(1));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -1487,8 +1519,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b/branch/e/f should contain moo and cow. // /layer/b/branch/e/f should contain moo and cow.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/d/e/f"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/d/e/f");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("cow", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("moo", listing.get(1).getName()); assertEquals("cow", list.get(0));
assertEquals("moo", list.get(1));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -1546,8 +1579,9 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b/c/fover/g/h/iover/j/k should contain pismo and foo. // /layer/b/c/fover/g/h/iover/j/k should contain pismo and foo.
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/c/fover/g/h/iover/j/k"); Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/c/fover/g/h/iover/j/k");
assertEquals(2, listing.size()); assertEquals(2, listing.size());
// assertEquals("foo", listing.get(0).getName()); List<String> list = new ArrayList<String>(listing.keySet());
// assertEquals("pismo", listing.get(1).getName()); assertEquals("foo", list.get(0));
assertEquals("pismo", list.get(1));
// Make a file in /flayer/g/h/iover/j/k // Make a file in /flayer/g/h/iover/j/k
fService.createFile("main:/flayer/g/h/iover/j/k", "zuma").close(); fService.createFile("main:/flayer/g/h/iover/j/k", "zuma").close();
fService.createSnapshot("main"); fService.createSnapshot("main");
@@ -1556,9 +1590,10 @@ public class AVMServiceTest extends AVMServiceTestBase
// /layer/b/c/fover/g/h/iover/j/k should contain foo, pismo, and zuma. // /layer/b/c/fover/g/h/iover/j/k should contain foo, pismo, and zuma.
listing = fService.getDirectoryListing(-1, "main:/layer/b/c/fover/g/h/iover/j/k"); listing = fService.getDirectoryListing(-1, "main:/layer/b/c/fover/g/h/iover/j/k");
assertEquals(3, listing.size()); assertEquals(3, listing.size());
// assertEquals("foo", listing.get(0).getName()); list = new ArrayList<String>(listing.keySet());
// assertEquals("pismo", listing.get(1).getName()); assertEquals("foo", list.get(0));
// assertEquals("zuma", listing.get(2).getName()); assertEquals("pismo", list.get(1));
assertEquals("zuma", list.get(2));
for (String val : history.values()) for (String val : history.values())
{ {
System.out.println(val); System.out.println(val);
@@ -1837,7 +1872,7 @@ public class AVMServiceTest extends AVMServiceTestBase
/** /**
* Test repository functions. * Test repository functions.
*/ */
public void testRepsitory() public void testRepository()
{ {
try try
{ {
@@ -1863,4 +1898,53 @@ public class AVMServiceTest extends AVMServiceTestBase
fail(); fail();
} }
} }
/**
* Test opacity and manipulations.
*/
public void testOpacity()
{
try
{
setupBasicTree();
fService.createLayeredDirectory("main:/a", "main:/", "layer");
fService.createSnapshot("main");
fService.createFile("main:/layer/b/c", "baz").close();
fService.createFile("main:/layer/b/c", "fig").close();
fService.createSnapshot("main");
Map<String, AVMNodeDescriptor> listing = fService.getDirectoryListing(-1, "main:/layer/b/c");
assertEquals(4, listing.size());
System.out.println(recursiveList("main", -1, true));
// Setting the opacity of layer to true will make no difference to what we see through
// main:/layer/b/c.
fService.setOpacity("main:/layer", true);
fService.createSnapshot("main");
assertTrue(fService.lookup(-1, "main:/layer").getOpacity());
assertEquals(4, fService.getDirectoryListing(-1, "main:/layer/b/c").size());
System.out.println(recursiveList("main", -1, true));
// If main:/layer/b/c is opaque, however, we'll only see two items in it.
fService.setOpacity("main:/layer", false);
fService.setOpacity("main:/layer/b/c", true);
fService.createSnapshot("main");
assertFalse(fService.lookup(-1, "main:/layer").getOpacity());
assertTrue(fService.lookup(-1, "main:/layer/b/c").getOpacity());
assertEquals(2, fService.getDirectoryListing(-1, "main:/layer/b/c").size());
System.out.println(recursiveList("main", -1, true));
// Gratuitous test of retarget.
fService.retargetLayeredDirectory("main:/layer", "main:/d");
fService.setOpacity("main:/layer/b/c", false);
fService.createSnapshot("main");
assertFalse(fService.lookup(-1, "main:/layer/b/c").getOpacity());
assertEquals(2, fService.getDirectoryListing(-1, "main:/layer/b/c").size());
// This is just testing that opacity setting works on latent
// layered directories.
fService.setOpacity("main:/layer/e/f", true);
System.out.println(recursiveList("main", -1, true));
}
catch (Exception e)
{
e.printStackTrace(System.err);
fail();
}
}
} }

View File

@@ -77,4 +77,17 @@ interface LayeredDirectoryNode extends DirectoryNode, Layered
* @return All deleted children. * @return All deleted children.
*/ */
public List<DeletedChild> getDeleted(); public List<DeletedChild> getDeleted();
/**
* Set the opacity of this.
* @param opacity Whether this should be opaque, i.e. not see the things it
* in its indirection.
*/
public void setOpacity(boolean opacity);
/**
* Get the opacity of this.
* @return The opacity.
*/
public boolean getOpacity();
} }

View File

@@ -53,6 +53,11 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
*/ */
private boolean fPrimaryIndirection; private boolean fPrimaryIndirection;
/**
* Whether this is opaque.
*/
private boolean fOpacity;
/** /**
* Default constructor. Called by Hibernate. * Default constructor. Called by Hibernate.
*/ */
@@ -71,6 +76,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fLayerID = -1; fLayerID = -1;
fIndirection = indirection; fIndirection = indirection;
fPrimaryIndirection = true; fPrimaryIndirection = true;
fOpacity = false;
repos.getSuperRepository().getSession().save(this); repos.getSuperRepository().getSession().save(this);
} }
@@ -88,6 +94,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fIndirection = other.getUnderlying(); fIndirection = other.getUnderlying();
fPrimaryIndirection = other.getPrimaryIndirection(); fPrimaryIndirection = other.getPrimaryIndirection();
fLayerID = -1; fLayerID = -1;
fOpacity = false;
sess.save(this); sess.save(this);
for (ChildEntry child : other.getChildren()) for (ChildEntry child : other.getChildren())
{ {
@@ -121,6 +128,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fIndirection = null; fIndirection = null;
fPrimaryIndirection = false; fPrimaryIndirection = false;
fLayerID = -1; fLayerID = -1;
fOpacity = false;
Session sess = repos.getSuperRepository().getSession(); Session sess = repos.getSuperRepository().getSession();
sess.save(this); sess.save(this);
if (copyContents) if (copyContents)
@@ -152,6 +160,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fIndirection = srcLookup.getIndirectionPath() + "/" + name; fIndirection = srcLookup.getIndirectionPath() + "/" + name;
fPrimaryIndirection = true; fPrimaryIndirection = true;
fLayerID = -1; fLayerID = -1;
fOpacity = false;
repo.getSuperRepository().getSession().save(this); repo.getSuperRepository().getSession().save(this);
} }
@@ -297,21 +306,28 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
{ {
// Get the base listing from the thing we indirect to. // Get the base listing from the thing we indirect to.
Map<String, AVMNode> baseListing = null; Map<String, AVMNode> baseListing = null;
try if (fOpacity)
{ {
Lookup lookup = SuperRepository.GetInstance().lookupDirectory(-1, getUnderlying(lPath));
DirectoryNode dir = (DirectoryNode)lookup.getCurrentNode();
baseListing = dir.getListing(lookup);
}
catch (AVMException re)
{
if (re instanceof AVMCycleException)
{
throw re;
}
// It's OK for an indirection to dangle.
baseListing = new HashMap<String, AVMNode>(); baseListing = new HashMap<String, AVMNode>();
} }
else
{
try
{
Lookup lookup = SuperRepository.GetInstance().lookupDirectory(-1, getUnderlying(lPath));
DirectoryNode dir = (DirectoryNode)lookup.getCurrentNode();
baseListing = dir.getListing(lookup);
}
catch (AVMException re)
{
if (re instanceof AVMCycleException)
{
throw re;
}
// It's OK for an indirection to dangle.
baseListing = new HashMap<String, AVMNode>();
}
}
// Filter the base listing by taking out anything in the deleted Set. // Filter the base listing by taking out anything in the deleted Set.
Map<String, AVMNode> listing = new TreeMap<String, AVMNode>(); Map<String, AVMNode> listing = new TreeMap<String, AVMNode>();
for (String name : baseListing.keySet()) for (String name : baseListing.keySet())
@@ -341,25 +357,30 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
throw new AVMBadArgumentException("Illegal null argument."); throw new AVMBadArgumentException("Illegal null argument.");
} }
Map<String, AVMNodeDescriptor> baseListing = new TreeMap<String, AVMNodeDescriptor>(); Map<String, AVMNodeDescriptor> baseListing = new TreeMap<String, AVMNodeDescriptor>();
try // If we are not opaque, get the underlying base listing.
if (!fOpacity)
{ {
Lookup lookup = SuperRepository.GetInstance().lookupDirectory(-1, dir.getIndirection()); try
DirectoryNode dirNode = (DirectoryNode)lookup.getCurrentNode();
Map<String, AVMNode> listing = dirNode.getListing(lookup);
for (String name : listing.keySet())
{ {
baseListing.put(name, Lookup lookup = SuperRepository.GetInstance().lookupDirectory(-1, dir.getIndirection());
listing.get(name).getDescriptor(dir.getPath(), name, DirectoryNode dirNode = (DirectoryNode)lookup.getCurrentNode();
lookup.getCurrentIndirection())); Map<String, AVMNode> listing = dirNode.getListing(lookup);
} for (String name : listing.keySet())
} {
catch (AVMException e) baseListing.put(name,
{ listing.get(name).getDescriptor(dir.getPath(), name,
if (e instanceof AVMCycleException) lookup.getCurrentIndirection()));
{ }
throw e; }
catch (AVMException e)
{
if (e instanceof AVMCycleException)
{
throw e;
}
} }
} }
// Remove anything deleted in this layer.
List<DeletedChild> deleted = getDeleted(); List<DeletedChild> deleted = getDeleted();
for (DeletedChild child : deleted) for (DeletedChild child : deleted)
{ {
@@ -397,6 +418,11 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
{ {
return AVMNodeUnwrapper.Unwrap(entry.getChild()); return AVMNodeUnwrapper.Unwrap(entry.getChild());
} }
// Don't check our underlying directory if we are opaque.
if (fOpacity)
{
return null;
}
// Not here so check our indirection. // Not here so check our indirection.
try try
{ {
@@ -437,6 +463,11 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
name, name,
mine.getIndirection()); mine.getIndirection());
} }
// If we are opaque don't check underneath.
if (fOpacity)
{
return null;
}
try try
{ {
Lookup lookup = SuperRepository.GetInstance().lookupDirectory(-1, mine.getIndirection()); Lookup lookup = SuperRepository.GetInstance().lookupDirectory(-1, mine.getIndirection());
@@ -568,6 +599,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
getUnderlying(lPath), getUnderlying(lPath),
fPrimaryIndirection, fPrimaryIndirection,
fLayerID, fLayerID,
fOpacity,
-1); -1);
} }
@@ -595,6 +627,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
getUnderlying(lPath), getUnderlying(lPath),
fPrimaryIndirection, fPrimaryIndirection,
fLayerID, fLayerID,
fOpacity,
-1); -1);
} }
@@ -633,6 +666,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
indirection, indirection,
fPrimaryIndirection, fPrimaryIndirection,
fLayerID, fLayerID,
fOpacity,
-1); -1);
} }
@@ -687,4 +721,23 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
public void setIsRoot(boolean isRoot) public void setIsRoot(boolean isRoot)
{ {
} }
/**
* Get the opacity of this.
* @return The opacity.
*/
public boolean getOpacity()
{
return fOpacity;
}
/**
* Set the opacity of this, ie, whether it blocks things normally
* seen through its indirection.
* @param opacity
*/
public void setOpacity(boolean opacity)
{
fOpacity = opacity;
}
} }

View File

@@ -172,6 +172,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
getUnderlying(lPath), getUnderlying(lPath),
false, false,
-1, -1,
false,
0); 0);
} }
@@ -198,6 +199,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
getUnderlying(lPath), getUnderlying(lPath),
false, false,
-1, -1,
false,
0); 0);
} }
@@ -226,6 +228,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
fIndirection, fIndirection,
false, false,
-1, -1,
false,
0); 0);
} }

View File

@@ -294,6 +294,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
null, null,
false, false,
-1, -1,
false,
-1); -1);
} }
@@ -320,6 +321,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
null, null,
false, false,
-1, -1,
false,
-1); -1);
} }
@@ -348,6 +350,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
null, null,
false, false,
-1, -1,
false,
-1); -1);
} }
} }

View File

@@ -162,6 +162,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
null, null,
false, false,
-1, -1,
false,
getContentForRead().getLength()); getContentForRead().getLength());
} }
@@ -188,6 +189,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
null, null,
false, false,
-1, -1,
false,
getContentForRead().getLength()); getContentForRead().getLength());
} }
@@ -216,6 +218,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
null, null,
false, false,
-1, -1,
false,
getContentForRead().getLength()); getContentForRead().getLength());
} }

View File

@@ -245,4 +245,12 @@ interface Repository
* @return The descriptor. * @return The descriptor.
*/ */
public RepositoryDescriptor getDescriptor(); public RepositoryDescriptor getDescriptor();
/**
* Set the opacity of a layered directory. An opaque directory hides
* what is pointed at by its indirection.
* @param path The path to the layered directory.
* @param opacity True is opaque; false is not.
*/
public void setOpacity(String path, boolean opacity);
} }

View File

@@ -835,4 +835,21 @@ class RepositoryImpl implements Repository, Serializable
{ {
return new RepositoryDescriptor(fName, fCreator, fCreateDate); return new RepositoryDescriptor(fName, fCreator, fCreateDate);
} }
/**
* Set the opacity of a layered directory. An opaque directory hides
* what is pointed at by its indirection.
* @param path The path to the layered directory.
* @param opacity True is opaque; false is not.
*/
public void setOpacity(String path, boolean opacity)
{
Lookup lPath = lookup(-1, path, true);
AVMNode node = lPath.getCurrentNode();
if (!(node instanceof LayeredDirectoryNode))
{
throw new AVMWrongTypeException("Not a LayeredDirectoryNode.");
}
((LayeredDirectoryNode)node).setOpacity(opacity);
}
} }

View File

@@ -868,6 +868,20 @@ class SuperRepository
return history; return history;
} }
/**
* Set the opacity of a layered directory. An opaque directory hides
* the things it points to via indirection.
* @param path The path to the layered directory.
* @param opacity True is opaque; false is not.
*/
public void setOpacity(String path, boolean opacity)
{
fLookupCount.set(1);
String[] pathParts = SplitPath(path);
Repository rep = getRepositoryByName(pathParts[0], true);
rep.setOpacity(pathParts[1], opacity);
}
/** /**
* Get the RepositoryDescriptor for a Repository. * Get the RepositoryDescriptor for a Repository.
* @param name The name of the Repository. * @param name The name of the Repository.

View File

@@ -62,18 +62,12 @@
container (false). --> container (false). -->
<property name="primaryIndirection" <property name="primaryIndirection"
column="primary_indirection" type="boolean"/> column="primary_indirection" type="boolean"/>
<property name="opacity" column="opacity" type="boolean"/>
<!-- Map of names to DirectoryEntries. --> <!-- Map of names to DirectoryEntries. -->
</subclass> </subclass>
<!-- Just plain directories. --> <!-- Just plain directories. -->
<subclass name="PlainDirectoryNodeImpl" <subclass name="PlainDirectoryNodeImpl"
discriminator-value="plaindirectory" proxy="PlainDirectoryNode" lazy="true"> discriminator-value="plaindirectory" proxy="PlainDirectoryNode" lazy="true">
<!-- 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
not cause it to be vacuumed away. TODO: for ease of queries,
this probably wants to be in the base class. -->
<!-- A map of names to DirectoryEntries. In the AVM world, it makes sense
that nodes don't know there own names, only their containers do. -->
</subclass> </subclass>
</subclass> </subclass>
<!-- There are two kinds of files, plain and symlinky. --> <!-- There are two kinds of files, plain and symlinky. -->