Examples of EAddress


Examples of com.avaje.tests.model.embedded.EAddress

  @Test
  public void testSimpleCase() {
   
    // prepare test
    EAddress ship = new EAddress();
    ship.setStreet("1 Banana St");
    ship.setSuburb("Suburb");
    ship.setCity("Auckland");

    EAddress bill = new EAddress();
    bill.setStreet("2 Apple St");
    bill.setSuburb("Suburb");
    bill.setCity("Auckland");

    EInvoice invoice = new EInvoice();
    invoice.setDate(new Date(System.currentTimeMillis()));
    invoice.setState(State.New);
    invoice.setShipAddress(ship);
    invoice.setBillAddress(bill);
   
    // act: save and fetch
    Ebean.save(invoice);
   
    EInvoice invoice2 = Ebean.find(EInvoice.class)
      .where().idEq(invoice.getId())
      .findUnique();
   
    // assert fetched bean populated as expected
    Assert.assertEquals(invoice.getId(), invoice2.getId());
    Assert.assertEquals(invoice.getState(), invoice2.getState());
    Assert.assertEquals(invoice.getDate(), invoice2.getDate());
    Assert.assertEquals("2 Apple St", invoice.getBillAddress().getStreet());
    Assert.assertEquals("2 Apple St", invoice2.getBillAddress().getStreet());
   
    // act: only update one of the embedded fields
    invoice2.getBillAddress().setStreet("3 Pineapple St");
    // bean should be dirty
    Ebean.save(invoice2);
   
    EInvoice invoice3 = Ebean.find(EInvoice.class)
        .where().idEq(invoice.getId())
        .findUnique();
   
    // assert field has updated value
    Assert.assertEquals("3 Pineapple St", invoice3.getBillAddress().getStreet());
   
   
    // fetch a partial
    EInvoice invoicePartial = Ebean.find(EInvoice.class)
        .select("state, date")
        .where().idEq(invoice.getId())
        .findUnique();
   
    // lazy load of embedded bean
    EAddress billAddress = invoicePartial.getBillAddress();
     
    Assert.assertNotNull(billAddress);
    Assert.assertEquals("3 Pineapple St", billAddress.getStreet());
  
    EbeanServer server = Ebean.getServer(null);
    ServerCacheManager serverCacheManager = server.getServerCacheManager();
   
    // get cache, clear the cache and statistics
    ServerCache beanCache = serverCacheManager.getBeanCache(EInvoice.class);
    beanCache.clear();
    beanCache.getStatistics(true);
   
    // fetch and load the cache
    EInvoice invoice4 = Ebean.find(EInvoice.class)
        .where().idEq(invoice.getId())
        .setUseCache(true)
        .findUnique();
   
    Assert.assertNotNull(invoice4);
   
    ServerCacheStatistics statistics = beanCache.getStatistics(false);

    Assert.assertEquals(1, statistics.getSize());
    Assert.assertEquals(0, statistics.getHitCount());

    // fetch out of the cache this time
    EInvoice invoice5 = Ebean.find(EInvoice.class)
        .where().idEq(invoice.getId())
        .setUseCache(true)
        .findUnique();

    Assert.assertNotNull(invoice5);
   
    statistics = beanCache.getStatistics(false);
    Assert.assertEquals(1, statistics.getSize());
    Assert.assertEquals(1, statistics.getHitCount());

    billAddress = invoice5.getBillAddress();
   
    Assert.assertNotNull(billAddress);
    Assert.assertEquals("3 Pineapple St", billAddress.getStreet());

  }
View Full Code Here

Examples of com.avaje.tests.model.embedded.EAddress

   
    SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
    BeanDescriptor<EPerson> desc = server.getBeanDescriptor(EPerson.class);
    BeanPropertyAssocOne<?> addressBeanProperty = (BeanPropertyAssocOne<?>)desc.getBeanProperty("address");

    EAddress address = new EAddress();
    address.setStreet("92 Someplace Else");
    address.setSuburb("Sandringham");
    address.setCity("Auckland");

    EPerson person = new EPerson();
    person.setId(98989L);
    person.setName("Rob");
    person.setAddress(address);
   
    CachedBeanData addressCacheData = (CachedBeanData)addressBeanProperty.getCacheDataValue((EntityBean) person);
   
    EPerson newPersonCheck = new EPerson();
    newPersonCheck.setId(98989L);
    addressBeanProperty.setCacheDataValue((EntityBean) newPersonCheck, addressCacheData);

    EAddress newAddress = newPersonCheck.getAddress();
    Assert.assertEquals(address.getStreet(), newAddress.getStreet());
    Assert.assertEquals(address.getCity(), newAddress.getCity());
    Assert.assertEquals(address.getSuburb(), newAddress.getSuburb());



   
    CachedBeanData cacheData = desc.cacheBeanExtractData((EntityBean)person);
View Full Code Here

Examples of org.apache.openjpa.persistence.xmlmapping.entities.EAddress

    private void persistEntities(EntityManager em) {
        Customer c2 = new Customer();
        c2.setCid( new Customer.CustomerKey("USA", 2) );
        c2.setName("A&J Auto");
        c2.setRating( CreditRating.GOOD );
        c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
                , "95123"));
        em.persist(c2);

        Customer c1 = new Customer();
        c1.setCid( new Customer.CustomerKey("USA", 1) );
        c1.setName("Harry's Auto");
        c1.setRating( CreditRating.GOOD );
        c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA",
                "95141"));
        em.persist(c1);

        Order o1 = new Order(ORDER_1_OID, ORDER_1_AMOUNT, ORDER_1_DELIVERED,
                c1);
View Full Code Here

Examples of org.apache.openjpa.persistence.xmlmapping.entities.EAddress

    private void persistEntities(EntityManager em) {
        Customer c2 = new Customer();
        c2.setCid( new Customer.CustomerKey("USA", 2) );
        c2.setName("A&J Auto");
        c2.setRating( CreditRating.GOOD );
        c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
                , "95123"));
        em.persist(c2);

        Customer c1 = new Customer();
        c1.setCid( new Customer.CustomerKey("USA", 1) );
        c1.setName("Harry's Auto");
        c1.setRating( CreditRating.GOOD );
        c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA",
                "95141"));
        em.persist(c1);

        Order o1 = new Order(ORDER_1_OID, ORDER_1_AMOUNT, ORDER_1_DELIVERED,
                c1);
View Full Code Here

Examples of org.apache.openjpa.persistence.xmlmapping.entities.EAddress

    private void persistEntities(EntityManager em) {
        Customer c2 = new Customer();
        c2.setCid( new Customer.CustomerKey("USA", 2) );
        c2.setName("A&J Auto");
        c2.setRating( CreditRating.GOOD );
        c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
                , "95123"));
        em.persist(c2);

        Customer c1 = new Customer();
        c1.setCid( new Customer.CustomerKey("USA", 1) );
        c1.setName("Harry's Auto");
        c1.setRating( CreditRating.GOOD );
        c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA",
                "95141"));
        em.persist(c1);

        Order o1 = new Order(ORDER_1_OID, ORDER_1_AMOUNT, ORDER_1_DELIVERED,
                c1);
View Full Code Here

Examples of org.apache.openjpa.persistence.xmlmapping.entities.EAddress

    private void persistEntities(EntityManager em) {
        Customer c2 = new Customer();
        c2.setCid( new Customer.CustomerKey("USA", 2) );
        c2.setName("A&J Auto");
        c2.setRating( CreditRating.GOOD );
        c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
                , "95123"));
        em.persist(c2);

        Customer c1 = new Customer();
        c1.setCid( new Customer.CustomerKey("USA", 1) );
        c1.setName("Harry's Auto");
        c1.setRating( CreditRating.GOOD );
        c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA",
                "95141"));
        em.persist(c1);

        Order o1 = new Order(ORDER_1_OID, ORDER_1_AMOUNT, ORDER_1_DELIVERED,
                c1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.