Package com.avaje.ebean.bean

Examples of com.avaje.ebean.bean.EntityBeanIntercept


  public void testEmbeddedUpdateSetNewBean() {
   
    EMain emain = new EMain();

    EntityBean eb = (EntityBean)emain;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();

    emain.setId(1);
    emain.setName("foo");
    Eembeddable embeddable = setEmbeddedBean(emain, "bar");
    setEmbeddedLoaded(embeddable);
   
    // sets loaded state so follow setters are deemed as changes to the bean
    ebi.setLoaded();
   
    emain.setName("changedFoo");

    Assert.assertSame(embeddable, emain.getEmbeddable());
View Full Code Here


    embeddable.setDescription(description);
   
    emain.setEmbeddable(embeddable);
   
    EntityBean owner = (EntityBean)emain;
    EntityBeanIntercept ebi= owner._ebean_getIntercept();
   
    // hooks the embeddable bean back to the owner
    int embeddablePropertyIndex = ebi.findProperty("embeddable");
    Assert.assertTrue(embeddablePropertyIndex > -1);
    ((EntityBean)embeddable)._ebean_getIntercept().setEmbeddedOwner(owner, embeddablePropertyIndex);
    return embeddable;
  }
View Full Code Here

  public void test() {
   
    PFile persistentFile = new PFile("test.txt", new PFileContent("test".getBytes()));

    EntityBean eb = (EntityBean)persistentFile;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();
   
    int namePos = ebi.findProperty("name");
    int fileContentPos = ebi.findProperty("fileContent");
   
    Assert.assertTrue(ebi.isLoadedProperty(namePos));
    Assert.assertTrue(ebi.isLoadedProperty(fileContentPos));
   
  }
View Full Code Here

    String generatedSql = query.getGeneratedSql();
    Assert.assertTrue(generatedSql.contains("select distinct t0.name c0 from o_customer t0"));
   
    for (Customer customer : customers) {
     
      EntityBeanIntercept ebi = ((EntityBean)customer)._ebean_getIntercept();
      Assert.assertTrue(ebi.isDisableLazyLoad());
      Assert.assertNull(ebi.getPersistenceContext());
     
      // lazy loading disabled
      Assert.assertNull(customer.getId());
      Assert.assertNull(customer.getAnniversary());
    }
View Full Code Here

    SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
    BeanDescriptor<Customer> custDesc = server.getBeanDescriptor(Customer.class);
   
    Customer customer = new Customer();
    EntityBean eb = (EntityBean)customer;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();
   
    BeanProperty contactsProperty = custDesc.getBeanProperty("contacts");
    Assert.assertFalse(ebi.isLoadedProperty(contactsProperty.getPropertyIndex()));
   
    Object contactsViaInternal = contactsProperty.getValue(eb);
    Assert.assertNull(contactsViaInternal);
    Assert.assertFalse(ebi.isLoadedProperty(contactsProperty.getPropertyIndex()));
   
    List<Contact> contacts = customer.getContacts();
    Assert.assertNotNull(contacts);
    Assert.assertTrue(contacts instanceof BeanCollection);
    Assert.assertTrue(ebi.isLoadedProperty(contactsProperty.getPropertyIndex()));
  }
View Full Code Here

  public void testIsReference() {
   
    BeanDescriptor<Customer> beanDescriptor = spiServer.getBeanDescriptor(Customer.class);
   
    Customer order = new Customer();
    EntityBeanIntercept ebi = getIntercept(order);
    Assert.assertFalse(beanDescriptor.hasIdPropertyOnly(ebi));
   
    order.setId(23);
    Assert.assertTrue(beanDescriptor.hasIdPropertyOnly(ebi));
View Full Code Here

       
    LoggedSqlCollector.start();
   
    Customer customer = query.findUnique();
    EntityBean eb = (EntityBean)customer;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();
   
    Assert.assertTrue(ebi.isFullyLoadedBean());
   
    // find the internal property index for "billingAddress"
    String[] propNames = eb._ebean_getPropertyNames();
    int pos = 0;
    for (int i = 0; i < propNames.length; i++) {
      if (propNames[i].equals("billingAddress")) {
        pos = i;
      }
    }
   
    // The billing address is loaded (but value null)
    Assert.assertTrue(ebi.isLoadedProperty(pos));
   
    Set<String> loadedPropertyNames = ebi.getLoadedPropertyNames();
    Assert.assertNull(loadedPropertyNames);
   
    // no lazy loading expected here, value is null
    Address billingAddress = customer.getBillingAddress();
    Assert.assertNull(billingAddress);
View Full Code Here

public class CachedBeanDataToBean {


  public static boolean load(BeanDescriptor<?> desc, EntityBean bean, CachedBeanData cacheBeanData) {
   
    EntityBeanIntercept ebi = bean._ebean_getIntercept();

   
    BeanProperty idProperty = desc.getIdProperty();
    if (idProperty != null) {
      // load the id property
      loadProperty(bean, cacheBeanData, ebi, idProperty);
    }
   
    // load the non-many properties
    BeanProperty[] props = desc.propertiesNonMany();
    for (int i = 0; i < props.length; i++) {
      loadProperty(bean, cacheBeanData, ebi, props[i]);
    }

    BeanPropertyAssocMany<?>[] manys = desc.propertiesMany();
    for (int i = 0; i < manys.length; i++) {
      manys[i].createReferenceIfNull(bean);
    }

    ebi.setLoadedLazy();

    return true;
  }
View Full Code Here

public class CachedBeanDataFromBean {


  public static CachedBeanData extract(BeanDescriptor<?> desc, EntityBean bean) {

    EntityBeanIntercept ebi = bean._ebean_getIntercept();
   
    Object[] data = new Object[desc.getPropertyCount()];
    boolean[] loaded = new boolean[desc.getPropertyCount()];
   
    BeanProperty idProperty = desc.getIdProperty();
    if (idProperty != null) {
      int propertyIndex = idProperty.getPropertyIndex();
      if (ebi.isLoadedProperty(propertyIndex)) {
        // extract the id property value
        data[propertyIndex] = idProperty.getCacheDataValue(bean);
        loaded[propertyIndex] = true;
      }
    }
    BeanProperty[] props = desc.propertiesNonMany();

    Object naturalKey = null;

    // extract all the non-many properties
    for (int i = 0; i < props.length; i++) {
      BeanProperty prop = props[i];
      if (ebi.isLoadedProperty(prop.getPropertyIndex())) {
        int propertyIndex = prop.getPropertyIndex();
        data[propertyIndex] = prop.getCacheDataValue(bean);
        loaded[propertyIndex] = true;
        if (prop.isNaturalKey()) {
          naturalKey = prop.getValue(bean);
View Full Code Here

    BeanProperty[] propertiesNonTransient = desc.propertiesNonTransient();
    for (int i = 0; i < propertiesNonTransient.length; i++) {
      Object v = propertiesNonTransient[i].getValue(bean);
      propertiesNonTransient[i].setValue(sharableBean, v);
    }
    EntityBeanIntercept intercept = sharableBean._ebean_intercept();
    intercept.setReadOnly(true);
    intercept.setLoaded();
    return sharableBean;
  }
View Full Code Here

TOP

Related Classes of com.avaje.ebean.bean.EntityBeanIntercept

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.