Search in sources :

Example 6 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class AbstractQuerydslProcessor method processDelegateMethods.

private Set<TypeElement> processDelegateMethods() {
    Set<? extends Element> delegateMethods = getElements(QueryDelegate.class);
    Set<TypeElement> typeElements = new HashSet<TypeElement>();
    for (Element delegateMethod : delegateMethods) {
        ExecutableElement method = (ExecutableElement) delegateMethod;
        Element element = delegateMethod.getEnclosingElement();
        String name = method.getSimpleName().toString();
        Type delegateType = typeFactory.getType(element.asType(), true);
        Type returnType = typeFactory.getType(method.getReturnType(), true);
        List<Parameter> parameters = elementHandler.transformParams(method.getParameters());
        // remove first element
        parameters = parameters.subList(1, parameters.size());
        EntityType entityType = null;
        for (AnnotationMirror annotation : delegateMethod.getAnnotationMirrors()) {
            if (TypeUtils.isAnnotationMirrorOfType(annotation, QueryDelegate.class)) {
                TypeMirror type = TypeUtils.getAnnotationValueAsTypeMirror(annotation, "value");
                if (type != null) {
                    entityType = typeFactory.getEntityType(type, true);
                }
            }
        }
        if (entityType != null) {
            registerTypeElement(entityType.getFullName(), (TypeElement) element);
            entityType.addDelegate(new Delegate(entityType, delegateType, name, parameters, returnType));
            TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(entityType.getFullName());
            boolean isAnnotated = false;
            for (Class<? extends Annotation> ann : conf.getEntityAnnotations()) {
                if (typeElement.getAnnotation(ann) != null) {
                    isAnnotated = true;
                }
            }
            if (isAnnotated) {
                // handle also properties of entity type
                typeElements.add(processingEnv.getElementUtils().getTypeElement(entityType.getFullName()));
            } else {
                // skip handling properties
                context.extensionTypes.put(entityType.getFullName(), entityType);
                context.allTypes.put(entityType.getFullName(), entityType);
            }
        }
    }
    return typeElements;
}
Also used : Type(com.querydsl.codegen.utils.model.Type) NoType(javax.lang.model.type.NoType) DeclaredType(javax.lang.model.type.DeclaredType) TypeMirror(javax.lang.model.type.TypeMirror) QueryDelegate(com.querydsl.core.annotations.QueryDelegate) Parameter(com.querydsl.codegen.utils.model.Parameter)

Example 7 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class AbstractQuerydslProcessor method addExternalParents.

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());
            }
            if (conf.isStrictMode() && !TypeUtils.hasAnnotationOfType(typeElement, conf.getEntityAnnotations())) {
                continue;
            }
            EntityType superEntityType = elementHandler.handleEntityType(typeElement);
            if (superEntityType.getSuperType() != null) {
                superTypes.push(superEntityType.getSuperType().getType());
            }
            context.allTypes.put(superType.getFullName(), superEntityType);
        }
    }
}
Also used : Type(com.querydsl.codegen.utils.model.Type) NoType(javax.lang.model.type.NoType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 8 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class AbstractQuerydslProcessor method getClassName.

protected String getClassName(EntityType model) {
    Type type = conf.getTypeMappings().getPathType(model, model, true);
    String packageName = type.getPackageName();
    return packageName.isEmpty() ? type.getSimpleName() : (packageName + "." + type.getSimpleName());
}
Also used : Type(com.querydsl.codegen.utils.model.Type) NoType(javax.lang.model.type.NoType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 9 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class MetaDataTest method setUp.

@Before
public void setUp() {
    NamingStrategy namingStrategy = new DefaultNamingStrategy();
    String packageName = "com.myproject.domain";
    String tableName = "vwServiceName";
    String className = namingStrategy.getClassName(tableName);
    Type classTypeModel = new SimpleType(TypeCategory.ENTITY, packageName + "." + className, packageName, className, false, false);
    classModel = new EntityType(classTypeModel);
    // classModel.addAnnotation(new TableImpl(namingStrategy.normalizeTableName(tableName)));
    classModel.getData().put("table", namingStrategy.normalizeTableName(tableName));
}
Also used : EntityType(com.querydsl.codegen.EntityType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Before(org.junit.Before)

Example 10 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class MetaDataSerializer method serializeForeignKeys.

protected void serializeForeignKeys(EntityType model, CodeWriter writer, Collection<? extends KeyData> foreignKeys, boolean inverse) throws IOException {
    for (KeyData foreignKey : foreignKeys) {
        String fieldName;
        if (inverse) {
            fieldName = namingStrategy.getPropertyNameForInverseForeignKey(foreignKey.getName(), model);
        } else {
            fieldName = namingStrategy.getPropertyNameForForeignKey(foreignKey.getName(), model);
        }
        StringBuilder value = new StringBuilder();
        if (inverse) {
            value.append("createInvForeignKey(");
        } else {
            value.append("createForeignKey(");
        }
        if (foreignKey.getForeignColumns().size() == 1) {
            value.append(namingStrategy.getPropertyName(foreignKey.getForeignColumns().get(0), model));
            value.append(", \"").append(foreignKey.getParentColumns().get(0)).append("\"");
        } else {
            StringBuilder local = new StringBuilder();
            StringBuilder foreign = new StringBuilder();
            for (int i = 0; i < foreignKey.getForeignColumns().size(); i++) {
                if (i > 0) {
                    local.append(", ");
                    foreign.append(", ");
                }
                local.append(namingStrategy.getPropertyName(foreignKey.getForeignColumns().get(i), model));
                foreign.append("\"").append(foreignKey.getParentColumns().get(i)).append("\"");
            }
            value.append("Arrays.asList(").append(local).append("), Arrays.asList(").append(foreign).append(")");
        }
        value.append(")");
        Type type = new ClassType(ForeignKey.class, foreignKey.getType());
        writer.publicFinal(type, fieldName, value.toString());
    }
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) ClassType(com.querydsl.codegen.utils.model.ClassType) ForeignKeyData(com.querydsl.sql.codegen.support.ForeignKeyData) PrimaryKeyData(com.querydsl.sql.codegen.support.PrimaryKeyData) KeyData(com.querydsl.sql.codegen.support.KeyData) InverseForeignKeyData(com.querydsl.sql.codegen.support.InverseForeignKeyData)

Aggregations

Type (com.querydsl.codegen.utils.model.Type)56 SimpleType (com.querydsl.codegen.utils.model.SimpleType)35 ClassType (com.querydsl.codegen.utils.model.ClassType)23 EntityType (com.querydsl.codegen.EntityType)15 Test (org.junit.Test)14 PropertyType (com.querydsl.core.annotations.PropertyType)9 QueryType (com.querydsl.core.annotations.QueryType)9 DeclaredType (javax.lang.model.type.DeclaredType)9 NoType (javax.lang.model.type.NoType)9 Parameter (com.querydsl.codegen.utils.model.Parameter)7 ArrayList (java.util.ArrayList)7 TypeCategory (com.querydsl.codegen.utils.model.TypeCategory)6 StringWriter (java.io.StringWriter)6 ArrayType (javax.lang.model.type.ArrayType)6 ErrorType (javax.lang.model.type.ErrorType)6 ExecutableType (javax.lang.model.type.ExecutableType)6 NullType (javax.lang.model.type.NullType)6 PrimitiveType (javax.lang.model.type.PrimitiveType)6 WildcardType (javax.lang.model.type.WildcardType)6 Annotation (java.lang.annotation.Annotation)5