1 package com.teamkonzept.db; 2 3 import java.sql.*; 4 import java.util.Enumeration ; 5 import java.util.Vector ; 6 7 import com.teamkonzept.lib.*; 8 9 public class TKDBVectorInterface extends TKDBInterface { 10 11 String [] tables; 12 13 Class [] putQueries; 14 Class [] getQueries; 15 Class deleteQuery; 16 17 public TKDBVectorInterface ( 18 Class newPrimQuery, Class updatePrimQuery, 19 Class getPrimQuery, Class delPrimQuery, 20 String [] tables, 21 Class [] putQueries, Class [] getQueries, 22 Class deleteQuery ) 23 { 24 super(newPrimQuery, updatePrimQuery, getPrimQuery, delPrimQuery); 25 this.tables = tables; 26 this.deleteQuery = deleteQuery; 27 this.putQueries = putQueries; 28 this.getQueries = getQueries; 29 } 30 31 public void delEntry (TKDBVectorData dbData) throws SQLException { 32 33 try { 34 TKDBManager.beginTransaction(); 35 36 delete(dbData); 37 super.delEntry(dbData); 38 39 TKDBManager.commitTransaction(); 40 } 41 catch(Throwable t){ 42 TKDBManager.safeRollbackTransaction(t); 43 } 44 } 45 46 47 48 private void delete (TKDBVectorData dbData) throws SQLException { 49 50 if ( deleteQuery == null ) { 51 return; 52 } 53 54 TKQuery query = TKDBManager.newQuery(deleteQuery); 55 56 dbData.insertIntoQuery( query ); 57 query.execute(); 58 query.close(); 59 } 60 61 public void insertVectorElements(TKDBTableData d, TKQuery query, String table, int i) 62 throws SQLException 63 { 64 d.insertIntoQuery( query ); 65 } 66 67 public void doNewEntryTables(TKDBVectorData dbData) 68 throws SQLException 69 { 70 int lists = tables.length; 71 for( int i=0; i<lists; i++ ) { 72 73 String table = tables[i]; 74 75 Enumeration eCN = dbData.getVector(table).elements(); 76 while( eCN.hasMoreElements() ) { 77 TKDBTableData d = (TKDBTableData) eCN.nextElement(); 78 d.updatePrimary (dbData); 79 } 80 } 81 } 82 83 public void newEntryTables(TKDBVectorData dbData) 84 throws SQLException 85 { 86 try{ 87 TKDBManager.beginTransaction(); 88 doNewEntryTables (dbData); 89 TKDBManager.commitTransaction(); 90 } 91 catch(Throwable t){ 92 TKDBManager.safeRollbackTransaction(t); 93 } 94 } 95 96 public void newEntry(TKDBVectorData dbData) 97 throws SQLException 98 { 99 try{ 100 TKDBManager.beginTransaction(); 101 102 super.newEntry(dbData); 103 doNewEntryTables (dbData); 104 TKDBManager.commitTransaction(); 105 } 106 catch(Throwable t){ 107 TKDBManager.safeRollbackTransaction(t); 108 } 109 } 110 111 public void doPutEntryTables(TKDBVectorData dbData) 112 throws SQLException 113 { 114 delete(dbData); 115 116 int lists = tables.length; 117 for( int i=0; i<lists; i++ ) { 118 119 TKQuery query = TKDBManager.newQuery(putQueries[i]); 120 String table = tables[i]; 121 int rc = 0; 122 Enumeration eCN = dbData.getVector(table).elements(); 123 while( eCN.hasMoreElements() ) { 124 TKDBTableData d = (TKDBTableData) eCN.nextElement(); 125 insertVectorElements( d, query, table, rc++ ); 126 query.execute(); 127 query.close(); 128 } 129 } 130 } 131 132 133 public void putEntryTables(TKDBVectorData dbData) 134 throws SQLException 135 { 136 try{ 137 TKDBManager.beginTransaction(); 138 doPutEntryTables (dbData); 139 TKDBManager.commitTransaction(); 140 } 141 catch(Throwable t){ 142 TKDBManager.safeRollbackTransaction(t); 143 } 144 } 145 146 147 public void putEntry(TKDBVectorData dbData) 148 throws SQLException 149 { 150 try{ 151 TKDBManager.beginTransaction(); 152 153 super.updateEntry(dbData); 154 doPutEntryTables (dbData); 155 TKDBManager.commitTransaction(); 156 } 157 catch(Throwable t){ 158 TKDBManager.safeRollbackTransaction(t); 159 } 160 } 161 162 public void getEntryTables(TKDBVectorData dbData) 163 throws SQLException 164 { 165 int lists = tables.length; 166 for( int i=0; i<lists; i++ ){ 167 168 String table = tables[i]; 169 if (dbData.isIgnoreTable(table)) continue; 170 171 TKQuery query = TKDBManager.newQuery(getQueries[i]); 172 173 dbData.insertIntoQuery( query ); 174 query.execute(); 175 ResultSet rs = query.fetchResultSet(); 176 TKDBTableData prototype = dbData.getProtoType( table ); 177 TKVector v = dbData.getVector( table ); 178 while(rs.next()) { 179 v.addElement( prototype.newFromResultSet( rs ) ); 180 } 181 query.close(); 182 } 183 } 184 185 public void getEntry(TKDBVectorData dbData) 186 throws SQLException 187 { 188 super.getEntry(dbData); 189 getEntryTables (dbData); 190 } 191 } 192 193 | Popular Tags |