Source Code Cross Referenced for AbstractDatabase.java in  » Database-JDBC-Connection-Pool » HA-JDBC » net » sf » hajdbc » sql » 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 JDBC Connection Pool » HA JDBC » net.sf.hajdbc.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HA-JDBC: High-Availability JDBC
003:         * Copyright (c) 2004-2007 Paul Ferraro
004:         * 
005:         * This library is free software; you can redistribute it and/or modify it 
006:         * under the terms of the GNU Lesser General Public License as published by the 
007:         * Free Software Foundation; either version 2.1 of the License, or (at your 
008:         * option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013:         * for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public License
016:         * along with this library; if not, write to the Free Software Foundation, 
017:         * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         * 
019:         * Contact: ferraro@users.sourceforge.net
020:         */
021:        package net.sf.hajdbc.sql;
022:
023:        import java.util.Properties;
024:
025:        import net.sf.hajdbc.Database;
026:
027:        /**
028:         * @author  Paul Ferraro
029:         * @param <D> either java.sql.Driver or javax.sql.DataSource
030:         * @since   1.0
031:         */
032:        public abstract class AbstractDatabase<D> implements  Database<D> {
033:            private String id;
034:            protected String user;
035:            protected String password;
036:            protected Properties properties = new Properties();
037:            private int weight = 1;
038:            private boolean dirty = false;
039:            private boolean local = false;
040:
041:            /**
042:             * @see net.sf.hajdbc.ActiveDatabaseMBean#getId()
043:             */
044:            @Override
045:            public String getId() {
046:                return this .id;
047:            }
048:
049:            /**
050:             * @param id
051:             */
052:            public void setId(String id) {
053:                this .checkDirty(this .id, id);
054:                this .id = id;
055:            }
056:
057:            /**
058:             * @see net.sf.hajdbc.ActiveDatabaseMBean#getUser()
059:             */
060:            @Override
061:            public String getUser() {
062:                return this .user;
063:            }
064:
065:            /**
066:             * @see net.sf.hajdbc.InactiveDatabaseMBean#setUser(java.lang.String)
067:             */
068:            @Override
069:            public void setUser(String user) {
070:                this .checkDirty(this .user, user);
071:                this .user = user;
072:            }
073:
074:            /**
075:             * @see net.sf.hajdbc.ActiveDatabaseMBean#getPassword()
076:             */
077:            @Override
078:            public String getPassword() {
079:                return this .password;
080:            }
081:
082:            /**
083:             * @see net.sf.hajdbc.InactiveDatabaseMBean#setPassword(java.lang.String)
084:             */
085:            @Override
086:            public void setPassword(String password) {
087:                this .checkDirty(this .password, password);
088:                this .password = password;
089:            }
090:
091:            /**
092:             * @see net.sf.hajdbc.ActiveDatabaseMBean#getWeight()
093:             */
094:            @Override
095:            public int getWeight() {
096:                return this .weight;
097:            }
098:
099:            /**
100:             * @see net.sf.hajdbc.InactiveDatabaseMBean#setWeight(int)
101:             */
102:            @Override
103:            public void setWeight(int weight) {
104:                if (weight < 0) {
105:                    throw new IllegalArgumentException();
106:                }
107:
108:                this .checkDirty(this .weight, weight);
109:                this .weight = weight;
110:            }
111:
112:            /**
113:             * @see java.lang.Object#hashCode()
114:             */
115:            @Override
116:            public int hashCode() {
117:                return this .id.hashCode();
118:            }
119:
120:            /**
121:             * @see java.lang.Object#equals(java.lang.Object)
122:             */
123:            @SuppressWarnings("unchecked")
124:            @Override
125:            public boolean equals(Object object) {
126:                if ((object == null) || !(object instanceof  Database))
127:                    return false;
128:
129:                String id = ((Database) object).getId();
130:
131:                return (id != null) && id.equals(this .id);
132:            }
133:
134:            /**
135:             * @see java.lang.Object#toString()
136:             */
137:            @Override
138:            public String toString() {
139:                return this .id;
140:            }
141:
142:            /**
143:             * @see net.sf.hajdbc.ActiveDatabaseMBean#getProperties()
144:             */
145:            @Override
146:            public Properties getProperties() {
147:                return this .properties;
148:            }
149:
150:            /**
151:             * @param properties
152:             */
153:            public void setProperties(Properties properties) {
154:                this .checkDirty(this .properties, properties);
155:                this .properties = properties;
156:            }
157:
158:            /**
159:             * @see net.sf.hajdbc.InactiveDatabaseMBean#removeProperty(java.lang.String)
160:             */
161:            @Override
162:            public void removeProperty(String name) {
163:                this .dirty |= this .properties.containsKey(name);
164:                this .properties.remove(name);
165:            }
166:
167:            /**
168:             * @see net.sf.hajdbc.InactiveDatabaseMBean#setProperty(java.lang.String, java.lang.String)
169:             */
170:            @Override
171:            public void setProperty(String name, String value) {
172:                if ((name == null) || (value == null)) {
173:                    throw new IllegalArgumentException();
174:                }
175:
176:                this .checkDirty(this .properties.getProperty(name), value);
177:                this .properties.setProperty(name, value);
178:            }
179:
180:            /**
181:             * @see net.sf.hajdbc.InactiveDatabaseMBean#setLocal(boolean)
182:             */
183:            @Override
184:            public void setLocal(boolean local) {
185:                this .checkDirty(this .local, local);
186:                this .local = local;
187:            }
188:
189:            /**
190:             * @see net.sf.hajdbc.ActiveDatabaseMBean#isLocal()
191:             */
192:            @Override
193:            public boolean isLocal() {
194:                return this .local;
195:            }
196:
197:            /**
198:             * @see net.sf.hajdbc.Database#clean()
199:             */
200:            @Override
201:            public void clean() {
202:                this .dirty = false;
203:            }
204:
205:            /**
206:             * @see net.sf.hajdbc.Database#isDirty()
207:             */
208:            @Override
209:            public boolean isDirty() {
210:                return this .dirty;
211:            }
212:
213:            /**
214:             * Set the dirty flag if the new value differs from the old value.
215:             * @param oldValue
216:             * @param newValue
217:             */
218:            protected void checkDirty(Object oldValue, Object newValue) {
219:                this .dirty |= ((oldValue != null) && (newValue != null)) ? !oldValue
220:                        .equals(newValue)
221:                        : (oldValue != newValue);
222:            }
223:
224:            /**
225:             * @see java.lang.Comparable#compareTo(Object)
226:             */
227:            @Override
228:            public int compareTo(Database<D> database) {
229:                return this.id.compareTo(database.getId());
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.