1 21 package oracle.toplink.essentials.platform.database; 23 24 import java.io.*; 25 import java.util.*; 26 import oracle.toplink.essentials.exceptions.*; 27 import oracle.toplink.essentials.internal.helper.*; 28 import oracle.toplink.essentials.internal.databaseaccess.*; 29 import oracle.toplink.essentials.queryframework.*; 30 31 40 public class InformixPlatform extends oracle.toplink.essentials.platform.database.DatabasePlatform { 41 42 47 protected void appendDate(java.sql.Date date, Writer writer) throws IOException { 48 if (usesNativeSQL()) { 49 writer.write("'"); 50 writer.write(Helper.printDate(date)); 51 writer.write("'"); 52 } else { 53 super.appendDate(date, writer); 54 } 55 } 56 57 61 protected void appendInformixTimestamp(java.sql.Timestamp timestamp, Writer writer) throws IOException { 62 writer.write("'"); 63 writer.write(Helper.printTimestampWithoutNanos(timestamp)); 64 writer.write('.'); 65 66 String nanoString = Integer.toString(timestamp.getNanos()); 69 int numberOfZeros = 0; 70 for (int num = Math.min(9 - nanoString.length(), 3); num > 0; num--) { 71 writer.write('0'); 72 numberOfZeros++; 73 } 74 if ((nanoString.length() + numberOfZeros) > 3) { 75 nanoString = nanoString.substring(0, (3 - numberOfZeros)); 76 } 77 writer.write(nanoString); 78 writer.write("'"); 79 } 80 81 86 protected void appendCalendar(Calendar calendar, Writer writer) throws IOException { 87 if (usesNativeSQL()) { 88 appendInformixCalendar(calendar, writer); 89 } else { 90 super.appendCalendar(calendar, writer); 91 } 92 } 93 94 98 protected void appendInformixCalendar(Calendar calendar, Writer writer) throws IOException { 99 writer.write("'"); 100 writer.write(Helper.printCalendar(calendar)); 101 writer.write("'"); 102 } 103 104 109 protected void appendTime(java.sql.Time time, Writer writer) throws IOException { 110 if (usesNativeSQL()) { 111 writer.write("'"); 112 writer.write(Helper.printTime(time)); 113 writer.write("'"); 114 } else { 115 super.appendTime(time, writer); 116 } 117 } 118 119 124 protected void appendTimestamp(java.sql.Timestamp timestamp, Writer writer) throws IOException { 125 if (usesNativeSQL()) { 126 appendInformixTimestamp(timestamp, writer); 127 } else { 128 super.appendTimestamp(timestamp, writer); 129 } 130 } 131 132 protected Hashtable buildFieldTypes() { 133 Hashtable fieldTypeMapping; 134 135 fieldTypeMapping = new Hashtable(); 136 fieldTypeMapping.put(Boolean .class, new FieldTypeDefinition("SMALLINT default 0", false)); 137 138 fieldTypeMapping.put(Integer .class, new FieldTypeDefinition("INTEGER", false)); 139 fieldTypeMapping.put(Long .class, new FieldTypeDefinition("NUMERIC", 19)); 140 fieldTypeMapping.put(Float .class, new FieldTypeDefinition("FLOAT(16)", false)); 141 fieldTypeMapping.put(Double .class, new FieldTypeDefinition("FLOAT(32)", false)); 142 fieldTypeMapping.put(Short .class, new FieldTypeDefinition("SMALLINT", false)); 143 fieldTypeMapping.put(Byte .class, new FieldTypeDefinition("SMALLINT", false)); 144 fieldTypeMapping.put(java.math.BigInteger .class, new FieldTypeDefinition("DECIMAL", 32)); 145 fieldTypeMapping.put(java.math.BigDecimal .class, new FieldTypeDefinition("DECIMAL", 32).setLimits(32, -19, 19)); 146 fieldTypeMapping.put(Number .class, new FieldTypeDefinition("DECIMAL", 32).setLimits(32, -19, 19)); 147 148 fieldTypeMapping.put(String .class, new FieldTypeDefinition("VARCHAR", 255)); 149 fieldTypeMapping.put(Character .class, new FieldTypeDefinition("CHAR", 1)); 150 151 fieldTypeMapping.put(Byte [].class, new FieldTypeDefinition("BYTE", false)); 152 fieldTypeMapping.put(Character [].class, new FieldTypeDefinition("TEXT", false)); 153 fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BYTE", false)); 154 fieldTypeMapping.put(char[].class, new FieldTypeDefinition("TEXT", false)); 155 fieldTypeMapping.put(java.sql.Blob .class, new FieldTypeDefinition("BYTE", false)); 156 fieldTypeMapping.put(java.sql.Clob .class, new FieldTypeDefinition("TEXT", false)); 157 158 fieldTypeMapping.put(java.sql.Date .class, new FieldTypeDefinition("DATE", false)); 159 fieldTypeMapping.put(java.sql.Time .class, new FieldTypeDefinition("DATETIME HOUR TO SECOND", false)); 160 fieldTypeMapping.put(java.sql.Timestamp .class, new FieldTypeDefinition("DATETIME YEAR TO FRACTION(5)", false)); 161 162 return fieldTypeMapping; 163 } 164 165 169 public ValueReadQuery buildSelectQueryForNativeSequence() { 170 ValueReadQuery selectQuery = new ValueReadQuery(); 171 StringWriter writer = new StringWriter(); 172 writer.write("SELECT DISTINCT(DBINFO('sqlca.sqlerrd1')) FROM systables"); 173 selectQuery.setSQLString(writer.toString()); 174 return selectQuery; 175 } 176 177 182 public int getMaxFieldNameSize() { 183 return 18; 184 } 185 186 190 public String getSelectForUpdateString() { 191 return " FOR UPDATE"; 192 } 193 194 public boolean isInformix() { 195 return true; 196 } 197 198 203 public boolean isInformixOuterJoin() { 204 return true; 205 } 206 207 213 public Hashtable maximumNumericValues() { 214 Hashtable values = new Hashtable(); 215 216 values.put(Integer .class, new Integer (Integer.MAX_VALUE)); 217 values.put(Long .class, new Long (Long.MAX_VALUE)); 218 values.put(Double .class, new Double ((double)Float.MAX_VALUE)); 219 values.put(Short .class, new Short (Short.MAX_VALUE)); 220 values.put(Byte .class, new Byte (Byte.MAX_VALUE)); 221 values.put(Float .class, new Float (Float.MAX_VALUE)); 222 values.put(java.math.BigInteger .class, new java.math.BigInteger ("99999999999999999999999999999999999999")); 223 values.put(java.math.BigDecimal .class, new java.math.BigDecimal ("9999999999999999999.9999999999999999999")); 224 return values; 225 } 226 227 233 public Hashtable minimumNumericValues() { 234 Hashtable values = new Hashtable(); 235 236 values.put(Integer .class, new Integer (Integer.MIN_VALUE)); 237 values.put(Long .class, new Long (Long.MIN_VALUE)); 238 values.put(Double .class, new Double ((double)1.4012984643247149E-44)); values.put(Short .class, new Short (Short.MIN_VALUE)); 240 values.put(Byte .class, new Byte (Byte.MIN_VALUE)); 241 values.put(Float .class, new Float (Float.MIN_VALUE)); 242 values.put(java.math.BigInteger .class, new java.math.BigInteger ("-99999999999999999999999999999999999999")); 243 values.put(java.math.BigDecimal .class, new java.math.BigDecimal ("-9999999999999999999.9999999999999999999")); 244 return values; 245 } 246 247 251 public void printFieldIdentityClause(Writer writer) throws ValidationException { 252 try { 253 writer.write(" SERIAL"); 254 } catch (IOException ioException) { 255 throw ValidationException.fileError(ioException); 256 } 257 } 258 259 263 public boolean requiresProcedureCallBrackets() { 264 return false; 265 } 266 267 273 public boolean shouldNativeSequenceAcquireValueAfterInsert() { 274 return true; 275 } 276 277 281 public boolean shouldPrintConstraintNameAfter() { 282 return true; 283 } 284 285 289 public boolean shouldPrintOuterJoinInWhereClause() { 290 return false; 291 } 292 293 298 public boolean supportsNativeSequenceNumbers() { 299 return true; 300 } 301 } 302 | Popular Tags |