Exemple #1
0
  /**
   * If ObjEntity qualifier is set, asks it to inject initial value to an object. Also performs all
   * Persistent initialization operations
   */
  protected void injectInitialValue(Object obj) {
    // must follow this exact order of property initialization per CAY-653,
    // i.e. have
    // the id and the context in place BEFORE setPersistence is called

    Persistent object = (Persistent) obj;

    object.setObjectContext(this);
    object.setPersistenceState(PersistenceState.NEW);

    GraphManager graphManager = getGraphManager();
    synchronized (graphManager) {
      graphManager.registerNode(object.getObjectId(), object);
      graphManager.nodeCreated(object.getObjectId());
    }

    ObjEntity entity;
    try {
      entity = getEntityResolver().getObjEntity(object.getClass());
    } catch (CayenneRuntimeException ex) {
      // ObjEntity cannot be fetched, ignored
      entity = null;
    }

    if (entity != null) {
      if (entity.getDeclaredQualifier() instanceof ValueInjector) {
        ((ValueInjector) entity.getDeclaredQualifier()).injectValue(object);
      }
    }

    // invoke callbacks
    getEntityResolver().getCallbackRegistry().performCallbacks(LifecycleEvent.POST_ADD, object);
  }
  /**
   * Returns entity qualifier expressed as DB path qualifier or null if entity has no qualifier.
   *
   * @since 3.0
   */
  public Expression getDbQualifier() {
    if (entity.getDeclaredQualifier() == null) {
      return null;
    }

    if (normalizedQualifier == null) {
      normalizedQualifier = entity.translateToDbPath(entity.getDeclaredQualifier());
    }

    return normalizedQualifier;
  }
  /**
   * Returns a qualifier Expression that matches root entity of this tree and all its subentities.
   */
  public Expression qualifierForEntityAndSubclasses() {
    Expression qualifier = entity.getDeclaredQualifier();

    if (qualifier == null) {
      // match all
      return null;
    }

    if (subentities != null) {
      for (EntityInheritanceTree child : subentities) {
        Expression childQualifier = child.qualifierForEntityAndSubclasses();

        // if any child qualifier is null, just return null, since no filtering is
        // possible
        if (childQualifier == null) {
          return null;
        }

        qualifier = qualifier.orExp(childQualifier);
      }
    }

    return qualifier;
  }