synchronized(collectionsCache) {
try {
//TODO : resolve URIs !
final XmldbURI[] segments = name.getPathSegments();
XmldbURI path = XmldbURI.ROOT_COLLECTION_URI;
Collection sub;
Collection current = getCollection(XmldbURI.ROOT_COLLECTION_URI);
if(current == null) {
if(LOG.isDebugEnabled()) {
LOG.debug("Creating root collection '" + XmldbURI.ROOT_COLLECTION_URI + "'");
}
final CollectionTrigger trigger = new CollectionTriggers(this);
trigger.beforeCreateCollection(this, transaction, XmldbURI.ROOT_COLLECTION_URI);
current = new Collection(this, XmldbURI.ROOT_COLLECTION_URI);
current.setId(getNextCollectionId(transaction));
current.setCreationTime(System.currentTimeMillis());
if(transaction != null) {
transaction.acquireLock(current.getLock(), Lock.WRITE_LOCK);
}
//TODO : acquire lock manually if transaction is null ?
saveCollection(transaction, current);
trigger.afterCreateCollection(this, transaction, current);
//import an initial collection configuration
try {
final String initCollectionConfig = readInitCollectionConfig();
if(initCollectionConfig != null) {
CollectionConfigurationManager collectionConfigurationManager = pool.getConfigurationManager();
if(collectionConfigurationManager == null) {
//might not yet have been initialised
pool.initCollectionConfigurationManager(this);
collectionConfigurationManager = pool.getConfigurationManager();
}
if(collectionConfigurationManager != null) {
collectionConfigurationManager.addConfiguration(transaction, this, current, initCollectionConfig);
}
}
} catch(final CollectionConfigurationException cce) {
LOG.error("Could not load initial collection configuration for /db: " + cce.getMessage(), cce);
}
}
for(int i = 1; i < segments.length; i++) {
final XmldbURI temp = segments[i];
path = path.append(temp);
if(current.hasSubcollectionNoLock(this, temp)) {
current = getCollection(path);
if(current == null) {
LOG.debug("Collection '" + path + "' not found!");