Package com.avaje.ebean.bean

Examples of com.avaje.ebean.bean.EntityBean


  private void diffEmbedded(String prefix, EntityBean a, EntityBean b, BeanDescriptor<?> desc, Map<String, ValuePair> map) {

    BeanPropertyAssocOne<?>[] emb = desc.propertiesEmbedded();

    for (int i = 0; i < emb.length; i++) {
      EntityBean aval = (EntityBean)emb[i].getValue(a);
      EntityBean bval = (EntityBean)emb[i].getValue(b);
     
      if (!isBothNull(aval, bval)) {
        String propName = (prefix == null) ? emb[i].getName() : prefix + emb[i].getName();
        if (isDiffNull(aval, bval)) {
          // one of the embedded beans is null
View Full Code Here


    }
  }

  private void deleteList(List<?> beanList, Transaction t) {
    for (int i = 0; i < beanList.size(); i++) {
      EntityBean bean = (EntityBean)beanList.get(i);
      delete(bean, t);
    }
  }
View Full Code Here

        } else {
          q.where().idEq(id);
          if (t.isLogSummary()) {
            t.logSummary("-- DeleteById of " + descriptor.getName() + " id[" + id + "] requires fetch of foreign key values");
          }
          EntityBean bean = (EntityBean)server.findUnique(q, t);
          if (bean == null) {
            return 0;
          } else {
            delete(bean, t);
            return 1;
View Full Code Here

   * bean to the child beans.
   * </p>
   */
  private void saveAssocMany(boolean insertedParent, PersistRequestBean<?> request, boolean insertMode) {

    EntityBean parentBean = request.getEntityBean();
    BeanDescriptor<?> desc = request.getBeanDescriptor();
    SpiTransaction t = request.getTransaction();

    // exported ones with cascade save
    BeanPropertyAssocOne<?>[] expOnes = desc.propertiesOneExportedSave();
    for (int i = 0; i < expOnes.length; i++) {
      BeanPropertyAssocOne<?> prop = expOnes[i];

      // check for partial beans
      if (request.isLoadedProperty(prop)) {
        EntityBean detailBean = prop.getValueAsEntityBean(parentBean);
        if (detailBean != null) {
          if (prop.isSaveRecurseSkippable(detailBean)) {
            // skip saving this bean
          } else {
            t.depth(+1);
View Full Code Here

        SpiTransaction t = saveMany.getTransaction();
        // increase depth for batching order
        t.depth(+1);
        for (Object removedBean : modifyRemovals) {
          if (removedBean instanceof EntityBean) {
            EntityBean eb = (EntityBean)removedBean;
            if (eb._ebean_getIntercept().isLoaded()) {
              // only delete if the bean was loaded meaning that
              // it is know to exist in the DB
              deleteRecurse(removedBean, t);
            }
          }
View Full Code Here

    // if a map, then we get the key value and
    // set it to the appropriate property on the
    // detail bean before we save it
    boolean isMap = ManyType.JAVA_MAP.equals(prop.getManyType());
    EntityBean parentBean = (EntityBean)saveMany.getParentBean();
    Object mapKeyValue = null;

    boolean saveSkippable = prop.isSaveRecurseSkippable();
    boolean skipSavingThisBean = false;

    for (Object detailBean : collection) {
      if (isMap) {
        // its a map so need the key and value
        Map.Entry<?, ?> entry = (Map.Entry<?, ?>) detailBean;
        mapKeyValue = entry.getKey();
        detailBean = entry.getValue();
      }

      if (detailBean instanceof EntityBean == false) {
        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
View Full Code Here

      BeanPropertyAssocMany<?> manyProp = (BeanPropertyAssocMany<?>) prop;
      saveMany(new SaveManyPropRequest(manyProp, parentBean, (SpiTransaction) t), true);

    } else if (prop instanceof BeanPropertyAssocOne<?>) {
      BeanPropertyAssocOne<?> oneProp = (BeanPropertyAssocOne<?>) prop;
      EntityBean assocBean = oneProp.getValueAsEntityBean(parentBean);

      int depth = oneProp.isOneToOneExported() ? 1 : -1;
      int revertDepth = -1 * depth;

      trans.depth(depth);
 
View Full Code Here

    t.depth(+1);

    if (additions != null && !additions.isEmpty()) {
      for (Object other : additions) {
        EntityBean otherBean = (EntityBean)other;
        // the object from the 'other' side of the ManyToMany
        if (deletions != null && deletions.remove(otherBean)) {
          String m = "Inserting and Deleting same object? " + otherBean;
          if (t.isLogSummary()) {
            t.logSummary(m);
          }
          logger.warn(m);

        } else {
          if (!prop.hasImportedId(otherBean)) {
            String msg = "ManyToMany bean " + otherBean + " does not have an Id value.";
            throw new PersistenceException(msg);

          } else {
            // build a intersection row for 'insert'
            IntersectionRow intRow = prop.buildManyToManyMapBean(saveManyPropRequest.getParentBean(), otherBean);
            SqlUpdate sqlInsert = intRow.createInsert(server);
            executeSqlUpdate(sqlInsert, t);
          }
        }
      }
    }
    if (deletions != null && !deletions.isEmpty()) {
      for (Object other : deletions) {
        EntityBean otherDelete = (EntityBean)other;
        // the object from the 'other' side of the ManyToMany
        // build a intersection row for 'delete'
        IntersectionRow intRow = prop.buildManyToManyMapBean(saveManyPropRequest.getParentBean(), otherDelete);
        SqlUpdate sqlDelete = intRow.createDelete(server);
        executeSqlUpdate(sqlDelete, t);
View Full Code Here

    SpiTransaction t = request.getTransaction();
    t.depth(-1);

    BeanDescriptor<?> desc = request.getBeanDescriptor();
    EntityBean parentBean = request.getEntityBean();

    BeanPropertyAssocOne<?>[] expOnes = desc.propertiesOneExportedDelete();
    if (expOnes.length > 0) {

      DeleteUnloadedForeignKeys unloaded = null;
      for (int i = 0; i < expOnes.length; i++) {
        BeanPropertyAssocOne<?> prop = expOnes[i];
        if (request.isLoadedProperty(prop)) {
          Object detailBean = prop.getValue(parentBean);
          if (detailBean != null) {
            deleteRecurse(detailBean, t);
          }
        } else {
          if (unloaded == null) {
            unloaded = new DeleteUnloadedForeignKeys(server, request);
          }
          unloaded.add(prop);
        }
      }
      if (unloaded != null) {
        unloaded.queryForeignKeys();
        unloaded.deleteCascade();
      }
    }

    // Many's with delete cascade
    BeanPropertyAssocMany<?>[] manys = desc.propertiesManyDelete();
    for (int i = 0; i < manys.length; i++) {
      if (manys[i].isManyToMany()) {
        // delete associated rows from intersection table
        deleteAssocManyIntersection(parentBean, manys[i], t);

      } else {

        if (ModifyListenMode.REMOVALS.equals(manys[i].getModifyListenMode())) {
          // PrivateOwned ...
          Object details = manys[i].getValue(parentBean);
          if (details instanceof BeanCollection<?>) {
            Set<?> modifyRemovals = ((BeanCollection<?>) details).getModifyRemovals();
            if (modifyRemovals != null && !modifyRemovals.isEmpty()) {

              // delete the orphans that have been removed from the collection
              for (Object detail : modifyRemovals) {
                EntityBean detailBean = (EntityBean)detail;
                if (manys[i].hasId(detailBean)) {
                  deleteRecurse(detailBean, t);
                }
              }
            }
View Full Code Here

    for (int i = 0; i < ones.length; i++) {
      BeanPropertyAssocOne<?> prop = ones[i];

      // check for partial objects
      if (request.isLoadedProperty(prop)) {
        EntityBean detailBean = prop.getValueAsEntityBean(request.getEntityBean());
        if (detailBean != null) {
          if (prop.isReference(detailBean)) {
            // skip saving a reference
          } else if (request.isParent(detailBean)) {
            // skip saving the parent as already saved
View Full Code Here

TOP

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

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.