001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.dataconnectivity.sql;
042:
043: import java.sql.SQLException;
044:
045: /**
046: * used to present datasources available for import
047: * can be annotated and tested
048: *
049: * @author John Kline
050: */
051: public class DataSourceImport {
052:
053: private boolean importable;
054: private String name;
055: private String driverClassName;
056: private String url;
057: private String username;
058: private String password;
059: private String validationQuery;
060: private SQLException testSQLException;
061: private String alias;
062:
063: public DataSourceImport(String name, String driverClassName,
064: String url, String username, String password,
065: String validationQuery) {
066:
067: importable = true;
068: this .name = name;
069: this .driverClassName = driverClassName;
070: this .url = url;
071: this .username = username;
072: this .password = password;
073: this .validationQuery = validationQuery;
074: testSQLException = null;
075: this .alias = null;
076: }
077:
078: public DataSourceImport(String name, String alias) {
079: importable = true;
080: this .name = name;
081: this .alias = alias;
082: }
083:
084: public boolean test() {
085: testSQLException = null;
086:
087: DesignTimeDataSource ds = new DesignTimeDataSource(null, false,
088: getDriverClassName(), getUrl(), getValidationQuery(),
089: getUsername(), getPassword());
090: boolean rc = ds.test();
091: testSQLException = ds.getTestException();
092: return rc;
093: }
094:
095: public SQLException getTestException() {
096: return testSQLException;
097: }
098:
099: public boolean isImportable() {
100: return importable;
101: }
102:
103: public void setImportable(boolean importable) {
104: this .importable = importable;
105: }
106:
107: public String getName() {
108: return name;
109: }
110:
111: public String getDisplayName() {
112: return getName().replaceFirst("java:comp/env/jdbc/", ""); // NOI18N
113: }
114:
115: public void setName(String name) {
116: this .name = name;
117: }
118:
119: public String getDriverClassName() {
120: return driverClassName;
121: }
122:
123: public void setDriverClassName(String driverClassName) {
124: this .driverClassName = driverClassName;
125: }
126:
127: public String getUrl() {
128: return url;
129: }
130:
131: public void setUrl(String url) {
132: this .url = url;
133: }
134:
135: public String getUsername() {
136: return username;
137: }
138:
139: public void setUsername(String username) {
140: this .username = username;
141: }
142:
143: public String getPassword() {
144: return password;
145: }
146:
147: public void setPassword(String password) {
148: this .password = password;
149: }
150:
151: public String getValidationQuery() {
152: return validationQuery;
153: }
154:
155: public void setValidationQuery(String validationQuery) {
156: this .validationQuery = validationQuery;
157: }
158:
159: // We only store the ValidationQuery as "select * from <table>"
160: // Extract the <table> here.
161: public String getValidationTable() {
162: // see if it start's with SELECT_PHRASE, otherwise try a hack
163: String validationTable = DesignTimeDataSource
164: .parseForValidationTable(getValidationQuery());
165: return (validationTable == null ? "" : validationTable); // NOI18N
166: }
167:
168: public void setValidationTable(String table) {
169: // setValidationQuery( DesignTimeDataSource.composeValidationQuery(table) ) ;
170: }
171:
172: public void setAlias(String alias) {
173: this .alias = alias;
174: }
175:
176: public String getAlias() {
177: return this .alias;
178: }
179:
180: public boolean isAlias() {
181: return (this.alias != null);
182: }
183: }
|