Search in sources :

Example 1 with SimpleType

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

the class SpatialSupport method registerTypes.

private static void registerTypes(TypeMappings typeMappings) {
    Map<String, String> additions = Maps.newHashMap();
    additions.put("Geometry", "GeometryPath");
    additions.put("GeometryCollection", "GeometryCollectionPath");
    additions.put("LinearRing", "LinearRingPath");
    additions.put("LineString", "LineStringPath");
    additions.put("MultiLineString", "MultiLineStringPath");
    additions.put("MultiPoint", "MultiPointPath");
    additions.put("MultiPolygon", "MultiPolygonPath");
    additions.put("Point", "PointPath");
    additions.put("Polygon", "PolygonPath");
    additions.put("PolyHedralSurface", "PolyhedralSurfacePath");
    for (Map.Entry<String, String> entry : additions.entrySet()) {
        typeMappings.register(new SimpleType("org.geolatte.geom." + entry.getKey()), new SimpleType("com.querydsl.spatial." + entry.getValue()));
    }
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) Map(java.util.Map)

Example 2 with SimpleType

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

the class SpatialSupport method registerJTSTypes.

private static void registerJTSTypes(TypeMappings typeMappings) {
    Map<String, String> additions = Maps.newHashMap();
    additions.put("Geometry", "JTSGeometryPath");
    additions.put("GeometryCollection", "JTSGeometryCollectionPath");
    additions.put("LinearRing", "JTSLinearRingPath");
    additions.put("LineString", "JTSLineStringPath");
    additions.put("MultiLineString", "JTSMultiLineStringPath");
    additions.put("MultiPoint", "JTSMultiPointPath");
    additions.put("MultiPolygon", "JTSMultiPolygonPath");
    additions.put("Point", "JTSPointPath");
    additions.put("Polygon", "JTSPolygonPath");
    for (Map.Entry<String, String> entry : additions.entrySet()) {
        typeMappings.register(new SimpleType("com.vividsolutions.jts.geom." + entry.getKey()), new SimpleType("com.querydsl.spatial.jts." + entry.getValue()));
    }
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) Map(java.util.Map)

Example 3 with SimpleType

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

the class CustomTypeTest method customType.

@Test
public void customType() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
    EntityType entityType = new EntityType(type);
    entityType.addProperty(new Property(entityType, "property", new ClassType(Double[].class)));
    typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    assertTrue(typeMappings.isRegistered(entityType.getProperties().iterator().next().getType()));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public final com.querydsl.codegen.Point property = " + "new com.querydsl.codegen.Point(forProperty(\"property\"));"));
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) JavaWriter(com.mysema.codegen.JavaWriter) ClassType(com.mysema.codegen.model.ClassType) Test(org.junit.Test)

Example 4 with SimpleType

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

the class PropertyTest method equals_and_hashCode.

@Test
public void equals_and_hashCode() {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Property p1 = new Property(type, "property", type, Collections.<String>emptyList());
    Property p2 = new Property(type, "property", type, Collections.<String>emptyList());
    assertEquals(p1, p1);
    assertEquals(p1, p2);
    assertEquals(p1.hashCode(), p2.hashCode());
}
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 5 with SimpleType

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

the class JPADomainExporter method handleProperty.

private void handleProperty(EntityType entityType, Class<?> cl, Attribute<?, ?> p) throws NoSuchMethodException, ClassNotFoundException {
    Class<?> clazz = Object.class;
    try {
        clazz = p.getJavaType();
    } catch (MappingException e) {
    // ignore
    }
    Type propertyType = getType(cl, clazz, p.getName());
    AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
    propertyType = getTypeOverride(propertyType, annotated);
    if (propertyType == null) {
        return;
    }
    if (p.isCollection()) {
        if (p instanceof MapAttribute) {
            MapAttribute<?, ?, ?> map = (MapAttribute<?, ?, ?>) p;
            Type keyType = typeFactory.get(map.getKeyJavaType());
            Type valueType = typeFactory.get(map.getElementType().getJavaType());
            valueType = getPropertyType(p, valueType);
            propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType));
        } else {
            Type valueType = typeFactory.get(((PluralAttribute<?, ?, ?>) p).getElementType().getJavaType());
            valueType = getPropertyType(p, valueType);
            propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), valueType));
        }
    } else {
        propertyType = getPropertyType(p, propertyType);
    }
    Property property = createProperty(entityType, p.getName(), propertyType, annotated);
    entityType.addProperty(property);
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) Type(com.mysema.codegen.model.Type) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.mysema.codegen.model.SimpleType) AnnotatedElement(java.lang.reflect.AnnotatedElement) Property(com.querydsl.codegen.Property) MappingException(org.hibernate.MappingException)

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