001: package org.jsqltool.conn;
002:
003: import java.util.*;
004:
005: /**
006: * <p>Title: JSqlTool Project</p>
007: * <p>Description: database connection descriptor:
008: * contains connection properties, old queries and tables filters.
009: * This window allows to create/edit/delete connections.
010: * </p>
011: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
012: *
013: * <p> This file is part of JSqlTool project.
014: * This library is free software; you can redistribute it and/or
015: * modify it under the terms of the (LGPL) Lesser General Public
016: * License as published by the Free Software Foundation;
017: *
018: * GNU LESSER GENERAL PUBLIC LICENSE
019: * Version 2.1, February 1999
020: *
021: * This library is distributed in the hope that it will be useful,
022: * but WITHOUT ANY WARRANTY; without even the implied warranty of
023: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
024: * Library General Public License for more details.
025: *
026: * You should have received a copy of the GNU Library General Public
027: * License along with this library; if not, write to the Free
028: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
029: *
030: * The author may be contacted at:
031: * maurocarniel@tin.it</p>
032: *
033: * @author Mauro Carniel
034: * @version 1.0
035: */
036: public class DbConnection {
037:
038: public static final int ORACLE_TYPE = 0;
039: public static final int SQLSERVER_TYPE = 1;
040: public static final int ODBC_TYPE = 2;
041: public static final int OTHER_TYPE = 3;
042:
043: public String getClassName(int dbType) {
044: if (dbType == ORACLE_TYPE)
045: return "oracle.jdbc.driver.OracleDriver";
046: else if (dbType == SQLSERVER_TYPE)
047: return "com.microsoft.jdbc.sqlserver.SQLServerDriver";
048: else if (dbType == ODBC_TYPE)
049: return "sun.jdbc.odbc.JdbcOdbcDriver";
050: else
051: // OTHER_TYPE
052: return "";
053: }
054:
055: public String getUrl(int dbType, String host, String port,
056: String sid) {
057: if (dbType == ORACLE_TYPE)
058: return "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid;
059: else if (dbType == SQLSERVER_TYPE)
060: return "jdbc:microsoft:sqlserver://" + host + ":" + port
061: + ";DatabaseName=" + sid + ";SelectMethod=cursor";
062: else if (dbType == ODBC_TYPE)
063: return "jdbc:odbc:" + sid;
064: else
065: // OTHER_TYPE
066: return "";
067: }
068:
069: public String getHost() {
070: if (dbType == ORACLE_TYPE)
071: return url.substring(18, url.indexOf(":", 18));
072: else if (dbType == SQLSERVER_TYPE)
073: return url.substring(27, url.indexOf(":", 27));
074: else if (dbType == ODBC_TYPE)
075: return "";
076: else
077: // OTHER_TYPE
078: return "";
079: }
080:
081: public String getPort() {
082: if (dbType == ORACLE_TYPE) {
083: int index = url.indexOf(":", 18);
084: return url
085: .substring(index + 1, url.indexOf(":", index + 1));
086: } else if (dbType == SQLSERVER_TYPE) {
087: int index = url.indexOf(":", 27);
088: return url
089: .substring(index + 1, url.indexOf(";", index + 1));
090: } else if (dbType == ODBC_TYPE)
091: return "";
092: else
093: // OTHER_TYPE
094: return "";
095: }
096:
097: public String getSID() {
098: if (dbType == ORACLE_TYPE) {
099: int index = url.indexOf(":", 18);
100: index = url.indexOf(":", index + 1);
101: return url.substring(index + 1);
102: } else if (dbType == SQLSERVER_TYPE) {
103: int index = url.indexOf("=");
104: return url
105: .substring(index + 1, url.indexOf(";", index + 1));
106: } else if (dbType == ODBC_TYPE) {
107: return url.substring(url.lastIndexOf(":") + 1);
108: } else
109: // OTHER_TYPE
110: return "";
111: }
112:
113: private int dbType;
114: private String name;
115: private String className;
116: private String url;
117: private String username;
118: private String password;
119: private boolean autoCommit;
120: private int isolationLevel;
121: private boolean readOnly;
122: private String catalog;
123: private boolean quotes;
124:
125: /** collection of filters/orderers, one for each table */
126: private Hashtable filters = new Hashtable();
127:
128: /** old queriesm, stored in the connection profile file */
129: private ArrayList oldQueries = new ArrayList();
130:
131: public DbConnection(int dbType, String name, String className,
132: String url, String username, String password,
133: boolean autoCommit, int isolationLevel, boolean readOnly,
134: String catalog, Hashtable filters, ArrayList oldQueries,
135: boolean quotes) {
136: this .dbType = dbType;
137: this .name = name;
138: this .className = className;
139: this .url = url;
140: this .username = username;
141: this .password = password;
142: this .autoCommit = autoCommit;
143: this .isolationLevel = isolationLevel;
144: this .readOnly = readOnly;
145: this .catalog = catalog;
146: this .filters = filters;
147: this .oldQueries = oldQueries;
148: this .quotes = quotes;
149: }
150:
151: public String getClassName() {
152: return className;
153: }
154:
155: public String getName() {
156: return name;
157: }
158:
159: public String getUrl() {
160: return url;
161: }
162:
163: public String getUsername() {
164: return username;
165: }
166:
167: public String getPassword() {
168: return password;
169: }
170:
171: public int getIsolationLevel() {
172: return isolationLevel;
173: }
174:
175: public boolean isAutoCommit() {
176: return autoCommit;
177: }
178:
179: public int getDbType() {
180: return dbType;
181: }
182:
183: public void setAutoCommit(boolean autoCommit) {
184: this .autoCommit = autoCommit;
185: }
186:
187: public void setClassName(String className) {
188: this .className = className;
189: }
190:
191: public void setDbType(int dbType) {
192: this .dbType = dbType;
193: }
194:
195: public void setIsolationLevel(int isolationLevel) {
196: this .isolationLevel = isolationLevel;
197: }
198:
199: public void setName(String name) {
200: this .name = name;
201: }
202:
203: public void setPassword(String password) {
204: this .password = password;
205: }
206:
207: public void setUrl(String url) {
208: this .url = url;
209: }
210:
211: public void setUsername(String username) {
212: this .username = username;
213: }
214:
215: public boolean isReadOnly() {
216: return readOnly;
217: }
218:
219: public void setReadOnly(boolean readOnly) {
220: this .readOnly = readOnly;
221: }
222:
223: public String getCatalog() {
224: return catalog;
225: }
226:
227: public void setCatalog(String catalog) {
228: this .catalog = catalog;
229: }
230:
231: public Hashtable getFilters() {
232: return filters;
233: }
234:
235: public ArrayList getOldQueries() {
236: return oldQueries;
237: }
238:
239: public void setOldQueries(ArrayList oldQueries) {
240: this .oldQueries = oldQueries;
241: }
242:
243: public void setFilters(Hashtable filters) {
244: this .filters = filters;
245: }
246:
247: public boolean isQuotes() {
248: return quotes;
249: }
250:
251: public void setQuotes(boolean quotes) {
252: this.quotes = quotes;
253: }
254:
255: }
|