Search in sources :

Example 11 with SimpleType

use of com.mysema.codegen.model.SimpleType in project querydsl by querydsl.

the class PackageSuffixTest method correct_imports.

@Test
public void correct_imports() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "test.Entity", "test", "Entity", false, false);
    EntityType entityType = new EntityType(type);
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("import test.Entity;"));
    assertTrue(writer.toString().contains("public class QEntity extends EntityPathBase<Entity> {"));
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 12 with SimpleType

use of com.mysema.codegen.model.SimpleType in project querydsl by querydsl.

the class TypeResolver method resolveWithParameters.

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;
            }
        }
    }
    if (transformed) {
        return new SimpleType(type, params);
    } else {
        return type;
    }
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) Type(com.mysema.codegen.model.Type) SimpleType(com.mysema.codegen.model.SimpleType)

Example 13 with SimpleType

use of com.mysema.codegen.model.SimpleType in project querydsl by querydsl.

the class PropertyTest method escapedName.

@Test
public void escapedName() {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Property property = new Property(type, "boolean", type, Collections.<String>emptyList());
    assertEquals("boolean$", property.getEscapedName());
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) Type(com.mysema.codegen.model.Type) SimpleType(com.mysema.codegen.model.SimpleType) Test(org.junit.Test)

Example 14 with SimpleType

use of com.mysema.codegen.model.SimpleType in project querydsl by querydsl.

the class HibernateDomainExporter method handleProperty.

private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p) throws NoSuchMethodException, ClassNotFoundException {
    if (p.isBackRef()) {
        return;
    }
    Class<?> clazz = Object.class;
    try {
        clazz = p.getType().getReturnedClass();
    } catch (MappingException e) {
    // ignore
    }
    Type propertyType = getType(cl, clazz, p.getName());
    try {
        propertyType = getPropertyType(p, propertyType);
    } catch (MappingException e) {
    // ignore
    }
    AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
    propertyType = getTypeOverride(propertyType, annotated);
    if (propertyType == null) {
        return;
    }
    if (p.isComposite()) {
        EntityType embeddedType = createEmbeddableType(propertyType);
        Iterator<?> properties = ((Component) p.getValue()).getPropertyIterator();
        while (properties.hasNext()) {
            handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property) properties.next());
        }
        propertyType = embeddedType;
    } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) {
        propertyType = createEntityType(propertyType);
    } else if (propertyType.getCategory() == TypeCategory.CUSTOM) {
        propertyType = createEmbeddableType(propertyType);
    } else if (p.getValue() instanceof org.hibernate.mapping.Collection) {
        org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) p.getValue();
        if (collection.getElement() instanceof OneToMany) {
            String entityName = ((OneToMany) collection.getElement()).getReferencedEntityName();
            if (entityName != null) {
                if (collection.isMap()) {
                    Type keyType = typeFactory.get(Class.forName(propertyType.getParameters().get(0).getFullName()));
                    Type valueType = typeFactory.get(Class.forName(entityName));
                    propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType));
                } else {
                    Type componentType = typeFactory.get(Class.forName(entityName));
                    propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), componentType));
                }
            }
        } else if (collection.getElement() instanceof Component) {
            Component component = (Component) collection.getElement();
            Class<?> embeddedClass = Class.forName(component.getComponentClassName());
            EntityType embeddedType = createEmbeddableType(embeddedClass);
            Iterator<?> properties = component.getPropertyIterator();
            while (properties.hasNext()) {
                handleProperty(embeddedType, embeddedClass, (org.hibernate.mapping.Property) properties.next());
            }
        }
    }
    Property property = createProperty(entityType, p.getName(), propertyType, annotated);
    entityType.addProperty(property);
}
Also used : org.hibernate.mapping(org.hibernate.mapping) AnnotatedElement(java.lang.reflect.AnnotatedElement) MappingException(org.hibernate.MappingException) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.mysema.codegen.model.SimpleType) Type(com.mysema.codegen.model.Type) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.mysema.codegen.model.SimpleType) Property(com.querydsl.codegen.Property)

Aggregations

SimpleType (com.mysema.codegen.model.SimpleType)14 Type (com.mysema.codegen.model.Type)7 Test (org.junit.Test)4 EntityType (com.querydsl.codegen.EntityType)3 JavaWriter (com.mysema.codegen.JavaWriter)2 ClassType (com.mysema.codegen.model.ClassType)2 BeanSerializer (com.querydsl.codegen.BeanSerializer)2 Property (com.querydsl.codegen.Property)2 Configuration (com.querydsl.sql.Configuration)2 MetaDataExporter (com.querydsl.sql.codegen.MetaDataExporter)2 NumericMapping (com.querydsl.sql.codegen.support.NumericMapping)2 RenameMapping (com.querydsl.sql.codegen.support.RenameMapping)2 TypeMapping (com.querydsl.sql.codegen.support.TypeMapping)2 File (java.io.File)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 MappingException (org.hibernate.MappingException)2 SchemaAndTable (com.querydsl.sql.SchemaAndTable)1