1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.cache.setup;
35
36 import info.magnolia.module.InstallContext;
37 import info.magnolia.module.delta.AbstractRepositoryTask;
38 import info.magnolia.module.delta.BootstrapSingleModuleResource;
39 import info.magnolia.module.delta.MoveNodeTask;
40 import info.magnolia.module.delta.RenameNodeTask;
41 import info.magnolia.module.delta.TaskExecutionException;
42 import info.magnolia.repository.RepositoryConstants;
43
44 import javax.jcr.RepositoryException;
45 import javax.jcr.Session;
46
47 import org.apache.commons.lang3.StringUtils;
48
49
50
51
52 public class SupportForMultipleCacheImplementationsTask extends AbstractRepositoryTask {
53
54 public SupportForMultipleCacheImplementationsTask() {
55 super("Install support for multiple cache implementations", "Install delegating cache factory");
56 }
57
58 @Override
59 protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
60 final Session session = installContext.getConfigJCRSession();
61 final String newCacheFactoryName = StringUtils.substringBefore(StringUtils.lowerCase(StringUtils.substringAfterLast(session.getNode("/modules/cache/config/cacheFactory/").getProperty("class").getString(), ".")), "factory");
62
63 new RenameNodeTask("", RepositoryConstants.CONFIG, "/modules/cache/config", "cacheFactory", newCacheFactoryName, false).execute(installContext);
64 new BootstrapSingleModuleResource("config.modules.cache.config.cacheFactory.xml").execute(installContext);
65 new MoveNodeTask("", "/modules/cache/config/" + newCacheFactoryName, "/modules/cache/config/cacheFactory/delegateFactories/" + newCacheFactoryName, false).execute(installContext);
66 }
67 }