001: //==============================================================================
002: //===
003: //=== SqlType (adapted class from druid project http://druid.sf.net)
004: //===
005: //=== Copyright (C) by Andrea Carboni.
006: //=== This file may be distributed under the terms of the GPL license.
007: //==============================================================================
008:
009: package org.fao.gast.lib.druid;
010:
011: import java.sql.Types;
012:
013: //==============================================================================
014:
015: public class SqlType {
016: //--- possible type sizes
017:
018: public static final int VAR = 0;
019: public static final int CONST = 1;
020: public static final int BOTH = 2;
021: public static final int UNKNOWN = 3;
022:
023: //---------------------------------------------------------------------------
024:
025: public int iId;
026: public String sName;
027: public int iSize;
028:
029: //---------------------------------------------------------------------------
030:
031: /** @param id This is the sql type as returned by JDBC
032: */
033:
034: public SqlType(int id, String name, int size) {
035: iId = id;
036: sName = name;
037: iSize = size;
038:
039: if (iSize < 0)
040: iSize = 0;
041: }
042:
043: //---------------------------------------------------------------------------
044:
045: public String toString() {
046: return "[id:" + iId + ", name:" + sName + "]";
047: }
048:
049: //---------------------------------------------------------------------------
050: //---
051: //--- Type static methods
052: //---
053: //---------------------------------------------------------------------------
054:
055: public boolean isInteger() {
056: return (iId == Types.BIGINT) || (iId == Types.INTEGER)
057: || (iId == Types.SMALLINT) || (iId == Types.TINYINT);
058: }
059:
060: //---------------------------------------------------------------------------
061:
062: public boolean isReal() {
063: return (iId == Types.DECIMAL) || (iId == Types.DOUBLE)
064: || (iId == Types.FLOAT) || (iId == Types.NUMERIC)
065: || (iId == Types.REAL);
066: }
067:
068: //---------------------------------------------------------------------------
069:
070: public boolean isNumber() {
071: return isInteger() || isReal();
072: }
073:
074: public boolean isString() {
075: return (iId == Types.CHAR) || (iId == Types.VARCHAR);
076: }
077:
078: public boolean isDate() {
079: return iId == Types.DATE;
080: }
081:
082: public boolean isTime() {
083: return iId == Types.TIME;
084: }
085:
086: public boolean isTimeStamp() {
087: return iId == Types.TIMESTAMP;
088: }
089:
090: public boolean isTemporalType() {
091: return (isDate() || isTime() || isTimeStamp());
092: }
093:
094: //---------------------------------------------------------------------------
095: //--- types not simply editable
096: //---------------------------------------------------------------------------
097:
098: public boolean isBinary() {
099: return iId == Types.BINARY;
100: }
101:
102: public boolean isVarBinary() {
103: return iId == Types.VARBINARY;
104: }
105:
106: public boolean isLongVarBinary() {
107: return iId == Types.LONGVARBINARY;
108: }
109:
110: public boolean isBinaryType() {
111: return isBinary() || isVarBinary() || isLongVarBinary();
112: }
113:
114: public boolean isLongVarChar() {
115: return iId == Types.LONGVARCHAR;
116: }
117:
118: public boolean isBlob() {
119: return iId == Types.BLOB;
120: }
121:
122: public boolean isClob() {
123: return iId == Types.CLOB;
124: }
125: }
126:
127: //==============================================================================
|