001: package com.quadcap.sql.types;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.Externalizable;
042: import java.io.IOException;
043: import java.io.ObjectInput;
044: import java.io.ObjectOutput;
045:
046: import java.sql.ResultSet;
047: import java.sql.SQLException;
048: import java.sql.Types;
049:
050: import com.quadcap.util.Debug;
051:
052: /**
053: * The SQL <b>TIME</b> type.
054: *
055: * @author Stan Bailes
056: */
057: public class TypeTime implements Type, Externalizable {
058: public static final TypeTime typeTime = new TypeTime();
059:
060: int precision = 0;
061: boolean tz = false;
062:
063: public TypeTime() {
064: }
065:
066: public TypeTime(int precision, boolean tz) {
067: this .precision = precision;
068: this .tz = tz;
069: }
070:
071: public String getTypeName() {
072: return "TIME";
073: }
074:
075: public int getJDBCType() {
076: return Types.TIME;
077: }
078:
079: public String getJDBCClassName() {
080: return "java.sql.Time";
081: }
082:
083: public int getPrecision() {
084: return precision;
085: }
086:
087: public int getScale() {
088: return 0;
089: }
090:
091: public int getMaxPrecision() {
092: return 32;
093: }
094:
095: public int getMinScale() {
096: return -1;
097: }
098:
099: public int getMaxScale() {
100: return -1;
101: }
102:
103: public boolean isCharType() {
104: return false;
105: }
106:
107: public boolean isCaseSensitive() {
108: return false;
109: }
110:
111: public boolean isCurrency() {
112: return false;
113: }
114:
115: public boolean isSigned() {
116: return false;
117: }
118:
119: public String toString() {
120: StringBuffer sb = new StringBuffer("TIME");
121: if (precision > 0) {
122: sb.append('(');
123: sb.append(Integer.toString(precision));
124: sb.append(')');
125: }
126: if (tz)
127: sb.append(" WITH TIME ZONE");
128: return sb.toString();
129: }
130:
131: public int getDisplayWidth() {
132: int wid = 8;
133: if (precision > 0)
134: wid += (precision + 1);
135: if (tz)
136: wid += 6;
137: return wid;
138: }
139:
140: public void readExternal(ObjectInput in) throws IOException {
141: precision = in.read();
142: tz = in.read() == 1;
143: }
144:
145: public void writeExternal(ObjectOutput out) throws IOException {
146: out.write(precision);
147: out.write(tz ? 1 : 0);
148: }
149:
150: public Value convert(Value v) throws ValueException {
151: return v.convert(this );
152: }
153:
154: public String getCreateParams() {
155: return null;
156: }
157: }
|