Search in sources :

Example 16 with Type

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

the class MetaDataExporter method createEntityType.

protected EntityType createEntityType(SchemaAndTable schemaAndTable, final String className) {
    EntityType classModel;
    if (beanSerializer == null) {
        String packageName = normalizePackage(module.getPackageName(), schemaAndTable);
        String simpleName = module.getPrefix() + className + module.getSuffix();
        Type classTypeModel = new SimpleType(TypeCategory.ENTITY, packageName + "." + simpleName, packageName, simpleName, false, false);
        classModel = new EntityType(classTypeModel, module.get(Function.class, CodegenModule.VARIABLE_NAME_FUNCTION_CLASS));
        typeMappings.register(classModel, classModel);
    } else {
        String beanPackage = normalizePackage(beanPackageName, schemaAndTable);
        String simpleName = module.getBeanPrefix() + className + module.getBeanSuffix();
        Type classTypeModel = new SimpleType(TypeCategory.ENTITY, beanPackage + "." + simpleName, beanPackage, simpleName, false, false);
        classModel = new EntityType(classTypeModel, module.get(Function.class, CodegenModule.VARIABLE_NAME_FUNCTION_CLASS));
        Type mappedType = queryTypeFactory.create(classModel);
        entityToWrapped.put(classModel, mappedType);
        typeMappings.register(classModel, mappedType);
    }
    classModel.getData().put("schema", schemaAndTable.getSchema());
    classModel.getData().put("table", schemaAndTable.getTable());
    return classModel;
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) SimpleType(com.mysema.codegen.model.SimpleType)

Example 17 with Type

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

the class MetaDataExporter method handleColumn.

private void handleColumn(EntityType classModel, String tableName, ResultSet columns) throws SQLException {
    String columnName = normalize(columns.getString("COLUMN_NAME"));
    String normalizedColumnName = namingStrategy.normalizeColumnName(columnName);
    int columnType = columns.getInt("DATA_TYPE");
    String typeName = columns.getString("TYPE_NAME");
    Number columnSize = (Number) columns.getObject("COLUMN_SIZE");
    Number columnDigits = (Number) columns.getObject("DECIMAL_DIGITS");
    int columnIndex = columns.getInt("ORDINAL_POSITION");
    int nullable = columns.getInt("NULLABLE");
    String propertyName = namingStrategy.getPropertyName(normalizedColumnName, classModel);
    Class<?> clazz = configuration.getJavaType(columnType, typeName, columnSize != null ? columnSize.intValue() : 0, columnDigits != null ? columnDigits.intValue() : 0, tableName, columnName);
    if (clazz == null) {
        clazz = Object.class;
    }
    TypeCategory fieldType = TypeCategory.get(clazz.getName());
    if (Number.class.isAssignableFrom(clazz)) {
        fieldType = TypeCategory.NUMERIC;
    } else if (Enum.class.isAssignableFrom(clazz)) {
        fieldType = TypeCategory.ENUM;
    }
    Type typeModel = new ClassType(fieldType, clazz);
    Property property = createProperty(classModel, normalizedColumnName, propertyName, typeModel);
    ColumnMetadata column = ColumnMetadata.named(normalizedColumnName).ofType(columnType).withIndex(columnIndex);
    if (nullable == DatabaseMetaData.columnNoNulls) {
        column = column.notNull();
    }
    if (columnSize != null) {
        column = column.withSize(columnSize.intValue());
    }
    if (columnDigits != null) {
        column = column.withDigits(columnDigits.intValue());
    }
    property.getData().put("COLUMN", column);
    if (columnAnnotations) {
        property.addAnnotation(new ColumnImpl(normalizedColumnName));
    }
    if (validationAnnotations) {
        if (nullable == DatabaseMetaData.columnNoNulls) {
            property.addAnnotation(new NotNullImpl());
        }
        int size = columns.getInt("COLUMN_SIZE");
        if (size > 0 && clazz.equals(String.class)) {
            property.addAnnotation(new SizeImpl(0, size));
        }
    }
    classModel.addProperty(property);
}
Also used : ClassType(com.mysema.codegen.model.ClassType) ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) SimpleType(com.mysema.codegen.model.SimpleType) TypeCategory(com.mysema.codegen.model.TypeCategory)

Example 18 with Type

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

the class SpatialSupport method registerTypes.

private static void registerTypes(TypeMappings typeMappings) {
    Map<Class<?>, Class<?>> mappings = Maps.newHashMap();
    mappings.put(GeometryCollection.class, GeometryCollectionPath.class);
    mappings.put(Geometry.class, GeometryPath.class);
    mappings.put(LinearRing.class, LinearRingPath.class);
    mappings.put(LineString.class, LineStringPath.class);
    mappings.put(MultiLineString.class, MultiLineStringPath.class);
    mappings.put(MultiPoint.class, MultiPointPath.class);
    mappings.put(MultiPolygon.class, MultiPolygonPath.class);
    mappings.put(Point.class, PointPath.class);
    mappings.put(Polygon.class, PolygonPath.class);
    mappings.put(PolyHedralSurface.class, PolyhedralSurfacePath.class);
    for (Map.Entry<Class<?>, Class<?>> entry : mappings.entrySet()) {
        Type type = new ClassType(entry.getKey());
        typeMappings.register(type, new ClassType(entry.getValue(), type));
    }
}
Also used : ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) ClassType(com.mysema.codegen.model.ClassType) Map(java.util.Map)

Example 19 with Type

use of com.mysema.codegen.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.mysema.codegen.model.SimpleType) EntityType(com.querydsl.codegen.EntityType) Type(com.mysema.codegen.model.Type) SimpleType(com.mysema.codegen.model.SimpleType) Before(org.junit.Before)

Example 20 with Type

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

the class EmbeddableSerializer method introClassHeader.

@Override
@SuppressWarnings(UNCHECKED)
protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException {
    Type queryType = typeMappings.getPathType(model, model, true);
    TypeCategory category = model.getOriginalCategory();
    Class<? extends Path> pathType;
    if (model.getProperties().isEmpty()) {
        switch(category) {
            case COMPARABLE:
                pathType = ComparablePath.class;
                break;
            case ENUM:
                pathType = EnumPath.class;
                break;
            case DATE:
                pathType = DatePath.class;
                break;
            case DATETIME:
                pathType = DateTimePath.class;
                break;
            case TIME:
                pathType = TimePath.class;
                break;
            case NUMERIC:
                pathType = NumberPath.class;
                break;
            case STRING:
                pathType = StringPath.class;
                break;
            case BOOLEAN:
                pathType = BooleanPath.class;
                break;
            default:
                pathType = BeanPath.class;
        }
    } else {
        pathType = BeanPath.class;
    }
    for (Annotation annotation : model.getAnnotations()) {
        writer.annotation(annotation);
    }
    writer.line("@Generated(\"", getClass().getName(), "\")");
    if (category == TypeCategory.BOOLEAN || category == TypeCategory.STRING) {
        writer.beginClass(queryType, new ClassType(pathType));
    } else {
        writer.beginClass(queryType, new ClassType(category, pathType, model));
    }
    // TODO : generate proper serialVersionUID here
    writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", model.hashCode() + "L");
}
Also used : ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) TypeCategory(com.mysema.codegen.model.TypeCategory) ClassType(com.mysema.codegen.model.ClassType) Annotation(java.lang.annotation.Annotation)

Aggregations

Type (com.mysema.codegen.model.Type)31 SimpleType (com.mysema.codegen.model.SimpleType)11 EntityType (com.querydsl.codegen.EntityType)8 Test (org.junit.Test)8 ClassType (com.mysema.codegen.model.ClassType)6 PropertyType (com.querydsl.core.annotations.PropertyType)5 QueryType (com.querydsl.core.annotations.QueryType)5 Parameter (com.mysema.codegen.model.Parameter)4 TypeCategory (com.mysema.codegen.model.TypeCategory)4 Property (com.querydsl.codegen.Property)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 DeclaredType (javax.lang.model.type.DeclaredType)3 NoType (javax.lang.model.type.NoType)3 Annotation (java.lang.annotation.Annotation)2 Field (java.lang.reflect.Field)2 MappingException (org.hibernate.MappingException)2 org.hibernate.mapping (org.hibernate.mapping)2 JavaWriter (com.mysema.codegen.JavaWriter)1 ScalaWriter (com.mysema.codegen.ScalaWriter)1 QueryDelegate (com.querydsl.core.annotations.QueryDelegate)1