1 21 package oracle.toplink.essentials.platform.database; 23 24 import java.io.*; 25 import java.util.Calendar ; 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 import oracle.toplink.essentials.expressions.ExpressionOperator; 29 import oracle.toplink.essentials.internal.databaseaccess.FieldTypeDefinition; 30 import oracle.toplink.essentials.internal.expressions.RelationExpression; 31 import oracle.toplink.essentials.internal.helper.Helper; 32 import oracle.toplink.essentials.queryframework.ValueReadQuery; 33 34 public class TimesTenPlatform extends DatabasePlatform { 35 36 private boolean supportsForeignKeyConstraints; 38 39 public TimesTenPlatform() { 40 supportsForeignKeyConstraints = true; 41 } 42 43 47 protected void appendByteArray(byte[] bytes, Writer writer) throws IOException { 48 if (usesNativeSQL()) { 49 writer.write("Ox"); 50 Helper.writeHexString(bytes, writer); 51 } else { 52 super.appendByteArray(bytes, writer); 53 } 54 } 55 56 60 protected void appendDate(java.sql.Date date, Writer writer) throws IOException { 61 if (usesNativeSQL()) { 62 writer.write("DATE '"); 63 writer.write(Helper.printDate(date)); 64 writer.write("'"); 65 } else { 66 super.appendDate(date, writer); 67 } 68 } 69 70 74 protected void appendTime(java.sql.Time time, Writer writer) throws IOException { 75 if (usesNativeSQL()) { 76 writer.write("TIME '"); 77 writer.write(Helper.printTime(time)); 78 writer.write("'"); 79 } else { 80 super.appendTime(time, writer); 81 } 82 } 83 84 88 protected void appendTimestamp(java.sql.Timestamp timestamp, Writer writer) throws IOException { 89 if (usesNativeSQL()) { 90 writer.write("TIMESTAMP '"); 91 writer.write(Helper.printTimestampWithoutNanos(timestamp)); 92 writer.write("'"); 93 } else { 94 super.appendTimestamp(timestamp, writer); 95 } 96 } 97 98 102 protected void appendCalendar(Calendar calendar, Writer writer) throws IOException { 103 if (usesNativeSQL()) { 104 writer.write("TIMESTAMP '"); 105 writer.write(Helper.printCalendarWithoutNanos(calendar)); 106 writer.write("'"); 107 } else { 108 super.appendCalendar(calendar, writer); 109 } 110 } 111 112 115 protected Hashtable buildFieldTypes() { 116 Hashtable fieldTypeMapping; 117 118 fieldTypeMapping = new Hashtable (); 119 fieldTypeMapping.put(Boolean .class, new FieldTypeDefinition("TINYINT", false)); 120 121 fieldTypeMapping.put(Integer .class, new FieldTypeDefinition("INTEGER", false)); 122 fieldTypeMapping.put(Long .class, new FieldTypeDefinition("BIGINT", false)); 123 fieldTypeMapping.put(Float .class, new FieldTypeDefinition("FLOAT", false)); 124 fieldTypeMapping.put(Double .class, new FieldTypeDefinition("DOUBLE", false)); 125 fieldTypeMapping.put(Short .class, new FieldTypeDefinition("SMALLINT", false)); 126 fieldTypeMapping.put(Byte .class, new FieldTypeDefinition("TINYINT", false)); 127 fieldTypeMapping.put(java.math.BigInteger .class, new FieldTypeDefinition("BIGINT", false)); 128 fieldTypeMapping.put(java.math.BigDecimal .class, new FieldTypeDefinition("DECIMAL(38)", false)); 129 fieldTypeMapping.put(Number .class, new FieldTypeDefinition("DECIMAL(38)", false)); 130 131 fieldTypeMapping.put(String .class, new FieldTypeDefinition("VARCHAR", 255)); 132 fieldTypeMapping.put(Character .class, new FieldTypeDefinition("CHAR", 1)); 133 134 fieldTypeMapping.put(Byte [].class, new FieldTypeDefinition("VARBINARY", 64000)); 135 fieldTypeMapping.put(Character [].class, new FieldTypeDefinition("VARCHAR", 64000)); 136 fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("VARBINARY", 64000)); 137 fieldTypeMapping.put(char[].class, new FieldTypeDefinition("VARCHAR", 64000)); 138 fieldTypeMapping.put(java.sql.Blob .class, new FieldTypeDefinition("VARBINARY", 64000)); 139 fieldTypeMapping.put(java.sql.Clob .class, new FieldTypeDefinition("VARCHAR", 64000)); 140 141 fieldTypeMapping.put(java.sql.Date .class, new FieldTypeDefinition("DATE", false)); 142 fieldTypeMapping.put(java.sql.Time .class, new FieldTypeDefinition("TIME", false)); 143 fieldTypeMapping.put(java.sql.Timestamp .class, new FieldTypeDefinition("TIMESTAMP", false)); 144 145 return fieldTypeMapping; 146 } 147 148 154 public ValueReadQuery buildSelectQueryForNativeSequence(String seqName, Integer size) { 155 return new ValueReadQuery("SELECT " + getQualifiedSequenceName(seqName) + ".NEXTVAL FROM DUAL"); 156 } 157 158 162 public String getCreateViewString() { 163 return "CREATE MATERIALIZED VIEW "; 164 } 165 166 169 protected String getQualifiedSequenceName(String seqName) { 170 if (getTableQualifier().equals("")) { 171 return seqName; 172 } else { 173 return getTableQualifier() + "." + seqName; 174 } 175 } 176 177 181 public String getSelectForUpdateString() { 182 return " FOR UPDATE"; 183 } 184 185 190 public ValueReadQuery getTimestampQuery() { 191 if (timestampQuery == null) { 192 timestampQuery = new ValueReadQuery(); 193 timestampQuery.setSQLString("SELECT SYSDATE FROM DUAL"); 194 } 195 return timestampQuery; 196 } 197 198 201 protected void initializePlatformOperators() { 202 super.initializePlatformOperators(); 203 addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Concat, "CONCAT")); 204 addOperator(operatorOuterJoin()); 205 addOperator(ExpressionOperator.ifNull()); 206 } 207 208 211 public boolean isTimesTen() { 212 return true; 213 } 214 215 218 protected ExpressionOperator operatorOuterJoin() { 219 ExpressionOperator result = new ExpressionOperator(); 220 result.setSelector(ExpressionOperator.EqualOuterJoin); 221 Vector v = new Vector (2); 222 v.addElement(" (+) = "); 223 result.printsAs(v); 224 result.bePostfix(); 225 result.setNodeClass(RelationExpression.class); 226 return result; 227 } 228 229 232 public boolean shouldPrintOuterJoinInWhereClause() { 233 return true; 234 } 235 236 240 public boolean supportsNativeSequenceNumbers() { 241 return true; 242 } 243 244 public boolean supportsForeignKeyConstraints() { 245 return supportsForeignKeyConstraints; 246 } 247 248 public void setSupportsForeignKeyConstraints(boolean supportsForeignKeyConstraints) { 249 this.supportsForeignKeyConstraints = supportsForeignKeyConstraints; 250 } 251 } | Popular Tags |