Source Code Cross Referenced for BankApplicationImpl.java in  » Database-ORM » Speedo_1.4.5 » bank » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Speedo_1.4.5 » bank 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package bank;
002:
003:        import javax.ejb.SessionBean;
004:        import javax.ejb.SessionContext;
005:        import javax.ejb.EJBException;
006:        import javax.jdo.PersistenceManagerFactory;
007:        import javax.jdo.PersistenceManager;
008:        import javax.jdo.Query;
009:        import javax.naming.InitialContext;
010:        import javax.naming.NamingException;
011:        import java.rmi.RemoteException;
012:        import java.util.List;
013:        import java.util.Collection;
014:        import java.util.Iterator;
015:        import java.util.ArrayList;
016:
017:        /**
018:         * @author S.Chassande-Barrioz
019:         */
020:        public class BankApplicationImpl implements  SessionBean {
021:
022:            protected SessionContext sessionContext = null;
023:
024:            public static PersistenceManagerFactory pmf = null;
025:
026:            private static Bank bank = null;
027:
028:            private static final String SOCIETE_GENERALE = "SG";
029:
030:            private static final String PMF_CTX_NAME = "java:comp/env/jdo/pmf";
031:
032:            public static Bank getBank(PersistenceManager pm) {
033:                if (bank != null) {
034:                    return bank;
035:                }
036:                synchronized (BankApplicationImpl.class) {
037:                    if (bank != null) {
038:                        return bank;
039:                    }
040:                    Query q = pm.newQuery(Bank.class);
041:                    q.declareParameters("String bn");
042:                    q.setFilter("(name==bn)");
043:                    Collection c = (Collection) q.execute(SOCIETE_GENERALE);
044:                    if (c.isEmpty()) {
045:                        //First execution: create the bank
046:                        bank = new Bank(SOCIETE_GENERALE);
047:                        pm.makePersistent(bank);
048:                    } else {
049:                        //Load from the persistence support
050:                        bank = (Bank) c.iterator().next();
051:                    }
052:                    q.closeAll();
053:                }
054:                return bank;
055:            }
056:
057:            // IMPLEMENTATION OF THE BankApplication INTERFACE //
058:            //-------------------------------------------------//
059:
060:            public void createAgency(String name) throws RemoteException {
061:                PersistenceManager pm = pmf.getPersistenceManager();
062:                getBank(pm).createAgency(name);
063:                pm.close();
064:            }
065:
066:            public List getAgencies() throws RemoteException {
067:                PersistenceManager pm = pmf.getPersistenceManager();
068:                Iterator it = getBank(pm).agencies.iterator();
069:                ArrayList res = new ArrayList(bank.agencies.size());
070:                while (it.hasNext()) {
071:                    res.add(((Agency) it.next()).name);
072:                }
073:                pm.close();
074:                return res;
075:            }
076:
077:            public boolean removeAgency(String name) throws RemoteException {
078:                PersistenceManager pm = pmf.getPersistenceManager();
079:                Iterator it = getBank(pm).agencies.iterator();
080:                while (it.hasNext()) {
081:                    Agency a = (Agency) it.next();
082:                    if (a.name.equals(name) && a.clients.isEmpty()) {
083:                        bank.agencies.remove(a);
084:                        pm.deletePersistent(a);
085:                        pm.close();
086:                        return true;
087:                    }
088:                }
089:                pm.close();
090:                return false;
091:            }
092:
093:            public void createClient(ClientId cid, String agencyName)
094:                    throws RemoteException {
095:                PersistenceManager pm = pmf.getPersistenceManager();
096:                Agency a = getBank(pm).getAgency(agencyName);
097:                if (a == null) {
098:                    pm.close();
099:                    throw new RemoteException("No agency '" + agencyName
100:                            + "' found.");
101:                }
102:                a.createClient(cid.firstName, cid.lastName, cid.address);
103:                pm.close();
104:            }
105:
106:            public List getClients(String agencyName) throws RemoteException {
107:                PersistenceManager pm = pmf.getPersistenceManager();
108:                Agency a = getBank(pm).getAgency(agencyName);
109:                if (a == null) {
110:                    pm.close();
111:                    throw new RemoteException("No agency '" + agencyName
112:                            + "' found.");
113:                }
114:                Iterator it = a.clients.iterator();
115:                ArrayList res = new ArrayList(a.clients.size());
116:                while (it.hasNext()) {
117:                    res.add(new ClientId((Client) it.next()));
118:                }
119:                pm.close();
120:                return res;
121:            }
122:
123:            public boolean removeClient(String agencyName, ClientId cid)
124:                    throws RemoteException {
125:                PersistenceManager pm = pmf.getPersistenceManager();
126:                Agency a = getBank(pm).getAgency(agencyName);
127:                if (a == null) {
128:                    pm.close();
129:                    throw new RemoteException("No agency '" + agencyName
130:                            + "' found.");
131:                }
132:                Client c = a
133:                        .getClient(cid.firstName, cid.lastName, cid.address);
134:                boolean remove = c != null && c.accounts.isEmpty();
135:                if (remove) {
136:                    a.removeClient(c);
137:                    pm.deletePersistent(c);
138:                }
139:                pm.close();
140:                return remove;
141:            }
142:
143:            public String createAccount(ClientId cid, String agencyName)
144:                    throws RemoteException {
145:                PersistenceManager pm = pmf.getPersistenceManager();
146:                Agency a = getBank(pm).getAgency(agencyName);
147:                if (a == null) {
148:                    pm.close();
149:                    throw new RemoteException("No agency '" + agencyName
150:                            + "' found.");
151:                }
152:                Client c = a
153:                        .getClient(cid.firstName, cid.lastName, cid.address);
154:                if (c == null) {
155:                    pm.close();
156:                    throw new RemoteException("No client '" + cid + "' found.");
157:                }
158:                String number = c.createAccount(a.getNextAccountNumber()).number;
159:                pm.close();
160:                return number;
161:            }
162:
163:            public AccountInfo getAccountInfo(String number, ClientId cid,
164:                    String agencyName) throws RemoteException {
165:                PersistenceManager pm = pmf.getPersistenceManager();
166:                Agency a = getBank(pm).getAgency(agencyName);
167:                if (a == null) {
168:                    pm.close();
169:                    throw new RemoteException("No agency '" + agencyName
170:                            + "' found.");
171:                }
172:                Client c = a
173:                        .getClient(cid.firstName, cid.lastName, cid.address);
174:                if (c == null) {
175:                    pm.close();
176:                    throw new RemoteException("No client '" + cid + "' found.");
177:                }
178:                Iterator it = c.accounts.iterator();
179:                while (it.hasNext()) {
180:                    Account ac = (Account) it.next();
181:                    if (ac.number.equals(number)) {
182:                        return new AccountInfo(ac.number, ac.solde);
183:                    }
184:                }
185:                pm.close();
186:                return null;
187:            }
188:
189:            public List getAccounts(String agencyName, ClientId cid)
190:                    throws RemoteException {
191:                PersistenceManager pm = pmf.getPersistenceManager();
192:                Agency a = getBank(pm).getAgency(agencyName);
193:                if (a == null) {
194:                    pm.close();
195:                    throw new RemoteException("No agency '" + agencyName
196:                            + "' found.");
197:                }
198:                Client c = a
199:                        .getClient(cid.firstName, cid.lastName, cid.address);
200:                if (c == null) {
201:                    pm.close();
202:                    throw new RemoteException("No client '" + cid + "' found.");
203:                }
204:                Iterator it = c.accounts.iterator();
205:                ArrayList res = new ArrayList(c.accounts.size());
206:                while (it.hasNext()) {
207:                    Account ac = (Account) it.next();
208:                    res.add(new AccountInfo(ac.number, ac.solde));
209:                }
210:                pm.close();
211:                return res;
212:            }
213:
214:            public AccountInfo closeAccount(String agencyName, ClientId cid,
215:                    String accountNumber) throws RemoteException {
216:                PersistenceManager pm = pmf.getPersistenceManager();
217:                Agency a = getBank(pm).getAgency(agencyName);
218:                if (a == null) {
219:                    pm.close();
220:                    throw new RemoteException("No agency '" + agencyName
221:                            + "' found.");
222:                }
223:                Client c = a
224:                        .getClient(cid.firstName, cid.lastName, cid.address);
225:                if (c == null) {
226:                    pm.close();
227:                    throw new RemoteException("No client '" + cid + "' found.");
228:                }
229:                Iterator it = c.accounts.iterator();
230:                while (it.hasNext()) {
231:                    Account ac = (Account) it.next();
232:                    if (ac.number.equals(accountNumber)) {
233:                        c.removeAccount(ac);
234:                        pm.deletePersistent(ac);
235:                        AccountInfo ai = new AccountInfo(ac.number, ac.solde);
236:                        pm.close();
237:                        return ai;
238:                    }
239:                }
240:                pm.close();
241:                return null;
242:            }
243:
244:            // IMPLEMENTATION OF THE SessionBean INTERFACE //
245:            //---------------------------------------------//
246:
247:            public void setSessionContext(SessionContext sessionContext)
248:                    throws EJBException, RemoteException {
249:                if (pmf == null) {
250:                    synchronized (BankApplicationImpl.class) {
251:                        if (pmf == null) {
252:                            try {
253:                                pmf = (PersistenceManagerFactory) new InitialContext()
254:                                        .lookup(PMF_CTX_NAME);
255:                            } catch (NamingException e) {
256:                                throw new EJBException(
257:                                        "No PersistenceMangerFactory registered"
258:                                                + " in JNDI with the name '"
259:                                                + PMF_CTX_NAME + "'");
260:                            }
261:                        }
262:                    }
263:                }
264:            }
265:
266:            public void ejbCreate() throws RemoteException {
267:            }
268:
269:            public void ejbRemove() throws EJBException, RemoteException {
270:            }
271:
272:            public void ejbActivate() throws EJBException, RemoteException {
273:            }
274:
275:            public void ejbPassivate() throws EJBException, RemoteException {
276:            }
277:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.