1 21 package oracle.toplink.essentials.platform.database; 23 24 import oracle.toplink.essentials.internal.databaseaccess.FieldTypeDefinition; 25 import oracle.toplink.essentials.internal.sessions.AbstractSession; 26 import oracle.toplink.essentials.internal.helper.DatabaseTable; 27 import oracle.toplink.essentials.exceptions.ValidationException; 28 import oracle.toplink.essentials.queryframework.ValueReadQuery; 29 30 import java.util.Vector ; 31 import java.io.Writer ; 32 import java.io.IOException ; 33 import java.sql.SQLException ; 34 import java.util.Hashtable ; 35 36 41 public class DerbyPlatform extends DB2Platform { 42 43 47 protected void appendByteArray(byte[] bytes, Writer writer) throws IOException { 48 super.appendByteArray(bytes, writer); 49 } 50 51 56 public ValueReadQuery getTimestampQuery() { 57 if (timestampQuery == null) { 58 timestampQuery = new ValueReadQuery(); 59 timestampQuery.setSQLString("VALUES CURRENT_TIMESTAMP"); 60 } 61 return timestampQuery; 62 63 } 64 65 public Vector getNativeTableInfo(String table, String creator, AbstractSession session) { 67 throw new RuntimeException ("Should never reach here"); 68 } 69 70 73 public String getProcedureEndString() { 74 return getBatchEndString(); 75 } 76 77 80 public String getProcedureBeginString() { 81 return getBatchBeginString(); 82 } 83 84 88 public String getInOutputProcedureToken() { 89 return "INOUT"; 90 } 91 92 96 public boolean shouldPrintOutputTokenAtStart() { 97 return false; 99 } 100 101 105 public boolean isDerby() { 106 return true; 107 } 108 109 public boolean isDB2() { 110 return false; 112 } 113 114 117 public boolean shouldIgnoreException(SQLException exception) { 118 return false; 120 } 121 122 123 126 protected String getCreateTempTableSqlSuffix() { 127 return " ON COMMIT DELETE ROWS NOT LOGGED"; 128 } 129 130 public boolean supportsNativeSequenceNumbers() { 131 return true; 132 } 133 134 140 public boolean shouldNativeSequenceAcquireValueAfterInsert() { 141 return true; 142 } 143 144 148 public ValueReadQuery buildSelectQueryForNativeSequence() { 149 ValueReadQuery selectQuery = new ValueReadQuery(); 150 selectQuery.setSQLString("values IDENTITY_VAL_LOCAL()"); 151 return selectQuery; 152 } 153 154 157 protected String getCreateTempTableSqlBodyForTable(DatabaseTable table) { 158 return null; 162 } 163 164 168 public void printFieldIdentityClause(Writer writer) throws ValidationException { 169 try { 170 writer.write(" GENERATED ALWAYS AS IDENTITY"); 171 } catch (IOException ioException) { 172 throw ValidationException.fileError(ioException); 173 } 174 } 175 176 protected Hashtable buildFieldTypes() { 177 Hashtable fieldTypeMapping = new Hashtable (); 178 179 fieldTypeMapping.put(Boolean .class, new FieldTypeDefinition("SMALLINT DEFAULT 0", false)); 180 181 fieldTypeMapping.put(Integer .class, new FieldTypeDefinition("INTEGER", false)); 182 fieldTypeMapping.put(Long .class, new FieldTypeDefinition("BIGINT", false)); 183 fieldTypeMapping.put(Float .class, new FieldTypeDefinition("FLOAT")); 184 fieldTypeMapping.put(Double .class, new FieldTypeDefinition("FLOAT", false)); 185 fieldTypeMapping.put(Short .class, new FieldTypeDefinition("SMALLINT", false)); 186 fieldTypeMapping.put(Byte .class, new FieldTypeDefinition("SMALLINT", false)); 187 fieldTypeMapping.put(java.math.BigInteger .class, new FieldTypeDefinition("BIGINT", false)); 188 fieldTypeMapping.put(java.math.BigDecimal .class, new FieldTypeDefinition("DECIMAL")); 189 fieldTypeMapping.put(Number .class, new FieldTypeDefinition("DECIMAL")); 190 191 fieldTypeMapping.put(String .class, new FieldTypeDefinition("VARCHAR", 255)); 192 fieldTypeMapping.put(Character .class, new FieldTypeDefinition("CHAR", 1)); 193 fieldTypeMapping.put(Byte [].class, new FieldTypeDefinition("BLOB", 64000)); 194 fieldTypeMapping.put(Character [].class, new FieldTypeDefinition("CLOB", 64000)); 195 fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BLOB", 64000)); 196 fieldTypeMapping.put(char[].class, new FieldTypeDefinition("CLOB", 64000)); 197 fieldTypeMapping.put(java.sql.Blob .class, new FieldTypeDefinition("BLOB", 64000)); 198 fieldTypeMapping.put(java.sql.Clob .class, new FieldTypeDefinition("CLOB", 64000)); 199 200 fieldTypeMapping.put(java.sql.Date .class, new FieldTypeDefinition("DATE", false)); 201 fieldTypeMapping.put(java.sql.Time .class, new FieldTypeDefinition("TIME", false)); 202 fieldTypeMapping.put(java.sql.Timestamp .class, new FieldTypeDefinition("TIMESTAMP", false)); 203 204 return fieldTypeMapping; 205 } 206 207 } 208 | Popular Tags |