1 package league.ejb.session; 2 import java.math.BigDecimal ; 3 import java.sql.Timestamp ; 4 import league.ejb.*; 5 import league.ejb.entity.*; 6 import java.util.*; 7 import league.util.League; 8 import league.util.Match; 9 import league.util.Result; 10 import league.util.Round; 11 12 17 public class LeagueFacadeBean implements javax.ejb.SessionBean , league.ejb.session.LeagueFacadeRemoteBusiness { 18 private javax.ejb.SessionContext context; 19 private league.ejb.entity.LeagueLocalHome league=null; 20 private league.ejb.entity.RoundLocalHome round=null; 21 private league.ejb.entity.GroupsLocalHome groups=null; 22 private league.ejb.entity.TeamLocalHome team=null; 23 private league.ejb.entity.PlayerLocalHome player=null; 24 private league.ejb.entity.PlaceInGroupLocalHome place=null; 25 private league.ejb.entity.MatchLocalHome match=null; 26 private league.ejb.entity.ResultLocalHome result=null; 27 28 29 35 public void setSessionContext(javax.ejb.SessionContext aContext) { 36 context = aContext; 37 } 38 39 42 public void ejbActivate() { 43 44 } 45 46 49 public void ejbPassivate() { 50 51 } 52 53 56 public void ejbRemove() { 57 58 } 59 61 65 public void ejbCreate() { 66 league=lookupLeague(); 71 round=lookupRound(); 72 groups=lookupGroups(); 73 team=lookupTeam(); 74 player=lookupPlayer(); 75 place=lookupPlaceInGroup(); 76 match=lookupMatch(); 77 result=lookupResult(); 78 } 79 80 private league.ejb.entity.LeagueLocalHome lookupLeague() { 81 try { 82 return (league.ejb.entity.LeagueLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/League"); 83 } catch(javax.naming.NamingException ne) { 84 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 85 throw new RuntimeException (ne); 86 } 87 } 88 89 private league.ejb.entity.RoundLocalHome lookupRound() { 90 try { 91 return (league.ejb.entity.RoundLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/Round"); 92 } catch(javax.naming.NamingException ne) { 93 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 94 throw new RuntimeException (ne); 95 } 96 } 97 98 private league.ejb.entity.GroupsLocalHome lookupGroups() { 99 try { 100 return (league.ejb.entity.GroupsLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/Groups"); 101 } catch(javax.naming.NamingException ne) { 102 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 103 throw new RuntimeException (ne); 104 } 105 } 106 107 private league.ejb.entity.TeamLocalHome lookupTeam() { 108 try { 109 return (league.ejb.entity.TeamLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/Team"); 110 } catch(javax.naming.NamingException ne) { 111 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 112 throw new RuntimeException (ne); 113 } 114 } 115 116 private league.ejb.entity.PlayerLocalHome lookupPlayer() { 117 try { 118 return (league.ejb.entity.PlayerLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/Player"); 119 } catch(javax.naming.NamingException ne) { 120 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 121 throw new RuntimeException (ne); 122 } 123 } 124 125 private league.ejb.entity.PlaceInGroupLocalHome lookupPlaceInGroup() { 126 try { 127 return (league.ejb.entity.PlaceInGroupLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/PlaceInGroup"); 128 } catch(javax.naming.NamingException ne) { 129 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 130 throw new RuntimeException (ne); 131 } 132 } 133 134 private league.ejb.entity.MatchLocalHome lookupMatch() { 135 try { 136 return (league.ejb.entity.MatchLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/Match"); 137 } catch(javax.naming.NamingException ne) { 138 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 139 throw new RuntimeException (ne); 140 } 141 } 142 143 private league.ejb.entity.ResultLocalHome lookupResult() { 144 try { 145 return (league.ejb.entity.ResultLocalHome) CachingServiceLocator.getInstance().getLocalHome("java:comp/env/ejb/Result"); 146 } catch(javax.naming.NamingException ne) { 147 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); 148 throw new RuntimeException (ne); 149 } 150 } 151 152 public league.util.League createLeague(java.lang.String name, java.util.Date startDate, java.util.Date endDate, java.lang.String note) { 153 try { 154 league.ejb.entity.LeagueLocal ll=league.create(name, startDate, endDate, note); 155 return new league.util.League(new Integer (ll.getId().intValue()), name, startDate, endDate, note); 156 } catch (javax.ejb.CreateException ce) { 157 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 158 throw new RuntimeException (ce); 159 } 160 } 161 162 public java.util.Collection findAllLeagues() { 163 try { 164 ArrayList al=new ArrayList(); 165 Iterator it=league.findAll().iterator(); 166 while (it.hasNext()) { 167 league.ejb.entity.LeagueLocal ll=(league.ejb.entity.LeagueLocal) it.next(); 168 al.add(new league.util.League(new Integer (ll.getId().intValue()), ll.getName(), ll.getStartDate(), ll.getEndDate(), ll.getNote())); 169 } 170 return al; 171 } catch (javax.ejb.FinderException fe) { 172 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 173 throw new RuntimeException (fe); 174 } 175 } 176 177 private league.ejb.entity.RoundLocal createEmptyRound(java.lang.String name, java.util.Date startDate, league.ejb.entity.LeagueLocal ll) { 178 try { 179 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"createEmptyRound() new round name : "+name); 180 return round.create(name, new java.sql.Timestamp (startDate.getTime()), ll); 181 } catch(javax.ejb.CreateException fe) { 182 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 183 throw new RuntimeException (fe); 184 } 185 } 186 187 public void createRound(java.lang.Integer leagueId, java.lang.String name, java.util.Date startDate) { 188 league.ejb.entity.LeagueLocal ll=null; 189 league.ejb.entity.RoundLocal rl=null; 190 if (leagueId==null) throw new RuntimeException ("unknown league when creating round"); 191 try { 192 ll=league.findByPrimaryKey(new java.math.BigDecimal (leagueId.intValue())); 193 194 } catch (javax.ejb.FinderException fe) { 195 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 196 throw new RuntimeException (fe); 197 } 198 227 228 229 233 if (rl==null) rl=createEmptyRound(name, startDate, ll); 235 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"new round name: "+rl.getName()); 236 } 237 238 public java.util.Collection getPlayersInRound(league.ejb.entity.RoundLocal rl) { 239 ArrayList al=new ArrayList(); 241 Iterator it=rl.getGroups().iterator(); 242 while (it.hasNext()) { 243 league.ejb.entity.GroupsLocal gl=(league.ejb.entity.GroupsLocal) it.next(); 244 PlaceInGroupLocal pll=(PlaceInGroupLocal) gl.getPlaceInGroup(); 245 al.add(pll.getTeam().getName()); 246 } 247 248 return null; 249 } 250 251 public void setTeamStartPoints(Integer teamId, Integer groupId, Integer startPoints) { 252 try { 253 PlaceInGroupPK pk=new PlaceInGroupPK(); 254 pk.groupId=new BigDecimal (groupId.intValue()); 255 pk.teamId=new BigDecimal (teamId.intValue()); 256 PlaceInGroupLocal pl=place.findByPrimaryKey(pk); 257 pl.setStartPoints(startPoints); 258 } catch (javax.ejb.FinderException fe) { 259 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 260 throw new RuntimeException (fe); 261 } 262 } 263 264 public java.lang.Integer createPlayer(java.lang.String name, java.lang.String note, java.lang.String userId) { 265 try { 266 league.ejb.entity.PlayerLocal pl=player.create(name, note, userId); 267 return new Integer (pl.getId().intValue()); 268 } catch (javax.ejb.CreateException ce) { 269 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 270 throw new RuntimeException (ce); 271 } 272 } 273 274 public league.util.Player getPlayer(league.ejb.entity.PlayerLocal pl) { 275 league.util.Player player=new league.util.Player(new Integer (pl.getId().intValue()), pl.getName(), pl.getUserid(), pl.getNote()); 276 return player; 277 } 278 279 private PlaceInGroupLocal getActualPlace(TeamLocal tl, RoundLocal rl) { 280 Iterator it=tl.getPlaceInGroup().iterator(); 282 283 while (it.hasNext()) { 284 PlaceInGroupLocal plg = (PlaceInGroupLocal) it.next(); 285 if (rl.equals(plg.getGroups().getRoundId())) return plg; 286 } 287 return null; 288 } 289 290 public league.util.Team getTeam(league.ejb.entity.TeamLocal tl, RoundLocal rl) { 291 Iterator it=tl.getPlayerId().iterator(); 292 ArrayList al=new ArrayList(); 293 while (it.hasNext()) { 295 league.ejb.entity.PlayerLocal pl=(league.ejb.entity.PlayerLocal) it.next(); 296 al.add(getPlayer(pl)); 297 } 298 299 PlaceInGroupLocal plg=getActualPlace(tl, rl); 300 301 Iterator resIter =tl.getResult().iterator(); 302 int points=0; 303 if (plg!=null) { 304 Integer i=plg.getStartPoints(); 305 if (i!=null) points=i.intValue(); 306 } 307 Integer startPoints=new Integer (points); 308 System.out.println("startPoints "+startPoints.toString()); 309 while (resIter.hasNext()) { 310 ResultLocal resl=(ResultLocal) resIter.next(); 311 if (rl.equals(resl.getMatch().getRound())) points += resl.getPoints().intValue(); 312 } 313 league.util.Team team=new league.util.Team(new Integer (tl.getId().intValue()), tl.getName(), al, new Integer (points), startPoints); 314 System.out.println("startPoints "+team.getStartPoints().toString()); 315 return team; 316 } 317 318 public league.util.Group getGroup(league.ejb.entity.GroupsLocal gl) { 319 try { 320 Collection placesCol=place.findByGroupId(gl.getId()); Vector teams=new Vector(placesCol.size()); 322 Iterator it=placesCol.iterator(); 323 while (it.hasNext()) { 324 league.ejb.entity.PlaceInGroupLocal pl=(league.ejb.entity.PlaceInGroupLocal) it.next(); 325 teams.add(getTeam(pl.getTeam(), gl.getRoundId())); 327 } 328 return new league.util.Group(new Integer (gl.getId().intValue()), gl.getName(), teams); 329 } catch (javax.ejb.FinderException fe) { 330 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 331 throw new RuntimeException (fe); 332 } 333 } 334 335 public league.util.Round getRound(Integer id) { 336 337 return getRound(findRound(id)); 338 339 } 340 341 private league.ejb.entity.TeamLocal findTeam(Integer id) { 342 try { 343 return team.findByPrimaryKey(new java.math.BigDecimal (id.intValue())); 344 } catch (javax.ejb.FinderException fe) { 345 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 346 throw new RuntimeException (fe); 347 } 348 } 349 private league.ejb.entity.RoundLocal findRound(Integer id) { 350 try { 351 return round.findByPrimaryKey(new java.math.BigDecimal (id.intValue())); 352 } catch (javax.ejb.FinderException fe) { 353 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 354 throw new RuntimeException (fe); 355 } 356 } 357 358 private league.ejb.entity.MatchLocal findMatch(Integer id) { 359 try { 360 return match.findByPrimaryKey(new java.math.BigDecimal (id.intValue())); 361 } catch (javax.ejb.FinderException fe) { 362 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 363 throw new RuntimeException (fe); 364 } 365 } 366 367 private league.ejb.entity.ResultLocal findResult(ResultPK pk) { 368 try { 369 return result.findByPrimaryKey(pk); 370 } catch (javax.ejb.FinderException fe) { 371 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 372 throw new RuntimeException (fe); 373 } 374 } 375 376 private league.ejb.entity.LeagueLocal findLeague(Integer id) { 377 try { 378 return league.findByPrimaryKey(new java.math.BigDecimal (id.intValue())); 379 } catch (javax.ejb.FinderException fe) { 380 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 381 throw new RuntimeException (fe); 382 } 383 } 384 385 private league.ejb.entity.GroupsLocal findGroups(Integer id) { 386 try { 387 return groups.findByPrimaryKey(new java.math.BigDecimal (id.intValue())); 388 } catch (javax.ejb.FinderException fe) { 389 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 390 throw new RuntimeException (fe); 391 } 392 } 393 394 public league.util.Round getRound(league.ejb.entity.RoundLocal rl) { 395 try { 396 Collection groupsCol=groups.findByRound(rl); Vector groups=new Vector(groupsCol.size()); 398 Iterator it=rl.getGroups().iterator(); 399 Hashtable ht=new Hashtable(); 400 while (it.hasNext()) { 401 league.ejb.entity.GroupsLocal gl=(league.ejb.entity.GroupsLocal) it.next(); 402 ht.put(new Integer (gl.getPlace().intValue()), getGroup(gl)); 403 404 } 405 for (int i=1; i<=ht.size(); i++) { 406 groups.add(ht.get(new Integer (i))); 407 } 408 return new league.util.Round(new Integer (rl.getId().intValue()), rl.getName(), rl.getStartDate(), groups); 409 } catch (javax.ejb.FinderException fe) { 410 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 411 throw new RuntimeException (fe); 412 } 413 } 414 415 public Collection getMatches(Integer roundId) { 416 RoundLocal rl=findRound(roundId); 417 ArrayList al=new ArrayList(); 418 Iterator it=rl.getMatches().iterator(); 419 while (it.hasNext()) { 420 MatchLocal ml=(MatchLocal) it.next(); 421 Match m=new Match(new Integer (ml.getId().intValue()), new Date(ml.getDatePlayed().getTime())); 422 Iterator resIter=ml.getResult().iterator(); 423 while (resIter.hasNext()) { 424 ResultLocal resl=(ResultLocal) resIter.next(); 425 m.addResult(new Result(m.getId(), new Integer (resl.getTeam().getId().intValue()), new Integer (resl.getScore().intValue()), new Integer (resl.getPoints().intValue()))); 426 } 427 al.add(m); 428 } 429 return al; 430 } 431 432 public Match getMatchById(Integer matchId) { 433 MatchLocal ml=findMatch(matchId); 434 Match m=new Match(new Integer (ml.getId().intValue()), new Date(ml.getDatePlayed().getTime())); 435 Iterator resIter=ml.getResult().iterator(); 436 while (resIter.hasNext()) { 437 ResultLocal resl=(ResultLocal) resIter.next(); 438 m.addResult(new Result(m.getId(), new Integer (resl.getTeam().getId().intValue()), new Integer (resl.getScore().intValue()), new Integer (resl.getPoints().intValue()))); 439 } 440 441 return m; 442 } 443 444 public java.lang.Integer createTeam(java.lang.String name, Integer leagueId) { 445 try { 446 LeagueLocal ll=league.findByPrimaryKey(new java.math.BigDecimal (leagueId.intValue())); 447 league.ejb.entity.TeamLocal tl=team.create(name, ll); 448 return new Integer (tl.getId().intValue()); 449 } catch (javax.ejb.CreateException ce) { 450 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 451 throw new RuntimeException (ce); 452 } catch (javax.ejb.FinderException fe) { 453 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 454 throw new RuntimeException (fe); 455 } 456 } 457 458 public void addPlayerToTeam(java.lang.Integer playerId, java.lang.Integer teamId) { 459 try { 460 league.ejb.entity.TeamLocal tl=team.findByPrimaryKey(new java.math.BigDecimal (teamId.intValue())); 461 league.ejb.entity.PlayerLocal pl=player.findByPrimaryKey(new java.math.BigDecimal (playerId.intValue())); 462 ArrayList al=new ArrayList(tl.getPlayerId()); 463 al.add(pl); 464 tl.setPlayerId(al); 465 } catch (javax.ejb.FinderException fe) { 466 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 467 throw new RuntimeException (fe); 468 } 469 } 470 471 public Collection getTeamsInLeague(Integer id) { 472 try { 473 return getTeamsInLeague(league.findByPrimaryKey(new java.math.BigDecimal (id.intValue()))); 474 } catch (javax.ejb.FinderException fe) { 475 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 476 throw new RuntimeException (fe); 477 } 478 } 479 480 public Collection getTeamsInLeague(league.ejb.entity.LeagueLocal ll) { 481 Iterator it=ll.getTeams().iterator(); 482 ArrayList al=new ArrayList(); 483 while (it.hasNext()) { 484 TeamLocal tl=(TeamLocal) it.next(); 485 al.add(getTeam(tl, getActiveRound(ll))); 486 } 487 return al; 488 } 489 490 private league.ejb.entity.GroupsLocal createGroup(String name, Integer place, league.ejb.entity.RoundLocal rl) { 491 try { 492 return groups.create(name, new BigDecimal (place.intValue()), rl); 493 } catch (javax.ejb.CreateException ce) { 494 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 495 throw new RuntimeException (ce); 496 } 497 } 498 499 public java.util.Collection getRounds(Integer leagueId) { 500 try { 501 LeagueLocal ll=findLeague(leagueId); 502 Iterator it=round.findByLeague(ll).iterator(); 503 ArrayList al=new ArrayList(); 504 while (it.hasNext()) { 505 league.ejb.entity.RoundLocal rl=(league.ejb.entity.RoundLocal) it.next(); 506 al.add(getRound(rl)); 507 } 508 return al; 509 } catch (javax.ejb.FinderException fe) { 510 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 511 throw new RuntimeException (fe); 512 } 513 514 } 515 516 521 public java.util.Collection getLeagues() { 522 try { 523 Iterator it=league.findAll().iterator(); 524 ArrayList al=new ArrayList(); 525 while (it.hasNext()) { 526 league.ejb.entity.LeagueLocal ll=(league.ejb.entity.LeagueLocal) it.next(); 527 al.add(new league.util.League(new Integer (ll.getId().intValue()), ll.getName(), ll.getStartDate(), ll.getEndDate(), ll.getNote())); 528 } 529 return al; 530 } catch (javax.ejb.FinderException fe) { 531 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 532 throw new RuntimeException (fe); 533 } 534 535 } 536 537 538 public League getLeagueById(Integer leagueId) { 539 LeagueLocal ll=findLeague(leagueId); 540 return new league.util.League(new Integer (ll.getId().intValue()), ll.getName(), ll.getStartDate(), ll.getEndDate(), ll.getNote()); 541 } 542 543 544 560 public Round getActiveRound(Integer leagueId) { 561 try { 562 LeagueLocal ll=league.findByPrimaryKey(new java.math.BigDecimal (leagueId.intValue())); 563 league.ejb.entity.RoundLocal rl=getActiveRound(ll); 564 if (rl==null) return null; 565 return getRound(rl); 566 } catch (javax.ejb.FinderException fe) { 567 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 568 throw new RuntimeException (fe); 569 } 570 } 571 572 public Integer createMatch(Integer roundId, Hashtable results) { 573 if (results.size()!=2) return null; 574 try { 575 576 Enumeration e=results.keys(); 577 RoundLocal rl=findRound(roundId); 578 MatchLocal ml=match.create(new java.sql.Timestamp (Calendar.getInstance().getTimeInMillis())); 579 ml.setRound(rl); 580 581 int a=0; 582 int b=0; 583 if (results.containsValue(new Integer (3))) { 584 if (results.containsValue(new Integer (0))) {a=7;b=1;} 585 if (results.containsValue(new Integer (1))) {a=6;b=2;} 586 if (results.containsValue(new Integer (2))) {a=5;b=3;} 587 } else 588 if (results.containsValue(new Integer (-1))) { 589 a=0;b=4; 590 } 591 while (e.hasMoreElements()) { 592 Integer teamId=(Integer ) e.nextElement(); 593 Integer score=(Integer ) results.get(teamId); 594 int p=0; 595 if (score.intValue()==-1) p=-1; 596 else if (score.intValue()==3) p=a; 597 else p=b; 598 result.create(new BigDecimal (score.intValue()), new BigDecimal (p), teamId, new Integer (ml.getId().intValue())); 599 } 600 return new Integer (ml.getId().intValue()); 601 } catch (javax.ejb.CreateException ce) { 602 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 603 throw new RuntimeException (ce); 604 } 605 606 } 607 608 public void updateMatch(Match m) { 609 MatchLocal ml=findMatch(m.getId()); 610 Iterator it=m.getResults().iterator(); 611 while (it.hasNext()) { 612 Result r=(Result) it.next(); 613 ResultPK pk=new ResultPK(); 614 pk.matchId=ml.getId(); 615 pk.teamId =new BigDecimal (r.getTeamId().intValue()); 616 ResultLocal rl=findResult(pk); 617 rl.setScore(new BigDecimal (r.getScore().intValue())); 618 rl.setPoints(new BigDecimal (r.getPoints().intValue())); 619 } 620 621 } 622 626 642 private league.ejb.entity.RoundLocal getActiveRound(league.ejb.entity.LeagueLocal ll) { 643 try { 644 Date last=round.getLastStartDate(); 645 if (last==null) return null; 646 return round.findByStartDate(new Timestamp (last.getTime())); 647 } catch (javax.ejb.FinderException fe) { 648 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,fe); 649 throw new RuntimeException (fe); 650 } 651 } 652 653 private void addTeamToGroup(GroupsLocal gl, TeamLocal tl) { 654 try { 655 656 Collection col=gl.getPlaceInGroup(); 657 place.create(gl, tl, new Integer (col.size()+1)); 658 663 665 } catch (javax.ejb.CreateException ce) { 666 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 667 throw new RuntimeException (ce); 668 } 669 670 } 671 public String testGroups() { 672 try { 673 LeagueLocal ll=league.findByPrimaryKey(new java.math.BigDecimal (0)); 674 RoundLocal rl=getActiveRound(ll); 675 int[] p= {1,0,3,6,2,4,7,9,5,8,11,13,10,15,14,17,12,16,18,21,19,23,20,25,22,26,24}; 678 for (int i=0;i<=26;i++) { 679 680 681 TeamLocal tl=team.findByPrimaryKey(new java.math.BigDecimal (p[i])); 682 } 684 685 } catch (Exception e) { 686 e.printStackTrace(); 687 } 688 return "abcd"; 689 } 690 public void addTeamToLastPlace(Integer roundId, Integer teamId) { 691 RoundLocal rl=findRound(roundId); 692 TeamLocal tl=findTeam(teamId); 693 addTeamToLastPlace(rl, tl); 694 } 695 private void addTeamToLastPlace(RoundLocal rl, TeamLocal tl) { 696 try { 697 Collection groupsCol=rl.getGroups(); 698 int groupsCount=groupsCol.size(); 699 if (groupsCol.isEmpty()) { 700 GroupsLocal gl=groups.create("group 1", new BigDecimal (1), rl); 701 addTeamToGroup(gl, tl); 702 return; 703 } 704 league.ejb.entity.GroupsLocal lastGroupLocal=null; 706 int maxGroupId=0; 707 Iterator it=groupsCol.iterator(); 708 int test=0; 709 int i=0; 710 while (it.hasNext()) { 711 test++; 712 league.ejb.entity.GroupsLocal gl=(league.ejb.entity.GroupsLocal) it.next(); 713 i=gl.getPlace().intValue(); 714 if (i>maxGroupId) { lastGroupLocal=gl;maxGroupId=i; } 715 } 717 if (lastGroupLocal.getPlaceInGroup().size()<4) addTeamToGroup(lastGroupLocal, tl); 720 else { 721 groupsCount++; 722 lastGroupLocal=this.groups.create("group "+String.valueOf(groupsCount), new BigDecimal (groupsCount), rl); 723 addTeamToGroup(lastGroupLocal, tl); 724 } 725 } catch (javax.ejb.CreateException ce) { 726 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce); 727 throw new RuntimeException (ce); 728 } 729 730 } 731 } 732 | Popular Tags |