1 21 22 package org.apache.derbyTesting.functionTests.util; 23 24 import org.apache.derby.iapi.db.*; 25 import java.sql.*; 26 import java.math.BigDecimal ; 27 import java.math.BigInteger ; 28 29 32 public class Triggers 33 { 34 private Triggers() 35 { 36 } 37 38 public static String triggerFiresMinimal(String string) throws Throwable 39 { 40 System.out.println("TRIGGER: " + "<"+string+">"); 41 return ""; 42 } 43 44 public static String triggerFires(String string) throws Throwable 45 { 46 TriggerExecutionContext tec = Factory.getTriggerExecutionContext(); 47 System.out.println("TRIGGER: " + "<"+string+"> on statement "+tec.getEventStatementText()); 48 printTriggerChanges(); 49 return ""; 50 } 51 52 public static int doNothingInt() throws Throwable 53 { 54 return 1; 55 } 56 57 public static void doNothing() throws Throwable 58 {} 59 60 public static int doConnCommitInt() throws Throwable 61 { 62 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 63 conn.commit(); 64 return 1; 65 } 66 67 public static void doConnCommit() throws Throwable 68 { 69 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 70 conn.commit(); 71 } 72 73 public static void doConnRollback() throws Throwable 74 { 75 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 76 conn.rollback(); 77 } 78 79 public static void doConnectionSetIsolation() throws Throwable 80 { 81 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 82 conn.setTransactionIsolation(conn.TRANSACTION_SERIALIZABLE); 83 } 84 85 public static int doConnStmtIntNoRS(String text) throws Throwable 86 { 87 doConnStmtNoRS(text); 88 return 1; 89 } 90 public static void doConnStmtNoRS(String text) throws Throwable 91 { 92 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 93 Statement stmt = conn.createStatement(); 94 stmt.execute(text); 95 } 96 97 public static int doConnStmtInt(String text) throws Throwable 98 { 99 doConnStmt(text); 100 return 1; 101 } 102 public static void doConnStmt(String text) throws Throwable 103 { 104 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 105 Statement stmt = conn.createStatement(); 106 if (stmt.execute(text)) 107 { 108 ResultSet rs = stmt.getResultSet(); 109 while (rs.next()) 110 {} 111 rs.close(); 112 } 113 stmt.close(); 114 conn.close(); 115 } 116 117 public static void getConnection() throws Throwable 118 { 119 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 120 conn.close(); 121 System.out.println("getConnection() called"); 122 } 123 static void zipThroughRs(ResultSet s) throws SQLException 125 { 126 if (s == null) 127 return; 128 129 while (s.next()) ; 130 } 131 132 private static void printTriggerChanges() throws Throwable 133 { 134 TriggerExecutionContext tec = Factory.getTriggerExecutionContext(); 135 System.out.println("BEFORE RESULT SET"); 136 dumpRS(tec.getOldRowSet()); 137 System.out.println("\nAFTER RESULT SET"); 138 dumpRS(tec.getNewRowSet()); 139 } 140 141 private static void dumpRS(ResultSet s) throws SQLException 143 { 144 if (s == null) 145 { 146 System.out.println("<NULL>"); 147 return; 148 } 149 150 ResultSetMetaData rsmd = s.getMetaData(); 151 152 int numCols = rsmd.getColumnCount(); 154 155 if (numCols <= 0) 156 { 157 System.out.println("(no columns!)"); 158 return; 159 } 160 161 StringBuffer heading = new StringBuffer ("\t "); 162 StringBuffer underline = new StringBuffer ("\t "); 163 164 int len; 165 for (int i=1; i<=numCols; i++) 167 { 168 if (i > 1) 169 { 170 heading.append(","); 171 underline.append(" "); 172 } 173 len = heading.length(); 174 heading.append(rsmd.getColumnLabel(i)); 175 len = heading.length() - len; 176 for (int j = len; j > 0; j--) 177 { 178 underline.append("-"); 179 } 180 } 181 System.out.println(heading.toString()); 182 System.out.println(underline.toString()); 183 184 185 StringBuffer row = new StringBuffer (); 186 while (s.next()) 188 { 189 row.append("\t{"); 190 for (int i=1; i<=numCols; i++) 193 { 194 if (i > 1) row.append(","); 195 row.append(s.getString(i)); 196 } 197 row.append("}\n"); 198 } 199 System.out.println(row.toString()); 200 s.close(); 201 } 202 203 public static long returnPrimLong(long x) 204 { 205 return x; 206 } 207 208 public static Long returnLong(Long x) 209 { 210 return x; 211 } 212 213 214 } | Popular Tags |