From 92a7348a431d77308033522f65fb1d9873e1cc07 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Sun, 2 Jul 2006 21:25:24 +0000 Subject: [PATCH] Wasn't updating mod time in appropriate places. Fixed that. Rewrote Issuer to be less stupid. Minor fix to the pathetically silly reallybad.jsp. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3276 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/avm-console-context.xml | 2 +- .../org/alfresco/repo/avm/AVMInterpreter.java | 15 ++- .../java/org/alfresco/repo/avm/AVMNode.java | 5 + .../org/alfresco/repo/avm/AVMNodeImpl.java | 8 ++ .../org/alfresco/repo/avm/AVMServiceImpl.java | 48 +++++--- source/java/org/alfresco/repo/avm/Issuer.java | 105 +----------------- .../org/alfresco/repo/avm/IssuerTest.java | 41 ------- .../alfresco/repo/avm/PlainFileNodeImpl.java | 1 - .../org/alfresco/repo/avm/RepositoryImpl.java | 13 ++- .../alfresco/repo/avm/SuperRepository.java | 3 + 10 files changed, 73 insertions(+), 168 deletions(-) delete mode 100644 source/java/org/alfresco/repo/avm/IssuerTest.java diff --git a/config/alfresco/avm-console-context.xml b/config/alfresco/avm-console-context.xml index 48c90deb07..06ec6b13e3 100644 --- a/config/alfresco/avm-console-context.xml +++ b/config/alfresco/avm-console-context.xml @@ -28,7 +28,7 @@ - /Users/britt/tomcat/alfresco/store + build/test-results/storage false diff --git a/source/java/org/alfresco/repo/avm/AVMInterpreter.java b/source/java/org/alfresco/repo/avm/AVMInterpreter.java index 84fde14749..8f197184ce 100644 --- a/source/java/org/alfresco/repo/avm/AVMInterpreter.java +++ b/source/java/org/alfresco/repo/avm/AVMInterpreter.java @@ -19,8 +19,6 @@ package org.alfresco.repo.avm; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; @@ -30,14 +28,8 @@ import java.util.Date; import java.util.List; import java.util.Map; -import org.alfresco.repo.avm.hibernate.HibernateHelper; import org.alfresco.repo.avm.util.BulkLoader; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.xml.XmlBeanFactory; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; -import org.springframework.core.io.InputStreamResource; /** * An interactive console for the AVM repository. @@ -124,6 +116,12 @@ public class AVMInterpreter } } + /** + * Interpret a single command using the BufferedReader passed in for any data needed. + * @param line The unparsed command + * @param in A Reader to be used for commands that need input data. + * @return The textual output of the command. + */ public String interpretCommand(String line, BufferedReader in) { String[] command = line.split("\\s+"); @@ -422,6 +420,7 @@ public class AVMInterpreter } catch (Exception e) { + e.printStackTrace(System.err); return e.toString(); } } diff --git a/source/java/org/alfresco/repo/avm/AVMNode.java b/source/java/org/alfresco/repo/avm/AVMNode.java index f3e00bddc9..1844745996 100644 --- a/source/java/org/alfresco/repo/avm/AVMNode.java +++ b/source/java/org/alfresco/repo/avm/AVMNode.java @@ -137,4 +137,9 @@ interface AVMNode * @return Whether this node is a root. */ public boolean getIsRoot(); + + /** + * Update the modification time of this node. + */ + public void updateModTime(); } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/avm/AVMNodeImpl.java b/source/java/org/alfresco/repo/avm/AVMNodeImpl.java index 055236e29f..60ca61180b 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeImpl.java @@ -302,4 +302,12 @@ abstract class AVMNodeImpl implements AVMNode, Serializable { fIsRoot = isRoot; } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNode#updateModTime() + */ + public void updateModTime() + { + fBasicAttributes.setModDate(System.currentTimeMillis()); + } } diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index 40659a8e95..a56f6d04a2 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -29,6 +29,7 @@ import org.alfresco.repo.avm.SuperRepository; import org.alfresco.repo.avm.hibernate.HibernateHelper; import org.alfresco.repo.avm.hibernate.HibernateTxn; import org.alfresco.repo.avm.hibernate.HibernateTxnCallback; +import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.tool.hbm2ddl.SchemaExport; @@ -99,29 +100,50 @@ public class AVMServiceImpl implements AVMService se.create(false, true); File storage = new File(fStorage); storage.mkdirs(); - fNodeIssuer = new Issuer(fStorage + File.separator + "node", 0L); - fContentIssuer = new Issuer(fStorage + File.separator + "content", 0L); - fLayerIssuer = new Issuer(fStorage + File.separator + "layer", 0L); + fNodeIssuer = new Issuer(0L); + fContentIssuer = new Issuer(0L); + fLayerIssuer = new Issuer(0L); fSuperRepository = new SuperRepository(fNodeIssuer, - fContentIssuer, - fLayerIssuer, - fStorage); - createRepository("main"); + fContentIssuer, + fLayerIssuer, + fStorage); + try + { + createRepository("main"); + } + catch (Exception e) + { + // TODO Log this and abort in some useful way. + } } else { try { - fNodeIssuer = new Issuer(fStorage + File.separator + "node"); - fContentIssuer = new Issuer(fStorage + File.separator + "content"); - fLayerIssuer = new Issuer(fStorage + File.separator + "layer"); + fTransaction.perform( + new HibernateTxnCallback() + { + public void perform(Session sess) + { + Query query = sess.createQuery("select max(an.id) from AVMNodeImpl an"); + Long val = (Long)query.uniqueResult(); + fNodeIssuer = new Issuer(val == null ? 0L : val + 1L); + query = sess.createQuery("select max(fc.id) from FileContentImpl fc"); + val = (Long)query.uniqueResult(); + fContentIssuer = new Issuer(val == null ? 0L : val + 1L); + query = sess.createQuery("select max(an.layerID) from AVMNodeImpl an"); + val = (Long)query.uniqueResult(); + fLayerIssuer = new Issuer(val == null ? 0L : val + 1L); + } + }, false); fSuperRepository = new SuperRepository(fNodeIssuer, - fContentIssuer, - fLayerIssuer, - fStorage); + fContentIssuer, + fLayerIssuer, + fStorage); } catch (Exception e) { + e.printStackTrace(System.err); // TODO Log this and abort in some useful way. } } diff --git a/source/java/org/alfresco/repo/avm/Issuer.java b/source/java/org/alfresco/repo/avm/Issuer.java index b9ad2d07ab..1e38061f94 100644 --- a/source/java/org/alfresco/repo/avm/Issuer.java +++ b/source/java/org/alfresco/repo/avm/Issuer.java @@ -17,89 +17,24 @@ package org.alfresco.repo.avm; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - /** * This is a helper class that knows how to issue identifiers. * @author britt */ class Issuer { - /** - * The path to this issuers persistent storage. - */ - private String fPath; - /** * The next number to issue. */ private long fNext; - /** - * Constructor for an already existing Issuer. - * @param path The path to this issuers persistent store. - */ - public Issuer(String path) - { - fPath = path; - try - { - DataInputStream in = new DataInputStream(new FileInputStream(fPath + ".new")); - fNext = in.readLong(); - fNext += 257; - in.close(); - save(); - return; - } - catch (IOException ie) - { - // Do nothing. - } - try - { - DataInputStream in = new DataInputStream(new FileInputStream(fPath)); - fNext = in.readLong(); - fNext += 257; - in.close(); - save(); - return; - } - catch (IOException ie) - { - // Do nothing. - } - // Last resort. - try - { - DataInputStream in = new DataInputStream(new FileInputStream(fPath + ".old")); - fNext = in.readLong(); - fNext += 513; - in.close(); - save(); - return; - } - catch (IOException ie) - { - // TODO Log this situation. - throw new AVMException("Could not restore issuer" + fPath, ie); - } - } - /** * Rich constructor. - * @param path The path to this issuers persistent store. * @param next The next number to issue. */ - public Issuer(String path, long next) + public Issuer(long next) { - fPath = path; fNext = next; - save(); } /** @@ -108,42 +43,6 @@ class Issuer */ public synchronized long issue() { - long val = fNext++; - if (fNext % 128 == 0) - { - save(); - } - return val; + return fNext++; } - - /** - * Persist this issuer. - */ - public void save() - { - while (true) - { - try - { - FileOutputStream fileOut = new FileOutputStream(fPath + ".new"); - DataOutputStream out = new DataOutputStream(fileOut); - out.writeLong(fNext); - out.flush(); - // Force data to physical storage. - fileOut.getChannel().force(true); - out.close(); - File from = new File(fPath); - File to = new File(fPath + ".old"); - from.renameTo(to); - from = new File(fPath + ".new"); - to = new File(fPath); - from.renameTo(to); - break; - } - catch (IOException ie) - { - // TODO Log this situation. - } - } - } } diff --git a/source/java/org/alfresco/repo/avm/IssuerTest.java b/source/java/org/alfresco/repo/avm/IssuerTest.java deleted file mode 100644 index 23ab13cf7a..0000000000 --- a/source/java/org/alfresco/repo/avm/IssuerTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2006 Alfresco, Inc. - * - * Licensed under the Mozilla Public License version 1.1 - * with a permitted attribution clause. You may obtain a - * copy of the License at - * - * http://www.alfresco.org/legal/license.txt - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific - * language governing permissions and limitations under the - * License. - */ - -package org.alfresco.repo.avm; - -import junit.framework.TestCase; - -/** - * Simple sanity test for Issuer; - * @author britt - */ -public class IssuerTest extends TestCase -{ - /** - * Sanity check issuer logic. - */ - public void testSanity() - { - Issuer issuer = new Issuer("test", 0L); - for (int i = 0; i < 500; i++) - { - issuer.issue(); - } - issuer = new Issuer("test"); - assertTrue(issuer.issue() >= 500); - } -} diff --git a/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java b/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java index 80cbdf43cb..b3f18fc901 100644 --- a/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java @@ -106,7 +106,6 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode { return fContent; } - /** * Get content for writing. */ diff --git a/source/java/org/alfresco/repo/avm/RepositoryImpl.java b/source/java/org/alfresco/repo/avm/RepositoryImpl.java index 593c05d407..d4b68b4ecc 100644 --- a/source/java/org/alfresco/repo/avm/RepositoryImpl.java +++ b/source/java/org/alfresco/repo/avm/RepositoryImpl.java @@ -184,6 +184,7 @@ class RepositoryImpl implements Repository, Serializable } newDir.setVersionID(getNextVersionID()); dir.putChild(name, newDir); + dir.updateModTime(); } /** @@ -218,6 +219,7 @@ class RepositoryImpl implements Repository, Serializable newDir.setLayerID(fSuper.issueLayerID()); } dir.putChild(name, newDir); + dir.updateModTime(); newDir.setVersionID(getNextVersionID()); } @@ -239,6 +241,7 @@ class RepositoryImpl implements Repository, Serializable PlainFileNodeImpl file = new PlainFileNodeImpl(this); file.setVersionID(getNextVersionID()); dir.putChild(name, file); + file.updateModTime(); return file.getContentForWrite().getOutputStream(); } @@ -261,6 +264,7 @@ class RepositoryImpl implements Repository, Serializable LayeredFileNodeImpl newFile = new LayeredFileNodeImpl(srcPath, this); dir.putChild(name, newFile); + dir.updateModTime(); newFile.setVersionID(getNextVersionID()); } @@ -321,7 +325,8 @@ class RepositoryImpl implements Repository, Serializable throw new AVMWrongTypeException("Not a file: " + path); } FileNode file = (FileNode)node; - FileContent content = file.getContentForWrite(); + FileContent content = file.getContentForWrite(); + file.updateModTime(); return content.getOutputStream(); } @@ -355,6 +360,7 @@ class RepositoryImpl implements Repository, Serializable if (write) { content = file.getContentForWrite(); + file.updateModTime(); } else { @@ -379,6 +385,7 @@ class RepositoryImpl implements Repository, Serializable throw new AVMNotFoundException("Does not exist: " + name); } dir.removeChild(name); + dir.updateModTime(); } /** @@ -396,6 +403,7 @@ class RepositoryImpl implements Repository, Serializable throw new AVMWrongTypeException("Not a layered directory: " + dirPath); } ((LayeredDirectoryNode)node).uncover(lPath, name); + node.updateModTime(); } // TODO This is problematic. As time goes on this returns @@ -638,6 +646,7 @@ class RepositoryImpl implements Repository, Serializable throw new AVMException("Not in a layered context: " + path); } dir.turnPrimary(lPath); + dir.updateModTime(); } /** @@ -655,6 +664,7 @@ class RepositoryImpl implements Repository, Serializable throw new AVMException("Not in a layered context: " + path); } dir.retarget(lPath, target); + dir.updateModTime(); } /** @@ -854,5 +864,6 @@ class RepositoryImpl implements Repository, Serializable throw new AVMWrongTypeException("Not a LayeredDirectoryNode."); } ((LayeredDirectoryNode)node).setOpacity(opacity); + node.updateModTime(); } } diff --git a/source/java/org/alfresco/repo/avm/SuperRepository.java b/source/java/org/alfresco/repo/avm/SuperRepository.java index cf79fa44fb..f70cb02cd6 100644 --- a/source/java/org/alfresco/repo/avm/SuperRepository.java +++ b/source/java/org/alfresco/repo/avm/SuperRepository.java @@ -242,6 +242,7 @@ class SuperRepository dstNode.setVersionID(dstRepo.getNextVersionID()); dstNode.setAncestor(srcNode); dirNode.putChild(name, dstNode); + dirNode.updateModTime(); } /** @@ -392,8 +393,10 @@ class SuperRepository dstNode = new PlainFileNodeImpl((PlainFileNode)srcNode, dstRepo); } srcDir.removeChild(srcName); + srcDir.updateModTime(); dstNode.setVersionID(dstRepo.getNextVersionID()); dstDir.putChild(dstName, dstNode); + dstDir.updateModTime(); dstNode.setAncestor(srcNode); }