Source Code Cross Referenced for SqlRunner.java in  » Chat » freecs » freecs » auth » sqlConnectionPool » 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 » Chat » freecs » freecs.auth.sqlConnectionPool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2005 KMFDM
003:         * Created: 16.01.2005 (22:40:14)
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License
007:         * as published by the Free Software Foundation; either version 2
008:         * of the License, or (at your option) any later version.
009:         * 
010:         * This program is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * along with this program; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018:         */package freecs.auth.sqlConnectionPool;
019:
020:        import freecs.Server;
021:        import freecs.core.CanceledRequestException;
022:        import freecs.core.ConnectionBuffer;
023:        import freecs.core.User;
024:        import freecs.interfaces.IRequest;
025:        import freecs.util.HashUtils;
026:
027:        /**
028:         * @author KMFDM
029:         *
030:         */
031:        public class SqlRunner implements  Runnable {
032:            private final String username, password, cookie;
033:            private final IRequest request;
034:            private final User u;
035:            private final short method;
036:            private final ConnectionPool connPool;
037:            public Exception catchedException = null;
038:            public User result = null;
039:
040:            public SqlRunner(String username, String password, String cookie,
041:                    IRequest request, ConnectionPool connPool) {
042:                // handle login
043:                this .u = null;
044:                this .username = username;
045:                this .password = password;
046:                this .cookie = cookie;
047:                this .request = request;
048:                this .connPool = connPool;
049:                this .method = 1;
050:            }
051:
052:            public SqlRunner(User u, String username, String password,
053:                    IRequest request, ConnectionPool connPool) {
054:                this .u = u;
055:                this .cookie = null;
056:                this .username = username;
057:                this .password = password;
058:                this .request = request;
059:                this .connPool = connPool;
060:                this .method = 2;
061:            }
062:
063:            public SqlRunner(User u, ConnectionPool connPool) {
064:                this .username = null;
065:                this .password = null;
066:                this .request = null;
067:                this .cookie = null;
068:                this .u = u;
069:                this .connPool = connPool;
070:                this .method = 3;
071:            }
072:
073:            public void run() {
074:                try {
075:                    switch (method) {
076:                    case 1:
077:                        this .result = loginUser(username, password, cookie,
078:                                request);
079:                        break;
080:                    case 2:
081:                        this .result = loginUser(u, username, password, request);
082:                        break;
083:                    case 3:
084:                        logoutUser(u);
085:                    }
086:                } catch (Exception e) {
087:                    catchedException = e;
088:                }
089:            }
090:
091:            public void logoutUser(User u) throws Exception {
092:                PoolElement el = null;
093:                boolean success = false;
094:                Exception le = null;
095:                for (int i = 0; i < connPool.size() + 1; i++) {
096:                    try {
097:                        el = connPool.getPoolElement(3, null);
098:                        el.logoutUser(u);
099:                        el.release();
100:                        success = true;
101:                        break;
102:                    } catch (Exception ee) {
103:                        if (el != null) {
104:                            el.cleanup();
105:                        }
106:                        Server.debug(this , "SQL-Exception", ee,
107:                                Server.MSG_ERROR, Server.LVL_MAJOR);
108:                        catchedException = ee;
109:                    }
110:                }
111:            }
112:
113:            public User loginUser(String username, String password,
114:                    String cookie, IRequest request) throws Exception {
115:                if (Server.srv.MD5_PASSWORDS)
116:                    password = HashUtils.encodeMD5(password);
117:                PoolElement el = null;
118:                User u = null;
119:                boolean success = false;
120:                Exception le = null;
121:                ConnectionBuffer cb = request.getConnectionBuffer();
122:                Thread curr = Thread.currentThread();
123:                for (int i = 0; i < connPool.size() + 1; i++) {
124:                    if (curr.isInterrupted() || !cb.isValid())
125:                        throw new CanceledRequestException(
126:                                "ConnectionBuffer has been invalidated");
127:                    try {
128:                        // retrieve PoolElement from ConnectionPool trying 3-times
129:                        el = connPool.getPoolElement(3, cb);
130:                        u = el.loginUser(username, password, cookie);
131:                        el.release();
132:                        success = true;
133:                        break;
134:                    } catch (Exception ee) {
135:                        // cleanup on exception
136:                        if (el != null) {
137:                            el.cleanup();
138:                        }
139:                        Server.debug(this , "Exception during loginUser", ee,
140:                                Server.MSG_ERROR, Server.LVL_MAJOR);
141:                        le = ee;
142:                    }
143:                }
144:                if (!success) {
145:                    if (le != null)
146:                        throw le;
147:                    throw new Exception("UnknownException occured");
148:                }
149:                return u;
150:            }
151:
152:            public User loginUser(User u, String username, String password,
153:                    IRequest request) throws Exception {
154:                PoolElement el = null;
155:                boolean success = false;
156:                Exception le = null;
157:                ConnectionBuffer cb = request.getConnectionBuffer();
158:                Thread curr = Thread.currentThread();
159:                for (int i = 0; i < connPool.size() + 1; i++) {
160:                    if (curr.isInterrupted())
161:                        throw new CanceledRequestException(
162:                                "ConnectionBuffer has been invalidated");
163:                    try {
164:                        // retrieve PoolElement from ConnectionPool trying 3-times
165:                        el = connPool.getPoolElement(3, cb);
166:                        u = el.loginUser(u, password);
167:                        el.release();
168:                        success = true;
169:                        break;
170:                    } catch (Exception ee) {
171:                        // cleanup on exception
172:                        if (el != null) {
173:                            el.cleanup();
174:                        }
175:                        Server.debug(this , "SQL-Exception", ee,
176:                                Server.MSG_ERROR, Server.LVL_MAJOR);
177:                        le = ee;
178:                    }
179:                }
180:                if (!success) {
181:                    if (le != null)
182:                        throw le;
183:                    throw new Exception("UnknownException occured");
184:                }
185:                return u;
186:            }
187:
188:            public String toString() {
189:                return "[SqlRunner]";
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.