1 package com.teamkonzept.webman.mainint.db.queries.postgresql; 2 3 import java.util.Enumeration ; 4 import java.sql.*; 5 import java.io.*; 6 import com.teamkonzept.db.*; 7 import com.teamkonzept.webman.mainint.db.queries.CheckTableExistence; 8 import com.teamkonzept.webman.mainint.db.queries.content.*; 9 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 10 import com.teamkonzept.lib.TKNull; 11 12 25 public class TKDBContentTreeGetOpen extends TKExtendedPrepQuery 26 { 27 28 public final static boolean ISPREPARED = true; 29 public final static String [] PARAMORDER = { "NODE_ID" }; 30 public final static Object [][] TYPES = null; 31 public final static boolean[] SETRELEVANTS = { true }; 32 33 private final static int QUERY_CHECK_EXISTENCE = 0; 34 private final static int QUERY_SELECT_CONTENT_NODE_ID = 1; 35 private final static int QUERY_SELECT_LEFT_RIGHT = 2; 36 private final static int QUERY_CREATE_TEMP_CONTENT_NODE_ID = 3; 37 private final static int QUERY_CREATE_TEMP_CONTENT_NODE_ID_NODE_ID = 4; 38 private final static int QUERY_INSERT_INTO_TEMP = 5; 39 private final static int QUERY_INSERT_TEMP_TABLE = 6; 40 private final static int QUERY_UPDATE_TEMP = 7; 41 private final static int QUERY_UPDATE_TEMP_SECOND = 8; 42 private final static int QUERY_SELECT_FROM_CONTENT = 9; 43 private final static int QUERY_DROP_TEMP_CONTENT_NODE_ID = 10; 44 private final static int QUERY_DROP_TEMP_CONTENT_NODE_ID_NODE_ID = 11; 45 46 protected static Class [] queryClasses = { 47 CheckTableExistence.class, SelectContentNodeIdFromContentTree.class, SelectLeftRightNrFromContentTree.class, CreateTempTableContentNodeId.class, CreateTempTableContentNodeIdNodeId.class, InsertIntoTempSelectContentNodeIdLeftRightFromContentTree.class, InsertTempTableContentNodeIdNodeId.class, UpdateTempTableContentNodeIdNodeId.class, UpdateTempTableContentNodeIdNodeId2.class, SelectFromContentTreeContentInstanceTempTable.class, DropTempTableContentNodeId.class, DropTempTableContentNodeIdNodeId.class }; 60 61 public boolean execute() 62 { 63 try 64 { 65 init(queryClasses); 67 Object nid = queryParams.get("NODE_ID"); 69 70 boolean isNotOpen = aTKDBConnection.isAutoCommit(); 71 72 if (isNotOpen) 73 { 74 TKDBManager.beginTransaction(); } 76 77 if (nid == null || nid instanceof TKNull) 79 { 80 queries[QUERY_SELECT_CONTENT_NODE_ID].execute(); 82 ResultSet rs = queries[QUERY_SELECT_CONTENT_NODE_ID].fetchResultSet(); 83 if (rs != null && rs.next()) 84 { 85 nid = rs.getObject(1); 86 } 87 } 88 Object lnr = null; 90 Object rnr = null; 91 queries[QUERY_SELECT_LEFT_RIGHT].setQueryParams("NODE_ID", nid); 92 queries[QUERY_SELECT_LEFT_RIGHT].execute(); 93 ResultSet rs = queries[QUERY_SELECT_LEFT_RIGHT].fetchResultSet(); 94 if (rs != null && rs.next()) 95 { 96 lnr = rs.getObject(1); 97 rnr = rs.getObject(2); 98 } 99 100 queries[QUERY_CHECK_EXISTENCE].setQueryParams("TABLE_NAME", "webman_temp"); queries[QUERY_CHECK_EXISTENCE].execute(); 102 ResultSet exist = queries[QUERY_CHECK_EXISTENCE].fetchResultSet(); 103 if (exist != null && exist.next()) 104 { 105 queries[QUERY_DROP_TEMP_CONTENT_NODE_ID].execute(); 106 } 107 queries[QUERY_CREATE_TEMP_CONTENT_NODE_ID].execute(); 109 110 queries[QUERY_CHECK_EXISTENCE].setQueryParams("TABLE_NAME", "webman_temp_2"); queries[QUERY_CHECK_EXISTENCE].execute(); 112 exist = queries[QUERY_CHECK_EXISTENCE].fetchResultSet(); 113 if (exist != null && exist.next()) 114 { 115 queries[QUERY_DROP_TEMP_CONTENT_NODE_ID_NODE_ID].execute(); 116 } 117 queries[QUERY_CREATE_TEMP_CONTENT_NODE_ID_NODE_ID].execute(); 119 120 124 queries[QUERY_INSERT_INTO_TEMP].setQueryParams("LEFT_NR", lnr); 127 queries[QUERY_INSERT_INTO_TEMP].setQueryParams("RIGHT_NR", rnr); 128 queries[QUERY_INSERT_INTO_TEMP].execute(); 129 130 queries[QUERY_INSERT_TEMP_TABLE].execute(); 135 136 queries[QUERY_UPDATE_TEMP].execute(); 147 148 queries[QUERY_UPDATE_TEMP_SECOND].execute(); 154 163 164 queries[QUERY_SELECT_FROM_CONTENT].execute(); 165 166 queries[QUERY_DROP_TEMP_CONTENT_NODE_ID].execute(); 167 queries[QUERY_DROP_TEMP_CONTENT_NODE_ID_NODE_ID].execute(); 168 169 addResult(queries[QUERY_SELECT_FROM_CONTENT].fetchResultSet()); 170 171 if (isNotOpen) 172 { 173 aTKDBConnection.commitTransaction(); } 175 176 } 177 catch(Throwable t) 178 { 179 TKDBManager.safeRollbackTransaction(t); 180 } 181 return hasResults(); 182 } 183 184 public void initQuery(Connection con) 185 { 186 super.initQuery(con, 187 ISPREPARED, PARAMORDER, TYPES, SETRELEVANTS, null); 188 } 189 } 190 | Popular Tags |