001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.util;
032:
033: import java.sql.ResultSet;
034: import java.sql.ResultSetMetaData;
035: import java.sql.SQLException;
036: import java.util.Hashtable;
037:
038: /**
039: * Base class for conversion from a different databases
040: *
041: * @author sqlbob@users
042: * @version 1.7.0
043: */
044: class TransferHelper {
045:
046: protected TransferDb db;
047: protected Traceable tracer;
048: protected String sSchema;
049: protected JDBCTypes JDBCT;
050: private String quote;
051:
052: TransferHelper() {
053:
054: db = null;
055: tracer = null;
056: quote = "\'";
057: JDBCT = new JDBCTypes();
058: }
059:
060: TransferHelper(TransferDb database, Traceable t, String q) {
061:
062: db = database;
063: tracer = t;
064: quote = q;
065: JDBCT = new JDBCTypes();
066: }
067:
068: void set(TransferDb database, Traceable t, String q) {
069:
070: db = database;
071: tracer = t;
072: quote = q;
073: }
074:
075: String formatIdentifier(String id) {
076:
077: if (id == null) {
078: return id;
079: }
080:
081: if (id.equals("")) {
082: return id;
083: }
084:
085: if (!Character.isLetter(id.charAt(0))
086: || (id.indexOf(' ') != -1)) {
087: return (quote + id + quote);
088: }
089:
090: return id;
091: }
092:
093: void setSchema(String _Schema) {
094: sSchema = _Schema;
095: }
096:
097: String formatName(String t) {
098:
099: String Name = "";
100:
101: if ((sSchema != null) && (sSchema.length() > 0)) {
102: Name = sSchema + ".";
103: }
104:
105: Name += formatIdentifier(t);
106:
107: return Name;
108: }
109:
110: int convertFromType(int type) {
111: return (type);
112: }
113:
114: int convertToType(int type) {
115: return (type);
116: }
117:
118: Hashtable getSupportedTypes() {
119:
120: Hashtable hTypes = new Hashtable();
121:
122: if (db != null) {
123: try {
124: ResultSet result = db.meta.getTypeInfo();
125:
126: while (result.next()) {
127: Integer intobj = new Integer(result.getShort(2));
128:
129: if (hTypes.get(intobj) == null) {
130: try {
131: hTypes.put(intobj, JDBCT.toString(result
132: .getShort(2)));
133: } catch (Exception e) {
134: }
135: }
136: }
137:
138: result.close();
139: } catch (SQLException e) {
140: }
141: }
142:
143: if (hTypes.isEmpty()) {
144: hTypes = JDBCT.getHashtable();
145: }
146:
147: return hTypes;
148: }
149:
150: String fixupColumnDefRead(TransferTable t, ResultSetMetaData meta,
151: String columnType, ResultSet columnDesc, int columnIndex)
152: throws SQLException {
153: return (columnType);
154: }
155:
156: String fixupColumnDefWrite(TransferTable t, ResultSetMetaData meta,
157: String columnType, ResultSet columnDesc, int columnIndex)
158: throws SQLException {
159: return (columnType);
160: }
161:
162: boolean needTransferTransaction() {
163: return (false);
164: }
165:
166: Object convertColumnValue(Object value, int column, int type) {
167: return (value);
168: }
169:
170: void beginDataTransfer() {
171: }
172:
173: void endDataTransfer() {
174: }
175:
176: String fixupColumnDefRead(String aTableName,
177: ResultSetMetaData meta, String columnType,
178: ResultSet columnDesc, int columnIndex) throws SQLException {
179: return columnType;
180: }
181:
182: String fixupColumnDefWrite(String aTableName,
183: ResultSetMetaData meta, String columnType,
184: ResultSet columnDesc, int columnIndex) throws SQLException {
185: return columnType;
186: }
187: }
|