示例#1
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());
 }
  protected ClassDescriptor getDescriptor(ObjEntity entity, Class<?> entityClass) {
    String superEntityName = entity.getSuperEntityName();

    ClassDescriptor superDescriptor =
        (superEntityName != null) ? descriptorMap.getDescriptor(superEntityName) : null;

    PersistentDescriptor descriptor = createDescriptor();

    descriptor.setEntity(entity);
    descriptor.setSuperclassDescriptor(superDescriptor);
    descriptor.setObjectClass(entityClass);
    descriptor.setPersistenceStateAccessor(
        new BeanAccessor(entityClass, "persistenceState", Integer.TYPE));

    // only include this entity attributes and skip superclasses...
    for (ObjAttribute attribute : descriptor.getEntity().getDeclaredAttributes()) {

      if (attribute instanceof EmbeddedAttribute) {
        EmbeddedAttribute embedded = (EmbeddedAttribute) attribute;
        for (ObjAttribute objAttribute : embedded.getAttributes()) {
          createEmbeddedAttributeProperty(descriptor, embedded, objAttribute);
        }
      } else {
        createAttributeProperty(descriptor, attribute);
      }
    }

    // only include this entity relationships and skip superclasses...
    for (ObjRelationship relationship : descriptor.getEntity().getDeclaredRelationships()) {

      if (relationship.isToMany()) {

        String collectionType = relationship.getCollectionType();
        if (collectionType == null
            || ObjRelationship.DEFAULT_COLLECTION_TYPE.equals(collectionType)) {
          createToManyListProperty(descriptor, relationship);
        } else if (collectionType.equals("java.util.Map")) {
          createToManyMapProperty(descriptor, relationship);
        } else if (collectionType.equals("java.util.Set")) {
          createToManySetProperty(descriptor, relationship);
        } else if (collectionType.equals("java.util.Collection")) {
          createToManyCollectionProperty(descriptor, relationship);
        } else {
          throw new IllegalArgumentException(
              "Unsupported to-many collection type: " + collectionType);
        }
      } else {
        createToOneProperty(descriptor, relationship);
      }
    }

    EntityInheritanceTree inheritanceTree =
        descriptorMap.getResolver().getInheritanceTree(descriptor.getEntity().getName());
    descriptor.setEntityInheritanceTree(inheritanceTree);
    indexSubclassDescriptors(descriptor, inheritanceTree);
    indexQualifiers(descriptor, inheritanceTree);

    appendDeclaredRootDbEntity(descriptor, descriptor.getEntity());
    indexRootDbEntities(descriptor, inheritanceTree);

    indexSuperclassProperties(descriptor);

    descriptor.sortProperties();

    return descriptor;
  }