blob: d9f348a89122494a4ac1162b8bb7796916f9e458 [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
2 * Copyright (c) 2001, 2018 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
7 *
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
13 *
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15 */
16
17package team;
18
19import java.util.*;
20import javax.ejb.*;
21import javax.naming.*;
22import util.Debug;
23
24public abstract class LeagueBean implements EntityBean {
25
26 private EntityContext context;
27
28 // Access methods for persistent fields
29
30 public abstract String getLeagueId();
31 public abstract void setLeagueId(String id);
32
33 public abstract String getName();
34 public abstract void setName(String name);
35
36 public abstract String getSport();
37 public abstract void setSport(String sport);
38
39
40 // Access methods for relationship fields
41
42 public abstract Collection getTeams();
43 public abstract void setTeams(Collection teams);
44
45 // Select methods
46
47 public abstract Set ejbSelectTeamsCity(LocalLeague league)
48 throws FinderException;
49
50 public abstract Set ejbSelectRemoteTeams(League league)
51 throws FinderException;
52
53
54 public abstract LocalTeam ejbSelectTeamByCity(String city)
55 throws FinderException;
56
57 public abstract Team ejbSelectRemoteTeamByCity(String city)
58 throws FinderException;
59
60 public abstract String ejbSelectTeamsNameByCity(String city)
61 throws FinderException;
62
63
64 public abstract Set ejbSelectPlayersByLeague(LocalLeague league)
65 throws FinderException;
66
67 public abstract Collection ejbSelectRemotePlayersByLeague(League league)
68 throws FinderException;
69
70 // Business methods
71
72 public Set getCitiesOfThisLeague() throws FinderException {
73
74 LocalLeague league =
75 (team.LocalLeague)context.getEJBLocalObject();
76
77 return ejbSelectTeamsCity(league);
78 }
79
80
81 public Set getRemoteTeamsOfThisLeague() throws FinderException {
82
83 League league = (team.League)context.getEJBObject();
84
85 return ejbSelectRemoteTeams(league);
86 }
87
88
89 public LocalTeam getTeamByCity(String city) throws FinderException {
90
91 return ejbSelectTeamByCity(city);
92 }
93
94 public Team getRemoteTeamByCity(String city) throws FinderException {
95
96 return ejbSelectRemoteTeamByCity(city);
97 }
98
99 public String getTeamsNameByCity(String city) throws FinderException {
100
101 return ejbSelectTeamsNameByCity(city);
102 }
103
104
105 public Set getPlayersFromLeague() throws FinderException{
106
107 LocalLeague league = (team.LocalLeague)context.getEJBLocalObject();
108
109 return ejbSelectPlayersByLeague(league);
110 }
111
112 public Collection getRemotePlayersFromLeague() throws FinderException{
113
114 League league = (team.League)context.getEJBObject();
115
116 return ejbSelectRemotePlayersByLeague(league);
117 }
118
119
120 public void addTeam(LocalTeam team) {
121
122 Debug.print("TeamBean addTeam");
123 try {
124 Collection teams = getTeams();
125 teams.add(team);
126 } catch (Exception ex) {
127 throw new EJBException(ex.getMessage());
128 }
129 }
130
131 public void dropTeam(LocalTeam team) {
132
133 Debug.print("TeamBean dropTeam");
134 try {
135 Collection teams = getTeams();
136 teams.remove(team);
137 } catch (Exception ex) {
138 throw new EJBException(ex.getMessage());
139 }
140 }
141
142 // EntityBean methods
143
144 public String ejbCreate (String id, String name, String sport)
145 throws CreateException {
146
147 Debug.print("LeagueBean ejbCreate");
148 setLeagueId(id);
149 setName(name);
150 setSport(sport);
151 return null;
152 }
153
154 public void ejbPostCreate (String id, String name, String sport)
155 throws CreateException { }
156
157 public void setEntityContext(EntityContext ctx) {
158 context = ctx;
159 }
160
161 public void unsetEntityContext() {
162 context = null;
163 }
164
165 public void ejbRemove() {
166 Debug.print("LeagueBean ejbRemove");
167 }
168
169 public void ejbLoad() {
170 Debug.print("LeagueBean ejbLoad");
171 }
172
173 public void ejbStore() {
174 Debug.print("LeagueBean ejbStore");
175 }
176
177 public void ejbPassivate() { }
178
179 public void ejbActivate() { }
180
181} // LeagueBean class