Made AVMRepository Springable. Modularized Spring configuration a bit.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3380 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-07-22 20:17:51 +00:00
parent cfa3991bfc
commit ff042f1988
10 changed files with 455 additions and 588 deletions

View File

@@ -35,7 +35,7 @@ import org.alfresco.service.namespace.QName;
* the implementors of the operations specified by AVMService.
* @author britt
*/
class AVMRepository
public class AVMRepository
{
/**
* The single instance of AVMRepository.
@@ -68,25 +68,56 @@ class AVMRepository
private String fStorage;
/**
* Create a new one. It's given issuers and a storage directory.
* @param nodeIssuer
* @param contentIssuer
* @param layerIssuer
* @param storage
* Create a new one.
*/
public AVMRepository(Issuer nodeIssuer,
Issuer contentIssuer,
Issuer layerIssuer,
String storage)
public AVMRepository()
{
fStorage = storage;
fNodeIssuer = nodeIssuer;
fContentIssuer = contentIssuer;
fLayerIssuer = layerIssuer;
fLookupCount = new ThreadLocal<Integer>();
fgInstance = this;
}
/**
* Set the storage directory.
* @param storage The absolute path to content storage directory.
*/
public void setStorage(String storage)
{
fStorage = storage;
}
/**
* Set the node issuer. For Spring.
* @param nodeIssuer The issuer.
*/
public void setNodeIssuer(Issuer nodeIssuer)
{
fNodeIssuer = nodeIssuer;
}
/**
* Set the content issuer. For Spring.
* @param contentIssuer The issuer.
*/
public void setContentIssuer(Issuer contentIssuer)
{
fContentIssuer = contentIssuer;
}
/**
* Set the layer issuer. For Spring.
* @param layerIssuer The issuer.
*/
public void setLayerIssuer(Issuer layerIssuer)
{
fLayerIssuer = layerIssuer;
}
public void init()
{
File storageDir = new File(fStorage);
storageDir.mkdirs();
}
/**
* Create a file.
* @param path The path to the containing directory.
@@ -97,7 +128,6 @@ class AVMRepository
fLookupCount.set(1);
String[] pathParts = SplitPath(path);
AVMStore rep = getAVMStoreByName(pathParts[0]);
// fSession.get().lock(rep, LockMode.UPGRADE);
return rep.createFile(pathParts[1], name);
}

View File

@@ -56,21 +56,6 @@ public class AVMServiceImpl implements AVMService
*/
private String fStorage;
/**
* The node id issuer.
*/
private Issuer fNodeIssuer;
/**
* The content id issuer.
*/
private Issuer fContentIssuer;
/**
* The layer id issuer.
*/
private Issuer fLayerIssuer;
/**
* Whether the tables should be dropped and created.
*/
@@ -83,43 +68,23 @@ public class AVMServiceImpl implements AVMService
{
}
/**
* Set the storage directory.
* @param storage The full path to the storage directory.
*/
public void setStorage(String storage)
{
fStorage = storage;
}
/**
* Final initialization of the service. Must be called only on a
* fully initialized instance.
*/
public void init()
{
try
{
fTransaction.perform(
new RetryingTransactionCallback()
{
public void perform()
{
IssuerDAO dao = AVMContext.fgInstance.fIssuerDAO;
Long val = dao.getNodeIssuerValue();
fNodeIssuer = new Issuer(val == null ? 0L : val + 1L);
val = dao.getContentIssuerValue();
fContentIssuer = new Issuer(val == null ? 0L : val + 1L);
val = dao.getLayerIssuerValue();
fLayerIssuer = new Issuer(val == null ? 0L : val + 1L);
}
}, false);
fAVMRepository = new AVMRepository(fNodeIssuer,
fContentIssuer,
fLayerIssuer,
fStorage);
fgLogger.info("Initialized AVMService and AVMRepository");
}
catch (Exception e)
{
fgLogger.fatal("Failed to initialize AVMService", e);
// TODO Abort in some useful way.
}
if (fInitialize)
{
File storageDir = new File(fStorage);
storageDir.mkdirs();
createAVMStore("main");
fgLogger.info("Created new main AVMStore");
}
@@ -134,15 +99,6 @@ public class AVMServiceImpl implements AVMService
fTransaction = txn;
}
/**
* Set the location of file storage.
* @param storage
*/
public void setStorage(String storage)
{
fStorage = storage;
}
/**
* Set whether we should create an initial AVMStore.
* @param initialize
@@ -152,6 +108,15 @@ public class AVMServiceImpl implements AVMService
fInitialize = initialize;
}
/**
* Set the repository reference. For Spring.
* @param avmRepository The repository reference.
*/
public void setAvmRepository(AVMRepository avmRepository)
{
fAVMRepository = avmRepository;
}
/**
* Get an InputStream from a file.
* @param version The version to look under.

View File

@@ -21,7 +21,7 @@ package org.alfresco.repo.avm;
* This is a helper class that knows how to issue identifiers.
* @author britt
*/
class Issuer
public class Issuer
{
/**
* The next number to issue.
@@ -29,12 +29,64 @@ class Issuer
private long fNext;
/**
* Rich constructor.
* @param next The next number to issue.
* The name of this issuer.
*/
public Issuer(long next)
private String fName;
/**
* The transactional wrapper.
*/
private RetryingTransaction fTransaction;
/**
* Default constructor.
*/
public Issuer()
{
fNext = next;
}
/**
* Set the name of this issuer. For Spring.
* @param name The name to set.
*/
public void setName(String name)
{
fName = name;
}
/**
* Set the transactional wrapper.
* @param retryingTransaction The transactional wrapper.
*/
public void setRetryingTransaction(RetryingTransaction retryingTransaction)
{
fTransaction = retryingTransaction;
}
/**
* After the database is up, get our value.
*/
public void init()
{
class TxnCallback implements RetryingTransactionCallback
{
public Long value;
public void perform()
{
value = AVMContext.fgInstance.fIssuerDAO.getIssuerValue(fName);
}
};
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
if (doit.value == null)
{
fNext = 0L;
}
else
{
fNext = doit.value;
}
}
/**

View File

@@ -24,17 +24,9 @@ package org.alfresco.repo.avm;
public interface IssuerDAO
{
/**
* Get the node Issuer value.
* Get the Issuer value.
* @param The name of the issuer.
* @return The largest id issued by the named issuer.
*/
public Long getNodeIssuerValue();
/**
* Get the content Issuer value.
*/
public Long getContentIssuerValue();
/**
* Get the layer Issuer value.
*/
public Long getLayerIssuerValue();
public Long getIssuerValue(String name);
}

View File

@@ -18,6 +18,7 @@
package org.alfresco.repo.avm.hibernate;
import org.alfresco.repo.avm.AVMException;
import org.alfresco.repo.avm.IssuerDAO;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
@@ -36,18 +37,28 @@ public class IssuerDAOHibernate extends HibernateDaoSupport implements
super();
}
public Long getContentIssuerValue()
/**
* Get the largest issued id for the named issuer.
* @param The name of the issuer.
* @return The value or null if the issuer is brand new.
* @throws AVMException on an invalid name.
*/
public Long getIssuerValue(String name)
{
return (Long)getSession().createQuery("select max(fc.id) from FileContentImpl fc").uniqueResult();
}
public Long getLayerIssuerValue()
{
return (Long)getSession().createQuery("select max(an.layerID) from AVMNodeImpl an").uniqueResult();
}
public Long getNodeIssuerValue()
{
return (Long)getSession().createQuery("select max(an.id) from AVMNodeImpl an").uniqueResult();
if (name.equals("content"))
{
return (Long)getSession().
createQuery("select max(fc.id) from FileContentImpl fc").uniqueResult();
}
else if (name.equals("layer"))
{
return (Long)getSession().
createQuery("select max(an.layerID) from AVMNodeImpl an").uniqueResult();
}
else if (name.equals("node"))
{
return (Long)getSession().createQuery("select max(an.id) from AVMNodeImpl an").uniqueResult();
}
throw new AVMException("Unknown issuer type: " + name);
}
}