本文整理汇总了Java中org.springframework.jdbc.Customer.setForename方法的典型用法代码示例。如果您正苦于以下问题:Java Customer.setForename方法的具体用法?Java Customer.setForename怎么用?Java Customer.setForename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.Customer
的用法示例。
在下文中一共展示了Customer.setForename方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapRow
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Override
public Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
示例2: testFindTooManyCustomers
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Test
public void testFindTooManyCustomers() throws SQLException {
given(resultSet.next()).willReturn(true, true, false);
given(resultSet.getInt("id")).willReturn(1, 2);
given(resultSet.getString("forename")).willReturn("rod", "rod");
class CustomerQuery extends MappingSqlQuery<Customer> {
public CustomerQuery(DataSource ds) {
super(ds, SELECT_ID_FORENAME_WHERE);
declareParameter(new SqlParameter(Types.VARCHAR));
compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
public Customer findCustomer(String id) {
return findObject(id);
}
}
CustomerQuery query = new CustomerQuery(dataSource);
thrown.expect(IncorrectResultSizeDataAccessException.class);
try {
query.findCustomer("rod");
}
finally {
verify(preparedStatement).setString(1, "rod");
verify(connection).prepareStatement(SELECT_ID_FORENAME_WHERE);
verify(resultSet).close();
verify(preparedStatement).close();
verify(connection).close();
}
}
示例3: testListCustomersIntInt
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Test
public void testListCustomersIntInt() throws SQLException {
given(resultSet.next()).willReturn(true, true, false);
given(resultSet.getInt("id")).willReturn(1, 2);
given(resultSet.getString("forename")).willReturn("rod", "dave");
class CustomerQuery extends MappingSqlQuery<Customer> {
public CustomerQuery(DataSource ds) {
super(ds, SELECT_ID_WHERE);
declareParameter(new SqlParameter(Types.NUMERIC));
declareParameter(new SqlParameter(Types.NUMERIC));
compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
}
CustomerQuery query = new CustomerQuery(dataSource);
List<Customer> list = query.execute(1, 1);
assertTrue("2 results in list", list.size() == 2);
assertThat(list.get(0).getForename(), is("rod"));
assertThat(list.get(1).getForename(), is("dave"));
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
verify(connection).prepareStatement(SELECT_ID_WHERE);
verify(resultSet).close();
verify(preparedStatement).close();
verify(connection).close();
}
示例4: testListCustomersString
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Test
public void testListCustomersString() throws SQLException {
given(resultSet.next()).willReturn(true, true, false);
given(resultSet.getInt("id")).willReturn(1, 2);
given(resultSet.getString("forename")).willReturn("rod", "dave");
class CustomerQuery extends MappingSqlQuery<Customer> {
public CustomerQuery(DataSource ds) {
super(ds, SELECT_ID_FORENAME_WHERE);
declareParameter(new SqlParameter(Types.VARCHAR));
compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
}
CustomerQuery query = new CustomerQuery(dataSource);
List<Customer> list = query.execute("one");
assertTrue("2 results in list", list.size() == 2);
assertThat(list.get(0).getForename(), is("rod"));
assertThat(list.get(1).getForename(), is("dave"));
verify(preparedStatement).setString(1, "one");
verify(connection).prepareStatement(SELECT_ID_FORENAME_WHERE);
verify(resultSet).close();
verify(preparedStatement).close();
verify(connection).close();
}
示例5: testUnnamedParameterDeclarationWithNamedParameterQuery
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Test
public void testUnnamedParameterDeclarationWithNamedParameterQuery()
throws SQLException {
class CustomerQuery extends MappingSqlQuery<Customer> {
public CustomerQuery(DataSource ds) {
super(ds, SELECT_ID_FORENAME_WHERE);
setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
declareParameter(new SqlParameter(Types.NUMERIC));
compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
public Customer findCustomer(int id) {
Map<String, Integer> params = new HashMap<String, Integer>();
params.put("id", id);
return executeByNamedParam(params).get(0);
}
}
// Query should not succeed since parameter declaration did not specify parameter name
CustomerQuery query = new CustomerQuery(dataSource);
thrown.expect(InvalidDataAccessApiUsageException.class);
query.findCustomer(1);
}
示例6: testNamedParameterUsingInvalidQuestionMarkPlaceHolders
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Test
public void testNamedParameterUsingInvalidQuestionMarkPlaceHolders()
throws SQLException {
given(
connection.prepareStatement(SELECT_ID_FORENAME_WHERE_ID_REUSED_1,
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY)).willReturn(preparedStatement);
class CustomerQuery extends MappingSqlQuery<Customer> {
public CustomerQuery(DataSource ds) {
super(ds, SELECT_ID_FORENAME_WHERE_ID_REUSED_1);
setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
declareParameter(new SqlParameter("id1", Types.NUMERIC));
compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
public List<Customer> findCustomers(Integer id1) {
Map<String, Integer> params = new HashMap<String, Integer>();
params.put("id1", id1);
return executeByNamedParam(params);
}
}
CustomerQuery query = new CustomerQuery(dataSource);
thrown.expect(InvalidDataAccessApiUsageException.class);
query.findCustomers(1);
}
示例7: testFindCustomerMixed
import org.springframework.jdbc.Customer; //导入方法依赖的package包/类
@Test
public void testFindCustomerMixed() throws SQLException {
reset(connection);
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
ResultSet resultSet2 = mock(ResultSet.class);
given(preparedStatement2.executeQuery()).willReturn(resultSet2);
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
given(resultSet2.next()).willReturn(false);
given(connection.prepareStatement(SELECT_ID_WHERE)).willReturn(preparedStatement, preparedStatement2);
class CustomerQuery extends MappingSqlQuery<Customer> {
public CustomerQuery(DataSource ds) {
super(ds, SELECT_ID_WHERE);
declareParameter(new SqlParameter(COLUMN_NAMES[0], COLUMN_TYPES[0]));
declareParameter(new SqlParameter(COLUMN_NAMES[1], COLUMN_TYPES[1]));
compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
public Customer findCustomer(int id, String name) {
return findObject(new Object[] { id, name });
}
}
CustomerQuery query = new CustomerQuery(dataSource);
Customer cust1 = query.findCustomer(1, "rod");
assertTrue("Found customer", cust1 != null);
assertTrue("Customer id was assigned correctly", cust1.getId() == 1);
Customer cust2 = query.findCustomer(1, "Roger");
assertTrue("No customer found", cust2 == null);
verify(preparedStatement).setObject(1, 1, Types.INTEGER);
verify(preparedStatement).setString(2, "rod");
verify(preparedStatement2).setObject(1, 1, Types.INTEGER);
verify(preparedStatement2).setString(2, "Roger");
verify(resultSet).close();
verify(resultSet2).close();
verify(preparedStatement).close();
verify(preparedStatement2).close();
verify(connection, times(2)).close();
}