1 30 31 32 package org.hsqldb.util; 33 34 import java.sql.ResultSet ; 35 import java.sql.ResultSetMetaData ; 36 import java.sql.SQLException ; 37 38 41 47 class OracleTransferHelper extends TransferHelper { 48 49 private final int ORACLE = 0; 50 private final int HSQLDB = 1; 51 String [][] Funcs = { 52 { 53 "now()", "\'now\'" 54 } 55 }; 56 57 OracleTransferHelper() { 58 59 super(); 60 61 System.out.println("simple init of OracleTransferHelper"); 62 } 63 64 OracleTransferHelper(TransferDb database, Traceable t, String q) { 65 super(database, t, q); 66 } 67 68 void set(TransferDb database, Traceable t, String q) { 69 70 super.set(database, t, q); 71 72 String dateFormatStmnt = 74 "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"; 75 76 System.out.println("dateFormatStmnt: " + dateFormatStmnt); 77 78 try { 79 tracer.trace("Executing " + dateFormatStmnt); 80 database.execute(dateFormatStmnt); 81 } catch (Exception e) { 82 tracer.trace("Ignoring error " + e.getMessage()); 83 System.out.println("Ignoring error " + e.getMessage()); 84 } 85 } 86 87 String fixupColumnDefRead(TransferTable t, ResultSetMetaData meta, 88 String columnType, ResultSet columnDesc, 89 int columnIndex) throws SQLException { 90 return fixupColumnDefRead(t.Stmts.sDestTable, meta, columnType, 91 columnDesc, columnIndex); 92 } 93 94 String fixupColumnDefWrite(TransferTable t, ResultSetMetaData meta, 95 String columnType, ResultSet columnDesc, 96 int columnIndex) throws SQLException { 97 98 if (columnType.equals("SERIAL")) { 99 String SeqName = new String ("_" + columnDesc.getString(4) 100 + "_seq"); 101 int spaceleft = 31 - SeqName.length(); 102 103 if (t.Stmts.sDestTable.length() > spaceleft) { 104 SeqName = t.Stmts.sDestTable.substring(0, spaceleft) 105 + SeqName; 106 } else { 107 SeqName = t.Stmts.sDestTable + SeqName; 108 } 109 110 String DropSequence = "DROP SEQUENCE " + SeqName + ";"; 111 112 t.Stmts.sDestDrop += DropSequence; 113 } 114 115 for (int Idx = 0; Idx < Funcs.length; Idx++) { 116 String HSQLDB_func = Funcs[Idx][HSQLDB]; 117 int iStartPos = columnType.indexOf(HSQLDB_func); 118 119 if (iStartPos >= 0) { 120 String NewColumnType = columnType.substring(0, iStartPos); 121 122 NewColumnType += Funcs[Idx][ORACLE]; 123 NewColumnType += columnType.substring(iStartPos 124 + HSQLDB_func.length()); 125 columnType = NewColumnType; 126 } 127 } 128 129 return (columnType); 130 } 131 132 void beginDataTransfer() { 133 134 try { 135 db.setAutoCommit(false); 136 } catch (Exception e) {} 137 } 138 139 void endDataTransfer() { 140 141 try { 142 db.commit(); 143 } catch (Exception e) {} 144 } 145 146 String fixupColumnDefRead(String aTableName, ResultSetMetaData meta, 147 String columnType, ResultSet columnDesc, 148 int columnIndex) throws SQLException { 149 150 String SeqName = new String ("_" + columnDesc.getString(4) + "_seq"); 151 int spaceleft = 31 - SeqName.length(); 152 153 if (aTableName.length() > spaceleft) { 154 SeqName = aTableName.substring(0, spaceleft) + SeqName; 155 } else { 156 SeqName = aTableName + SeqName; 157 } 158 159 String CompareString = "nextval(\'\"" + SeqName + "\"\'"; 160 161 if (columnType.indexOf(CompareString) >= 0) { 162 163 columnType = "SERIAL"; 165 } 166 167 for (int Idx = 0; Idx < Funcs.length; Idx++) { 168 String ORACLE_func = Funcs[Idx][ORACLE]; 169 int iStartPos = columnType.indexOf(ORACLE_func); 170 171 if (iStartPos >= 0) { 172 String NewColumnType = columnType.substring(0, iStartPos); 173 174 NewColumnType += Funcs[Idx][HSQLDB]; 175 NewColumnType += columnType.substring(iStartPos 176 + ORACLE_func.length()); 177 columnType = NewColumnType; 178 } 179 } 180 181 return (columnType); 182 } 183 } 184 | Popular Tags |