Source Code Cross Referenced for PitBossListImpl.java in  » J2EE » Enhydra-Demos » poker » business » 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 » J2EE » Enhydra Demos » poker.business 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package poker.business;
002:
003:        import java.util.Vector;
004:        import java.sql.SQLException;
005:        import poker.data.DODS_GameData.*;
006:        import poker.data.DODS_PitBoss.*;
007:        import poker.data.game.*;
008:        import com.lutris.appserver.server.sql.*;
009:        import com.lutris.appserver.server.Enhydra;
010:        import com.lutris.logging.Logger;
011:        import com.lutris.util.*; //import dods.builder.sourceGenerators.Query.*;
012:        import com.lutris.dods.builder.generator.query.*;
013:        import poker.spec.*;
014:
015:        /**
016:         *
017:         * EnhyDraw!, beta 4, 5/21/99
018:         *
019:         * Copyright 1999, Larry Wolcot & Daryl Tempesta
020:         * ALL rights reserved. Not for commercial use
021:         * without written permission from both authors.
022:         *
023:         * FIX: This thing only runs in "Vector" mode for now.
024:         * I ran outta time to finish  :(
025:         * Hopefully, I can get some time to finish in the next few months.
026:         *
027:         * This is the PitBossList object that does all of the database dirtywork.
028:         * specific to each game module like Poker, BlackJack21 and Slots.
029:         *
030:         */
031:        public class PitBossListImpl extends Vector implements  PitBossList,
032:                java.io.Serializable {
033:            private boolean useDB = false;
034:            private String appName = "Poker";
035:
036:            /**
037:             * Public Constructor
038:             */
039:            public PitBossListImpl() {
040:                super (0);
041:            }
042:
043:            /**
044:             * This method returns a copy of the PitBoss object.
045:             */
046:            protected PitBossList getCopy() {
047:                PitBossListImpl newCopy = new PitBossListImpl();
048:                newCopy = this ;
049:                return newCopy;
050:            }
051:
052:            /**
053:             * Here is where we determine how to store our data.. db or memory.
054:             */
055:            public void setUseDB(boolean useDB) throws Exception {
056:                //FIX
057:                // This is all bunk. PitBoss DODS Object needs
058:                // to be finished.. It's 95% done but I ran out of time
059:                // for now.
060:                try {
061:                    this .useDB = useDB;
062:                    if (!getDoesExist(this .appName)) {
063:                        PitBossVDO newPitBossVDO = new PitBossVDO();
064:                        newPitBossVDO.setGameName(appName);
065:                        addPitBoss(newPitBossVDO);
066:                    }
067:
068:                } catch (Exception e) {
069:                    e.printStackTrace();
070:                    throw e;
071:                }
072:            }
073:
074:            /**
075:             * Send to the Vector() or the DB depending on the useDB flag
076:             * This is where we hook into the DODS_GameData Object
077:             */
078:            public synchronized void addPitBoss(PitBossVDO this PitBoss) {
079:                if (!useDB) {
080:                    super .addElement(this PitBoss);
081:                } else {
082:                    try {
083:                        addPitBossToDB(this PitBoss);
084:                    } catch (Exception e) {
085:                        //There was a problem adding the game!  bummer..
086:                    }
087:                }
088:            }
089:
090:            /**
091:             * This is a private method that maps the PokerGame to
092:             * a GameDataDO Object so it can be inserted into the database.
093:             */
094:            public synchronized void addPitBossToDB(PitBossVDO this PitBossVDO)
095:                    throws Exception {
096:                //remap the PokerGame Object into a GameDataDO built by DODS.
097:                PitBossDO nullDO = null;
098:                PitBossDO newPitBossDO = mapToDO(nullDO, this PitBossVDO);
099:                try {
100:                    DBTransaction db = Enhydra.getDatabaseManager()
101:                            .createTransaction();
102:                    try {
103:                        //Insert the newly mapped object into the DB
104:                        db.insert(newPitBossDO);
105:                        db.commit();
106:                    } catch (SQLException se) {
107:                        //Something went wrong, so roll it back and pass it on!
108:                        db.rollback();
109:                        throw se;
110:                    } finally {
111:                        //This releases all resources allocated in last trans
112:                        db.release();
113:                    }
114:                } catch (Exception e) {
115:                    throw e;
116:                }
117:            }
118:
119:            /**
120:             * This private method takes a PitBossVDO (Vector) object and maps it
121:             * into a DODS PitBossDO object. Ideally, they would be the same
122:             * but this is used to illustrate adding a DODS object to
123:             * a completed application.
124:             */
125:            private synchronized PitBossDO mapToDO(PitBossDO newPitBossDO,
126:                    PitBossVDO newPitBossVDO) {
127:                try {
128:                    newPitBossDO = PitBossDO.createVirgin();
129:                    newPitBossDO.setGameName(newPitBossVDO.getGameName());
130:                    newPitBossDO.setTotalDollars(newPitBossVDO
131:                            .getTotalDollars());
132:                    newPitBossDO.setTotalHandsDealt(newPitBossVDO
133:                            .getTotalHandsDealt());
134:                    newPitBossDO.setTotalHandsWon(newPitBossVDO
135:                            .getTotalHandsWon());
136:                    newPitBossDO.setTotalBankrupt(newPitBossVDO
137:                            .getTotalBankrupt());
138:                } catch (Exception e) {
139:                    //This is a DODS sourceGenetaror exception
140:                }
141:                return newPitBossDO;
142:            }
143:
144:            /**
145:             * This private method takes a GameDataDO object and maps it
146:             * into a PokerGame object. Ideally, they would be the same
147:             * but this is used to illustrate adding a DODS objects to
148:             * a completed application.
149:             */
150:            private synchronized PitBossVDO mapNewPitBossVDO(
151:                    PitBossDO this PitBossDO) {
152:                PitBossVDO newPitBossVDO = new PitBossVDO();
153:
154:                try {
155:                    newPitBossVDO.setGameName(this PitBossDO.getGameName());
156:                    newPitBossVDO.setTotalDollars(this PitBossDO
157:                            .getTotalDollars());
158:                    newPitBossVDO.setTotalBankrupt(this PitBossDO
159:                            .getTotalBankrupt());
160:                    newPitBossVDO.setTotalHandsDealt(this PitBossDO
161:                            .getTotalHandsDealt());
162:                    newPitBossVDO.setTotalHandsWon(this PitBossDO
163:                            .getTotalHandsWon());
164:                } catch (Exception e) {
165:                    //There really shouldn't be an exception
166:                }
167:                return newPitBossVDO;
168:            }
169:
170:            /**
171:             * This is a provate method that returns the GameDataDO
172:             * from the database where oId = id
173:             */
174:            private PitBossDO getPitBossDOByName(String name) throws Exception {
175:                PitBossDO gotPitBossDO = null;
176:                PitBossQuery dq = new PitBossQuery();
177:                dq.setQueryGameName(name);
178:
179:                try {
180:                    gotPitBossDO = (PitBossDO) dq.getNextDO();
181:                } finally {
182:                    // Free up any resources
183:                    //dq.release();
184:                }
185:                return gotPitBossDO;
186:            }
187:
188:            /**
189:             * This method ddtermines which storage medium is ised, then
190:             * doles the getGameByName request to the right place.
191:             */
192:            public PitBossVDO getPitBossVDO(String name) {
193:                PitBossVDO this PitBossVDO = new PitBossVDO();
194:
195:                if (useDB) {
196:                    try {
197:                        PitBossDO this DO = null;
198:                        this DO = getPitBossDOByName(name);
199:                        this PitBossVDO = mapNewPitBossVDO(this DO);
200:
201:                    } catch (Exception e) {
202:                        //FIX: Still need to take care of some exceptions :)
203:                    }
204:                } else {
205:                    this PitBossVDO = getPitBossInMemory(name);
206:                }
207:
208:                return this PitBossVDO;
209:            }
210:
211:            /**
212:             * Return the game that belongs to user name
213:             * from the Vector in memory
214:             */
215:            public synchronized PitBossVDO getPitBossInMemory(String name) {
216:
217:                PitBossVDO this PitBossVDO = new PitBossVDO();
218:
219:                //Get copy of the PitBossList object so we dont have to
220:                //worry about locking it for threadsafe opps
221:                PitBossListImpl PitBossListCopy = (PitBossListImpl) this 
222:                        .getCopy();
223:                //Yeah, I could have done this another way, but I didn't
224:                for (int i = 0; i < PitBossListCopy.size(); i++) {
225:                    this PitBossVDO = (PitBossVDO) PitBossListCopy.elementAt(i);
226:                    if (this PitBossVDO.getGameName().equals(name)) {
227:                        return this PitBossVDO;
228:                    }
229:                }
230:                return this PitBossVDO;
231:            }
232:
233:            /**
234:             * Check to see if the DO changes need to be updated to the DB
235:             */
236:            public synchronized void updatePitBoss(PitBossVDO this VDO) {
237:                if (this .useDB) {
238:                    try {
239:                        PitBossDO pitBossDO = getPitBossDOByName(this VDO
240:                                .getGameName());
241:                        pitBossDO.setGameName(this VDO.getGameName());
242:                        pitBossDO.setTotalDollars(this VDO.getTotalDollars());
243:                        pitBossDO.setTotalBankrupt(this VDO.getTotalBankrupt());
244:                        pitBossDO.setTotalHandsDealt(this VDO
245:                                .getTotalHandsDealt());
246:                        pitBossDO.setTotalHandsWon(this VDO.getTotalHandsWon());
247:
248:                        DBTransaction db = Enhydra.getDatabaseManager()
249:                                .createTransaction();
250:                        try {
251:                            db.update(pitBossDO);
252:                            db.commit();
253:                        } catch (SQLException sqle) {
254:                            db.rollback();
255:                            throw sqle;
256:                        } finally {
257:                            db.release();
258:                        }
259:                    } catch (Exception e) {
260:                        Enhydra.getLogChannel().write(Logger.DEBUG,
261:                                "ERROR! " + e.toString());
262:                        //FIX: Still need to take care of some exceptions :)
263:                    }
264:                }
265:            }
266:
267:            /**
268:             * This method ddtermines which storage medium is ised, then
269:             * doles the exists request to the right place.
270:             */
271:            public boolean getDoesExist(String name) {
272:                boolean exists = false;
273:                PitBossVDO this VDO = getPitBossVDO(name);
274:
275:                if ((this VDO != null) && (!this VDO.getGameName().equals(""))) {
276:                    exists = true;
277:                }
278:
279:                return exists;
280:            }
281:
282:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.