File: VirtuosoColumn.java

package info (click to toggle)
virtuoso-opensource 6.1.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 260,060 kB
  • ctags: 123,765
  • sloc: ansic: 652,532; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (501 lines) | stat: -rw-r--r-- 13,710 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/*
 *  $Id$
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2012 OpenLink Software
 *
 *  This project is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; only version 2 of the License, dated June 1991.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

package virtuoso.jdbc2;

import java.sql.*;
import java.util.*;
import openlink.util.*;

/**
 * The VirtuosoColumn class is designed to store and retrieve meta data
 * about a column in a table.
 *
 * @version 1.0 (JDBC API 2.0 implementation)
 */
class VirtuosoColumn
{
   // The type of object stored by this column
   private int typeObject;

   // The column's name
   private String name;

   // The SQL type corresponding to this column
   private int typeSQL;

   // The column's normal max width in chars
   private int length;

   // The column's scale
   private int scale;

   // The column's precision
   private int precision;

   // The column's auto increment flag
   private boolean isAutoIncrement = false;

   // The column's case sensitive flag
   private boolean isCaseSensitive = false;

   // The column's currency flag
   private boolean isCurrency = false;

   // The column's nullable flag
   private int isNullable = ResultSetMetaData.columnNullable;

   // The column's searchable flag
   private boolean isSearchable = false;

   // The column's updateable flag
   private boolean isUpdateable = false;

   // The column's signed flag
   private boolean isSigned = false;

   // The case mode
   private int _case;

   // XML wrapped into DV_.*WIDE
   private boolean _isXml = false;

   /**
    * Construct a new VirtuosoColumn class which stores only the column's name.
    * (Useful to use equals and hashCode without others parameters).
    *
    * @param String  The column's name.
    */
   VirtuosoColumn(String name, int dtp, VirtuosoConnection connection)
   {
      // Set column's name
      this.name = name;
      this._case = connection.getCase();
      this.typeObject = dtp;
   }

   /**
    * Construct a new VirtuosoColumn class which stores meta data about
    * a column in a ResultSet.
    *
    * @param Vector  Description about the column.
    * @exception VirtuosoException   An internal error occurred.
    */
   VirtuosoColumn(openlink.util.Vector args, VirtuosoConnection connection)
   {
      try
      {
         // Set variables
	 if (connection.charset != null)
	   name = connection.uncharsetBytes((String)args.firstElement());
	 else if (connection.utf8_execs)
	   name = new String (((String)args.firstElement()).getBytes("8859_1"), "UTF8");
	 else
	   name = (String)args.firstElement();
         if (null != args.elementAt(1))
	   typeObject = ((Number)args.elementAt(1)).intValue();
         else
           typeObject = VirtuosoTypes.DV_STRING;
         if( args.elementAt(2)!=null)
         length = scale = ((Number)args.elementAt(2)).intValue();
         if( args.elementAt(3)!=null)
         precision = ((Number)args.elementAt(3)).intValue();
         if( args.elementAt(4)!=null && ((Number)args.elementAt(4)).intValue() == 1)
            isNullable = ResultSetMetaData.columnNullable;
         if( args.elementAt(5)!=null && ((Number)args.elementAt(5)).intValue() == 1)
            isUpdateable = true;
         if( args.elementAt(6)!=null && ((Number)args.elementAt(6)).intValue() == 1)
            isSearchable = true;
         this._case = connection.getCase();

	 if (args.size () >= 12)
	   {
	       /* that has the members up to cd_flags */
	       int cd_flags = ((Number)args.elementAt(11)).intValue();

	       if ((cd_flags & VirtuosoTypes.CDF_XMLTYPE) != 0)
		 _isXml = true;
	       if ((cd_flags & VirtuosoTypes.CDF_AUTOINCREMENT) != 0)
		 isAutoIncrement = true;
	   }

      }
      catch(Exception e)
      {
      }
   }

   /**
    * Returns the name of the object which can represent this column.
    *
    * @return String The name of the class.
    * @see java.sql.ResultSetMetaData#getColumnClassName
    */
  protected String getColumnClassName () throws VirtuosoException
    {
      if (_isXml)
        return "org.w3c.dom.Document";

      return getColumnClassName (typeObject);
    }
  protected static String getColumnClassName (int _typeObject) throws VirtuosoException
  {
    switch (_typeObject)
      {
      case VirtuosoTypes.DV_NULL:
	return "java.lang.Void";
	case VirtuosoTypes.DV_SHORT_CONT_STRING:
	case VirtuosoTypes.DV_SHORT_STRING_SERIAL:
	case VirtuosoTypes.DV_STRICT_STRING:
	case VirtuosoTypes.DV_LONG_CONT_STRING:
	case VirtuosoTypes.DV_STRING:
	case VirtuosoTypes.DV_C_STRING:
	case VirtuosoTypes.DV_WIDE:
	case VirtuosoTypes.DV_LONG_WIDE:
	return "java.lang.String";
	case VirtuosoTypes.DV_STRING_SESSION:
	return "java.lang.StringBuffer";
	case VirtuosoTypes.DV_C_SHORT:
	case VirtuosoTypes.DV_SHORT_INT:
	return "java.lang.Short";
	case VirtuosoTypes.DV_LONG_INT:
	return "java.lang.Integer";
	case VirtuosoTypes.DV_C_INT:
	return "java.lang.Integer";
	case VirtuosoTypes.DV_SINGLE_FLOAT:
	return "java.lang.Float";
	case VirtuosoTypes.DV_DOUBLE_FLOAT:
	return "java.lang.Double";
	case VirtuosoTypes.DV_CHARACTER:
	return "java.lang.Character";
	case VirtuosoTypes.DV_ARRAY_OF_LONG_PACKED:
	/*typeObject=new VectorOfLongPacked().getClass().getName(); typeSQL=Types.ARRAY; */
	case VirtuosoTypes.DV_ARRAY_OF_FLOAT:
	case VirtuosoTypes.DV_ARRAY_OF_DOUBLE:
	case VirtuosoTypes.DV_ARRAY_OF_LONG:
	case VirtuosoTypes.DV_ARRAY_OF_POINTER:
	case VirtuosoTypes.DV_LIST_OF_POINTER:
	return "java.util.Vector";
	case VirtuosoTypes.DV_OBJECT_AND_CLASS:
	case VirtuosoTypes.DV_OBJECT_REFERENCE:
	return "java.lang.Object";
	case VirtuosoTypes.DV_BLOB_BIN:
	case VirtuosoTypes.DV_BLOB:
	case VirtuosoTypes.DV_BLOB_HANDLE:
	case VirtuosoTypes.DV_BIN:
	case VirtuosoTypes.DV_LONG_BIN:
	return "java.sql.Blob";
	case VirtuosoTypes.DV_NUMERIC:
	return "java.lang.BigDecimal";
	case VirtuosoTypes.DV_DATE:
	case VirtuosoTypes.DV_DATETIME:
	case VirtuosoTypes.DV_TIMESTAMP:
	case VirtuosoTypes.DV_TIMESTAMP_OBJ:
	case VirtuosoTypes.DV_TIME:
	return "java.lang.Date";
	default:
	// Problem
	//System.out.println("Tag not defined.");
	return "java.lang.Object";
      }
  }

   /**
    * Returns the name of this column.
    *
    * @return String The name of the column.
    * @see java.sql.ResultSetMetaData#getColumnName
    * @see java.sql.ResultSetMetaData#getColumnLabel
    */
   protected String getColumnName()
   {
      return name;
   }

   protected void setColumnName(String s)
   {
      name = s;
   }

   /**
    * Indicates the column's normal max width in chars.
    *
    * @return int The max length of the column.
    * @see java.sql.ResultSetMetaData#getColumnDisplaySize
    */
   protected int getColumnDisplaySize()
   {
      return length;
   }

   /**
    * Returns the SQL type which can be contained in this column.
    *
    * @return int The SQL type.
    * @see java.sql.ResultSetMetaData#getColumnType
    * @see java.sql.Types
    */
  protected int getColumnType () throws VirtuosoException
  {
    return getColumnType (typeObject);
  }
  protected static int getColumnType (int _typeObject) throws VirtuosoException
  {
    switch (_typeObject)
      {
      case VirtuosoTypes.DV_C_SHORT:
      case VirtuosoTypes.DV_SHORT_INT:
	return Types.SMALLINT;

      case VirtuosoTypes.DV_LONG_INT:
      case VirtuosoTypes.DV_C_INT:
	return Types.INTEGER;

      case VirtuosoTypes.DV_DOUBLE_FLOAT:
	return Types.DOUBLE;

      case VirtuosoTypes.DV_NUMERIC:
	return Types.NUMERIC;

      case VirtuosoTypes.DV_SINGLE_FLOAT:
	return Types.REAL;

      case VirtuosoTypes.DV_BLOB:
	return Types.LONGVARCHAR;

      case VirtuosoTypes.DV_BLOB_BIN:
	return Types.LONGVARBINARY;

      case VirtuosoTypes.DV_BLOB_WIDE:
	return -10; /* SQL_WLONGVARCHAR */

      case VirtuosoTypes.DV_DATE:
	return Types.DATE;

      case VirtuosoTypes.DV_TIMESTAMP:
      case VirtuosoTypes.DV_TIMESTAMP_OBJ:
      case VirtuosoTypes.DV_DATETIME:
	return Types.TIMESTAMP;

      case VirtuosoTypes.DV_TIME:
	return Types.TIME;

      case VirtuosoTypes.DV_LONG_BIN:
      case VirtuosoTypes.DV_BIN:
	return Types.VARBINARY;

      case VirtuosoTypes.DV_WIDE:
      case VirtuosoTypes.DV_LONG_WIDE:
	return -9; /* SQL_NVARCHAR */

      /* custom cases follow */
      case VirtuosoTypes.DV_DB_NULL:
      case VirtuosoTypes.DV_NULL:
	return Types.NULL;
      case VirtuosoTypes.DV_SHORT_CONT_STRING:
      case VirtuosoTypes.DV_SHORT_STRING_SERIAL:
      case VirtuosoTypes.DV_STRICT_STRING:
      case VirtuosoTypes.DV_LONG_CONT_STRING:
      case VirtuosoTypes.DV_STRING:
      case VirtuosoTypes.DV_C_STRING:
	return Types.VARCHAR;
      case VirtuosoTypes.DV_STRING_SESSION:
	return Types.LONGVARCHAR;

      case VirtuosoTypes.DV_CHARACTER:
	return Types.CHAR;

      case VirtuosoTypes.DV_ARRAY_OF_LONG_PACKED:
	/*typeObject=new VectorOfLongPacked().getClass().getName(); typeSQL=Types.ARRAY; */
      case VirtuosoTypes.DV_ARRAY_OF_FLOAT:
      case VirtuosoTypes.DV_ARRAY_OF_DOUBLE:
      case VirtuosoTypes.DV_ARRAY_OF_LONG:
      case VirtuosoTypes.DV_ARRAY_OF_POINTER:
      case VirtuosoTypes.DV_LIST_OF_POINTER:
	return Types.ARRAY;

      case VirtuosoTypes.DV_OBJECT_AND_CLASS:
      case VirtuosoTypes.DV_OBJECT_REFERENCE:
	return Types.OTHER;

      case VirtuosoTypes.DV_BLOB_HANDLE:
      case VirtuosoTypes.DV_BLOB_WIDE_HANDLE:
	return Types.BLOB;
      default:
	return Types.OTHER;
      }
  }

   /**
    * Returns the column's number of decimal digits.
    *
    * @return int The column's precision.
    * @see java.sql.ResultSetMetaData#getPrecision
    */
   protected int getPrecision()
   {
      return precision;
   }

   /**
    * Returns the column's number of digits to right of the decimal point.
    *
    * @return int The column's scale.
    * @see java.sql.ResultSetMetaData#getScale
    */
   protected int getScale()
   {
      return scale;
   }

   /**
    * Indicates whether the column is automatically numbered, thus read-only.
    *
    * @return boolean   The autoincrement flag.
    * @see java.sql.ResultSetMetaData#isAutoIncrement
    */
   protected boolean isAutoIncrement()
   {
      return isAutoIncrement;
   }

   /**
    * Indicates whether a column's case matters.
    *
    * @return boolean   The case sensitive flag.
    * @see java.sql.ResultSetMetaData#isCaseSensitive
    */
   protected boolean isCaseSensitive()
   {
      return isCaseSensitive;
   }

   /**
    * Indicates whether the column is a cash value.
    *
    * @return boolean   The currency flag.
    * @see java.sql.ResultSetMetaData#isCurrency
    */
   protected boolean isCurrency()
   {
      return isCurrency;
   }

   /**
    * Indicates the nullability of values in the designated column.
    *
    * @return int The nullability flag.
    * @see java.sql.ResultSetMetaData#isNullable
    */
   protected int isNullable()
   {
      return isNullable;
   }

   /**
    * Indicates whether the column can be used in a where clause.
    *
    * @return boolean   The searchable flag.
    * @see java.sql.ResultSetMetaData#isSearchable
    */
   protected boolean isSearchable()
   {
      return isSearchable;
   }

   /**
    * Indicates whether values in the column are signed numbers.
    *
    * @return boolean   The sign flag.
    * @see java.sql.ResultSetMetaData#isSigned
    */
   protected boolean isSigned()
   {
      return isSigned;
   }

   /**
    * Indicates if the column is updateable.
    *
    * @return boolean   The update flag.
    */
   protected boolean isUpdateable()
   {
      return isUpdateable;
   }

   /**
    * Returns a hash code value for the object.
    *
    * @return int	The hash code value.
    */
   public int hashCode()
   {
/*      if(name != null && _case == 2)
         return name.hashCode();
      if(name != null && _case == 1)
         return name.toUpperCase().hashCode();
      if(name != null && _case == 0)
         return name.toLowerCase().hashCode();*/
      if(name != null && _case == 2)
         return name.toUpperCase().hashCode();
      if(name != null)
         return name.hashCode();
      return 0;
   }

   /**
    * Compares two Objects for equality.
    *
    * @return boolean	True if two objects are equal, else false.
    */
   public boolean equals(Object obj)
   {
      // First check if the object is not null or the same object type
      if(obj != null && (obj instanceof VirtuosoColumn))
      {
/*         if(name != null && _case == 2)
            return ((VirtuosoColumn)obj).name.equals(name);
         if(name != null && _case == 1)
            return ((VirtuosoColumn)obj).name.toUpperCase().equals(name);
         if(name != null && _case == 0)
            return ((VirtuosoColumn)obj).name.toLowerCase().equals(name);*/
         if(name != null && _case == 2)
            return ((VirtuosoColumn)obj).name.toUpperCase().equals(name.toUpperCase());
         if(name != null)
            return ((VirtuosoColumn)obj).name.equals(name);
      }
      return false;
   }

   protected int getDtp ()
     {
       return typeObject;
     }

   protected boolean isXml ()
     {
       return _isXml;
     }
}