public List<Machine> getCustomerMachinesList(Customer cust) { try { ResultSet rs = executeQuery( "SELECT machines.* FROM customers JOIN machines ON customers.id=cid AND cid=" + cust.getId() + ";"); List list = new ArrayList(); while (rs.next()) { MachineData machData = new MachineData(); int id = rs.getInt(1); for (int i = 0; i < MachineData.fieldsName.length; i++) { String fieldValue = rs.getString(MachineData.fieldsName[i]); machData.updateByFieldName(MachineData.fieldsName[i], fieldValue); } Machine mach = new Machine(machData); mach.setId(id); mach.setCid(cust.getId()); list.add(mach); } return list; } catch (SQLException e) { e.printStackTrace(); } return null; }
public CustomersResource() { System.out.println("[CustomerResource] Instantiated " + this); Customer customer1 = new Customer(); customer1.setId(1111); customer1.setName("CustomerOne"); customer1.setAddress("Bombay, India"); Customer customer2 = new Customer(); customer2.setId(2222); customer2.setName("CustomerTwo"); customer2.setAddress("Pune, India"); Customer customer3 = new Customer(); customer3.setId(3333); customer3.setName("CustomerThree"); customer3.setAddress("Bangalore, India"); customerMap.put(customer1.getId(), customer1); customerMap.put(customer2.getId(), customer2); customerMap.put(customer3.getId(), customer3); if (testBean != null) { System.out.println("[CustomersResource] testBean NOT NULL " + testBean); testBean.setCustomerMap(customerMap); } else { System.out.println("[CustomersResource] testBean IS NULL"); } }
@Test public void testDeleteCustomer() { Customer c1 = getNewCustomerWithUniqueName(); Customer c1FromDb = getCustomerComponent().getById(c1.getId()); getCustomerComponent().delete(c1FromDb); Customer c1FromDbAgain = getCustomerComponent().getById(c1.getId()); assertNull(c1FromDbAgain); }
public String addDefaultCustomer(Customer customer) { customerMap.put(customer.getId(), customer); return "Customer ID: " + customer.getId() + " Name: " + customer.getName() + " Address: " + customer.getAddress(); }
@Test public void updateExistingCustomer() { final String newFirstname = "Bernard"; final String newLastname = "Montgomery"; final Customer customer = new Customer(CUSTOMER.getId(), newFirstname, newLastname); impl.updateCustomer(customer); final Customer cust = impl.getCustomerById(CUSTOMER.getId()); assertEquals(newFirstname, cust.getFirstName()); assertEquals(newLastname, cust.getLastName()); }
@Test public void testCustomerInsertAndGet() { Customer c1 = getNewCustomerWithUniqueName(); Customer c2 = getNewCustomerWithUniqueName(); assertEquals(c1.getId() + 1, c2.getId()); Customer c1FromDb = getCustomerComponent().getById(c1.getId()); assertEquals(c1.getName(), c1FromDb.getName()); }
@Test public void testCustomerUpdateAndGet() { Customer c1 = getNewCustomerWithUniqueName(); Customer c1FromDb = getCustomerComponent().getById(c1.getId()); String NEW_PHONE = "415-555-1212"; c1FromDb.setPhoneNumber(NEW_PHONE); getCustomerComponent().persist(c1FromDb); Customer c1FromDbAgain = getCustomerComponent().getById(c1.getId()); assertEquals(NEW_PHONE, c1FromDbAgain.getPhoneNumber()); }
@PUT @Path("/customers/") public Response updateCustomer(Customer customer) { Customer c = customers.get(customer.getId()); Response r; if (c != null) { customers.put(customer.getId(), customer); r = Response.ok().build(); } else { r = Response.status(406).entity("Cannot find the customer!").build(); } return r; }
public void addMachineToDatabase(Machine mach, Customer cust) { int id = getNextId("machines"); String query = "INSERT INTO machines SET id=" + id + ", "; query = query + "cid=" + cust.getId() + ", "; for (int i = 0; i < MachineData.fieldsName.length; i++) { String fieldname = MachineData.fieldsName[i]; String val = mach.getInfoByFieldName(fieldname); query = query + fieldname + "= \"" + val + "\""; if (i != MachineData.fieldsName.length - 1) query = query + ", "; } query = query + ";"; executeUpdate(query); mach.setId(id); mach.setCid(cust.getId()); }
@Test public void testFindIterate() { // insert 1000 customers int j = 0; for (int i = 0; i < 1000; i++) { Customer customer = new Customer(); customer.setName("Hello" + j++); customer.save(); } QueryIterator<Customer> iterate = Customer.find .query() .select("id") // .fetch("contacts", new FetchConfig().lazy(20)) .findIterate(); try { while (iterate.hasNext()) { Customer customer = iterate.next(); // do something interesting with customer // customer.getContacts().size(); System.out.println("got name " + customer.getId() + " " + customer.getName()); } } finally { // close the underlying resources held by the QueryIterator // those are: ResultSet and Connection iterate.close(); } }
@Test public void testBasicExpectedBehavior() { Session session = getNewSession("jboss"); session.beginTransaction(); Customer steve = new Customer(1L, "steve"); session.save(steve); session.getTransaction().commit(); session.close(); session = getNewSession("acme"); try { session.beginTransaction(); Customer check = (Customer) session.get(Customer.class, steve.getId()); Assert.assertNull("tenancy not properly isolated", check); } finally { session.getTransaction().commit(); session.close(); } session = getNewSession("jboss"); session.beginTransaction(); session.delete(steve); session.getTransaction().commit(); session.close(); }
public List<Service> getCustomerServicesList(Customer cust) { try { ResultSet rs = executeQuery( "SELECT services.* FROM customers JOIN machines JOIN services ON customers.id=cid AND machines.id=mid AND cid=" + cust.getId() + ";"); List list = new ArrayList(); while (rs.next()) { ServiceData servData = new ServiceData(); int id = rs.getInt(1); int mid = rs.getInt(2); for (int i = 0; i < ServiceData.fieldsName.length; i++) { String fieldValue = rs.getString(ServiceData.fieldsName[i]); servData.updateByFieldName(ServiceData.fieldsName[i], fieldValue); } Service serv = new Service(servData); serv.setId(id); serv.setMid(mid); list.add(serv); } return list; } catch (SQLException e) { e.printStackTrace(); } return null; }
public void testLoadingStrategies() { Session s = openSession(); s.beginTransaction(); Customer cust = new Customer("Acme, Inc."); Order order = new Order(new Order.Id(cust, 1)); cust.getOrders().add(order); s.save(cust); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); cust = (Customer) s.get(Customer.class, cust.getId()); assertEquals(1, cust.getOrders().size()); s.clear(); cust = (Customer) s.createQuery("from Customer").uniqueResult(); assertEquals(1, cust.getOrders().size()); s.clear(); cust = (Customer) s.createQuery("from Customer c join fetch c.orders").uniqueResult(); assertEquals(1, cust.getOrders().size()); s.clear(); s.delete(cust); s.getTransaction().commit(); s.close(); }
/** Hibernate Test class */ public static void main(String[] args) { // TODO Auto-generated method stub // Session session = HibernateUtil.currentSession(); Session session = HibernateSessionFactory.getSession(); session.beginTransaction(); // create query object Query query = session.createQuery("from Customer"); // create customer list List<Customer> list = query.list(); Customer cus = null; if (list != null && list.size() > 0) { /*for(int i = 0;i<list.size();i++){ cus = (Customer)list.get(i); System.out.println("" + "+i= " + i + "ID = "+ cus.getId()+ "name = "+ cus.getName()+"Age = " +cus.getAge()); }*/ for (Customer customer : list) { cus = customer; System.out.println( "ID = " + cus.getId() + " name = " + cus.getName() + " Age = " + cus.getAge()); } } session.beginTransaction().commit(); // submit }
@Test public void onCustomer() { Result<Customer> customerResult = gateway.customer().create(new CustomerRequest().paymentMethodNonce(Nonce.Coinbase)); assertTrue(customerResult.isSuccess()); Customer customer = customerResult.getTarget(); List<CoinbaseAccount> accounts = gateway.customer().find(customer.getId()).getCoinbaseAccounts(); assertEquals(1, accounts.size()); CoinbaseAccount account = accounts.get(0); assertNotNull(account); assertNotNull(account.getToken()); assertNotNull(account.getUserId()); assertThat(account.getUserId(), not(equalTo(""))); assertNotNull(account.getUserName()); assertThat(account.getUserName(), not(equalTo(""))); assertNotNull(account.getUserEmail()); assertThat(account.getUserEmail(), not(equalTo(""))); String token = account.getToken(); gateway.paymentMethod().delete(token); exception.expect(NotFoundException.class); gateway.paymentMethod().find(token); }
@Test public void updateCreditCardFromTransparentRedirect() { Customer customer = gateway.customer().create(new CustomerRequest()).getTarget(); CreditCardRequest request = new CreditCardRequest() .customerId(customer.getId()) .number("5105105105105100") .expirationDate("05/12"); CreditCard card = gateway.creditCard().create(request).getTarget(); CreditCardRequest updateRequest = new CreditCardRequest(); CreditCardRequest trParams = new CreditCardRequest() .paymentMethodToken(card.getToken()) .number("4111111111111111") .expirationDate("10/10"); String queryString = TestHelper.simulateFormPostForTR( gateway, trParams, updateRequest, gateway.transparentRedirect().url()); Result<CreditCard> result = gateway.transparentRedirect().confirmCreditCard(queryString); assertTrue(result.isSuccess()); CreditCard updatedCreditCard = gateway.creditCard().find(card.getToken()); assertEquals("411111", updatedCreditCard.getBin()); assertEquals("1111", updatedCreditCard.getLast4()); assertEquals("10/2010", updatedCreditCard.getExpirationDate()); }
final void init() { Customer c = new Customer(); c.setName("John"); c.setId(123); customers.put(c.getId(), c); c = new Customer(); c.setName("Dan"); c.setId(113); customers.put(c.getId(), c); Order o = new Order(); o.setDescription("order 223"); o.setId(223); orders.put(o.getId(), o); }
@POST @Path("/customersUniqueResponseCode/") public Response addCustomerUniqueResponseCode(Customer customer) { customer.setId(currentId.incrementAndGet()); customers.put(customer.getId(), customer); return Response.status(201).entity(customer).build(); }
@Test public void updateCustomerFromTransparentRedirect() { CustomerRequest request = new CustomerRequest().firstName("John").lastName("Doe"); Customer customer = gateway.customer().create(request).getTarget(); CustomerRequest updateRequest = new CustomerRequest().firstName("Jane"); CustomerRequest trParams = new CustomerRequest().customerId(customer.getId()).lastName("Dough"); String queryString = TestHelper.simulateFormPostForTR( gateway, trParams, updateRequest, gateway.transparentRedirect().url()); Result<Customer> result = gateway.transparentRedirect().confirmCustomer(queryString); assertTrue(result.isSuccess()); Customer updatedCustomer = gateway.customer().find(customer.getId()); assertEquals("Jane", updatedCustomer.getFirstName()); assertEquals("Dough", updatedCustomer.getLastName()); }
public static void main(String[] args) throws Exception { HashMap map = new HashMap(); // map.put("hibernate.show_sql", "true"); EntityManagerFactory factory = Persistence.createEntityManagerFactory("titan", map); EntityManager entityManager = factory.createEntityManager(); entityManager.getTransaction().begin(); try { System.out.println("Initialize DB"); InitializeDB.initialize(entityManager); System.out.println(); System.out.println(); System.out.println("Find Bill Burke by named parameter"); Customer cust = findCustomerByNamedParameter(entityManager, "Bill", "Burke"); System.out.println("Bill Burke's cust id: " + cust.getId()); System.out.println(); System.out.println(); System.out.println("Find Gavin King by indexed parameter"); cust = findCustomerByIndexedParameter(entityManager, "Gavin", "King"); System.out.println("Gavin King's cust id: " + cust.getId()); System.out.println(); System.out.println(); System.out.println("Output all customers via paging"); List results; int first = 0; int max = 2; do { results = getCustomers(entityManager, max, first); Iterator it = results.iterator(); while (it.hasNext()) { Customer c = (Customer) it.next(); System.out.println(c.getFirstName() + " " + c.getLastName()); } entityManager.clear(); first = first + results.size(); } while (results.size() > 0); } finally { entityManager.getTransaction().commit(); entityManager.close(); factory.close(); } }
@RequestMapping(value = "/customers", method = RequestMethod.POST) ResponseEntity<Resource<Customer>> post(@RequestBody Customer c) { Customer customer = this.customerRepository.save(new Customer(c.getFirstName(), c.getLastName())); URI uri = MvcUriComponentsBuilder.fromController(getClass()) .path("/customers/{id}") .buildAndExpand(customer.getId()) .toUri(); return ResponseEntity.created(uri).body(this.customerResourceAssembler.toResource(customer)); }
@Test public void updateNonExistingCustomer() { final int nonExistingId = getNonExistingCustomerId(); final String newFirstname = "Douglas"; final String newLastname = "MacArthur"; final Customer customer = new Customer(nonExistingId, newFirstname, newLastname); impl.updateCustomer(customer); assertNull(impl.getCustomerById(nonExistingId)); final Customer existingCustomer = impl.getCustomerById(CUSTOMER.getId()); assertEquals(CUSTOMER.getFirstName(), existingCustomer.getFirstName()); assertEquals(CUSTOMER.getLastName(), existingCustomer.getLastName()); }
@POST @Path("/customers/") public Response addCustomer(Customer customer) { if (StringUtils.isEmpty(customer.getName())) { return Response.status(422).build(); } customer.setId(currentId.incrementAndGet()); customers.put(customer.getId(), customer); return Response.ok(customer).build(); }
@POST @Path("add") @Produces(MediaType.APPLICATION_XML) @Consumes("application/x-www-form-urlencoded") public Customer addCustomer( @FormParam("custId") int id, @FormParam("custName") String name, @FormParam("custAddress") String address) { Customer customer = new Customer(); customer.setId(id); customer.setName(name); customer.setAddress(address); customerMap.put(customer.getId(), customer); testBean.setCustomerMap(customerMap); return customer; }
public static void main(String[] args) { Set<Customer> customers = new TreeSet<Customer>(); Customer id1 = new Customer(); id1.setId(1l); customers.add(id1); Customer id2 = new Customer(); id2.setId(2l); customers.add(id2); Customer c = new Customer(); c.setId(1l); customers.add(c); // mereplace id1 karena mempunyai id yang sama Iterator<Customer> i = customers.iterator(); while (i.hasNext()) { Customer current = i.next(); System.out.println("keranjang no-" + current.hashCode() + " idnya:" + current.getId()); } }
public static String generateEuropeBankAccountNonce(BraintreeGateway gateway, Customer customer) { SEPAClientTokenRequest request = new SEPAClientTokenRequest(); request.customerId(customer.getId()); request.mandateType(EuropeBankAccount.MandateType.BUSINESS); request.mandateAcceptanceLocation("Rostock, Germany"); String encodedClientToken = gateway.clientToken().generate(request); String clientToken = TestHelper.decodeClientToken(encodedClientToken); String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); Configuration configuration = gateway.getConfiguration(); String url = configuration.getBaseURL() + configuration.getMerchantPath() + "/client_api/v1/sepa_mandates"; QueryString payload = new QueryString(); payload .append("authorization_fingerprint", authorizationFingerprint) .append("sepa_mandate[locale]", "de-DE") .append("sepa_mandate[bic]", "DEUTDEFF") .append("sepa_mandate[iban]", "DE89370400440532013000") .append("sepa_mandate[accountHolderName]", "Bob Holder") .append("sepa_mandate[billingAddress][streetAddress]", "123 Currywurst Way") .append("sepa_mandate[billingAddress][extendedAddress]", "Lager Suite") .append("sepa_mandate[billingAddress][firstName]", "Wilhelm") .append("sepa_mandate[billingAddress][lastName]", "Dix") .append("sepa_mandate[billingAddress][locality]", "Frankfurt") .append("sepa_mandate[billingAddress][postalCode]", "60001") .append("sepa_mandate[billingAddress][countryCodeAlpha2]", "DE") .append("sepa_mandate[billingAddress][region]", "Hesse"); String responseBody; String nonce = ""; try { responseBody = HttpHelper.post(url, payload.toString()); nonce = extractParamFromJson("nonce", responseBody); } catch (Exception e) { throw new RuntimeException(e); } return nonce; }
public void insertSale(Customer c) throws SQLException { int id = c.getId(); String name = c.getName(); String address = c.getAddress(); String phone = c.getPhoneNumber(); String cardType = c.getCardType(); String cardNumber = c.getCardNumber(); String cardExp = c.getCardExp(); String secCode = c.getSecCode(); String cartDetails = ""; for (Product p : c.getCart().getProductList()) cartDetails += p.getName() + "@" + p.getUnitPrice() + "x" + p.getQuantity() + " "; BigDecimal cartTotal = c.getCart().getTotal().setScale(2); Statement stmt = con.createStatement(); String sql = "INSERT INTO App.SALES VALUES(" + id + ",'" + name + "','" + address + "','" + phone + "','" + cardType + "','" + cardNumber + "','" + cardExp + "','" + secCode + "','" + cartDetails + "'," + cartTotal + ",'" + getCurrentTimeStamp() + "')"; stmt.executeUpdate(sql); }
public static Customer createCreditCard(EntityManagerFactory factory, Customer cust) { CreditCard card = new CreditCard(); card.setExpirationDate(new java.util.Date()); card.setNumber("4444-4444-4444-4444"); card.setNameOnCard("William Burke"); card.setCreditOrganization("Capital One"); card.setCustomer(cust); EntityManager manager = factory.createEntityManager(); try { manager.getTransaction().begin(); manager.persist(card); manager.getTransaction().commit(); // Show that card.getCustomer() returns null manager.clear(); CreditCard cardCopy = manager.find(CreditCard.class, card.getId()); System.out.println("should be null: " + cardCopy.getCustomer()); manager.getTransaction().begin(); System.out.println("now set the owning side of the relationship"); Customer custCopy = manager.find(Customer.class, cust.getId()); custCopy.setCreditCard(cardCopy); manager.getTransaction().commit(); manager.clear(); cardCopy = manager.find(CreditCard.class, card.getId()); System.out.println("should be set now: " + cardCopy.getCustomer().getFirstName()); } finally { manager.close(); } return cust; }
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; }
/** * called when this event "happens". The customer first chooses the "best" checkout line, then * either starts checking out or waits in line. * * @externals requires Checkout, Customer, StartCheckoutEvent */ public void action() { SoopaStore.readNextArrival(); Checkout checkout = SoopaStore.preferableCheckout(); Customer customer = (Customer) this.getActor(); if (checkout.getLength() == 0) { // fire a StartCheckoutEvent at the next time unit. Event event = new StartCheckoutEvent(time + 1, customer, checkout); checkout.setCheckingOut(customer); SoopaStore.getEventList().insertInOrder(event); } else { // append self to queue. (stand in line) customer.startWaiting(time); checkout.getInLine(customer); } System.out.printf( "Time %d: Customer %d arrives (%d items, Patience %d, checkout %d)\n", time, customer.getId(), customer.getNumItems(), customer.getPatience(), checkout.getIndex()); }