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