Package com.mysema.codegen.model

Examples of com.mysema.codegen.model.Type


        EntityType classModel;

        if (beanSerializer == null) {
            String packageName = normalizePackage(module.getPackageName(), schemaName);
            String simpleName = module.getPrefix() + className + module.getSuffix();
            Type classTypeModel = new SimpleType(TypeCategory.ENTITY,
                    packageName + "." + simpleName,  packageName, simpleName, false, false);
            classModel = new EntityType(classTypeModel);
            typeMappings.register(classModel, classModel);

        } else {
            String beanPackage = normalizePackage(beanPackageName, schemaName);
            String simpleName = module.getBeanPrefix() + className + module.getBeanSuffix();
            Type classTypeModel = new SimpleType(TypeCategory.ENTITY,
                    beanPackage + "." + simpleName, beanPackage, simpleName, false, false);
            classModel = new EntityType(classTypeModel);

            Type mappedType = queryTypeFactory.create(classModel);
            entityToWrapped.put(classModel, mappedType);
            typeMappings.register(classModel, mappedType);
        }

        classModel.getData().put("schema", schemaName);
View Full Code Here


        TypeMappings typeMappings = new JavaTypeMappings();
        EntityType model = new EntityType(new ClassType(TypeMappingsTest.class));
        EntityType type = new EntityType(new ClassType(Entity.class));
        typeMappings.register(type, new QueryTypeFactoryImpl("Q","","").create(type));

        Type pathType = typeMappings.getPathType(type, model, false);
        assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName());
    }
View Full Code Here

    private void addConstructors(Class<?> cl, EntityType type) {
        for (Constructor<?> constructor : cl.getConstructors()) {
            if (constructor.getAnnotation(QueryProjection.class) != null) {
                List<Parameter> parameters = Lists.newArrayList();
                for (int i = 0; i < constructor.getParameterTypes().length; i++) {
                    Type parameterType = typeFactory.get(
                            constructor.getParameterTypes()[i],
                            constructor.getGenericParameterTypes()[i]);
                    for (Annotation annotation : constructor.getParameterAnnotations()[i]) {
                        if (annotation.annotationType().equals(QueryType.class)) {
                            QueryType queryType = (QueryType)annotation;
                            parameterType = parameterType.as(TypeCategory.valueOf(queryType.value().name()));
                        }
                    }
                    parameters.add(new Parameter("param" + i, parameterType));
                }
                type.addConstructor(new com.mysema.codegen.model.Constructor(parameters));
View Full Code Here

                    if (Modifier.isTransient(field.getModifiers()) && !field.isAnnotationPresent(QueryType.class)) {
                        continue;
                    }
                    AnnotatedElement annotated = ReflectionUtils.getAnnotatedElement(cl, field.getName(), field.getType());
                    Method method = ReflectionUtils.getGetterOrNull(cl, field.getName(), field.getType());
                    Type propertyType = null;
                    if (method != null) {
                        propertyType = getPropertyType(cl, annotated, method.getReturnType(), method.getGenericReturnType());
                    } else {
                        propertyType = getPropertyType(cl, annotated, field.getType(), field.getGenericType());
                    }
                    Property property = createProperty(type, field.getName(), propertyType, field);
                    if (property != null) {
                        type.addProperty(property);
                    }
                    handled.add(field.getName());
                }
            }
        }

        // getters
        if (handleMethods) {
            for (Method method : cl.getDeclaredMethods()) {
                String name = method.getName();
                if (method.getParameterTypes().length == 0
                    && ((name.startsWith("get") && name.length() > 3)
                     || (name.startsWith("is") && name.length() > 2))) {
                    String propertyName;
                    if (name.startsWith("get")) {
                        propertyName = BeanUtils.uncapitalize(name.substring(3));
                    } else {
                        propertyName = BeanUtils.uncapitalize(name.substring(2));
                    }
                    if (handled.contains(propertyName)) {
                        continue;
                    }
                    Type propertyType = getPropertyType(cl, method, method.getReturnType(), method.getGenericReturnType());
                    Property property = createProperty(type, propertyName, propertyType, method);
                    if (property != null) {
                        type.addProperty(property);
                    }
                }
View Full Code Here

        }
    }

    private Type getPropertyType(Class<?> cl, AnnotatedElement annotated, Class<?> type,
            java.lang.reflect.Type genericType) {
        Type propertyType = null;
        if (annotated.isAnnotationPresent(embeddedAnnotation)) {
            Class<?> embeddableType = type;
            if (Collection.class.isAssignableFrom(type)) {
                embeddableType = ReflectionUtils.getTypeParameterAsClass(genericType, 0);
            } else if (Map.class.isAssignableFrom(type)) {
View Full Code Here

        }
    }

    private void serialize(Serializer serializer, Map<Class<?>, EntityType> types) throws IOException {
        for (Map.Entry<Class<?>, EntityType> entityType : types.entrySet()) {
            Type type = typeMappings.getPathType(entityType.getValue(), entityType.getValue(), true);
            String packageName = type.getPackageName();
            String className = packageName.length() > 0 ? (packageName + "." + type.getSimpleName()) : type.getSimpleName();
            SerializerConfig config = serializerConfig;
            if (entityType.getKey().isAnnotationPresent(Config.class)) {
                config = SimpleSerializerConfig.getConfig(entityType.getKey().getAnnotation(Config.class));
            }
            String fileSuffix = createScalaSources ? ".scala" : ".java";
View Full Code Here

    @SuppressWarnings("unchecked")
    @Before
    public void setUp() {
        // type
        Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false, false);
        type = new EntityType(typeModel);

        // property
        type.addProperty(new Property(type, "entityField", type));
        type.addProperty(new Property(type, "collection", new ClassType(TypeCategory.COLLECTION, Collection.class, typeModel)));
        type.addProperty(new Property(type, "listField", new ClassType(TypeCategory.LIST, List.class, typeModel)));
        type.addProperty(new Property(type, "setField", new ClassType(TypeCategory.SET, Set.class, typeModel)));
        type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class, typeModel)));
        type.addProperty(new Property(type, "mapField", new ClassType(TypeCategory.MAP, List.class, typeModel, typeModel)));
        type.addProperty(new Property(type, "superTypeField", new TypeExtends(new ClassType(TypeCategory.MAP, List.class, typeModel, typeModel))));
        type.addProperty(new Property(type, "extendsTypeField", new TypeSuper(new ClassType(TypeCategory.MAP, List.class, typeModel, typeModel))));

        for (Class<?> cl : Arrays.asList(Boolean.class, Comparable.class, Integer.class, Date.class, java.sql.Date.class, java.sql.Time.class)) {
            Type classType = new ClassType(TypeCategory.get(cl.getName()), cl);
            type.addProperty(new Property(type, StringUtils.uncapitalize(cl.getSimpleName()), classType));
        }

        // constructor
        Parameter firstName = new Parameter("firstName", new ClassType(TypeCategory.STRING, String.class));
View Full Code Here

     * @param declaringType
     * @param context
     * @return
     */
    public static Type resolve(Type type, Type declaringType, EntityType context) {        
        Type resolved = unwrap(type);
       
        String varName = getVarName(resolved);       
        if (varName != null) {
            resolved = resolveVar(resolved, varName, declaringType, context);
        } else if (!resolved.getParameters().isEmpty()) {
            resolved = resolveWithParameters(resolved, declaringType, context);
        }
       
        // rewrap entity type
        if (type instanceof EntityType) {
View Full Code Here

     */
    private static Type resolveVar(Type resolved, String varName, Type declaringType, EntityType context) {
        // get parameter index of var in declaring type
        int index = -1;
        for (int i = 0; i < declaringType.getParameters().size(); i++) {
            Type param = unwrap(declaringType.getParameters().get(i));
            if (param instanceof TypeExtends && Objects.equal(((TypeExtends)param).getVarName(), varName)) {
                index = i;
            }
        }
       
View Full Code Here

     */
    private static Type resolveWithParameters(Type type, Type declaringType, EntityType context) {
        Type[] params = new Type[type.getParameters().size()];
        boolean transformed = false;
        for (int i = 0; i < type.getParameters().size(); i++) {
            Type param = type.getParameters().get(i);
            if (param != null && !param.getFullName().equals(type.getFullName())) {
                params[i] = resolve(param, declaringType, context);
                if (!params[i].equals(param)) {
                    transformed = true;
                }
            }
View Full Code Here

TOP

Related Classes of com.mysema.codegen.model.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.