@Override public AccessControlModel load(String id, boolean cacheAllowed) { ConnectionPool pool = DbcpSource.getPool(dbcpId); if (pool == null){ LOG.error("Can not find the connection pool named:" + dbcpId); return null; } Connection conn = null; boolean error = false; try { conn = pool.getConnection(); if (conn != null){ return loadACM(conn,id); }else{ LOG.error("Can not get db connection from pool:" + dbcpId); return null; } }catch (BaseException ex){ LOG.error(ExceptionUtils.getStackTrace(ex)); return null; }finally{ pool.recycle(conn, error); } }
protected int onJson(Context ctx) { JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class); List<Object> list = new ArrayList<Object>(); DbcpSource src = DbcpSource.get(); Collection<ConnectionPool> pools = src.current(); for (ConnectionPool pool:pools){ Map<String,Object> map = new HashMap<String,Object>(); pool.report(map); list.add(map); } msg.getRoot().put("pool", list); return 0; }
public void close(boolean force)throws SQLException{ if (force || pool == null){ //如果强行关闭 real.close(); }else{ pool.recycle(this, false); } } public <T> T unwrap(Class<T> iface) throws SQLException {
found = pool.getConnection(timeout);
public void recycle(Connection conn,boolean hasError){ if (conn != null){ if (conn instanceof ManagedConnection){ //ManagedConnection不能close,否则会死循环 ManagedConnection _conn = (ManagedConnection)conn; ConnectionPool _pool = _conn.getPool(); if (_pool == this){ //是由本pool创建的 returnObject(conn,hasError); }else{ //不是我创建的,交给相应的pool去回收 _pool.recycle(conn, hasError); } }else{ returnObject(conn,hasError); } } }
@Override public AccessAppKey load(String id, boolean cacheAllowed) { ConnectionPool pool = DbcpSource.getPool(dbcpId); if (pool == null){ LOG.error("Can not find the connection pool named:" + dbcpId); return null; } Connection conn = null; boolean error = false; try { conn = pool.getConnection(); if (conn != null){ return loadAAK(conn,id); }else{ LOG.error("Can not get db connection from pool:" + dbcpId); return null; } }catch (BaseException ex){ LOG.error(ExceptionUtils.getStackTrace(ex)); return null; }finally{ pool.recycle(conn, error); } }
protected int onXml(Context ctx){ XMLMessage msg = (XMLMessage) ctx.asMessage(XMLMessage.class); Document doc = msg.getDocument(); Element root = msg.getRoot(); DbcpSource src = DbcpSource.get(); Collection<ConnectionPool> pools = src.current(); for (ConnectionPool pool:pools){ Element elem = doc.createElement("pool"); pool.report(elem); root.appendChild(elem); } return 0; } protected int onJson(Context ctx) {
@Override protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) { ConnectionPool pool = DbcpSource.getPool(dbcpId); if (pool == null) { logger.error("Can't get connection pool by dbcpId:" + dbcpId + ", The database connection pool is null!"); return ; } Connection conn = pool.getConnection(); if (conn == null) { logger.error("The database connection is null!"); return ; } boolean hasError = false; try { conn.setAutoCommit(autoCommit); ctx.setObject(dbconn, conn); super.onExecute(root, current, ctx, watcher); } catch (SQLException ex) { hasError = true; throw new BaseException("core.e1300",ex.getMessage()); } finally { ctx.removeObject(dbconn); pool.recycle(conn, hasError); } }
protected int onJson(Context ctx){ JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class); String id = getArgument("id",ctx); DbcpSource src = DbcpSource.get(); ConnectionPool found = src.get(id); if (found == null){ throw new ServantException("clnt.e2007","Can not find the db connection pool :" + id); } Map<String,Object> map = new HashMap<String,Object>(); found.report(map); msg.getRoot().put("dbcp", map); return 0; }
protected CacheObject loadObject(String id,Object[] ids) { ConnectionPool pool = DbcpSource.getPool(dbcp); if (pool == null) { throw new BaseException("core.e1003", "Can not get a connection pool named " + dbcp); } Connection conn = pool.getConnection(); try { Map<String,Object> result = DBTools.selectAsObjects(conn,sql, ids); if (result != null){ CacheObject found = new CacheObject.Simple(id); found.fromJson(result); return found; } return null; } finally { pool.recycle(conn); } } }
protected int onXml(Context ctx){ XMLMessage msg = (XMLMessage) ctx.asMessage(XMLMessage.class); String id = getArgument("id",ctx); Document doc = msg.getDocument(); Element root = msg.getRoot(); DbcpSource src = DbcpSource.get(); ConnectionPool found = src.get(id); if (found == null){ throw new ServantException("clnt.e2007","Can not find the db connection pool :" + id); } Element elem = doc.createElement("dbcp"); found.report(elem); root.appendChild(elem); return 0; }
boolean error = false; try { conn = pool.getConnection(); if (conn != null){ long pid = DBTools.selectAsLong(conn, "select pid from util_snowflake where client = ?", -1, client); LOG.error(ExceptionUtils.getStackTrace(ex)); }finally{ pool.recycle(conn, error);
public CacheObject loadObject(String id,Object[] ids) { ConnectionPool pool = DbcpSource.getPool(dbcp); if (pool == null) { throw new BaseException("core.e1003", "Can not get a connection pool named " + dbcp); } Connection conn = pool.getConnection(); try { List<String> result = new ArrayList<String>(); DBTools.list(conn, result,single,sql,ids); if (!result.isEmpty()){ CacheObject found = new CacheObject.Simple(id); for (String item:result){ found.sAdd(CacheObject.DEFAULT_GROUP, item); } if (found.isValid()){ return found; } } return null; } finally { pool.recycle(conn); } } }
return ; conn = pool.getConnection(); if (conn == null) { logger.error("The database connection is null!"); } finally { ctx.removeObject(dbconn); pool.recycle(conn, hasError);
boolean error = false; try { conn = pool.getConnection(); if (conn != null){ List<Map<String,Object>> result = DBTools.listAsObject(conn,sql,lastScanTime); LOG.error(ExceptionUtils.getStackTrace(ex)); }finally{ pool.recycle(conn, error);
boolean error = false; try { conn = pool.getConnection(); if (conn != null){ DBTools.setAutoCommit(conn, false); throw ex; }finally{ pool.recycle(conn, error);