Package com.avaje.tests.model.basic

Examples of com.avaje.tests.model.basic.Customer


   
    List<Customer> list = Ebean.find(Customer.class).findList();
   
    Listener listener = new Listener();
   
    Customer customer = list.get(0);
    Ebean.getBeanState(customer).addPropertyChangeListener(listener);
   
    customer.setName("modName");
    customer.setSmallnote("modSmallNote");
   
    Assert.assertEquals(2, listener.events.size());
    Assert.assertEquals("modName", listener.events.get(0).getNewValue());
    Assert.assertEquals("name", listener.events.get(0).getPropertyName());
    Assert.assertEquals("modSmallNote", listener.events.get(1).getNewValue());
View Full Code Here


    Assert.assertTrue(list.size() > 1);
    // Assert.assertEquals(list.size(),
    // custCache.getStatistics(false).getSize());

    Customer customer = list.get(0);
    List<Contact> contacts = customer.getContacts();
    // Assert.assertEquals(0, custManyIdsCache.getStatistics(false).getSize());
    contacts.size();
    Assert.assertTrue(contacts.size() > 1);
    // Assert.assertEquals(1, custManyIdsCache.getStatistics(false).getSize());
    // Assert.assertEquals(0,
    // custManyIdsCache.getStatistics(false).getHitCount());

    fetchCustomer(customer.getId());
    // Assert.assertEquals(1,
    // custManyIdsCache.getStatistics(false).getHitCount());

    fetchCustomer(customer.getId());
    // Assert.assertEquals(2,
    // custManyIdsCache.getStatistics(false).getHitCount());

    int currentNumContacts = fetchCustomer(customer.getId());
    // Assert.assertEquals(3,
    // custManyIdsCache.getStatistics(false).getHitCount());

    Contact newContact = ResetBasicData.createContact("Check", "CollIds");
    newContact.setCustomer(customer);

    Ebean.save(newContact);

    int currentNumContacts2 = fetchCustomer(customer.getId());
    Assert.assertEquals(currentNumContacts + 1, currentNumContacts2);

    System.out.println("custCache:" + custCache.getStatistics(false));
    System.out.println("contactCache:" + contactCache.getStatistics(false));
    System.out.println("custManyIdsCache:" + custManyIdsCache.getStatistics(false));
View Full Code Here

  }

  private int fetchCustomer(Integer id) {

    Customer customer2 = Ebean.find(Customer.class).setId(id)
    // .setUseCache(true)
        .findUnique();

    List<Contact> contacts2 = customer2.getContacts();
    contacts2.size();
    for (Contact contact : contacts2) {
      contact.getFirstName();
      contact.getEmail();
    }
View Full Code Here

      Order order = oa.getOrder();
      Integer id = order.getId();
      Status status = order.getStatus();
      System.out.println("Order: " + id + " " + status + " total:" + totalAmount);

      Customer c = order.getCustomer();
      System.out.println("   -> customer: " + c.getId() + " " + c.getName());

      // invoke lazy loading as this property
      // has not populated originally
      // order.getOrderDate();
    }
View Full Code Here

      Order order = oa.getOrder();
      Integer id = order.getId();
      Status status = order.getStatus();
      System.out.println("Order: " + id + " " + status + " total:" + totalAmount);

      Customer c = order.getCustomer();
      System.out.println("   -> customer: " + c.getId() + " " + c.getName());

      // invoke lazy loading as this property
      // has not populated originally
      // order.getOrderDate();
    }
View Full Code Here

    ResetBasicData.reset();

    ServerCacheManager serverCacheManager = Ebean.getServerCacheManager();
    boolean originallyBeanCaching = serverCacheManager.isBeanCaching(Customer.class);

    Customer customer = Ebean.getReference(Customer.class, 1);

    // invoke lazy loading
    customer.getName();

    if (!originallyBeanCaching) {
      // the lazy loading shouldn't start the L2 bean cache
      boolean beanCachingAfter = serverCacheManager.isBeanCaching(Customer.class);
      Assert.assertFalse(beanCachingAfter);
View Full Code Here

    Address a = new Address();
    a.setId((short)12);
    a.setLine1("line1");
    a.setCity("Auckland");
   
    Customer c0 = new Customer();
    c0.setBillingAddress(a);

    Customer c1 = new Customer();

    SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
    BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);

    ElPropertyValue elProp = descriptor.getElGetValue("billingAddress.id");
View Full Code Here

        // .fetch("customer.contacts","id")
        .fetch("customer.contacts.notes", "title").findList();

    for (Order order : list) {
      order.getStatus();
      Customer customer = order.getCustomer();
      List<Contact> contacts = customer.getContacts();
      for (Contact contact : contacts) {
        System.out.println("contact:" + contact);
        List<ContactNote> notes = contact.getNotes();
        for (ContactNote contactNote : notes) {
          System.out.println("note:" + contactNote.getTitle());
View Full Code Here

        .fetch("customer", "name", new FetchConfig().query(10))
        .fetch("customer.contacts", "firstName, lastName, mobile")
        .fetch("customer.shippingAddress", "line1, city").order().asc("id").findList();

    Order o0 = l0.get(0);
    Customer c0 = o0.getCustomer();
    List<Contact> contacts = c0.getContacts();
    Assert.assertTrue(contacts.size() > 0);

    // query 1) find order (status, shipDate)
    // query 2) find orderDetail (quantity, price) join product (sku, name)
    // where order.id in (?,? ...)
    // query 3) find customer (name) join contacts (*) join shippingAddress (*)
    // where id in (?,?,?,?,?)

    List<Order> orders = Ebean.find(Order.class)
    // .select("status")
        .fetch("customer", new FetchConfig().query(3).lazy(10)).order().asc("id").findList();
    // .join("customer.contacts");

    // List<Order> list = query.findList();

    Order order = orders.get(0);
    Customer customer = order.getCustomer();

    // this invokes lazy loading on a property that is
    // not one of the selected ones (name, status) ... and
    // therefore the lazy load query selects all properties
    // in the customer (not just name and status)
    Address billingAddress = customer.getBillingAddress();

    Assert.assertNotNull(billingAddress);

    List<Order> list = Ebean.find(Order.class).fetch("customer", "name", new FetchConfig().lazy(5))
        .fetch("customer.contacts", "contactName, phone, email").fetch("customer.shippingAddress")
        .where().eq("status", Order.Status.NEW).order().asc("id").findList();

    Order order2 = list.get(0);
    Customer customer2 = order2.getCustomer();
    // customer2.getStatus();
    String name = customer2.getName();
    Assert.assertNotNull(name);

    String q = "find order join customer (+query(1) +lazy(10) name, status) join customer.contacts ";
    Query<Order> query = Ebean.createQuery(Order.class, q);

View Full Code Here

        //.fetch("orders.details", new FetchConfig().query())
        //.fetch("orders.shipments", new FetchConfig().query())
        .findList();
   
    for (Order order : list) {
      Customer customer = order.getCustomer();
      customer.getName();
    }

  }
View Full Code Here

TOP

Related Classes of com.avaje.tests.model.basic.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.