View Javadoc
1 package com.bonevich.erj.model; 2 3 import com.bonevich.util.dependency.Dynamic; 4 5 /*** A class that represents ... 6 * 7 * @see Attribute 8 * @author Jeffrey D. Bonevich <bonevich@telocity.com> 9 */ 10 public final class DataType implements AttributeType, Cloneable 11 { 12 ////////////////////////////////////////////////////////// 13 // Constants - SQL92 draft standard data types 14 public static final DataType SQL92_CHAR = new DataType("CHAR", "8"); 15 public static final DataType SQL92_CHAR_VARYING = new DataType("VARCHAR", "8"); 16 public static final DataType SQL92_BIT = new DataType("BIT", "8"); 17 public static final DataType SQL92_BIT_VARYING = new DataType("BIT VARYING", "8"); 18 public static final DataType SQL92_NUMERIC = new DataType("NUMERIC", "8,2"); 19 public static final DataType SQL92_DECIMAL = new DataType("DEC", "8"); 20 public static final DataType SQL92_INTEGER = new DataType("INT"); 21 public static final DataType SQL92_SMALLINT = new DataType("SMALLINT"); 22 public static final DataType SQL92_FLOAT = new DataType("FLOAT"); 23 public static final DataType SQL92_REAL = new DataType("REAL"); 24 public static final DataType SQL92_DOUBLE = new DataType("DOUBLE PRECISION"); 25 public static final DataType SQL92_DATE = new DataType("DATE"); 26 public static final DataType SQL92_TIME = new DataType("TIME"); 27 public static final DataType SQL92_TIMESTAMP = new DataType("TIMESTAMP"); 28 public static final DataType SQL92_INTERVAL = new DataType("INTERVAL"); 29 30 public static final DataType[] SQL92_DATATYPE_ARRAY = { 31 SQL92_CHAR, 32 SQL92_CHAR_VARYING, 33 SQL92_BIT, 34 SQL92_BIT_VARYING, 35 SQL92_NUMERIC, 36 SQL92_DECIMAL, 37 SQL92_INTEGER, 38 SQL92_SMALLINT, 39 SQL92_FLOAT, 40 SQL92_REAL, 41 SQL92_DOUBLE, 42 SQL92_DATE, 43 SQL92_TIME, 44 SQL92_TIMESTAMP, 45 SQL92_INTERVAL 46 }; 47 48 ////////////////////////////////////////////////////////// 49 // Attributes 50 private String _name; 51 private boolean _descriptorFlag = false; 52 private String _defaultDescriptor = "16"; 53 private String _descriptor = null; 54 55 ///////////////////////////////////////////////////////// 56 // Dynamic Sentries 57 private Dynamic _dyn_descriptor = new Dynamic(); 58 59 ////////////////////////////////////////////////////////// 60 // Constructors 61 private DataType(DataType that) 62 { 63 setName(that.getName()); 64 setDescriptorFlag(that.takesDescriptor()); 65 setDefaultDescriptor(that.getDefaultDescriptor()); 66 setDescriptor(that.getDefaultDescriptor()); 67 } 68 public DataType(String name) 69 { 70 setName(name); 71 setDescriptorFlag(false); 72 } 73 public DataType(String name, String descriptor) 74 { 75 setName(name); 76 setDescriptorFlag(true); 77 setDefaultDescriptor(descriptor); 78 _descriptor = descriptor; 79 } 80 81 ////////////////////////////////////////////////////////// 82 // Getter/Setters 83 public String getName() 84 { 85 return _name; 86 } 87 private void setName(String name) 88 { 89 _name = name; 90 } 91 92 public boolean takesDescriptor() 93 { 94 return _descriptorFlag; 95 } 96 private void setDescriptorFlag(boolean takesDescriptor) 97 { 98 _descriptorFlag = takesDescriptor; 99 } 100 101 public String getDefaultDescriptor() 102 { 103 return _defaultDescriptor; 104 } 105 private void setDefaultDescriptor(String descriptor) 106 { 107 _defaultDescriptor = descriptor; 108 } 109 110 public String getDescriptor() 111 { 112 _dyn_descriptor.onGet(); 113 return _descriptor; 114 } 115 public void setDescriptor(String descriptor) 116 { 117 // we will not allow constants to have their descriptor set 118 if (isTypeConstant()) 119 { 120 System.err.println("Someone tried to set the descriptor on a DataType constant!!"); 121 return; 122 } 123 if ( !(_descriptor != null && _descriptor.equals(descriptor)) ) 124 { 125 _dyn_descriptor.onSet(); 126 _descriptor = descriptor; 127 } 128 } 129 130 private boolean isTypeConstant() 131 { 132 boolean found = false; 133 for(int i = 0; i < SQL92_DATATYPE_ARRAY.length; i++) 134 { 135 if (this == SQL92_DATATYPE_ARRAY[i]) 136 { 137 found = true; 138 break; 139 } 140 } 141 return found; 142 } 143 144 ////////////////////////////////////////////////////////// 145 // Operations 146 public Object clone() 147 { 148 return new DataType(this); 149 } 150 151 public boolean equals(Object rhs) 152 { 153 if (rhs != null && rhs instanceof DataType) 154 { 155 DataType that = (DataType)rhs; 156 if (that.getName().equals(getName())) 157 { 158 return true; 159 } 160 } 161 return false; 162 } 163 164 public String toString() 165 { 166 StringBuffer buf = new StringBuffer(getName()); 167 if (takesDescriptor()) 168 { 169 buf.append("("); 170 buf.append( 171 getDescriptor() != null 172 ? getDescriptor() 173 : getDefaultDescriptor() 174 ); 175 buf.append(")"); 176 } 177 return buf.toString(); 178 } 179 180 } /* end class DataType */

This page was automatically generated by Maven