1 /*
2 * PROJECT : DAR Runtime and Tools
3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE
5 * Version 2.1, February 1999
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 package org.enableit.db.beans;
22
23 import org.apache.log4j.Logger;
24
25
26 /***
27 * Convenience methods extending generated class.
28 */
29 public class ProviderExt extends Provider {
30 /***
31 * The system specific end of line character
32 */
33 private static String EOL = System.getProperty("line.separator");
34
35 /***
36 * The Log4J <code>Logger</code> doing the logging.
37 */
38 private static Logger logger = Logger.getLogger(ProviderExt.class);
39
40 /***
41 * CVS info ABOUT this class and its current version
42 */
43 public static final String ABOUT = "$Revision: 1.8 $";
44
45 /*
46 * Constructors
47 */
48
49 /***
50 * Default Constructor
51 */
52 public ProviderExt() {
53 super();
54 }
55
56 /*
57 * Methods
58 */
59
60 /***
61 *
62 */
63 public void setConnectionProperties(String driver, String url,
64 String userid, String password) {
65 logger.info("METHOD_ENTRY: setConnectionProperties");
66
67 Driver d = new Driver();
68
69 d.setClassName(driver);
70 setDriver(d);
71 setUrl(url);
72 setUsername(userid);
73 setPassword(password);
74
75 logger.info("METHOD_EXIT: setConnectionProperties");
76 }
77
78 /***
79 *
80 */
81 public void setConnectionProperties(String driver, String url,
82 String userid, String password, String schemaName) {
83 setConnectionProperties(driver, url, userid, password);
84 setSchemaName(schemaName);
85 }
86
87 /***
88 * Returns string representation of the provider.
89 *
90 * @param provider May be null.
91 */
92 public static String toString(Provider provider) {
93 StringBuffer sb = new StringBuffer("Database provider details:");
94
95 if (provider == null) {
96 sb.append("null");
97 } else {
98 sb.append(EOL);
99
100 if (provider.getJdbc2DatasourceName() == null) {
101 try {
102 Driver driver = provider.getDriver();
103
104 sb.append("Driver class name: " + driver.getClassName()
105 + EOL);
106 sb.append("Driver name: " + driver.getName() + EOL);
107
108 //sb.append("Driver product name: " + driver.getProductName() + EOL) ;
109 sb.append("Driver version: " + driver.getVersion() + EOL);
110 } catch (NullPointerException e) {
111 logger.debug("Driver is null");
112 sb.append("Driver: null" + EOL);
113 }
114
115 sb.append("Url: " + provider.getUrl() + EOL);
116 sb.append("Username: " + provider.getUsername() + EOL);
117
118 //sb.append("Username: " + provider.getDriver().getUsername() + EOL) ;
119 sb.append("Password: " + provider.getPassword() + EOL);
120 } else {
121 sb.append("Driver jdbc datasource name: "
122 + provider.getJdbc2DatasourceName() + EOL);
123 }
124
125 sb.append("SchemaName: " + provider.getSchemaName() + EOL);
126 }
127
128 return sb.toString();
129 }
130
131 /***
132 * Return whether the 2 providers represent the same object.
133 */
134 public static boolean equals(Provider a, Provider b) {
135 logger.info("METHOD_ENTRY: equals");
136
137 boolean retVal = false;
138
139 if (a instanceof Provider && b instanceof Provider) {
140 if ((a == null) && (b == null)) {
141 retVal = true;
142 } else if ((a != null) && (b != null)) {
143 // TODO compare Drivers
144 // Compare Urls
145 if ((a.getUrl() == null) && (b.getUrl() == null)) {
146 } else if ((a.getUrl() != null) && (b.getUrl() != null)
147 && a.getUrl().equals(b.getUrl())) {
148 retVal = true;
149 } else {
150 retVal = false;
151 }
152
153 // Compare usernames
154 if (retVal && (a.getUsername() == null)
155 && (b.getUsername() == null)) {
156 retVal = true;
157 } else if (retVal && (a.getUsername() != null)
158 && (b.getUsername() != null)
159 && a.getUsername().equals(a.getUsername())) {
160 retVal = true;
161 } else {
162 retVal = false;
163 }
164
165 // Compare passwords
166 if (retVal && (a.getPassword() == null)
167 && (b.getPassword() == null)) {
168 retVal = true;
169 } else if (retVal && (a.getPassword() != null)
170 && (b.getPassword() != null)
171 && a.getPassword().equals(a.getPassword())) {
172 retVal = true;
173 } else {
174 retVal = false;
175 }
176 } else {
177 retVal = false;
178 }
179 }
180
181 logger.info("METHOD_EXIT: equals");
182
183 return retVal;
184 }
185 }
This page was automatically generated by Maven