001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.sql.rowset;
019:
020: import java.sql.SQLException;
021: import java.sql.Types;
022: import org.apache.harmony.sql.internal.nls.Messages;
023:
024: class SqlUtil {
025: /*
026: * FIXME:Validate column types is defined by java.sql.Types, current
027: * implementation is ugly, need to find an elegant and effient way to check
028: * all constants defined in java.util.sql.Types
029: */
030: static void validateType(int type) throws SQLException {
031: switch (type) {
032: case Types.ARRAY:
033: case Types.BIGINT:
034: case Types.BINARY:
035: case Types.BIT:
036: case Types.BLOB:
037: case Types.BOOLEAN:
038: case Types.CHAR:
039: case Types.CLOB:
040: case Types.DATALINK:
041: case Types.DATE:
042: case Types.DECIMAL:
043: case Types.DISTINCT:
044: case Types.DOUBLE:
045: case Types.FLOAT:
046: case Types.INTEGER:
047: case Types.JAVA_OBJECT:
048: case Types.LONGVARBINARY:
049: case Types.LONGVARCHAR:
050: case Types.NULL:
051: case Types.NUMERIC:
052: case Types.OTHER:
053: case Types.REAL:
054: case Types.REF:
055: case Types.SMALLINT:
056: case Types.STRUCT:
057: case Types.TIME:
058: case Types.TIMESTAMP:
059: case Types.TINYINT:
060: case Types.VARBINARY:
061: case Types.VARCHAR:
062: return;
063: }
064: throw new SQLException(Messages.getString("sql.28")); //$NON-NLS-1$
065: }
066:
067: static String getClassNameByType(int type) {
068: String className = null;
069: switch (type) {
070: case Types.BINARY:
071: case Types.BLOB:
072: case Types.LONGVARBINARY:
073: case Types.VARBINARY:
074: className = new byte[0].getClass().getName();
075: break;
076: case Types.DOUBLE:
077: case Types.FLOAT:
078: className = Double.class.getName();
079: break;
080: case Types.BIGINT:
081: className = Long.class.getName();
082: break;
083: case Types.BIT:
084: className = Boolean.class.getName();
085: break;
086: case Types.DECIMAL:
087: case Types.NUMERIC:
088: className = java.math.BigDecimal.class.getName();
089: break;
090: case Types.CLOB:
091: className = new char[0].getClass().getName();
092: break;
093: case Types.DATE:
094: className = java.sql.Date.class.getName();
095: break;
096: case Types.INTEGER:
097: className = Integer.class.getName();
098: break;
099: case Types.REAL:
100: className = Float.class.getName();
101: break;
102: case Types.SMALLINT:
103: className = Short.class.getName();
104: break;
105: case Types.TIME:
106: className = java.sql.Time.class.getName();
107: break;
108: case Types.TIMESTAMP:
109: className = java.sql.Timestamp.class.getName();
110: break;
111: case Types.TINYINT:
112: className = Byte.class.getName();
113: break;
114: default:
115: className = String.class.getName();
116: }
117: return className;
118: }
119: }
|