1 21 22 package org.apache.derby.impl.drda; 23 24 import java.sql.Types ; 25 import java.sql.SQLException ; 26 import org.apache.derby.iapi.reference.DRDAConstants; 27 import org.apache.derby.iapi.reference.JDBC30Translation; 28 29 30 31 class SQLTypes { 32 33 35 private SQLTypes() {} 37 38 39 48 49 static protected int mapDB2SqlTypeToJdbcType (int sqlType, long length, int ccsid) 50 { 51 switch (getNonNullableSqlType (sqlType)) { case DRDAConstants.DB2_SQLTYPE_SMALL: 53 return java.sql.Types.SMALLINT; 54 case DRDAConstants.DB2_SQLTYPE_INTEGER: 55 return java.sql.Types.INTEGER; 56 case DRDAConstants.DB2_SQLTYPE_BIGINT: 57 return java.sql.Types.BIGINT; 58 case DRDAConstants.DB2_SQLTYPE_FLOAT: 59 if (length == 16) return java.sql.Types.DECIMAL; 61 else if (length == 8) return java.sql.Types.DOUBLE; 63 else if (length == 4) 64 return java.sql.Types.REAL; 65 else 66 return 0; 67 case DRDAConstants.DB2_SQLTYPE_DECIMAL: case DRDAConstants.DB2_SQLTYPE_ZONED: case DRDAConstants.DB2_SQLTYPE_NUMERIC: return java.sql.Types.DECIMAL; 72 case DRDAConstants.DB2_SQLTYPE_CHAR: if (ccsid == 0xffff || ccsid == 0) return java.sql.Types.BINARY; 75 else 76 return java.sql.Types.CHAR; 77 case DRDAConstants.DB2_SQLTYPE_CSTR: case DRDAConstants.DB2_SQLTYPE_GRAPHIC: return java.sql.Types.CHAR; 80 case DRDAConstants.DB2_SQLTYPE_VARGRAPH: case DRDAConstants.DB2_SQLTYPE_VARCHAR: if (ccsid == 0xffff || ccsid == 0) return java.sql.Types.VARBINARY; 85 else 86 return java.sql.Types.VARCHAR; 87 case DRDAConstants.DB2_SQLTYPE_LSTR: return java.sql.Types.VARCHAR; 89 case DRDAConstants.DB2_SQLTYPE_LONGRAPH: case DRDAConstants.DB2_SQLTYPE_LONG: if (ccsid == 0xffff || ccsid == 0) return java.sql.Types.LONGVARBINARY; 93 else 94 return java.sql.Types.LONGVARCHAR; 95 case DRDAConstants.DB2_SQLTYPE_DATE: 96 return java.sql.Types.DATE; 97 case DRDAConstants.DB2_SQLTYPE_TIME: 98 return java.sql.Types.TIME; 99 case DRDAConstants.DB2_SQLTYPE_TIMESTAMP: 100 return java.sql.Types.TIMESTAMP; 101 case DRDAConstants.DB2_SQLTYPE_CLOB: case DRDAConstants.DB2_SQLTYPE_DBCLOB: return java.sql.Types.CLOB; 104 case DRDAConstants.DB2_SQLTYPE_BLOB: case DRDAConstants.DB2_SQLTYPE_BLOB_LOCATOR: 106 case DRDAConstants.DB2_SQLTYPE_CLOB_LOCATOR: 107 case DRDAConstants.DB2_SQLTYPE_DBCLOB_LOCATOR: 108 return java.sql.Types.BLOB; 109 default: 110 return 0; 112 } 113 } 114 115 116 121 122 123 133 134 static protected int mapJdbcTypeToDB2SqlType (int jdbctype, boolean nullable, 135 int[] outlen) 136 throws SQLException 137 { 138 int nullAddVal =0; 139 140 if (nullable) 141 nullAddVal =1; 142 143 FdocaConstants.mapJdbcTypeToDrdaType(jdbctype,nullable,outlen); 145 146 switch(jdbctype) 147 { 148 case JDBC30Translation.BOOLEAN: 149 case java.sql.Types.BIT: 150 case java.sql.Types.TINYINT: 151 case java.sql.Types.SMALLINT: 152 return DRDAConstants.DB2_SQLTYPE_SMALL + nullAddVal; 153 case java.sql.Types.INTEGER: 154 return DRDAConstants.DB2_SQLTYPE_INTEGER + nullAddVal; 155 case java.sql.Types.BIGINT: 156 return DRDAConstants.DB2_SQLTYPE_BIGINT + nullAddVal; 157 case java.sql.Types.DOUBLE: 158 case java.sql.Types.REAL: 159 return DRDAConstants.DB2_SQLTYPE_FLOAT + nullAddVal; 160 case java.sql.Types.DECIMAL: 161 case java.sql.Types.NUMERIC: 162 return DRDAConstants.DB2_SQLTYPE_DECIMAL + nullAddVal; 163 case java.sql.Types.DATE: 164 return DRDAConstants.DB2_SQLTYPE_DATE + nullAddVal; 165 case java.sql.Types.TIME: 166 return DRDAConstants.DB2_SQLTYPE_TIME + nullAddVal; 167 case java.sql.Types.TIMESTAMP: 168 return DRDAConstants.DB2_SQLTYPE_TIMESTAMP + nullAddVal; 169 case java.sql.Types.CHAR: 170 return DRDAConstants.DB2_SQLTYPE_CHAR + nullAddVal; case java.sql.Types.BINARY: 172 return DRDAConstants.DB2_SQLTYPE_CHAR + nullAddVal; 173 174 case java.sql.Types.VARCHAR: 175 case java.sql.Types.VARBINARY: 176 return DRDAConstants.DB2_SQLTYPE_VARCHAR + nullAddVal; 177 case java.sql.Types.LONGVARBINARY: 178 return DRDAConstants.DB2_SQLTYPE_LONG + nullAddVal; 179 case java.sql.Types.JAVA_OBJECT: 180 return DRDAConstants.DB2_SQLTYPE_LONG + nullAddVal; 181 case java.sql.Types.BLOB: 182 return DRDAConstants.DB2_SQLTYPE_BLOB + nullAddVal; 183 case java.sql.Types.CLOB: 184 return DRDAConstants.DB2_SQLTYPE_CLOB + nullAddVal; 185 case java.sql.Types.LONGVARCHAR: 186 return DRDAConstants.DB2_SQLTYPE_LONG + nullAddVal; 187 case java.sql.Types.ARRAY: 188 case java.sql.Types.DISTINCT: 189 case java.sql.Types.NULL: 190 case java.sql.Types.OTHER: 191 case java.sql.Types.REF: 192 case java.sql.Types.STRUCT: 193 throw new SQLException ("Jdbc type" + jdbctype + "not Supported yet"); 194 default: 195 throw new SQLException ("unrecognized sql type: " + jdbctype); 196 198 } 199 } 200 201 207 protected static int getNonNullableSqlType (int sqlType) 208 { 209 return sqlType & ~1; 210 } 211 212 213 } 214 | Popular Tags |