public DB acquire(final String iURL, final String iUserName, final String iUserPassword) throws OLockException { return acquire(iURL, iUserName, iUserPassword, null); }
/** * Closes the entire pool freeing all the connections. */ public void close() { if (dbPool != null) { dbPool.close(); dbPool = null; } }
public int getConnectionsInCurrentThread(final String name, final String userName) { if (dbPool == null) return 0; return dbPool.getConnectionsInCurrentThread(name, userName); }
/** * Removes from memory the pool associated to the closed storage. This avoids pool open against closed storages. */ public void onStorageUnregistered(final OStorage iStorage) { final String storageURL = iStorage.getURL(); lock(); try { Set<String> poolToClose = null; for (Entry<String, OReentrantResourcePool<String, DB>> e : pools.entrySet()) { final int pos = e.getKey().indexOf("@"); final String dbName = e.getKey().substring(pos + 1); if (storageURL.equals(dbName)) { if (poolToClose == null) poolToClose = new HashSet<String>(); poolToClose.add(e.getKey()); } } if (poolToClose != null) for (String pool : poolToClose) remove(pool); } finally { unlock(); } }
public void release(final DB iDatabase) { // REMOVE ANY INTENT BEFORE. THIS RESTORE ANYTHING BEFORE THE CLOSE, LIKE THE USER NAME IN CASE OF MASSIVE INSERT iDatabase.declareIntent(null); final String dbPooledName = iDatabase.getUser().getName() + "@" + iDatabase.getURL(); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) throw new OLockException("Cannot release a database URL not acquired before. URL: " + iDatabase.getName()); if (pool.returnResource(iDatabase)) this.notifyEvictor(dbPooledName, iDatabase); }
/** * Don't call it directly but use database.close(). * * @param iDatabase */ public void release(final DB iDatabase) { if (dbPool != null) dbPool.release(iDatabase); }
/** * Returns all the configured pools. * */ public Map<String, OReentrantResourcePool<String, DB>> getPools() { return dbPool.getPools(); }
/** * Returns the maximum size of the pool * */ public int getMaxSize() { setup(); return dbPool.getMaxSize(); }
public int getCreatedInstances(final String name, final String userName) { setup(); return dbPool.getCreatedInstances(name, userName); }
/** * Returns amount of available connections which you can acquire for given source and user name. Source id is consist of * "source name" and "source user name". * * @param name * Source name. * @param userName * User name which is used to acquire source. * @return amount of available connections which you can acquire for given source and user name. */ public int getAvailableConnections(final String name, final String userName) { setup(); return dbPool.getAvailableConnections(name, userName); }
public int getMaxConnections(final String url, final String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) return maxSize; return pool.getMaxResources(); }
public int getAvailableConnections(final String url, final String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) return 0; return pool.getAvailableResources(); }
/** * Acquires a connection from the pool using the configured URL, user-name and user-password. If the pool is empty, then the * caller thread will wait for it. * * @return A pooled database instance */ public DB acquire() { setup(); return dbPool.acquire(url, userName, userPassword); }
@Override public void onShutdown() { close(); }
public int getConnectionsInCurrentThread(final String url, final String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) return 0; return pool.getConnectionsInCurrentThread(url); }
/** * Acquires a connection from the pool. If the pool is empty, then the caller thread will wait for it. * * @param iName * Database name * @param iUserName * User name * @param iUserPassword * User password * @return A pooled database instance */ public DB acquire(final String iName, final String iUserName, final String iUserPassword) { setup(); return dbPool.acquire(iName, iUserName, iUserPassword); }
public int getCreatedInstances(String url, String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); lock(); try { final OReentrantResourcePool<String, DB> pool = pools.get(dbPooledName); if (pool == null) return 0; return pool.getCreatedInstances(); } finally { unlock(); } }
/** * Acquires a connection from the pool specifying options. If the pool is empty, then the caller thread will wait for it. * * @param iName * Database name * @param iUserName * User name * @param iUserPassword * User password * @return A pooled database instance */ public DB acquire(final String iName, final String iUserName, final String iUserPassword, final Map<String, Object> iOptionalParams) { setup(); return dbPool.acquire(iName, iUserName, iUserPassword, iOptionalParams); }
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); OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); if (pool == null) // CREATE A NEW ONE pool = new OReentrantResourcePool<String, DB>(maxSize, this); // PUT IN THE POOL MAP ONLY IF AUTHENTICATION SUCCEED pools.put(dbPooledName, pool); } finally { unlock(); } final DB db = pool.getResource(iURL, timeout, iUserName, iUserPassword, iOptionalParams); return db; }