KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > drda > FdocaConstants


1 /*
2
3    Derby - Class org.apache.derby.impl.drda.FdocaConstants
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21 package org.apache.derby.impl.drda;
22
23 import java.sql.Types JavaDoc;
24 import org.apache.derby.iapi.reference.JDBC30Translation;
25 import org.apache.derby.iapi.reference.DRDAConstants;
26 import java.sql.SQLException JavaDoc;
27 import org.apache.derby.iapi.reference.Limits;
28
29 class FdocaConstants
30 {
31   //
32
// This is where DRDA FD:OCA constants used to live. They were removed
33
// because they were not referenced anywhere.
34
//
35

36   static final int CPT_TRIPLET_TYPE = 0x7F; // CPT triplet type
37
static final int MDD_TRIPLET_TYPE = 0x78; // MDD triplet type
38
static final int NGDA_TRIPLET_TYPE = 0x76; // N-GDA triplet type
39
static final int RLO_TRIPLET_TYPE = 0x71; // RLO triplet type
40
static final int SDA_TRIPLET_TYPE = 0x70; // SDA triplet type
41

42   static final int SDA_MD_TYPE = 1; // SDA MD type
43
static final int GDA_MD_TYPE = 2; // GDA MD type
44
static final int ROW_MD_TYPE = 3; // Row MD type
45

46   static final int SQLCADTA_LID = 0xE0;
47   static final int SQLDTAGRP_LID = 0xD0; // SQLDTAGRP LID
48
static final int NULL_LID = 0x00;
49
50   static final int INDICATOR_NULLABLE = 0x00;
51   static final int NULL_DATA = 0xFF;
52   static final int TYP_NULLIND = 1;
53   static final int MAX_ENV_LID = 0x49; // Largest possible N-GDA/CPT repeating
54

55   static final int MAX_VARS_IN_NGDA = 84; // Number of SQLVARs in full SQLDTAGRP
56
// N-GDA or CPT
57
static final int FULL_NGDA_SIZE = 255; // Size of full SQLDTAGRP N-GDA or CPT
58
static final int MDD_TRIPLET_SIZE = 7; // Size of MDD triplet
59
static final int SDA_TRIPLET_SIZE = 12; // Size of SDA triplet
60
static final int SQLDTA_RLO_SIZE = 6; // Size of SQLDTA RLO triplet
61
static final int RLO_RPT_GRP_SIZE = 3; // Size of RLO repeating group
62
static final int SQLDTAGRP_SIZE = 3; // Size of SQLDTAGRP descriptor
63
static final int CPT_SIZE = 3; // Size of CPT descriptor
64
static final int FDODSC_FOOTER_SIZE = 6; // Size of regular FDODSC "footer" (RLO)
65
static final int SQLDTAGRP_COL_DSC_SIZE = 3; // Env. LID & len. bytes
66
static final int MAX_OVERRIDES = 250; // Max nbr of overrides via pairs of MDD + SDA
67
static final int MDD_REST_SIZE = 5; // Size of the MDD group minus length and type
68

69   // Hard-coded SQLCADTA MDD
70
static final byte[] SQLCADTA_MDD = {
71     (byte)0x07, (byte)0x78, (byte)0x00,
72     (byte)0x05, (byte)0x03, (byte)0x01,
73     (byte)0xE0
74   };
75
76   // Hard-coded SQLDTA MDD
77
static final byte[] SQLDTA_MDD = {
78     (byte)0x07, (byte)0x78, (byte)0x00,
79     (byte)0x05, (byte)0x04, (byte)0x01,
80     (byte)0xF0
81   };
82
83   // Hard-coded SQLDTA MDD
84
static final byte[] SQLDTAGRP_MDD = {
85     (byte)0x07, (byte)0x78, (byte)0x00,
86     (byte)0x05, (byte)0x02, (byte)0x01,
87     (byte)0xD0
88   };
89
90   // Hard-coded SQLCADTA+SQLDTARD footer bytes
91
static final byte[] SQLCADTA_SQLDTARD_RLO = {
92     (byte)0x09, (byte)0x71, (byte)0xE0, // SQLCADTA
93
(byte)0x54, (byte)0x00, (byte)0x01,
94     (byte)0xD0, (byte)0x00, (byte)0x01,
95     (byte)0x06, (byte)0x71, (byte)0xF0, // SQLDTARD
96
(byte)0xE0, (byte)0x00, (byte)0x00
97   };
98
99   // Hard-coded SQLDTA RLO
100
static final byte[] SQLDTA_RLO = {
101     (byte)0x06, (byte)0x71, (byte)0xE4,
102     (byte)0xD0, (byte)0x00, (byte)0x01
103   };
104
105   static final int SQLCADTA_SQLDTARD_RLO_SIZE = SQLCADTA_SQLDTARD_RLO.length;
106
107     protected static boolean isNullable(int fdocaType)
108     {
109         return ( (fdocaType & 1) == 1);
110     }
111
112     // The maxumum length for LONG VARCHAR RETURN RESULTS IS
113
// 64K, since we send an unsigned short. We should be
114
// able to send the number of bytes in which we encode the
115
// length as 4 (or more) , but JCC does not support this yet.
116
// JAVA_OBJECTS are returned as LONG VARCHAR values by calling
117
// their toString() method and their limit is 64K as well.
118
// BUT, that said, we ultimately have to match DB2's limit,
119
// so just use that...
120
protected static int LONGVARCHAR_MAX_LEN = Limits.DB2_LONGVARCHAR_MAXWIDTH;
121     protected static int LONGVARBINARY_MAX_LEN = Limits.DB2_LONGVARCHAR_MAXWIDTH;
122     protected static int LONGVARCHAR_LEN_NUMBYTES = 2;
123
124     // JCC only supports a max precision of 31 like DB2
125
protected static int NUMERIC_MAX_PRECISION=31;
126     protected static int NUMERIC_DEFAULT_PRECISION=NUMERIC_MAX_PRECISION;
127     protected static int NUMERIC_DEFAULT_SCALE=15;
128
129     /***
130      * Map jdbctype to fdoca drda type
131      * @param jdbcType - Jdbc type for mappingy
132      * @param nullable - true if type is nullable
133      * @param outlen - output parameter with length of type.
134      * @return standard drdaTypeLength. -1 if we don't know.
135      **/

136     protected static int mapJdbcTypeToDrdaType(int jdbcType, boolean nullable,
137                                                int[] outlen)
138         throws SQLException JavaDoc
139     {
140         int drdaType = 0;
141         switch (jdbcType) {
142             case JDBC30Translation.BOOLEAN:
143             case java.sql.Types.BIT:
144             case java.sql.Types.TINYINT:
145             case java.sql.Types.SMALLINT:
146                 drdaType = DRDAConstants.DRDA_TYPE_NSMALL;
147                 outlen[0] = 2;
148                 break;
149             case java.sql.Types.INTEGER:
150                 drdaType = DRDAConstants.DRDA_TYPE_NINTEGER;
151                 outlen[0] = 4;
152                 break;
153             case java.sql.Types.BIGINT:
154                 drdaType = DRDAConstants.DRDA_TYPE_NINTEGER8;
155                 outlen[0] = 8;
156                 break;
157             case java.sql.Types.REAL:
158                 drdaType = DRDAConstants.DRDA_TYPE_NFLOAT4;
159                 outlen[0] = 4;
160                 break;
161             case java.sql.Types.DOUBLE:
162             case java.sql.Types.FLOAT:
163                 drdaType = DRDAConstants.DRDA_TYPE_NFLOAT8;
164                 outlen[0] = 8;
165                 break;
166             case java.sql.Types.NUMERIC:
167             case java.sql.Types.DECIMAL:
168                 drdaType = DRDAConstants.DRDA_TYPE_NDECIMAL;
169                 //needs to be adjusted for actual value
170
outlen[0] = -1;
171                 break;
172             case java.sql.Types.DATE:
173                 drdaType = DRDAConstants.DRDA_TYPE_NDATE;
174                 outlen[0] = 10;
175                 break;
176             case java.sql.Types.TIME:
177                 drdaType = DRDAConstants.DRDA_TYPE_NTIME;
178                 outlen[0] = 8;
179                 break;
180             case java.sql.Types.TIMESTAMP:
181                 drdaType = DRDAConstants.DRDA_TYPE_NTIMESTAMP;
182                 outlen[0] = 26;
183                 break;
184             case java.sql.Types.CHAR:
185 // drdaType = DRDAConstants.DRDA_TYPE_NCHAR;
186
//making this NVARMIX for now to handle different byte length
187
//characters - checking with Paul to see if this is the
188
//correct way to handle it.
189
drdaType = DRDAConstants.DRDA_TYPE_NVARMIX;
190                 outlen[0] = -1;
191                 break;
192             case java.sql.Types.VARCHAR:
193                 drdaType = DRDAConstants.DRDA_TYPE_NVARCHAR;
194                 outlen[0] = -1;
195                 break;
196                 // we will just convert a java object to a string
197
// since jcc doesn't support it.
198
case java.sql.Types.JAVA_OBJECT:
199                 drdaType = DRDAConstants.DRDA_TYPE_NLONG;
200                 outlen[0] = LONGVARCHAR_MAX_LEN;
201                 break;
202             case java.sql.Types.LONGVARCHAR:
203                     drdaType = DRDAConstants.DRDA_TYPE_NLONG;
204                     outlen[0] = LONGVARCHAR_MAX_LEN;
205                 break;
206             case java.sql.Types.BINARY:
207             case java.sql.Types.VARBINARY:
208                 drdaType = DRDAConstants.DRDA_TYPE_NVARBYTE;
209                 outlen[0] = -1;
210                 break;
211             case java.sql.Types.LONGVARBINARY:
212                     drdaType = DRDAConstants.DRDA_TYPE_NLONGVARBYTE;
213                     outlen[0] = LONGVARBINARY_MAX_LEN;
214                 break;
215                 // blob begin
216
// merge BLOB and BLOB_LOCATOR ????
217
case java.sql.Types.BLOB:
218                 drdaType = DRDAConstants.DRDA_TYPE_NLOBBYTES;
219                 // indicates fdocadata is a place holder with 4 byte length
220
outlen[0] = 0x8004;
221                 break;
222             case java.sql.Types.CLOB:
223                 drdaType = DRDAConstants.DRDA_TYPE_NLOBCMIXED;
224                 outlen[0] = 0x8004;
225                 break;
226                 // blob end
227
case java.sql.Types.ARRAY:
228             case java.sql.Types.DISTINCT:
229             case java.sql.Types.NULL:
230             case java.sql.Types.OTHER:
231             case java.sql.Types.REF:
232             case java.sql.Types.STRUCT:
233                 throw new SQLException JavaDoc("Jdbc type" + jdbcType + "not Supported yet");
234             default:
235                 throw new SQLException JavaDoc ("unrecognized sql type: " + jdbcType);
236         }
237
238         if (!nullable)
239             drdaType--;
240         return drdaType;
241     }
242
243
244 }
245
Popular Tags