예제 #1
0
  public static ArrayList<Customer> getAllCustomers() {
    ArrayList<Customer> list = new ArrayList<Customer>();

    DBHelper db = new DBHelper();

    try {
      String queryString = "SELECT * FROM customer";
      ResultSet rs = db.executeQuery(queryString);

      while (rs.next()) {
        Customer customer = new Customer();

        customer.setId(rs.getInt("id"));
        customer.setFirstName(rs.getString("first_name"));
        customer.setLastName(rs.getString("last_name"));
        customer.setPhone(rs.getString("phone"));
        customer.setAddress(rs.getString("address"));
        customer.setZipCode(rs.getInt("zipcode"));
        customer.setCity(rs.getString("city"));
        customer.setEmail(rs.getString("email"));
        customer.setPassword(rs.getString("password"));

        list.add(customer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    db.close();

    return list;
  }
  /**
   * Get a customer by id
   *
   * @param id customer id
   * @return a customer
   */
  public Customer getACustomer(int id) {
    String sql = "Select * From Customer where cid = ?";

    try {

      PreparedStatement statement = (PreparedStatement) connection.prepareStatement(sql);
      statement.setInt(1, id);
      ResultSet rs = statement.executeQuery();

      if (rs.next()) {
        Customer customer = new Customer();
        customer.setEmail(rs.getString("email"));
        customer.setFirstName(rs.getString("firstName"));
        customer.setLastName(rs.getString("lastName"));
        customer.setId(rs.getInt("cid"));

        if (statement != null) statement.close();

        return customer;
      } else {
        return null;
      }

    } catch (SQLException e) {
      e.printStackTrace();
      System.out.println("Error at get a customer");
      return null;
    }
  }
예제 #3
0
  // Reports
  public ArrayList<Customer> getAllCustomers() {
    con = new DBConnection();
    ArrayList<Customer> customers = new ArrayList<Customer>();
    try {
      cstmt = con.connection.prepareCall("{call getAllCustomer()}");
      ResultSet rs = cstmt.executeQuery();
      while (rs.next()) {
        Customer objCustomer = new Customer();
        Area objArea = new Area();
        objCustomer.setFirstName(rs.getString("FirstName"));
        objCustomer.setLastName(rs.getString("LastName"));
        objArea.setAreaName(rs.getString("AreaName"));
        objCustomer.setArea(objArea);
        objCustomer.setUserName(rs.getString("UserName"));
        objCustomer.setLane(rs.getString("Lane"));
        objCustomer.setMobileNo(rs.getString("MobileNo"));
        objCustomer.setEmailID(rs.getString("EmailID"));
        objCustomer.setStatus(rs.getBoolean("Status"));
        customers.add(objCustomer);
      }
      rs.close();
    } catch (Exception ex) {
      ex.getMessage();
    } finally {

      con.closeConnection();
    }
    return customers;
  }
예제 #4
0
  public List<Customer> getAllCustomer() {
    List<Customer> customerList = new ArrayList<Customer>() {};
    con = new DBConnection();
    try {

      cstmt = con.connection.prepareCall("{call getAllCustomer()}");
      // cstmt.setString(1, UserName);

      ResultSet rs = cstmt.executeQuery();

      while (rs.next()) {
        Customer objCustomer = new Customer();
        objCustomer.setUserName(rs.getString("UserName"));
        objCustomer.setFirstName(rs.getString("FirstName"));
        objCustomer.setLastName(rs.getString("LastName"));

        customerList.add(objCustomer);
      }
      rs.close();
    } catch (Exception ex) {
      ex.getMessage();
    } finally {

      con.closeConnection();
    }
    return customerList;
  }
예제 #5
0
 private static Customer customerUnmarshaller(Node customerNode) {
   Customer customer = new Customer();
   NamedNodeMap customerAttributes = customerNode.getAttributes();
   customer.setFirstName(customerAttributes.item(0).getNodeValue());
   customer.setLastName(customerAttributes.item(1).getNodeValue());
   Node addressNode = customerNode.getFirstChild().getNextSibling();
   customer.setAddress(unmarshallAddress(addressNode));
   Node dataNode = customerNode.getFirstChild().getNextSibling().getNextSibling().getNextSibling();
   customer.setData(unmarshallData(dataNode));
   return customer;
 }
  private Customer buildCustomer() {
    Customer customer = new Customer();

    customer.setFirstName(firstNames[generator.nextInt(firstNames.length - 1)]);
    customer.setMiddleInitial(
        String.valueOf(middleInitial.charAt(generator.nextInt(middleInitial.length() - 1))));
    customer.setLastName(lastNames[generator.nextInt(lastNames.length - 1)]);
    customer.setAddress(
        generator.nextInt(9999) + " " + streets[generator.nextInt(streets.length - 1)]);
    customer.setCity(cities[generator.nextInt(cities.length - 1)]);
    customer.setState(states[generator.nextInt(states.length - 1)]);
    customer.setZip(String.valueOf(generator.nextInt(99999)));

    return customer;
  }
 @Override
 public <G extends Customer> CreateResponse<G> createOrRetrieveCopyInstance(
     MultiTenantCopyContext context) throws CloneNotSupportedException {
   CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this);
   if (createResponse.isAlreadyPopulated()) {
     return createResponse;
   }
   Customer cloned = createResponse.getClone();
   cloned.setAnonymous(anonymous);
   cloned.setChallengeAnswer(challengeAnswer);
   cloned.setChallengeQuestion(challengeQuestion);
   cloned.setCookied(cookied);
   for (CustomerAddress entry : customerAddresses) {
     CustomerAddress clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
     clonedEntry.setCustomer(cloned);
     cloned.getCustomerAddresses().add(clonedEntry);
   }
   for (Map.Entry<String, CustomerAttribute> entry : customerAttributes.entrySet()) {
     CustomerAttribute clonedEntry =
         entry.getValue().createOrRetrieveCopyInstance(context).getClone();
     clonedEntry.setCustomer(cloned);
     cloned.getCustomerAttributes().put(entry.getKey(), clonedEntry);
   }
   cloned.setLoggedIn(loggedIn);
   cloned.setUsername(username);
   cloned.setUnencodedPassword(unencodedPassword);
   cloned.setTaxExemptionCode(taxExemptionCode);
   cloned.setUnencodedChallengeAnswer(unencodedChallengeAnswer);
   cloned.setRegistered(registered);
   cloned.setReceiveEmail(receiveEmail);
   cloned.setPasswordChangeRequired(passwordChangeRequired);
   cloned.setPassword(password);
   cloned.setLastName(lastName);
   cloned.setFirstName(firstName);
   cloned.setEmailAddress(emailAddress);
   cloned.setDeactivated(deactivated);
   for (CustomerPayment entry : customerPayments) {
     CustomerPayment clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
     clonedEntry.setCustomer(cloned);
     cloned.getCustomerPayments().add(clonedEntry);
   }
   for (CustomerPhone entry : customerPhones) {
     CustomerPhone clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
     clonedEntry.setCustomer(cloned);
     cloned.getCustomerPhones().add(clonedEntry);
   }
   return createResponse;
 }
  public static List<Customer> createDummyData() {
    LinkedList<Customer> list = new LinkedList<>();

    for (int i = 1; i <= 10000; i++) {

      Customer customer = new Customer();
      customer.setId(i);
      customer.setFirstName(testData.getFirstName());
      customer.setLastName(testData.getLastName());
      customer.setFood(testData.getItem(Customer.Food.values()));
      customer.setPhoto(
          new ThemeResource(
              "../demotheme/demophotos/cat" + testData.getNumberBetween(1, 4) + ".jpg"));

      list.add(customer);
    }
    return list;
  }
  @Before
  public void setUp() throws Exception {
    this.em = Persistence.createEntityManagerFactory("fast-lane-reader").createEntityManager();
    this.et = this.em.getTransaction();

    this.query = new CustomerQueryPageOrEverythingBean();
    this.query.em = this.em;
    this.mgr = new CustomerMgrBean();
    this.mgr.em = this.em;

    this.et.begin();
    for (int i = 0; i < 10; i++) {
      Customer customer = new Customer();
      customer.setFirstName("Robin " + i);
      customer.setLastName("Long");
      customer.setBornDate(new Date());

      this.mgr.create(customer);
    }
    this.et.commit();
  }
예제 #10
0
 public static Customer getCustomer(int id) {
   Customer customer = new Customer();
   DBHelper db = new DBHelper();
   try {
     String queryString = "SELECT * FROM customer WHERE id = " + id;
     ResultSet rs = db.executeQuery(queryString);
     if (rs != null && rs.next()) {
       customer.setId(rs.getInt("id"));
       customer.setFirstName(rs.getString("first_name"));
       customer.setLastName(rs.getString("last_name"));
       customer.setPhone(rs.getString("phone"));
       customer.setAddress(rs.getString("address"));
       customer.setZipCode(rs.getInt("zipcode"));
       customer.setCity(rs.getString("city"));
       customer.setEmail(rs.getString("email"));
       customer.setPassword(rs.getString("password"));
     }
     db.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return customer;
 }
예제 #11
0
  /**
   * Get a customer to put in the database
   *
   * @param id for the customer
   * @param warehouse for the customer
   * @param station for the customer
   * @return customer
   */
  public Customer getCustomer(int id, Warehouse warehouse, Station station) {
    Customer customer = new Customer();

    customer.setCustomerID(id);
    customer.setWarehouseID(warehouse.getWarehouseID());
    customer.setStationID(station.getStationID());
    customer.setFirstName(fnames.get(randInt(0, fnames.size())));
    customer.setMiddleInitial(letters[randInt(0, letters.length)]);
    customer.setLastName(lnames.get(randInt(0, lnames.size())));
    customer.setAddress(randAddress());
    customer.setCity(cities.get(randInt(0, cities.size())));
    customer.setState(states.get(randInt(0, states.size())));
    customer.setZip(zips.get(randInt(0, zips.size())));
    customer.setPhone(randInt(100, 1000) + "-" + randInt(100, 1000) + "-" + randInt(1000, 10000));
    customer.setDateAdded(randDate());
    customer.setDiscount(new BigDecimal(randDouble(minDiscount, maxDiscount)));
    customer.setBalance(new BigDecimal(0));
    customer.setTotalPaid(new BigDecimal(0));
    customer.setNumPayments(0);
    customer.setDeliveriesReceived(0);

    return customer;
  }
  @Override
  protected Object getControlObject() {
    Customer customer = new Customer();
    customer.setFirstName(CONTROL_FIRST_NAME);
    customer.setLastName(CONTROL_LAST_NAME);
    customer.setSurname(CONTROL_SURNAME);
    customer.getNicknames().add("A");
    customer.getNicknames().add("B");

    Address address = new Address();
    address.setStreet(CONTROL_STREET);
    customer.setAddress(address);

    PhoneNumber phoneNumber1 = new PhoneNumber();
    phoneNumber1.setValue(CONTROL_PHONE_NUMBER_1);
    customer.getPhoneNumbers().add(phoneNumber1);

    PhoneNumber phoneNumber2 = new PhoneNumber();
    phoneNumber2.setValue(CONTROL_PHONE_NUMBER_2);
    customer.getPhoneNumbers().add(phoneNumber2);

    return customer;
  }
예제 #13
0
  public static Customer createCustomerAddress(EntityManagerFactory factory) {
    System.out.println("Create 1st Customer");
    Customer cust = new Customer();
    cust.setFirstName("Bill");
    cust.setLastName("Burke");
    Address address = new Address();
    address.setStreet("Beacon Street");
    address.setCity("Boston");
    address.setState("MA");
    address.setZip("02115");
    cust.setAddress(address);

    EntityManager manager = factory.createEntityManager();
    try {
      manager.getTransaction().begin();
      manager.persist(cust);
      manager.getTransaction().commit();
    } finally {
      manager.close();
    }
    System.out.println("Address was also persisted with auto-generated key: " + address.getId());
    System.out.println("Return detached Customer instance: " + cust.getId());
    return cust;
  }
예제 #14
0
  public List<Customer> viewCustomerProfile(String user_name) {
    // Author: Vivek Shukla
    // Date: 14-October-2013
    // Description:
    List<Customer> customerList = new ArrayList<Customer>();
    try {
      cstmt = con.connection.prepareCall("{call viewCustomerProfile(?)}");
      cstmt.setString(1, user_name);
      ResultSet rs = cstmt.executeQuery();
      if (rs.next()) {
        Customer objCustomer = new Customer();
        objCustomer.setUserName(rs.getString("UserName"));
        objCustomer.setPassword(rs.getString("Password"));
        objCustomer.setFirstName(rs.getString("FirstName"));
        objCustomer.setLane(rs.getString("Lane"));
        objCustomer.setLastName(rs.getString("LastName"));

        Area objArea = new Area();
        objArea.setAreaName(rs.getString("AreaName"));
        objCustomer.setArea(objArea);

        objCustomer.setMobileNo(rs.getString("MobileNo"));
        objCustomer.setEmailID(rs.getString("EmailID"));

        customerList.add(objCustomer);
      } else {
        return null;
      }
    } catch (Exception ex) {
      ex.getMessage();
    } finally {

      con.closeConnection();
    }
    return customerList;
  }