private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p)
     throws NoSuchMethodException, ClassNotFoundException {
   Type propertyType = getType(cl, p.getName());
   if (p.isComposite()) {
     Class<?> embeddedClass = Class.forName(propertyType.getFullName());
     EntityType embeddedType = createEmbeddableType(embeddedClass);
     Iterator<?> properties = ((Component) p.getValue()).getPropertyIterator();
     while (properties.hasNext()) {
       handleProperty(
           embeddedType, embeddedClass, (org.hibernate.mapping.Property) properties.next());
     }
     propertyType = embeddedType;
   } else if (propertyType.getCategory() == TypeCategory.ENTITY) {
     propertyType = createEntityType(Class.forName(propertyType.getFullName()));
   }
   AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
   Property property = createProperty(entityType, p.getName(), propertyType, annotated);
   entityType.addProperty(property);
 }
예제 #2
0
  @Override
  public void serialize(
      final EntityType model, SerializerConfig serializerConfig, CodeWriter writer)
      throws IOException {
    // intro
    intro(model, writer);

    String localName = writer.getRawName(model);

    for (Constructor c : model.getConstructors()) {
      // begin
      writer.beginConstructor(
          c.getParameters(),
          new Function<Parameter, Parameter>() {
            @Override
            public Parameter apply(Parameter p) {
              return new Parameter(
                  p.getName(), typeMappings.getExprType(p.getType(), model, false, false, true));
            }
          });

      // body
      writer.beginLine("super(" + localName + ".class");
      writer.append(", new Class[]{");
      boolean first = true;

      for (Parameter p : c.getParameters()) {
        if (!first) {
          writer.append(", ");
        }
        if (Types.PRIMITIVES.containsKey(p.getType())) {
          Type primitive = Types.PRIMITIVES.get(p.getType());
          writer.append(primitive.getFullName() + ".class");
        } else {
          writer.append(writer.getRawName(p.getType()));
          writer.append(".class");
        }
        first = false;
      }
      writer.append("}");

      for (Parameter p : c.getParameters()) {
        writer.append(", " + p.getName());
      }

      // end
      writer.append(");\n");
      writer.end();
    }

    // outro
    outro(model, writer);
  }
 private void addExternalParents(EntityType entityType) {
   Deque<Type> superTypes = new ArrayDeque<Type>();
   if (entityType.getSuperType() != null) {
     superTypes.push(entityType.getSuperType().getType());
   }
   while (!superTypes.isEmpty()) {
     Type superType = superTypes.pop();
     if (!context.allTypes.containsKey(superType.getFullName())) {
       TypeElement typeElement =
           processingEnv.getElementUtils().getTypeElement(superType.getFullName());
       if (typeElement == null) {
         throw new IllegalStateException("Found no type for " + superType.getFullName());
       }
       EntityType superEntityType = elementHandler.handleEntityType(typeElement);
       if (entityType.getSuperType() != null) {
         superTypes.push(entityType.getSuperType().getType());
       }
       context.allTypes.put(superType.getFullName(), superEntityType);
     }
   }
 }