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>VARCHAR</b> type.
054: *
055: * @author Stan Bailes
056: */
057: public class TypeVarChar implements Type, Externalizable {
058: public static final TypeVarChar typeVarChar = new TypeVarChar();
059:
060: int max = -1;
061:
062: public TypeVarChar() {
063: }
064:
065: public TypeVarChar(int max) {
066: this .max = max;
067: }
068:
069: public String getTypeName() {
070: return "VARCHAR";
071: }
072:
073: public int getMax() {
074: return max;
075: }
076:
077: public int getJDBCType() {
078: return Types.VARCHAR;
079: }
080:
081: public String getJDBCClassName() {
082: return "java.lang.Integer";
083: }
084:
085: public int getPrecision() {
086: return -1;
087: }
088:
089: public int getScale() {
090: return 0;
091: }
092:
093: public int getMaxPrecision() {
094: return -1;
095: }
096:
097: public int getMinScale() {
098: return -1;
099: }
100:
101: public int getMaxScale() {
102: return -1;
103: }
104:
105: public boolean isCharType() {
106: return true;
107: }
108:
109: public boolean isCaseSensitive() {
110: return false;
111: }
112:
113: public boolean isCurrency() {
114: return false;
115: }
116:
117: public boolean isSigned() {
118: return false;
119: }
120:
121: public int getDisplayWidth() {
122: return max;
123: }
124:
125: public String toString() {
126: StringBuffer sb = new StringBuffer();
127: sb.append("VARCHAR");
128: if (max > 0) {
129: sb.append('(');
130: sb.append(Integer.toString(max));
131: sb.append(')');
132: }
133: return sb.toString();
134: }
135:
136: /**
137: * We don't bother serializing the data, since Java serialization is
138: * only used for the type portion of a table column.
139: */
140: public void readExternal(ObjectInput in) throws IOException {
141: max = in.readInt();
142: }
143:
144: public void writeExternal(ObjectOutput out) throws IOException {
145: out.writeInt(max);
146: }
147:
148: public Value convert(Value v) throws ValueException {
149: return v.convert(this );
150: }
151:
152: public String getCreateParams() {
153: return "length";
154: }
155: }
|