@Override public List<ZooKeeperCluster> getAllZooKeeperClusterIdAndName() throws DaoException { List<ZooKeeperCluster> zookeeperClusterList = new ArrayList<ZooKeeperCluster>(); ResultSet rs = null; DBConnectionResource myResultSet = null; try { myResultSet = DbcpUtil.executeQuery(SQL_QUERY_ALL_CLUSTER_ID_NAME); if (null == myResultSet) throw new DaoException("没有返回结果"); rs = myResultSet.resultSet; while (rs.next()) { int clusterId = rs.getInt("cluster_id"); String clusterName = rs.getString("cluster_name"); ZooKeeperCluster zookeeperCluster = new ZooKeeperCluster(); zookeeperCluster.setClusterId(clusterId); zookeeperCluster.setClusterName(clusterName); zookeeperClusterList.add(zookeeperCluster); } return zookeeperClusterList; } catch (Exception e) { throw new DaoException( "Error when query all zookeeper cluster id and name, Error: " + e.getMessage(), e); } finally { if (null != myResultSet) { DbcpUtil.closeResultSetAndStatement(rs, myResultSet.statement); DbcpUtil.returnBackConnectionToPool(myResultSet.connection); } } }
public ZooKeeperCluster getZooKeeperClusterByCulsterId(int clusterId) throws DaoException { ZooKeeperCluster zookeeperCluster = null; // 从数据库中获取指定zookeeper集群中所有机器 ResultSet rs = null; DBConnectionResource myResultSet = null; try { String querySQL = StringUtil.replaceSequenced(SQL_QUERY_CLUSTER_BY_ID, clusterId + EMPTY_STRING); myResultSet = DbcpUtil.executeQuery(querySQL); if (null == myResultSet) throw new DaoException("没有返回结果"); rs = myResultSet.resultSet; if (rs.next()) { String clusterName = rs.getString("cluster_name"); String serverListStr = rs.getString("server_list"); String description = rs.getString("description"); List<String> serverList = null; if (!StringUtil.isBlank(serverListStr)) { String[] serverListArray = serverListStr.split(COMMA); serverList = ArrayUtil.toArrayList(serverListArray); } zookeeperCluster = new ZooKeeperCluster(); zookeeperCluster.setClusterId(clusterId); zookeeperCluster.setClusterName(clusterName); zookeeperCluster.setServerList(serverList); zookeeperCluster.setDescription(description); } return zookeeperCluster; } catch (Exception e) { throw new DaoException( "Error when query zookeeper cluster by cluster_id: " + clusterId + ", Error: " + e.getMessage(), e); } finally { if (null != myResultSet) { DbcpUtil.closeResultSetAndStatement(rs, myResultSet.statement); DbcpUtil.returnBackConnectionToPool(myResultSet.connection); } } }
@Override public List<ZooKeeperCluster> getAllDetailZooKeeperCluster() throws DaoException { List<ZooKeeperCluster> zookeeperClusterList = new ArrayList<ZooKeeperCluster>(); // 从数据库中获取指定zookeeper集群中所有机器 ResultSet rs = null; DBConnectionResource myResultSet = null; try { myResultSet = DbcpUtil.executeQuery(SQL_QUERY_ALL_DETAIL_CLUSTER); if (null == myResultSet) throw new DaoException("没有返回结果"); rs = myResultSet.resultSet; while (rs.next()) { int clusterId = rs.getInt("cluster_id"); String clusterName = rs.getString("cluster_name"); String serverListStr = rs.getString("server_list"); String description = rs.getString("description"); List<String> serverList = null; if (!StringUtil.isBlank(serverListStr)) { String[] serverListArray = serverListStr.split(COMMA); serverList = ArrayUtil.toArrayList(serverListArray); } ZooKeeperCluster zookeeperCluster = new ZooKeeperCluster(); zookeeperCluster.setClusterId(clusterId); zookeeperCluster.setClusterName(clusterName); zookeeperCluster.setServerList(serverList); zookeeperCluster.setDescription(description); zookeeperClusterList.add(zookeeperCluster); } return zookeeperClusterList; } catch (Exception e) { throw new DaoException("Error when query all zookeeper cluster, Error: " + e.getMessage(), e); } finally { if (null != myResultSet) { DbcpUtil.closeResultSetAndStatement(rs, myResultSet.statement); DbcpUtil.returnBackConnectionToPool(myResultSet.connection); } } }