1 21 22 package org.apache.derby.impl.tools.dblook; 23 24 import java.sql.Connection ; 25 import java.sql.Statement ; 26 import java.sql.PreparedStatement ; 27 import java.sql.ResultSet ; 28 import java.sql.SQLException ; 29 30 import java.util.HashMap ; 31 import java.util.ArrayList ; 32 import java.util.StringTokenizer ; 33 34 import org.apache.derby.tools.dblook; 35 36 public class DB_Check { 37 38 45 46 public static void doChecks(Connection conn) 47 throws SQLException 48 { 49 50 Statement stmt = conn.createStatement(); 51 ResultSet rs = stmt.executeQuery("SELECT CS.CONSTRAINTNAME, " + 52 "CS.TABLEID, CS.SCHEMAID, CK.CHECKDEFINITION FROM SYS.SYSCONSTRAINTS CS, " + 53 "SYS.SYSCHECKS CK WHERE CS.CONSTRAINTID = " + 54 "CK.CONSTRAINTID AND CS.STATE != 'D' ORDER BY CS.TABLEID"); 55 56 boolean firstTime = true; 57 while (rs.next()) { 58 59 String tableId = rs.getString(2); 60 String tableName = dblook.lookupTableId(tableId); 61 if (dblook.isExcludedTable(tableName)) 62 continue; 64 65 if (firstTime) { 66 Logs.reportString("----------------------------------------------"); 67 Logs.reportMessage("DBLOOK_ChecksHeader"); 68 Logs.reportString("----------------------------------------------\n"); 69 } 70 71 StringBuffer chkString = createCheckString(tableName, rs); 72 Logs.writeToNewDDL(chkString.toString()); 73 Logs.writeStmtEndToNewDDL(); 74 Logs.writeNewlineToNewDDL(); 75 firstTime = false; 76 77 } 78 79 stmt.close(); 80 rs.close(); 81 return; 82 83 } 84 85 93 94 private static StringBuffer createCheckString (String tableName, 95 ResultSet aCheck) throws SQLException 96 { 97 98 StringBuffer sb = new StringBuffer ("ALTER TABLE "); 99 sb.append(tableName); 100 sb.append(" ADD"); 101 102 String constraintName = dblook.addQuotes( 103 dblook.expandDoubleQuotes(aCheck.getString(1))); 104 sb.append(" CONSTRAINT "); 105 sb.append(constraintName); 106 sb.append(" CHECK "); 107 sb.append(dblook.removeNewlines(aCheck.getString(4))); 108 109 return sb; 110 111 } 112 113 } 114 | Popular Tags |