First-cut dynamic Dictionary & Namespaces - updated caches to be cluster-aware & tenant-aware

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6675 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2007-09-04 14:23:55 +00:00
parent d51344044d
commit 6e854e6166
16 changed files with 1992 additions and 238 deletions

View File

@@ -24,16 +24,20 @@
*/
package org.alfresco.repo.dictionary;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.cache.EhCacheAdapter;
import org.alfresco.repo.dictionary.constraint.RegexConstraint;
import org.alfresco.repo.dictionary.constraint.StringLengthConstraint;
import org.alfresco.repo.tenant.SingleTServiceImpl;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.Constraint;
@@ -45,7 +49,6 @@ import org.alfresco.service.cmr.dictionary.ModelDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
public class DictionaryDAOTest extends TestCase
@@ -65,8 +68,14 @@ public class DictionaryDAOTest extends TestCase
I18NUtil.registerResourceBundle(TEST_RESOURCE_MESSAGES);
// Instantiate Dictionary Service
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
TenantService tenantService = new SingleTServiceImpl();
NamespaceDAOImpl namespaceDAO = new NamespaceDAOImpl();
namespaceDAO.setTenantService(tenantService);
initNamespaceCaches(namespaceDAO);
DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
dictionaryDAO.setTenantService(tenantService);
initDictionaryCaches(dictionaryDAO);
// Populate with appropriate models
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
@@ -78,6 +87,7 @@ public class DictionaryDAOTest extends TestCase
bootstrap.setModels(bootstrapModels);
bootstrap.setLabels(labels);
bootstrap.setDictionaryDAO(dictionaryDAO);
bootstrap.setTenantService(tenantService);
bootstrap.bootstrap();
DictionaryComponent component = new DictionaryComponent();
@@ -85,11 +95,55 @@ public class DictionaryDAOTest extends TestCase
service = component;
}
private void initDictionaryCaches(DictionaryDAOImpl dictionaryDAO)
{
CacheManager cacheManager = new CacheManager();
Cache uriToModelsEhCache = new Cache("uriToModelsCache", 50, false, true, 0L, 0L);
cacheManager.addCache(uriToModelsEhCache);
EhCacheAdapter<String, Map<String, List<CompiledModel>>> uriToModelsCache = new EhCacheAdapter<String, Map<String, List<CompiledModel>>>();
uriToModelsCache.setCache(uriToModelsEhCache);
dictionaryDAO.setUriToModelsCache(uriToModelsCache);
Cache compileModelsEhCache = new Cache("compiledModelsCache", 50, false, true, 0L, 0L);
cacheManager.addCache(compileModelsEhCache);
EhCacheAdapter<String, Map<QName,CompiledModel>> compileModelCache = new EhCacheAdapter<String, Map<QName,CompiledModel>>();
compileModelCache.setCache(compileModelsEhCache);
dictionaryDAO.setCompiledModelsCache(compileModelCache);
}
private void initNamespaceCaches(NamespaceDAOImpl namespaceDAO)
{
CacheManager cacheManager = new CacheManager();
Cache urisEhCache = new Cache("urisCache", 50, false, true, 0L, 0L);
cacheManager.addCache(urisEhCache);
EhCacheAdapter<String, List<String>> urisCache = new EhCacheAdapter<String, List<String>>();
urisCache.setCache(urisEhCache);
namespaceDAO.setUrisCache(urisCache);
Cache prefixesEhCache = new Cache("prefixesCache", 50, false, true, 0L, 0L);
cacheManager.addCache(prefixesEhCache);
EhCacheAdapter<String, Map<String, String>> prefixesCache = new EhCacheAdapter<String, Map<String, String>>();
prefixesCache.setCache(prefixesEhCache);
namespaceDAO.setPrefixesCache(prefixesCache);
}
public void testBootstrap()
{
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
TenantService tenantService = new SingleTServiceImpl();
NamespaceDAOImpl namespaceDAO = new NamespaceDAOImpl();
namespaceDAO.setTenantService(tenantService);
initNamespaceCaches(namespaceDAO);
DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
dictionaryDAO.setTenantService(tenantService);
initDictionaryCaches(dictionaryDAO);
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
List<String> bootstrapModels = new ArrayList<String>();
@@ -107,7 +161,8 @@ public class DictionaryDAOTest extends TestCase
bootstrap.setModels(bootstrapModels);
bootstrap.setDictionaryDAO(dictionaryDAO);
bootstrap.bootstrap();
bootstrap.setTenantService(tenantService);
bootstrap.bootstrap();
}