1 5 6 package org.exoplatform.services.jcr.impl.storage.inmemory; 7 8 9 import javax.jcr.PathNotFoundException; 10 import javax.jcr.ItemExistsException; 11 12 import java.util.*; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.codec.binary.Base64; 16 import org.exoplatform.services.jcr.core.NodeData; 17 import org.exoplatform.services.jcr.core.ReferenceableNodeLocation; 18 import org.exoplatform.services.jcr.impl.storage.BaseRepositoryManager; 19 import org.exoplatform.services.log.LogUtil; 20 21 27 28 public class RepositoryManagerImpl extends BaseRepositoryManager { 29 30 protected Log log; 31 32 private static long id = System.currentTimeMillis(); 33 34 private Map workspaceContainers; 35 private Map referenceTables; 36 37 public RepositoryManagerImpl(String name) { 38 log = LogUtil.getLog("org.exoplatform.services.jcr"); 39 workspaceContainers = new HashMap(); 40 referenceTables = new HashMap(); 41 } 42 43 synchronized public String generateUUID(NodeData context) { 44 return String.valueOf(++id); 45 } 46 47 synchronized public ReferenceableNodeLocation getLocationByUUID(String workspaceContainerName, String UUID) throws PathNotFoundException { 48 49 log.debug("RepositoryManagerImpl is finding location by UUID "+UUID); 50 51 Map container = getWorkspaceContainer(workspaceContainerName); 52 if(container == null) 53 throw new PathNotFoundException("Workspace container '"+workspaceContainerName+"' not found."); 54 55 ReferenceableNodeLocation loc = (ReferenceableNodeLocation)container.get(UUID); 56 log.debug("RepositoryManagerImpl found location by UUID "+UUID+" "+loc); 57 if (loc == null) 58 throw new PathNotFoundException("UUID '"+UUID+"' not found."); 59 60 return loc; 61 62 } 63 64 synchronized public ReferenceableNodeLocation getLocationByPath(String workspaceContainerName, String path) throws PathNotFoundException { 65 66 log.debug("RepositoryManagerImpl is finding location by path "+path); 67 68 Map refTable = getReferenceTable(workspaceContainerName); 69 if(refTable == null) { 70 refTable = new HashMap(); 71 } 72 73 String uuid = (String ) refTable.get(path); 74 75 if ( uuid == null) 76 throw new PathNotFoundException("Path '"+path+"' not found."); 77 78 return getLocationByUUID(workspaceContainerName, uuid); 79 80 } 81 82 synchronized public void addLocation(String workspaceContainerName, String UUID, String path, boolean isNew) throws PathNotFoundException, ItemExistsException { 83 84 Map container = getWorkspaceContainer(workspaceContainerName); 85 if(container == null) { 86 throw new PathNotFoundException("RepositoryManagerImpl.addLocation() Container "+workspaceContainerName+" not found"); 87 } 90 91 Map refTable = getReferenceTable(workspaceContainerName); 92 if(refTable == null) { 93 throw new PathNotFoundException("RepositoryManagerImpl.addLocation() Container "+workspaceContainerName+" not found"); 94 95 } 98 99 String realPath; 100 refTable.put(path, UUID); 101 if(isNew) { 102 container.put(UUID, new ReferenceableNodeLocation(path, UUID, path)); 103 } else { 104 ReferenceableNodeLocation loc = (ReferenceableNodeLocation)container.get(UUID); 105 loc.addReferencedPath(path); 106 } 107 108 log.debug("RepositoryManagerImpl added reference "+path+" isNew= "+isNew+" to "+UUID+" size "+refTable.size()); 109 110 } 111 112 synchronized public void deleteLocationByPath(String workspaceContainerName, String path) { 113 114 Map refTable = getReferenceTable(workspaceContainerName); 115 if(refTable == null) 116 return; 117 118 String uuid = (String )refTable.get(path); 119 if(uuid == null) 120 return; 121 122 log.debug("RepositoryManagerImpl is deleting location by path "+path); 123 124 deleteLocationByUUID(workspaceContainerName, uuid); 125 126 } 127 128 synchronized public void deleteLocationByUUID(String workspaceContainerName, String UUID) { 129 130 Map refTable = getReferenceTable(workspaceContainerName); 131 if(refTable == null) 132 return; 133 134 log.debug("RepositoryManagerImpl is deleting location by UUID "+UUID); 135 136 Iterator entries = refTable.keySet().iterator(); 137 ArrayList paths = new ArrayList(); 138 while (entries.hasNext()) { 139 String testPath = (String ) entries.next(); 140 String testUUID = (String ) refTable.get(testPath); 141 if(testUUID.equals(UUID)) 142 paths.add(testPath); 143 } 145 146 for(int i=0; i<paths.size(); i++) { 147 log.debug("RepositoryManagerImpl deleted path "+paths.get(i)); 148 refTable.remove(paths.get(i)); 149 } 150 151 Map container = getWorkspaceContainer(workspaceContainerName); 152 if(container != null) 153 container.remove(UUID); 154 155 } 156 157 synchronized public void addWorkspaceContainer(String workspaceContainerName) { 158 159 Map container = getWorkspaceContainer(workspaceContainerName); 160 if(container == null) { 161 container = new HashMap(); 162 workspaceContainers.put(workspaceContainerName, container); 163 log.debug("RepositoryManagerImpl.addWorkspaceContainer() Container "+workspaceContainerName+" added"); 164 } else { 165 log.debug("RepositoryManagerImpl.addWorkspaceContainer() Container "+workspaceContainerName+" already exists"); 166 } 167 168 Map refTable = getReferenceTable(workspaceContainerName); 169 if(refTable == null) { 170 refTable = new HashMap(); 171 referenceTables.put(workspaceContainerName, refTable); 172 log.debug("RepositoryManagerImpl.addWorkspaceContainer() Ref table "+workspaceContainerName+" added"); 173 } else { 174 log.debug("RepositoryManagerImpl.addWorkspaceContainer() Ref table "+workspaceContainerName+" already exists"); 175 } 176 177 } 178 179 180 private Map getWorkspaceContainer(String workspaceContainerName) { 181 return (Map) workspaceContainers.get(workspaceContainerName); 182 } 183 184 private Map getReferenceTable(String workspaceContainerName) { 185 return (Map) referenceTables.get(workspaceContainerName); 186 } 187 188 } 189 | Popular Tags |