Polishing
This commit is contained in:
@@ -173,11 +173,11 @@ public class NamedParameterQueryTests {
|
|||||||
parms.addValue("id", 3);
|
parms.addValue("id", 3);
|
||||||
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
|
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
|
||||||
parms, new RowMapper<Object>() {
|
parms, new RowMapper<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||||
return rs.getInt(1);
|
return rs.getInt(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertTrue("Correct result type", o instanceof Integer);
|
assertTrue("Correct result type", o instanceof Integer);
|
||||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
||||||
@@ -225,7 +225,7 @@ public class NamedParameterQueryTests {
|
|||||||
given(resultSet.getInt(1)).willReturn(22);
|
given(resultSet.getInt(1)).willReturn(22);
|
||||||
|
|
||||||
MapSqlParameterSource parms = new MapSqlParameterSource();
|
MapSqlParameterSource parms = new MapSqlParameterSource();
|
||||||
parms.addValue("ids", Arrays.asList(new Object[] { 3, 4 }));
|
parms.addValue("ids", Arrays.asList(3, 4));
|
||||||
Object o = template.queryForObject(sql, parms, Integer.class);
|
Object o = template.queryForObject(sql, parms, Integer.class);
|
||||||
|
|
||||||
assertTrue("Correct result type", o instanceof Integer);
|
assertTrue("Correct result type", o instanceof Integer);
|
||||||
@@ -241,8 +241,8 @@ public class NamedParameterQueryTests {
|
|||||||
|
|
||||||
MapSqlParameterSource parms = new MapSqlParameterSource();
|
MapSqlParameterSource parms = new MapSqlParameterSource();
|
||||||
List<Object[]> l1 = new ArrayList<Object[]>();
|
List<Object[]> l1 = new ArrayList<Object[]>();
|
||||||
l1.add(new Object[] { 3, "Rod" });
|
l1.add(new Object[] {3, "Rod"});
|
||||||
l1.add(new Object[] { 4, "Juergen" });
|
l1.add(new Object[] {4, "Juergen"});
|
||||||
parms.addValue("multiExpressionList", l1);
|
parms.addValue("multiExpressionList", l1);
|
||||||
Object o = template.queryForObject(
|
Object o = template.queryForObject(
|
||||||
"SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN (:multiExpressionList)",
|
"SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN (:multiExpressionList)",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,11 +20,12 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
@@ -117,7 +118,7 @@ public class NamedParameterUtilsTests {
|
|||||||
@Test(expected = InvalidDataAccessApiUsageException.class)
|
@Test(expected = InvalidDataAccessApiUsageException.class)
|
||||||
public void buildValueArrayWithMissingParameterValue() throws Exception {
|
public void buildValueArrayWithMissingParameterValue() throws Exception {
|
||||||
String sql = "select count(0) from foo where id = :id";
|
String sql = "select count(0) from foo where id = :id";
|
||||||
NamedParameterUtils.buildValueArray(sql, new HashMap());
|
NamedParameterUtils.buildValueArray(sql, Collections.<String, Object>emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -168,7 +169,7 @@ public class NamedParameterUtilsTests {
|
|||||||
|
|
||||||
String sql4 = "/*+ HINT */ xxx /* comment :a ? */ :a yyyy :b :c :a zzzzz /* :xx XX*";
|
String sql4 = "/*+ HINT */ xxx /* comment :a ? */ :a yyyy :b :c :a zzzzz /* :xx XX*";
|
||||||
ParsedSql psql4 = NamedParameterUtils.parseSqlStatement(sql4);
|
ParsedSql psql4 = NamedParameterUtils.parseSqlStatement(sql4);
|
||||||
Map parameters = Collections.singletonMap("a", "0");
|
Map<String, String> parameters = Collections.singletonMap("a", "0");
|
||||||
assertEquals("/*+ HINT */ xxx /* comment :a ? */ ? yyyy ? ? ? zzzzz /* :xx XX*",
|
assertEquals("/*+ HINT */ xxx /* comment :a ? */ ? yyyy ? ? ? zzzzz /* :xx XX*",
|
||||||
NamedParameterUtils.substituteNamedParameters(psql4, new MapSqlParameterSource(parameters)));
|
NamedParameterUtils.substituteNamedParameters(psql4, new MapSqlParameterSource(parameters)));
|
||||||
}
|
}
|
||||||
@@ -235,7 +236,6 @@ public class NamedParameterUtilsTests {
|
|||||||
assertEquals(0, parsedSql2.getParameterNames().size());
|
assertEquals(0, parsedSql2.getParameterNames().size());
|
||||||
String finalSql2 = NamedParameterUtils.substituteNamedParameters(parsedSql2, null);
|
String finalSql2 = NamedParameterUtils.substituteNamedParameters(parsedSql2, null);
|
||||||
assertEquals(expectedSql2, finalSql2);
|
assertEquals(expectedSql2, finalSql2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -294,4 +294,5 @@ public class NamedParameterUtilsTests {
|
|||||||
assertEquals(1, psql2.getTotalParameterCount());
|
assertEquals(1, psql2.getTotalParameterCount());
|
||||||
assertEquals("xxx", psql2.getParameterNames().get(0));
|
assertEquals("xxx", psql2.getParameterNames().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user