return current;
} catch (ReadOnlyException e) { LOG.debug("database read-only"); return null; } catch (LockException e) { LOG.warn("failed to acquire lock on collections store"); } finally { lock.release();
	public Collection getOrCreateCollection(User user, String name)		throws PermissionDeniedException {		//		final long start = System.currentTimeMillis();		name = normalizeCollectionName(name);		if (name.length() > 0 && name.charAt(0) != '/')			name = "/" + name;		if (!name.startsWith("/db"))			name = "/db" + name;		if (name.endsWith("/") && name.length() > 1)			name = name.substring(0, name.length() - 1);		synchronized (collections) {			Collection current;			try {				StringTokenizer tok = new StringTokenizer(name, "/");				String temp = tok.nextToken();				String path = "/db";				Collection sub;				current = getCollection("/db");				if (current == null) {					LOG.debug("creating root collection /db");					current = new Collection(this, "/db");					current.getPermissions().setPermissions(0777);					current.getPermissions().setOwner(user);					current.getPermissions().setGroup(user.getPrimaryGroup());					current.setId(getNextCollectionId());					saveCollection(current);				}				while (tok.hasMoreTokens()) {					temp = tok.nextToken();					path = path + "/" + temp;					if (current.hasSubcollection(temp))						current = getCollection(path);					else {						if (!current.getPermissions().validate(user, Permission.WRITE))							throw new PermissionDeniedException("not allowed to write to collection");						LOG.debug("creating collection " + path);						sub = new Collection(this, path);						sub.getPermissions().setOwner(user);						sub.getPermissions().setGroup(user.getPrimaryGroup());						sub.setId(getNextCollectionId());						current.addCollection(sub);						saveCollection(current);						current = sub;					}				}			} catch (ReadOnlyException e) {				LOG.debug("database read-only");				return null;			}			//			LOG.debug("getOrCreateCollection took " + 			//				(System.currentTimeMillis() - start) + "ms.");			return current;		}	}