@Test public void testGenerate() { String sql = " select * from abc where a=:test1 and b like :test2 an p = :test1"; Map<String, Object> params = new HashMap<String, Object>(); params.put("test1", 1); params.put("test2", "%t"); ParamTransformGenerator generator = new ParamTransformGenerator(sql, params); generator.generate(); Assert.assertTrue(" select * from abc where a=? and b like ? an p = ?".equals(generator.getSql())); Assert.assertTrue(generator.getArgs().length == 3); }
public void generate() throws DataAccessException { if (oraSql == null || "".equalsIgnoreCase(oraSql.trim())) { throw new DataAccessException("SQL is null"); } List<Object> arglist = new ArrayList<Object>(); Pattern p = Pattern.compile(PATTERN); Matcher m = p.matcher(oraSql); while (m.find()) { String key = m.group(); if (!params.containsKey(key.substring(1))) { throw new DataAccessException("Params not contains key~" + key + ";"); } arglist.add(params.get(key.substring(1))); } sql = oraSql.replaceAll(PATTERN, "?"); args = arglist.toArray(); }
ParamTransformGenerator implements Generator { public void generate() throws DataAccessException { if (oraSql == null || "".equalsIgnoreCase(oraSql.trim())) { throw new DataAccessException("SQL is null"); } List<Object> arglist = new ArrayList<Object>(); Pattern p = Pattern.compile(PATTERN); Matcher m = p.matcher(oraSql); while (m.find()) { String key = m.group(); if (!params.containsKey(key.substring(1))) { throw new DataAccessException("Params not contains key~" + key + ";"); } arglist.add(params.get(key.substring(1))); } sql = oraSql.replaceAll(PATTERN, "?"); args = arglist.toArray(); } }
ParamTransformGenerator implements Generator { public void generate() throws DataAccessException { if (oraSql == null || "".equalsIgnoreCase(oraSql.trim())) { throw new DataAccessException("SQL is null"); } List<Object> arglist = new ArrayList<Object>(); Pattern p = Pattern.compile(PATTERN); Matcher m = p.matcher(oraSql); while (m.find()) { String key = m.group(); if (!params.containsKey(key.substring(1))) { throw new DataAccessException("Params not contains key~" + key + ";"); } arglist.add(params.get(key.substring(1))); } sql = oraSql.replaceAll(PATTERN, "?"); args = arglist.toArray(); } ParamTransformGenerator(String sql, Map<String, Object> params); }
ParamTransformGenerator implements Generator { public void generate() throws DataAccessException { if (oraSql == null || "".equalsIgnoreCase(oraSql.trim())) { throw new DataAccessException("SQL is null"); } List<Object> arglist = new ArrayList<Object>(); Pattern p = Pattern.compile(PATTERN); Matcher m = p.matcher(oraSql); while (m.find()) { String key = m.group(); if (!params.containsKey(key.substring(1))) { throw new DataAccessException("Params not contains key~" + key + ";"); } arglist.add(params.get(key.substring(1))); } sql = oraSql.replaceAll(PATTERN, "?"); args = arglist.toArray(); } ParamTransformGenerator(String sql, Map<String, Object> params); void generate(); String getSql(); Object[] getArgs(); }
ParamTransformGenerator implements Generator { public void generate() throws DataAccessException { if (oraSql == null || "".equalsIgnoreCase(oraSql.trim())) { throw new DataAccessException("SQL is null"); } List<Object> arglist = new ArrayList<Object>(); Pattern p = Pattern.compile(PATTERN); Matcher m = p.matcher(oraSql); while (m.find()) { String key = m.group(); if (!params.containsKey(key.substring(1))) { throw new DataAccessException("Params not contains key~" + key + ";"); } arglist.add(params.get(key.substring(1))); } sql = oraSql.replaceAll(PATTERN, "?"); args = arglist.toArray(); } ParamTransformGenerator(String sql, Map<String, Object> params); void generate(); String getSql(); Object[] getArgs();  }