1 package de.webman.acl.db.queries; 2 3 import java.sql.Connection ; 4 import java.sql.Types ; 5 import java.sql.SQLException ; 6 import java.sql.ResultSet ; 7 import com.teamkonzept.db.*; 8 import com.teamkonzept.webman.mainint.db.queries.accesscontrol.*; 9 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 10 11 18 public class UserInsert 19 extends TKExtendedPrepQuery 20 { 21 22 24 public static final String [] ORDER = 25 { 26 "NAME", 27 "LOGIN", 28 "TYPE" 29 }; 30 31 public static final Object [][] TYPES = 32 { 33 {"NAME", new Integer (Types.VARCHAR)}, 34 {"LOGIN", new Integer (Types.VARCHAR)}, 35 {"TYPE", new Integer (Types.CHAR)} 36 }; 37 38 public static final boolean[] RELEVANTS = 39 { 40 true 41 }; 42 43 48 49 protected static Class [] queryClasses = { 50 SelectIDWMUser.class, 51 InsertWMUser.class, 52 SelectWMUser.class 53 }; 54 55 57 public boolean execute() { 58 try { 59 init(queryClasses); 60 61 boolean isNotOpen = aTKDBConnection.isAutoCommit(); 62 if (isNotOpen) { 63 aTKDBConnection.beginTransaction(); } 65 queries[0].execute(); ResultSet rs = queries[0].fetchResultSet(); 67 Integer wmUserId = null; 68 if (rs != null && rs.next()) { 69 int max = 1; 70 max = rs.getInt(1) + 1; wmUserId = new Integer (max); 72 } 73 74 queries[1].setQueryParams("WM_USER_ID", wmUserId); 75 queries[1].setQueryParams("NAME", queryParams.get("NAME")); 76 queries[1].setQueryParams("LOGIN", queryParams.get("LOGIN")); 77 queries[1].setQueryParams("TYPE", queryParams.get("TYPE")); 78 queries[1].execute(); 80 queries[2].setQueryParams("WM_USER_ID", wmUserId); 81 queries[2].execute(); addResult(queries[2].fetchResultSet()); 83 84 if (isNotOpen) { 85 aTKDBConnection.commitTransaction(); 86 } 87 88 } 89 catch (SQLException sqle) { 90 WebmanExceptionHandler.getException(sqle); 91 try { 92 aTKDBConnection.rollbackTransaction(); 93 } 94 catch (SQLException sqle2) { 95 WebmanExceptionHandler.getException(sqle2); 96 } 97 } 98 finally { 99 return hasResults(); 100 } 101 } 102 103 public void initQuery (Connection connection) 104 { 105 super.initQuery(connection, 106 true, 107 ORDER, 108 TYPES, 109 RELEVANTS, 110 null); 111 } 112 113 } 114 | Popular Tags |