public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
    ObjEntity entity = resolver.getObjEntity(((ObjectId) nodeId).getEntityName());
    ObjRelationship relationship = (ObjRelationship) entity.getRelationship(arcId.toString());

    if (relationship.isSourceIndependentFromTargetChange()) {

      if (!((ObjectId) nodeId).isTemporary()) {
        indirectModifications.add(nodeId);
      }

      if (relationship.isFlattened()) {
        if (relationship.isReadOnly()) {
          throw new CayenneRuntimeException(
              "Cannot set the read-only flattened relationship '"
                  + relationship.getName()
                  + "' in ObjEntity '"
                  + relationship.getSourceEntity().getName()
                  + "'.");
        }

        // Register this combination (so we can remove it later if an insert
        // occurs before commit)
        FlattenedArcKey key =
            new FlattenedArcKey((ObjectId) nodeId, (ObjectId) targetNodeId, relationship);

        // If this combination has already been deleted, simply undelete it.
        if (!flattenedDeletes.remove(key)) {
          flattenedInserts.add(key);
        }
      }
    }
  }
  public void testPrefetch_ToManyNoReverseWithQualifier() throws Exception {
    createTwoArtistsAndTwoPaintingsDataSet();

    ObjEntity paintingEntity = context.getEntityResolver().lookupObjEntity(Painting.class);
    ObjRelationship relationship = (ObjRelationship) paintingEntity.getRelationship("toArtist");
    paintingEntity.removeRelationship("toArtist");

    try {

      SelectQuery q = new SelectQuery(Artist.class);
      q.setQualifier(ExpressionFactory.matchExp("artistName", "artist2"));
      q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);

      final List<Artist> result = context.performQuery(q);

      queryInterceptor.runWithQueriesBlocked(
          new UnitTestClosure() {

            public void execute() {
              assertFalse(result.isEmpty());
              Artist a1 = result.get(0);
              List<?> toMany = (List<?>) a1.readPropertyDirectly("paintingArray");
              assertNotNull(toMany);
              assertFalse(((ValueHolder) toMany).isFault());
            }
          });

    } finally {
      paintingEntity.addRelationship(relationship);
    }
  }
Esempio n. 3
0
  /**
   * Returns a named Relationship that either belongs to this ObjEntity or is inherited. Returns
   * null if no matching attribute is found.
   */
  @Override
  public ObjRelationship getRelationship(String name) {
    ObjRelationship relationship = (ObjRelationship) super.getRelationship(name);
    if (relationship != null) {
      return relationship;
    }

    if (superEntityName == null) {
      return null;
    }

    ObjEntity superEntity = getSuperEntity();
    return (superEntity != null) ? superEntity.getRelationship(name) : null;
  }
Esempio n. 4
0
 /**
  * Simule la présence d'une valeur.
  *
  * <p>Seules les relations toOne sont supportées.
  *
  * @param property La propriété à simuler.
  */
 public void fake(String property) {
   // Test de la propriété
   ObjEntity ent = objEntity();
   ObjRelationship rel = (ObjRelationship) ent.getRelationship(property);
   if (rel == null) {
     throw new IllegalArgumentException("Pas de relation " + ent.getName() + "." + property);
   }
   if (rel.isToMany()) {
     throw new IllegalArgumentException(
         "La relation " + ent.getName() + "." + property + " n'est pas un toOne");
   }
   ObjEntity targetEntity = (ObjEntity) rel.getTargetEntity();
   // Ok, ajout.
   fakes.put(property, targetEntity.getJavaClass());
 }