mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
<bean id="avmService" class="org.alfresco.repo.avm.AVMServiceImpl"
|
<bean id="avmService" class="org.alfresco.repo.avm.AVMServiceImpl"
|
||||||
init-method="init">
|
init-method="init">
|
||||||
<property name="storage">
|
<property name="storage">
|
||||||
<value>/Users/britt/tomcat/alfresco/store</value>
|
<value>build/test-results/storage</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="createTables">
|
<property name="createTables">
|
||||||
<value>false</value>
|
<value>false</value>
|
||||||
|
@@ -19,8 +19,6 @@ package org.alfresco.repo.avm;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
@@ -30,14 +28,8 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
|
||||||
import org.alfresco.repo.avm.util.BulkLoader;
|
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.context.support.FileSystemXmlApplicationContext;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interactive console for the AVM repository.
|
* 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)
|
public String interpretCommand(String line, BufferedReader in)
|
||||||
{
|
{
|
||||||
String[] command = line.split("\\s+");
|
String[] command = line.split("\\s+");
|
||||||
@@ -422,6 +420,7 @@ public class AVMInterpreter
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
e.printStackTrace(System.err);
|
||||||
return e.toString();
|
return e.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -137,4 +137,9 @@ interface AVMNode
|
|||||||
* @return Whether this node is a root.
|
* @return Whether this node is a root.
|
||||||
*/
|
*/
|
||||||
public boolean getIsRoot();
|
public boolean getIsRoot();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the modification time of this node.
|
||||||
|
*/
|
||||||
|
public void updateModTime();
|
||||||
}
|
}
|
@@ -302,4 +302,12 @@ abstract class AVMNodeImpl implements AVMNode, Serializable
|
|||||||
{
|
{
|
||||||
fIsRoot = isRoot;
|
fIsRoot = isRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.avm.AVMNode#updateModTime()
|
||||||
|
*/
|
||||||
|
public void updateModTime()
|
||||||
|
{
|
||||||
|
fBasicAttributes.setModDate(System.currentTimeMillis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ import org.alfresco.repo.avm.SuperRepository;
|
|||||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||||
import org.alfresco.repo.avm.hibernate.HibernateTxn;
|
import org.alfresco.repo.avm.hibernate.HibernateTxn;
|
||||||
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
|
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
|
||||||
|
import org.hibernate.Query;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
|
|
||||||
@@ -99,29 +100,50 @@ public class AVMServiceImpl implements AVMService
|
|||||||
se.create(false, true);
|
se.create(false, true);
|
||||||
File storage = new File(fStorage);
|
File storage = new File(fStorage);
|
||||||
storage.mkdirs();
|
storage.mkdirs();
|
||||||
fNodeIssuer = new Issuer(fStorage + File.separator + "node", 0L);
|
fNodeIssuer = new Issuer(0L);
|
||||||
fContentIssuer = new Issuer(fStorage + File.separator + "content", 0L);
|
fContentIssuer = new Issuer(0L);
|
||||||
fLayerIssuer = new Issuer(fStorage + File.separator + "layer", 0L);
|
fLayerIssuer = new Issuer(0L);
|
||||||
fSuperRepository = new SuperRepository(fNodeIssuer,
|
fSuperRepository = new SuperRepository(fNodeIssuer,
|
||||||
fContentIssuer,
|
fContentIssuer,
|
||||||
fLayerIssuer,
|
fLayerIssuer,
|
||||||
fStorage);
|
fStorage);
|
||||||
createRepository("main");
|
try
|
||||||
|
{
|
||||||
|
createRepository("main");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// TODO Log this and abort in some useful way.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fNodeIssuer = new Issuer(fStorage + File.separator + "node");
|
fTransaction.perform(
|
||||||
fContentIssuer = new Issuer(fStorage + File.separator + "content");
|
new HibernateTxnCallback()
|
||||||
fLayerIssuer = new Issuer(fStorage + File.separator + "layer");
|
{
|
||||||
|
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,
|
fSuperRepository = new SuperRepository(fNodeIssuer,
|
||||||
fContentIssuer,
|
fContentIssuer,
|
||||||
fLayerIssuer,
|
fLayerIssuer,
|
||||||
fStorage);
|
fStorage);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
e.printStackTrace(System.err);
|
||||||
// TODO Log this and abort in some useful way.
|
// TODO Log this and abort in some useful way.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,89 +17,24 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.avm;
|
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.
|
* This is a helper class that knows how to issue identifiers.
|
||||||
* @author britt
|
* @author britt
|
||||||
*/
|
*/
|
||||||
class Issuer
|
class Issuer
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The path to this issuers persistent storage.
|
|
||||||
*/
|
|
||||||
private String fPath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The next number to issue.
|
* The next number to issue.
|
||||||
*/
|
*/
|
||||||
private long fNext;
|
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.
|
* Rich constructor.
|
||||||
* @param path The path to this issuers persistent store.
|
|
||||||
* @param next The next number to issue.
|
* @param next The next number to issue.
|
||||||
*/
|
*/
|
||||||
public Issuer(String path, long next)
|
public Issuer(long next)
|
||||||
{
|
{
|
||||||
fPath = path;
|
|
||||||
fNext = next;
|
fNext = next;
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,42 +43,6 @@ class Issuer
|
|||||||
*/
|
*/
|
||||||
public synchronized long issue()
|
public synchronized long issue()
|
||||||
{
|
{
|
||||||
long val = fNext++;
|
return fNext++;
|
||||||
if (fNext % 128 == 0)
|
|
||||||
{
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -106,7 +106,6 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
|
|||||||
{
|
{
|
||||||
return fContent;
|
return fContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get content for writing.
|
* Get content for writing.
|
||||||
*/
|
*/
|
||||||
|
@@ -184,6 +184,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
}
|
}
|
||||||
newDir.setVersionID(getNextVersionID());
|
newDir.setVersionID(getNextVersionID());
|
||||||
dir.putChild(name, newDir);
|
dir.putChild(name, newDir);
|
||||||
|
dir.updateModTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,6 +219,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
newDir.setLayerID(fSuper.issueLayerID());
|
newDir.setLayerID(fSuper.issueLayerID());
|
||||||
}
|
}
|
||||||
dir.putChild(name, newDir);
|
dir.putChild(name, newDir);
|
||||||
|
dir.updateModTime();
|
||||||
newDir.setVersionID(getNextVersionID());
|
newDir.setVersionID(getNextVersionID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,6 +241,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
PlainFileNodeImpl file = new PlainFileNodeImpl(this);
|
PlainFileNodeImpl file = new PlainFileNodeImpl(this);
|
||||||
file.setVersionID(getNextVersionID());
|
file.setVersionID(getNextVersionID());
|
||||||
dir.putChild(name, file);
|
dir.putChild(name, file);
|
||||||
|
file.updateModTime();
|
||||||
return file.getContentForWrite().getOutputStream();
|
return file.getContentForWrite().getOutputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +264,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
LayeredFileNodeImpl newFile =
|
LayeredFileNodeImpl newFile =
|
||||||
new LayeredFileNodeImpl(srcPath, this);
|
new LayeredFileNodeImpl(srcPath, this);
|
||||||
dir.putChild(name, newFile);
|
dir.putChild(name, newFile);
|
||||||
|
dir.updateModTime();
|
||||||
newFile.setVersionID(getNextVersionID());
|
newFile.setVersionID(getNextVersionID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +325,8 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
throw new AVMWrongTypeException("Not a file: " + path);
|
throw new AVMWrongTypeException("Not a file: " + path);
|
||||||
}
|
}
|
||||||
FileNode file = (FileNode)node;
|
FileNode file = (FileNode)node;
|
||||||
FileContent content = file.getContentForWrite();
|
FileContent content = file.getContentForWrite();
|
||||||
|
file.updateModTime();
|
||||||
return content.getOutputStream();
|
return content.getOutputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,6 +360,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
if (write)
|
if (write)
|
||||||
{
|
{
|
||||||
content = file.getContentForWrite();
|
content = file.getContentForWrite();
|
||||||
|
file.updateModTime();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -379,6 +385,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
throw new AVMNotFoundException("Does not exist: " + name);
|
throw new AVMNotFoundException("Does not exist: " + name);
|
||||||
}
|
}
|
||||||
dir.removeChild(name);
|
dir.removeChild(name);
|
||||||
|
dir.updateModTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -396,6 +403,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
throw new AVMWrongTypeException("Not a layered directory: " + dirPath);
|
throw new AVMWrongTypeException("Not a layered directory: " + dirPath);
|
||||||
}
|
}
|
||||||
((LayeredDirectoryNode)node).uncover(lPath, name);
|
((LayeredDirectoryNode)node).uncover(lPath, name);
|
||||||
|
node.updateModTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO This is problematic. As time goes on this returns
|
// 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);
|
throw new AVMException("Not in a layered context: " + path);
|
||||||
}
|
}
|
||||||
dir.turnPrimary(lPath);
|
dir.turnPrimary(lPath);
|
||||||
|
dir.updateModTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -655,6 +664,7 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
throw new AVMException("Not in a layered context: " + path);
|
throw new AVMException("Not in a layered context: " + path);
|
||||||
}
|
}
|
||||||
dir.retarget(lPath, target);
|
dir.retarget(lPath, target);
|
||||||
|
dir.updateModTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -854,5 +864,6 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
throw new AVMWrongTypeException("Not a LayeredDirectoryNode.");
|
throw new AVMWrongTypeException("Not a LayeredDirectoryNode.");
|
||||||
}
|
}
|
||||||
((LayeredDirectoryNode)node).setOpacity(opacity);
|
((LayeredDirectoryNode)node).setOpacity(opacity);
|
||||||
|
node.updateModTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -242,6 +242,7 @@ class SuperRepository
|
|||||||
dstNode.setVersionID(dstRepo.getNextVersionID());
|
dstNode.setVersionID(dstRepo.getNextVersionID());
|
||||||
dstNode.setAncestor(srcNode);
|
dstNode.setAncestor(srcNode);
|
||||||
dirNode.putChild(name, dstNode);
|
dirNode.putChild(name, dstNode);
|
||||||
|
dirNode.updateModTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -392,8 +393,10 @@ class SuperRepository
|
|||||||
dstNode = new PlainFileNodeImpl((PlainFileNode)srcNode, dstRepo);
|
dstNode = new PlainFileNodeImpl((PlainFileNode)srcNode, dstRepo);
|
||||||
}
|
}
|
||||||
srcDir.removeChild(srcName);
|
srcDir.removeChild(srcName);
|
||||||
|
srcDir.updateModTime();
|
||||||
dstNode.setVersionID(dstRepo.getNextVersionID());
|
dstNode.setVersionID(dstRepo.getNextVersionID());
|
||||||
dstDir.putChild(dstName, dstNode);
|
dstDir.putChild(dstName, dstNode);
|
||||||
|
dstDir.updateModTime();
|
||||||
dstNode.setAncestor(srcNode);
|
dstNode.setAncestor(srcNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user