Package org.springframework.jdbc

Examples of org.springframework.jdbc.Customer


        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, int otherNum) {
        return findObject(id, otherNum);
      }
    }

    CustomerQuery query = new CustomerQuery(dataSource);
    Customer cust = query.findCustomer(1, 1);

    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
    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();
View Full Code Here


        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);
    Customer cust = query.findCustomer("rod");

    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly",
        cust.getForename().equals("rod"));
    verify(preparedStatement).setString(1, "rod");
    verify(connection).prepareStatement(SELECT_ID_FORENAME_WHERE);
    verify(resultSet).close();
    verify(preparedStatement).close();
    verify(connection).close();
View Full Code Here

        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);
View Full Code Here

        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);
View Full Code Here

        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);
View Full Code Here

        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);
View Full Code Here

        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) {
        return findObject(id);
      }
    }

    CustomerQuery query = new CustomerQuery(dataSource);
    Customer cust = query.findCustomer(1);
    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
    verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
    verify(resultSet).close();
    verify(preparedStatement).close();
    verify(connection).close();
  }
View Full Code Here

        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>();
View Full Code Here

        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 country) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        params.put("country", country);
        return executeByNamedParam(params).get(0);
      }
    }

    CustomerQuery query = new CustomerQuery(dataSource);
    Customer cust = query.findCustomer(1, "UK");
    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
    verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
    verify(preparedStatement).setString(2, "UK");
    verify(resultSet).close();
    verify(preparedStatement).close();
    verify(connection).close();
View Full Code Here

        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(List<Integer> ids) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        return executeByNamedParam(params);
      }
    }

    CustomerQuery query = new CustomerQuery(dataSource);
    List<Integer> ids = new ArrayList<Integer>();
    ids.add(1);
    ids.add(2);
    List<Customer> cust = query.findCustomers(ids);

    assertEquals("We got two customers back", cust.size(), 2);
    assertEquals("First customer id was assigned correctly", cust.get(0).getId(), 1);
    assertEquals("First customer forename was assigned correctly", cust.get(0).getForename(), "rod");
    assertEquals("Second customer id was assigned correctly", cust.get(1).getId(), 2);
    assertEquals("Second customer forename was assigned correctly", cust.get(1).getForename(), "juergen");
    verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
    verify(preparedStatement).setObject(2, 2, Types.NUMERIC);
    verify(resultSet).close();
    verify(preparedStatement).close();
    verify(connection).close();
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.Customer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.