protected Connection applyConnection(boolean readOnly, String username, String password) throws SQLException { List<DataSourceMarker> tryList = New.arrayList(); DataSourceMarker selected = dataSource.doRoute(readOnly); while (selected != null) { try { tryList.add(selected); return (username != null) ? database.haGet(selected, username, password) : database.haGet(selected); } catch (SQLException e) { selected = dataSource.doRoute(readOnly, tryList); } } throw new SQLException("No avaliable datasource in shard " + dataSource); }