diff --git a/config/alfresco/avm-base-context.xml b/config/alfresco/avm-base-context.xml
new file mode 100644
index 0000000000..c14f52042b
--- /dev/null
+++ b/config/alfresco/avm-base-context.xml
@@ -0,0 +1,304 @@
+
+
+
+
+
+
+
+
+ ${db.driver}
+
+
+ ${db.url}
+
+
+ ${db.username}
+
+
+ ${db.password}
+
+
+ ${db.pool.initial}
+
+
+ ${db.pool.max}
+
+
+ 1
+
+
+ 60
+
+
+
+
+
+
+
+
+
+
+ ${hibernate.dialect}
+ ${hibernate.current_session_context_class}
+ ${hibernate.connection.isolation}
+ ${hibernate.default_batch_fetch_size}
+ ${hibernate.jdbc.batch_versioned_data}
+ ${hibernate.cache.use_second_level_cache}
+ ${hibernate.hbm2ddl.auto}
+
+
+
+
+ org/alfresco/repo/avm/hibernate/AVM.hbm.xml
+
+
+
+
+
+
+ node
+
+
+
+
+
+
+
+
+ content
+
+
+
+
+
+
+
+
+ layer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PROPAGATION_REQUIRES_NEW
+
+
+ ISOLATION_READ_COMMITTED
+
+
+ true
+
+
+
+
+
+
+ PROPAGATION_REQUIRES_NEW
+
+
+ ISOLATION_READ_COMMITTED
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 4000
+
+
+ 1000
+
+
+ 50
+
+
+
+
+
+
+
+
+ ${avm.storage}
+
+
+ ${avm.initialize}
+
+
+
+
+
+
+
+
+
+
+
+ ${avm.storage}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/alfresco/avm-console-context.xml b/config/alfresco/avm-console-context.xml
index c0dcafbb6b..dde3a4f6da 100644
--- a/config/alfresco/avm-console-context.xml
+++ b/config/alfresco/avm-console-context.xml
@@ -13,239 +13,7 @@
-
-
-
- PROPAGATION_REQUIRES_NEW
-
-
- ISOLATION_READ_COMMITTED
-
-
- true
-
-
-
-
-
-
- PROPAGATION_REQUIRES_NEW
-
-
- ISOLATION_READ_COMMITTED
-
-
- false
-
-
-
-
-
-
- ${db.driver}
-
-
- ${db.url}
-
-
- ${db.username}
-
-
- ${db.password}
-
-
- ${db.pool.initial}
-
-
- ${db.pool.max}
-
-
- 1
-
-
- 60
-
-
-
-
-
-
-
-
-
-
- ${hibernate.dialect}
- ${hibernate.current_session_context_class}
- ${hibernate.connection.isolation}
- ${hibernate.default_batch_fetch_size}
- ${hibernate.jdbc.batch_versioned_data}
- ${hibernate.cache.use_second_level_cache}
- ${hibernate.hbm2ddl.auto}
-
-
-
-
- org/alfresco/repo/avm/hibernate/AVM.hbm.xml
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 30000
-
-
- 1000
-
-
- 50
-
-
-
-
-
+
@@ -253,19 +21,6 @@
-
-
- build/test-results/storage
-
-
- ${avm.initialize}
-
-
-
-
-
-
diff --git a/config/alfresco/avm-console.properties b/config/alfresco/avm-console.properties
index ba26929f28..29e89be9db 100644
--- a/config/alfresco/avm-console.properties
+++ b/config/alfresco/avm-console.properties
@@ -14,4 +14,5 @@ hibernate.jdbc.batch_versioned_data=true
hibernate.cache.use_second_level_cache=true
hibernate.hbm2ddl.auto=update
# AVM specific properties.
+avm.storage=build/test-results/storage
avm.initialize=false
diff --git a/config/alfresco/avm-test-context.xml b/config/alfresco/avm-test-context.xml
index 263d9163b8..0f30ffc1b0 100644
--- a/config/alfresco/avm-test-context.xml
+++ b/config/alfresco/avm-test-context.xml
@@ -13,250 +13,6 @@
-
-
-
- ${db.driver}
-
-
- ${db.url}
-
-
- ${db.username}
-
-
- ${db.password}
-
-
- ${db.pool.initial}
-
-
- ${db.pool.max}
-
-
- 1
-
-
- 60
-
-
+
-
-
-
-
-
-
-
- ${hibernate.dialect}
- ${hibernate.current_session_context_class}
- ${hibernate.connection.isolation}
- ${hibernate.default_batch_fetch_size}
- ${hibernate.jdbc.batch_versioned_data}
- ${hibernate.cache.use_second_level_cache}
- ${hibernate.hbm2ddl.auto}
-
-
-
-
- org/alfresco/repo/avm/hibernate/AVM.hbm.xml
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PROPAGATION_REQUIRES_NEW
-
-
- ISOLATION_READ_COMMITTED
-
-
- true
-
-
-
-
-
-
- PROPAGATION_REQUIRES_NEW
-
-
- ISOLATION_READ_COMMITTED
-
-
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 4000
-
-
- 1000
-
-
- 50
-
-
-
-
-
-
-
-
- build/test-results/storage
-
-
- ${avm.initialize}
-
-
-
-
-
diff --git a/config/alfresco/avm-test.properties b/config/alfresco/avm-test.properties
index d479dc0d3e..b7eafd73db 100644
--- a/config/alfresco/avm-test.properties
+++ b/config/alfresco/avm-test.properties
@@ -14,4 +14,5 @@ hibernate.jdbc.batch_versioned_data=true
hibernate.cache.use_second_level_cache=true
hibernate.hbm2ddl.auto=create
# AVM specific properties.
+avm.storage=build/test-results/storage
avm.initialize=true
diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java
index 0cb4f56d08..aeeced87a8 100644
--- a/source/java/org/alfresco/repo/avm/AVMRepository.java
+++ b/source/java/org/alfresco/repo/avm/AVMRepository.java
@@ -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();
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);
}
diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java
index ce75e0135f..e535710a59 100644
--- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java
+++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java
@@ -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.
diff --git a/source/java/org/alfresco/repo/avm/Issuer.java b/source/java/org/alfresco/repo/avm/Issuer.java
index 1e38061f94..33dc665874 100644
--- a/source/java/org/alfresco/repo/avm/Issuer.java
+++ b/source/java/org/alfresco/repo/avm/Issuer.java
@@ -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;
+ }
}
/**
diff --git a/source/java/org/alfresco/repo/avm/IssuerDAO.java b/source/java/org/alfresco/repo/avm/IssuerDAO.java
index 3fd8ff965c..71a42e24d3 100644
--- a/source/java/org/alfresco/repo/avm/IssuerDAO.java
+++ b/source/java/org/alfresco/repo/avm/IssuerDAO.java
@@ -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);
}
diff --git a/source/java/org/alfresco/repo/avm/hibernate/IssuerDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/IssuerDAOHibernate.java
index 055225863c..4324b99d84 100644
--- a/source/java/org/alfresco/repo/avm/hibernate/IssuerDAOHibernate.java
+++ b/source/java/org/alfresco/repo/avm/hibernate/IssuerDAOHibernate.java
@@ -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);
}
}