001: /*
002:
003: Derby - Class org.apache.derby.impl.drda.FdocaConstants
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021: package org.apache.derby.impl.drda;
022:
023: import java.sql.Types;
024: import org.apache.derby.iapi.reference.JDBC30Translation;
025: import org.apache.derby.iapi.reference.DRDAConstants;
026: import java.sql.SQLException;
027: import org.apache.derby.iapi.reference.Limits;
028:
029: class FdocaConstants {
030: //
031: // This is where DRDA FD:OCA constants used to live. They were removed
032: // because they were not referenced anywhere.
033: //
034:
035: static final int CPT_TRIPLET_TYPE = 0x7F; // CPT triplet type
036: static final int MDD_TRIPLET_TYPE = 0x78; // MDD triplet type
037: static final int NGDA_TRIPLET_TYPE = 0x76; // N-GDA triplet type
038: static final int RLO_TRIPLET_TYPE = 0x71; // RLO triplet type
039: static final int SDA_TRIPLET_TYPE = 0x70; // SDA triplet type
040:
041: static final int SDA_MD_TYPE = 1; // SDA MD type
042: static final int GDA_MD_TYPE = 2; // GDA MD type
043: static final int ROW_MD_TYPE = 3; // Row MD type
044:
045: static final int SQLCADTA_LID = 0xE0;
046: static final int SQLDTAGRP_LID = 0xD0; // SQLDTAGRP LID
047: static final int NULL_LID = 0x00;
048:
049: static final int INDICATOR_NULLABLE = 0x00;
050: static final int NULL_DATA = 0xFF;
051: static final int TYP_NULLIND = 1;
052: static final int MAX_ENV_LID = 0x49; // Largest possible N-GDA/CPT repeating
053:
054: static final int MAX_VARS_IN_NGDA = 84; // Number of SQLVARs in full SQLDTAGRP
055: // N-GDA or CPT
056: static final int FULL_NGDA_SIZE = 255; // Size of full SQLDTAGRP N-GDA or CPT
057: static final int MDD_TRIPLET_SIZE = 7; // Size of MDD triplet
058: static final int SDA_TRIPLET_SIZE = 12; // Size of SDA triplet
059: static final int SQLDTA_RLO_SIZE = 6; // Size of SQLDTA RLO triplet
060: static final int RLO_RPT_GRP_SIZE = 3; // Size of RLO repeating group
061: static final int SQLDTAGRP_SIZE = 3; // Size of SQLDTAGRP descriptor
062: static final int CPT_SIZE = 3; // Size of CPT descriptor
063: static final int FDODSC_FOOTER_SIZE = 6; // Size of regular FDODSC "footer" (RLO)
064: static final int SQLDTAGRP_COL_DSC_SIZE = 3; // Env. LID & len. bytes
065: static final int MAX_OVERRIDES = 250; // Max nbr of overrides via pairs of MDD + SDA
066: static final int MDD_REST_SIZE = 5; // Size of the MDD group minus length and type
067:
068: // Hard-coded SQLCADTA MDD
069: static final byte[] SQLCADTA_MDD = { (byte) 0x07, (byte) 0x78,
070: (byte) 0x00, (byte) 0x05, (byte) 0x03, (byte) 0x01,
071: (byte) 0xE0 };
072:
073: // Hard-coded SQLDTA MDD
074: static final byte[] SQLDTA_MDD = { (byte) 0x07, (byte) 0x78,
075: (byte) 0x00, (byte) 0x05, (byte) 0x04, (byte) 0x01,
076: (byte) 0xF0 };
077:
078: // Hard-coded SQLDTA MDD
079: static final byte[] SQLDTAGRP_MDD = { (byte) 0x07, (byte) 0x78,
080: (byte) 0x00, (byte) 0x05, (byte) 0x02, (byte) 0x01,
081: (byte) 0xD0 };
082:
083: // Hard-coded SQLCADTA+SQLDTARD footer bytes
084: static final byte[] SQLCADTA_SQLDTARD_RLO = {
085: (byte) 0x09,
086: (byte) 0x71,
087: (byte) 0xE0, // SQLCADTA
088: (byte) 0x54, (byte) 0x00, (byte) 0x01, (byte) 0xD0,
089: (byte) 0x00, (byte) 0x01, (byte) 0x06, (byte) 0x71,
090: (byte) 0xF0, // SQLDTARD
091: (byte) 0xE0, (byte) 0x00, (byte) 0x00 };
092:
093: // Hard-coded SQLDTA RLO
094: static final byte[] SQLDTA_RLO = { (byte) 0x06, (byte) 0x71,
095: (byte) 0xE4, (byte) 0xD0, (byte) 0x00, (byte) 0x01 };
096:
097: static final int SQLCADTA_SQLDTARD_RLO_SIZE = SQLCADTA_SQLDTARD_RLO.length;
098:
099: protected static boolean isNullable(int fdocaType) {
100: return ((fdocaType & 1) == 1);
101: }
102:
103: // The maxumum length for LONG VARCHAR RETURN RESULTS IS
104: // 64K, since we send an unsigned short. We should be
105: // able to send the number of bytes in which we encode the
106: // length as 4 (or more) , but JCC does not support this yet.
107: // JAVA_OBJECTS are returned as LONG VARCHAR values by calling
108: // their toString() method and their limit is 64K as well.
109: // BUT, that said, we ultimately have to match DB2's limit,
110: // so just use that...
111: protected static int LONGVARCHAR_MAX_LEN = Limits.DB2_LONGVARCHAR_MAXWIDTH;
112: protected static int LONGVARBINARY_MAX_LEN = Limits.DB2_LONGVARCHAR_MAXWIDTH;
113: protected static int LONGVARCHAR_LEN_NUMBYTES = 2;
114:
115: // JCC only supports a max precision of 31 like DB2
116: protected static int NUMERIC_MAX_PRECISION = 31;
117: protected static int NUMERIC_DEFAULT_PRECISION = NUMERIC_MAX_PRECISION;
118: protected static int NUMERIC_DEFAULT_SCALE = 15;
119:
120: /***
121: * Map jdbctype to fdoca drda type
122: * @param jdbcType - Jdbc type for mappingy
123: * @param nullable - true if type is nullable
124: * @param outlen - output parameter with length of type.
125: * @return standard drdaTypeLength. -1 if we don't know.
126: **/
127: protected static int mapJdbcTypeToDrdaType(int jdbcType,
128: boolean nullable, int[] outlen) throws SQLException {
129: int drdaType = 0;
130: switch (jdbcType) {
131: case JDBC30Translation.BOOLEAN:
132: case java.sql.Types.BIT:
133: case java.sql.Types.TINYINT:
134: case java.sql.Types.SMALLINT:
135: drdaType = DRDAConstants.DRDA_TYPE_NSMALL;
136: outlen[0] = 2;
137: break;
138: case java.sql.Types.INTEGER:
139: drdaType = DRDAConstants.DRDA_TYPE_NINTEGER;
140: outlen[0] = 4;
141: break;
142: case java.sql.Types.BIGINT:
143: drdaType = DRDAConstants.DRDA_TYPE_NINTEGER8;
144: outlen[0] = 8;
145: break;
146: case java.sql.Types.REAL:
147: drdaType = DRDAConstants.DRDA_TYPE_NFLOAT4;
148: outlen[0] = 4;
149: break;
150: case java.sql.Types.DOUBLE:
151: case java.sql.Types.FLOAT:
152: drdaType = DRDAConstants.DRDA_TYPE_NFLOAT8;
153: outlen[0] = 8;
154: break;
155: case java.sql.Types.NUMERIC:
156: case java.sql.Types.DECIMAL:
157: drdaType = DRDAConstants.DRDA_TYPE_NDECIMAL;
158: //needs to be adjusted for actual value
159: outlen[0] = -1;
160: break;
161: case java.sql.Types.DATE:
162: drdaType = DRDAConstants.DRDA_TYPE_NDATE;
163: outlen[0] = 10;
164: break;
165: case java.sql.Types.TIME:
166: drdaType = DRDAConstants.DRDA_TYPE_NTIME;
167: outlen[0] = 8;
168: break;
169: case java.sql.Types.TIMESTAMP:
170: drdaType = DRDAConstants.DRDA_TYPE_NTIMESTAMP;
171: outlen[0] = 26;
172: break;
173: case java.sql.Types.CHAR:
174: // drdaType = DRDAConstants.DRDA_TYPE_NCHAR;
175: //making this NVARMIX for now to handle different byte length
176: //characters - checking with Paul to see if this is the
177: //correct way to handle it.
178: drdaType = DRDAConstants.DRDA_TYPE_NVARMIX;
179: outlen[0] = -1;
180: break;
181: case java.sql.Types.VARCHAR:
182: drdaType = DRDAConstants.DRDA_TYPE_NVARCHAR;
183: outlen[0] = -1;
184: break;
185: // we will just convert a java object to a string
186: // since jcc doesn't support it.
187: case java.sql.Types.JAVA_OBJECT:
188: drdaType = DRDAConstants.DRDA_TYPE_NLONG;
189: outlen[0] = LONGVARCHAR_MAX_LEN;
190: break;
191: case java.sql.Types.LONGVARCHAR:
192: drdaType = DRDAConstants.DRDA_TYPE_NLONG;
193: outlen[0] = LONGVARCHAR_MAX_LEN;
194: break;
195: case java.sql.Types.BINARY:
196: case java.sql.Types.VARBINARY:
197: drdaType = DRDAConstants.DRDA_TYPE_NVARBYTE;
198: outlen[0] = -1;
199: break;
200: case java.sql.Types.LONGVARBINARY:
201: drdaType = DRDAConstants.DRDA_TYPE_NLONGVARBYTE;
202: outlen[0] = LONGVARBINARY_MAX_LEN;
203: break;
204: // blob begin
205: // merge BLOB and BLOB_LOCATOR ????
206: case java.sql.Types.BLOB:
207: drdaType = DRDAConstants.DRDA_TYPE_NLOBBYTES;
208: // indicates fdocadata is a place holder with 4 byte length
209: outlen[0] = 0x8004;
210: break;
211: case java.sql.Types.CLOB:
212: drdaType = DRDAConstants.DRDA_TYPE_NLOBCMIXED;
213: outlen[0] = 0x8004;
214: break;
215: // blob end
216: case java.sql.Types.ARRAY:
217: case java.sql.Types.DISTINCT:
218: case java.sql.Types.NULL:
219: case java.sql.Types.OTHER:
220: case java.sql.Types.REF:
221: case java.sql.Types.STRUCT:
222: throw new SQLException("Jdbc type" + jdbcType
223: + "not Supported yet");
224: default:
225: throw new SQLException("unrecognized sql type: " + jdbcType);
226: }
227:
228: if (!nullable)
229: drdaType--;
230: return drdaType;
231: }
232:
233: }
|