Package com.avaje.ebean.bean

Examples of com.avaje.ebean.bean.EntityBeanIntercept


    // take a copy of the raw data and loaded status
    boolean[] copyLoaded = existingData.copyLoaded();
    Object[] copyData = existingData.copyData();

    EntityBeanIntercept ebi = updateBean._ebean_getIntercept();

    Object newNaturalKey = null;
    Object oldNaturalKey = existingData.getNaturalKey();

    BeanProperty[] props = desc.propertiesNonMany();
    for (int i = 0; i < props.length; i++) {
      // check if the properties was in the update
      int propertyIndex = props[i].getPropertyIndex();
      if (ebi.isLoadedProperty(propertyIndex)) {
        if (props[i].isNaturalKey()) {
          newNaturalKey = updateBean._ebean_getField(propertyIndex);
        }
        // set the cache safe value for the property and mark it as loaded
        copyData[propertyIndex] = props[i].getCacheDataValue(updateBean);
View Full Code Here


        skipSavingThisBean = true;
        logger.debug("Skip non entity bean");
     
      } else {
        EntityBean detail = (EntityBean)detailBean;
        EntityBeanIntercept ebi = detail._ebean_getIntercept();
        if (prop.isManyToMany()) {
          skipSavingThisBean = targetDescriptor.isReference(ebi);
        } else {
          if (targetDescriptor.isReference(ebi)) {
            // we can skip this one
            skipSavingThisBean = true;

          } else if (ebi.isNewOrDirty()) {
            skipSavingThisBean = false;
            // set the parent bean to detailBean
            prop.setJoinValuesToChild(parentBean, detail, mapKeyValue);           

          } else {
View Full Code Here

      if (context.hitCache) {
        // Check each of the beans in the batch to see if they are in the L2 cache.
        Iterator<EntityBeanIntercept> iterator = list.iterator();
        while (iterator.hasNext()) {
          EntityBeanIntercept bean = iterator.next();
          if (context.desc.cacheBeanLoad(bean)) {
            iterator.remove();
          }
        }
      }
View Full Code Here

    loadManyInternal(parentBean, propertyName, t, true, null, false);
  }

  private void loadManyInternal(EntityBean parentBean, String propertyName, Transaction t, boolean refresh, ObjectGraphNode node, boolean onlyIds) {

    EntityBeanIntercept ebi = ((EntityBean) parentBean)._ebean_getIntercept();
    PersistenceContext pc = ebi.getPersistenceContext();

    BeanDescriptor<?> parentDesc = server.getBeanDescriptor(parentBean.getClass());
    BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>) parentDesc.getBeanProperty(propertyName);

    BeanCollection<?> beanCollection = null;
    ExpressionList<?> filterMany = null;
   
    Object currentValue = many.getValue(parentBean);
    if (currentValue instanceof BeanCollection<?>) {
      beanCollection = (BeanCollection<?>) currentValue;
      filterMany = beanCollection.getFilterMany();
    }

    Object parentId = parentDesc.getId(parentBean);

    if (pc == null) {
      pc = new DefaultPersistenceContext();
      pc.put(parentId, parentBean);
    }

    boolean useManyIdCache = beanCollection != null && parentDesc.isManyPropCaching();
    if (useManyIdCache) {
      Boolean readOnly = null;
      if (ebi != null && ebi.isReadOnly()) {
        readOnly = Boolean.TRUE;
      }
      if (parentDesc.cacheManyPropLoad(many, beanCollection, parentId, readOnly)) {
        return;
      }
    }

    SpiQuery<?> query = (SpiQuery<?>) server.createQuery(parentDesc.getBeanType());

    if (refresh) {
      // populate a new collection
      Object emptyCollection = many.createEmpty(false);
      many.setValue(parentBean, emptyCollection);
      query.setLoadDescription("+refresh", null);
    } else {
      query.setLoadDescription("+lazy", null);
    }

    if (node != null) {
      // so we can hook back to the root query
      query.setParentNode(node);
    }

    String idProperty = parentDesc.getIdBinder().getIdProperty();
    query.select(idProperty);

    if (onlyIds) {
      query.fetch(many.getName(), many.getTargetIdProperty());
    } else {
      query.fetch(many.getName());
    }
    if (filterMany != null) {
      query.setFilterMany(many.getName(), filterMany);
    }

    query.where().idEq(parentId);
    query.setUseCache(false);
    query.setMode(Mode.LAZYLOAD_MANY);
    query.setLazyLoadManyPath(many.getName());
    query.setPersistenceContext(pc);

    if (ebi != null) {
      if (ebi.isReadOnly()) {
        query.setReadOnly(true);
      }
    }

    server.findUnique(query, t);
View Full Code Here

    EntityBeanIntercept[] ebis = batch.toArray(new EntityBeanIntercept[batch.size()]);
    ArrayList<Object> idList = new ArrayList<Object>(batchSize);

    for (int i = 0; i < batch.size(); i++) {
      EntityBeanIntercept ebi = batch.get(i);
      EntityBean bean = ebi.getOwner();
      Object id = desc.getId(bean);
      idList.add(id);
    }

    if (idList.isEmpty()) {
View Full Code Here

    refreshBeanInternal(ebi.getOwner(), SpiQuery.Mode.LAZYLOAD_BEAN, -1);
  }

  private void refreshBeanInternal(EntityBean bean, SpiQuery.Mode mode, int embeddedOwnerIndex) {

    EntityBeanIntercept ebi = ((EntityBean) bean)._ebean_getIntercept();;
    PersistenceContext pc = ebi.getPersistenceContext();

    BeanDescriptor<?> desc = server.getBeanDescriptor(bean.getClass());
    if (EntityType.EMBEDDED == desc.getEntityType()) {
      // lazy loading on an embedded bean property
      EntityBean embeddedOwner = (EntityBean)ebi.getEmbeddedOwner();
      int ownerIndex = ebi.getEmbeddedOwnerIndex();

      refreshBeanInternal(embeddedOwner, mode, ownerIndex);
    }
   
    Object id = desc.getId(bean);

    if (pc == null) {
      // a reference with no existing persistenceContext
      pc = new DefaultPersistenceContext();
      pc.put(id, bean);
      if (ebi != null) {
        ebi.setPersistenceContext(pc);
      }
    }

    if (embeddedOwnerIndex == -1) {
      if (SpiQuery.Mode.LAZYLOAD_BEAN.equals(mode) && desc.isBeanCaching()) {
        // lazy loading and the bean cache is active
        if (desc.cacheBeanLoad((EntityBean)bean, ebi, id)) {
          return;
        }
      }
      if (desc.lazyLoadMany(ebi)) {
        return;
      }
    }

    SpiQuery<?> query = (SpiQuery<?>) server.createQuery(desc.getBeanType());
    if (ebi != null) {
      query.setLazyLoadProperty(ebi.getLazyLoadProperty());
    }

    if (embeddedOwnerIndex > -1) {
      String embeddedBeanPropertyName = ebi.getProperty(embeddedOwnerIndex);
      query.select("id,"+embeddedBeanPropertyName);
    }
   
    // don't collect autoFetch usage profiling information
    // as we just copy the data out of these fetched beans
    // and put the data into the original bean
    query.setUsageProfiling(false);
    query.setPersistenceContext(pc);

    query.setMode(mode);
    query.setId(id);

    if (embeddedOwnerIndex > -1 || mode.equals(SpiQuery.Mode.REFRESH_BEAN)) {
      // make sure the query doesn't use the cache
      query.setUseCache(false);
    }

    if (ebi.isReadOnly()) {
      query.setReadOnly(true);
    }
   
    if (SpiQuery.Mode.REFRESH_BEAN.equals(mode)) {
      // explicitly state to load all properties on REFRESH.
View Full Code Here

        createListProxies(localDesc, ctx, localBean);
      }
      localDesc.postLoad(localBean, null);

      if (localBean instanceof EntityBean) {
        EntityBeanIntercept ebi = ((EntityBean) localBean)._ebean_getIntercept();
        ebi.setPersistenceContext(persistenceContext);
        if (Mode.LAZYLOAD_BEAN.equals(queryMode)) {
          // Lazy Load does not reset the dirty state
          ebi.setLoadedLazy();
        } else {
          // normal bean loading
          ebi.setLoaded();
        }

        if (partialObject) {
          if (readId) {
            // register for lazy loading
            ctx.register(null, ebi);
          }
        } else {
          ebi.setFullyLoadedBean(true);
        }

        if (disableLazyLoad) {
          // bean does not have an Id or is SqlSelect based
          ebi.setDisableLazyLoad(true);
        }
        if (ctx.isAutoFetchProfiling()) {
          // collect autofetch profiling for this bean...
          ctx.profileBean(ebi, prefix);
        }
View Full Code Here

   
    tunedInfo.autoFetchTune((SpiQuery<?>)query);
   
    Order order = query.findUnique();
    EntityBean eb = (EntityBean)order;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();
   
    Assert.assertTrue(ebi.isFullyLoadedBean());
   
    Set<String> loadedPropertyNames = ebi.getLoadedPropertyNames();
    Assert.assertNull(loadedPropertyNames);
   
    // invoke lazy loading
    order.getCustomer();
  }
View Full Code Here

   
    tunedInfo.autoFetchTune((SpiQuery<?>)query);
   
    Order order = query.findUnique();
    EntityBean eb = (EntityBean)order;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();
   
    Assert.assertTrue(ebi.isFullyLoadedBean());
   
    Set<String> loadedPropertyNames = ebi.getLoadedPropertyNames();
    Assert.assertNull(loadedPropertyNames);
   
    // invoke lazy loading
    order.getCustomer();
  }
View Full Code Here

   
    LoggedSqlCollector.start();
   
    Order order = query.findUnique();
    EntityBean eb = (EntityBean)order;
    EntityBeanIntercept ebi = eb._ebean_getIntercept();
   
    Assert.assertFalse(ebi.isFullyLoadedBean());
   
    // id and any ToMany relationships
    Set<String> loadedPropertyNames = ebi.getLoadedPropertyNames();
    Assert.assertNotNull(loadedPropertyNames);
   
    // invoke lazy loading
    order.getCustomer();
   
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.