1 package dinamica.validators; 2 3 import java.util.HashMap ; 4 import javax.servlet.http.HttpServletRequest ; 5 import dinamica.*; 6 7 33 34 public class DuplicatedKeyValidator extends AbstractValidator 35 { 36 37 40 public boolean isValid( 41 HttpServletRequest req, 42 Recordset inputParams, 43 HashMap attribs) 44 throws Throwable  45 { 46 47 boolean flag = true; 48 49 Db db = getDb(); 51 52 boolean bSql = attribs.containsKey("sql"); 54 55 String sql = ""; 56 57 if (!bSql) 58 { 59 boolean b1 = attribs.containsKey("table"); 61 if (!b1) 62 throw new Throwable ("Bad configuration - 'table' attribute not found."); 63 boolean b2 = attribs.containsKey("column"); 64 if (!b2) 65 throw new Throwable ("Bad configuration - 'column' attribute not found."); 66 boolean b3 = attribs.containsKey("varchar"); 67 if (!b3) 68 throw new Throwable ("Bad configuration - 'varchar' attribute not found."); 69 70 String delim = ""; 72 String isVarchar = (String )attribs.get("varchar"); 73 if (isVarchar.equals("true")) 74 delim = "'"; 75 76 String table = (String )attribs.get("table"); 78 String col = (String )attribs.get("column"); 79 80 String value = String.valueOf(inputParams.getValue(col)); 82 83 sql = "select " + col + " from " + table + " where " + col + " = " + delim + value + delim; 85 } 86 else 87 { 88 String query = (String )attribs.get("sql"); 89 sql = getResource(query); 90 sql = getSQL(sql, inputParams); 91 } 92 93 Recordset rs = db.get(sql); 95 if (rs.getRecordCount()>0) 96 flag = false; 97 98 return flag; 99 100 } 101 102 } 103
| Popular Tags
|