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 PolicyInsert 19 extends TKExtendedPrepQuery 20 { 21 22 24 public static final String [] ORDER = 25 { 26 "WM_USER_ID", 27 "WM_ROLE_ID", 28 "WM_CONTEXT_ID", 29 "OBJECT_REFERENCE", 30 "OBJECT_TYPE", 31 "POLICY_ACCESS" 32 }; 33 34 public static final Object [][] TYPES = 35 { 36 {"WM_USER_ID", new Integer (Types.INTEGER)}, 37 {"WM_ROLE_ID", new Integer (Types.INTEGER)}, 38 {"WM_CONTEXT_ID", new Integer (Types.INTEGER)}, 39 {"OBJECT_REFERENCE", new Integer (Types.INTEGER)}, 40 {"OBJECT_TYPE", new Integer (Types.INTEGER)}, 41 {"POLICY_ACCESS", new Integer (Types.CHAR)} 42 }; 43 44 public static final boolean[] RELEVANTS = 45 { 46 true 47 }; 48 49 54 55 public static final String SQL = null; 56 57 protected static Class [] queryClasses = { 58 SelectIDWMPolicy.class, InsertWMPolicy.class, SelectWMPolicy.class }; 62 63 64 66 public boolean execute() { 67 try { 68 init(queryClasses); 69 70 if (aTKDBConnection.isAutoCommit()) { 71 aTKDBConnection.beginTransaction(); 72 } 73 74 queries[0].execute(); ResultSet rs = queries[0].fetchResultSet(); 76 int max = 1; 77 78 if (rs != null && rs.next()) { 79 max = rs.getInt(1) + 1; } 81 82 queries[1].setQueryParams("WM_POLICY_ID", new Integer (max)); 83 for (int i = 0; i < ORDER.length; i++) { 84 queries[1].setQueryParams(paramOrder[i], queryParams.get(paramOrder[i])); 85 } 86 queries[1].execute(); 88 queries[2].setQueryParams("MAX", new Integer (max)); 89 queries[2].execute(); 90 addResult(queries[2].fetchResultSet()); 92 if (aTKDBConnection.isAutoCommit()) { 93 aTKDBConnection.commitTransaction(); 94 } 95 } 96 catch (SQLException sqle) { 97 WebmanExceptionHandler.getException(sqle); 98 try { 99 aTKDBConnection.rollbackTransaction(); 100 } 101 catch (SQLException sqle2) { 102 WebmanExceptionHandler.getException(sqle2); 103 } 104 } 105 finally { 106 return hasResults(); 107 } 108 } 109 110 public void initQuery (Connection connection) 111 { 112 super.initQuery(connection, 113 true, 114 ORDER, 115 TYPES, 116 RELEVANTS, 117 SQL); 118 } 119 120 } 121 | Popular Tags |