public OStorage registerStorage(final OStorage iStorage) throws IOException { acquireExclusiveLock(); try { for (OOrientListener l : listeners) l.onStorageRegistered(iStorage); if (!storages.containsKey(iStorage.getName())) storages.put(iStorage.getName(), iStorage); } finally { releaseExclusiveLock(); } return iStorage; }
public OStorage loadStorage(String iURL) { if (iURL == null || iURL.length() == 0) throw new IllegalArgumentException("URL missed"); if (iURL.endsWith("/")) iURL = iURL.substring(0, iURL.length() - 1); // SEARCH FOR ENGINE int pos = iURL.indexOf(':'); if (pos <= 0) throw new OConfigurationException( "Error in database URL: the engine was not specified. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL); final String engineName = iURL.substring(0, pos); acquireExclusiveLock(); try { final OEngine engine = engines.get(engineName.toLowerCase()); if (engine == null) throw new OConfigurationException( "Error on opening database: the engine '" + engineName + "' was not found. URL was: " + iURL + ". Registered engines are: " + engines.keySet()); // SEARCH FOR DB-NAME iURL = iURL.substring(pos + 1); pos = iURL.indexOf('?'); Map<String, String> parameters = null; String dbPath = null; if (pos > 0) { dbPath = iURL.substring(0, pos); iURL = iURL.substring(pos + 1); // PARSE PARAMETERS parameters = new HashMap<String, String>(); String[] pairs = iURL.split("&"); String[] kv; for (String pair : pairs) { kv = pair.split("="); if (kv.length < 2) throw new OConfigurationException( "Error on opening database: parameter has no value. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL); parameters.put(kv[0], kv[1]); } } else dbPath = iURL; final String dbName; pos = dbPath.lastIndexOf('/'); if (pos > -1) dbName = dbPath.substring(pos + 1); else dbName = dbPath; OStorage storage; if (engine.isShared()) { // SEARCH IF ALREADY USED storage = storages.get(dbName); if (storage == null) { // NOT FOUND: CREATE IT storage = engine.createStorage(dbPath, parameters); storages.put(dbName, storage); } } else { // REGISTER IT WITH A SERIAL NAME TO AVOID BEING REUSED storage = engine.createStorage(dbPath, parameters); storages.put(dbName + "__" + serialId.incrementAndGet(), storage); } for (OOrientListener l : listeners) l.onStorageRegistered(storage); return storage; } finally { releaseExclusiveLock(); } }