private void getPlayerData(String playerID) { QueryBuilder<Player> playerQB = CustomApplcation.getDaoSession(mContext).getPlayerDao().queryBuilder(); playerQB.where(com.kinth.football.dao.PlayerDao.Properties.Uuid.eq(playerID)); List<Player> list = playerQB.list(); for (int i = 0; i < list.size(); i++) { playerList.add(list.get(i)); } }
@Override protected Void doInBackground(List<PlayerInTeam>... params) { // TODO Auto-generated method stub PlayerDao playerDao = CustomApplcation.getDaoSession(mContext).getPlayerDao(); TeamPlayerDao tpDao = CustomApplcation.getDaoSession(mContext).getTeamPlayerDao(); Query<TeamPlayer> tpQuery = CustomApplcation.getDaoSession(mContext) .getTeamPlayerDao() .queryBuilder() .where( TeamPlayerDao.Properties.Player_id.eq(""), TeamPlayerDao.Properties.Team_id.eq("")) .build(); // (1)、将球队成员数据放入到Player表中 List<PlayerInTeam> teamMebList = params[0]; for (PlayerInTeam teamRe : teamMebList) { // 去掉了数据库表Player的自增长ID之后,才能使用insertOrReplace方法 playerDao.insertOrReplace(teamRe.getPlayer()); // (2)、同时,在成员Player与球队Team关联表TeamPlayer表中,也要添加相对应的数据 TeamPlayer team_player = new TeamPlayer(); team_player.setPlayer_id(teamRe.getPlayer().getUuid()); team_player.setTeam_id(onlyTeam.getUuid()); team_player.setCreator(teamRe.isCreator()); // 1创建者 team_player.setType(teamRe.getType()); tpQuery.setParameter(0, teamRe.getPlayer().getUuid()); tpQuery.setParameter(1, onlyTeam.getUuid()); TeamPlayer teamPlayerSearch = tpQuery.unique(); if (teamPlayerSearch != null) { team_player.setId(teamPlayerSearch.getId()); // 找到已有的teamplayer映射的id tpDao.insertOrReplace(team_player); } else { tpDao.insertOrReplace(team_player); } } return null; }
@Override protected List<Player> doInBackground(Void... params) { QueryBuilder<TeamPlayer> tpQB = CustomApplcation.getDaoSession(mContext).getTeamPlayerDao().queryBuilder(); tpQB.where(com.kinth.football.dao.TeamPlayerDao.Properties.Team_id.eq(onlyTeam.getUuid())); List<TeamPlayer> teamId_playerId_List = tpQB.list(); if (teamId_playerId_List.size() != 0) { for (TeamPlayer teamplayer : teamId_playerId_List) { getPlayerData(teamplayer.getPlayer_id()); } } return playerList; }