public void release(final DB iDatabase) { final String dbPooledName = iDatabase instanceof ODatabaseComplex ? ((ODatabaseComplex<?>) iDatabase).getUser().getName() + "@" + iDatabase.getURL() : iDatabase.getURL(); synchronized (pools) { final OResourcePool<String, DB> pool = pools.get(dbPooledName); if (pool == null) throw new OLockException( "Cannot release a database URL not acquired before. URL: " + iDatabase.getName()); pool.returnResource(iDatabase); } }
public void remove(final String iPoolName) { synchronized (pools) { final OResourcePool<String, DB> pool = pools.get(iPoolName); if (pool != null) { for (DB db : pool.getResources()) { if (db.getStorage().getStatus() == OStorage.STATUS.OPEN) try { OLogManager.instance().debug(this, "Closing pooled database '%s'...", db.getName()); ((ODatabasePooled) db).forceClose(); OLogManager.instance().debug(this, "OK", db.getName()); } catch (Exception e) { OLogManager.instance().debug(this, "Error: %d", e.toString()); } } pool.close(); pools.remove(iPoolName); } } }
public DB acquire( final String iURL, final String iUserName, final String iUserPassword, final Map<String, Object> iOptionalParams) throws OLockException { final String dbPooledName = OIOUtils.getUnixFileName(iUserName + "@" + iURL); synchronized (pools) { OResourcePool<String, DB> pool = pools.get(dbPooledName); if (pool == null) // CREATE A NEW ONE pool = new OResourcePool<String, DB>(maxSize, this); final DB db = pool.getResource(iURL, timeout, iUserName, iUserPassword, iOptionalParams); // PUT IN THE POOL MAP ONLY IF AUTHENTICATION SUCCEED pools.put(dbPooledName, pool); return db; } }