Package org.springframework.jdbc

Examples of org.springframework.jdbc.Customer


        declareParameter(new SqlParameter(Types.NUMERIC));
        compile();
      }

      protected Object 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 (Customer) findObject(id, otherNum);
      }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    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"));
  }
View Full Code Here


        declareParameter(new SqlParameter(Types.VARCHAR));
        compile();
      }

      protected Object 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 (Customer) findObject(id);
      }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    Customer cust = query.findCustomer("rod");

    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
  }
View Full Code Here

          new SqlParameter(COLUMN_NAMES[1], COLUMN_TYPES[1]));
        compile();
      }

      protected Object 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 (Customer) findObject(
          new Object[] { new Integer(id), name });
      }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);

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

        declareParameter(new SqlParameter(Types.VARCHAR));
        compile();
      }

      protected Object 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 (Customer) findObject(id);
      }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    try {
      Customer cust = query.findCustomer("rod");
      fail("Should fail if more than one row found");
    }
    catch (IncorrectResultSizeDataAccessException ex) {
      // OK
    }
View Full Code Here

        declareParameter(new SqlParameter(Types.NUMERIC));
        compile();
      }

      protected Object 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(mockDataSource);
    List list = query.execute(1, 1);
    assertTrue("2 results in list", list.size() == 2);
    for (Iterator itr = list.iterator(); itr.hasNext();) {
      Customer cust = (Customer) itr.next();
    }
  }
View Full Code Here

        declareParameter(new SqlParameter(Types.VARCHAR));
        compile();
      }

      protected Object 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(mockDataSource);
    List list = query.execute("one");
    assertTrue("2 results in list", list.size() == 2);
    for (Iterator itr = list.iterator(); itr.hasNext();) {
      Customer cust = (Customer) itr.next();
    }
  }
View Full Code Here

        declareParameter(new SqlParameter(Types.NUMERIC));
        compile();
      }

      protected Object 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 (Customer) findObject(id);
      }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    Customer cust = query.findCustomer(1);
    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
  }
View Full Code Here

        declareParameter(new SqlParameter(Types.NUMERIC));
        compile();
      }

      protected Object 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 params = new HashMap();
        params.put("id", new Integer(id));
        return (Customer) executeByNamedParam(params).get(0);
      }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    try {
      Customer cust = query.findCustomer(1);
      fail("Query should not succeed since parameter declaration did not specify parameter name");
    }
    catch (InvalidDataAccessApiUsageException ex) {
      // OK - it worked
    }
View Full Code Here

        }
        compile();
      }

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

    CustomerQuery query = new CustomerQuery(mockDataSource);
    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"));
  }
View Full Code Here

        declareParameter(new SqlParameter("ids", Types.NUMERIC));
        compile();
      }

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

    CustomerQuery query = new CustomerQuery(mockDataSource);
    List ids = new ArrayList();
    ids.add(new Integer(1));
    ids.add(new Integer(2));
    List cust = query.findCustomers(ids);

    assertEquals("We got two customers back", cust.size(), 2);
    assertEquals("First customer id was assigned correctly", ((Customer)cust.get(0)).getId(), 1);
    assertEquals("First customer forename was assigned correctly", ((Customer)cust.get(0)).getForename(), "rod");
    assertEquals("Second customer id was assigned correctly", ((Customer)cust.get(1)).getId(), 2);
    assertEquals("Second customer forename was assigned correctly", ((Customer)cust.get(1)).getForename(), "juergen");
  }
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.