1 22 23 package org.webdocwf.util.loader; 24 25 import java.util.*; 26 import java.sql.*; 27 import org.webdocwf.util.loader.logging.*; 28 29 36 public class CheckRowCache { 37 private Hashtable rowExist = new Hashtable(); 38 private Hashtable rowVersionValue = new Hashtable(); 39 40 private static String currentKey = ""; 41 private Logger logger; 42 private int currentVersion = 0; 43 44 47 public CheckRowCache() { 48 } 49 50 53 public void setCheckRowValue() { 54 if (!this.currentKey.equalsIgnoreCase("")) 55 rowExist.put(this.currentKey, "true"); 56 } 57 58 62 public void setCheckRowVersionValue(String val) { 63 if (!this.currentKey.equalsIgnoreCase("")) { 64 if (rowVersionValue.get(this.currentKey) != null) 65 rowVersionValue.remove(this.currentKey); 66 rowVersionValue.put(this.currentKey, val); 67 } 68 } 69 70 74 public int getCheckRowVersionValue() { 75 String ret = (String )rowVersionValue.get(this.currentKey); 76 return Integer.parseInt(ret); 77 } 78 79 83 public static String getKey() { 84 return currentKey; 85 } 86 87 95 public boolean getCheckRowValue(String key, Connection conn, 96 int iTargetFirstColumnResult, String versionColumnName) throws Exception { 97 98 this.currentKey = key; 99 Object obj = rowExist.get(key); 100 if (obj == null) { 101 this.logger.write("full", "\tQuery '" + key + "' will be executed"); 102 try { 103 Statement stmtCheckTarget = conn.createStatement(); 104 ResultSet rsetCheckTarget = stmtCheckTarget.executeQuery(key); 105 if (rsetCheckTarget.next()) { this.setCheckRowValue(); 107 if (iTargetFirstColumnResult != 100) { 108 this.currentVersion = rsetCheckTarget.getInt(versionColumnName); 110 this.setCheckRowVersionValue(String.valueOf(this.currentVersion)); 111 } 112 rsetCheckTarget.close(); 113 stmtCheckTarget.close(); 114 return true; 115 } else { this.setCheckRowVersionValue(String.valueOf(0)); 117 rsetCheckTarget.close(); 118 stmtCheckTarget.close(); 119 } 120 return false; 121 } 122 catch (Exception ex) { 123 this.logger.write("full", ex.getMessage()); 124 throw ex; 125 } 126 } else { return true; 128 } 129 } 130 131 134 public void resetCheckRowCache() { 135 rowExist.clear(); 136 rowVersionValue.clear(); 137 currentKey = ""; 138 } 139 140 144 public void setLogger(Logger logger) { 145 this.logger = logger; 146 } 147 148 152 public int getCurrentVersion() { 153 return this.currentVersion; 154 } 155 156 } | Popular Tags |