Search in sources :

Example 1 with ColumnMetadata

use of com.querydsl.sql.ColumnMetadata in project querydsl by querydsl.

the class MetaDataSerializer method outro.

@Override
protected void outro(EntityType model, CodeWriter writer) throws IOException {
    writer.beginPublicMethod(Types.VOID, "addMetadata");
    List<Property> properties = Lists.newArrayList(model.getProperties());
    if (columnComparator != null) {
        Collections.sort(properties, columnComparator);
    }
    for (Property property : properties) {
        String name = property.getEscapedName();
        ColumnMetadata metadata = (ColumnMetadata) property.getData().get("COLUMN");
        StringBuilder columnMeta = new StringBuilder();
        columnMeta.append("ColumnMetadata");
        columnMeta.append(".named(\"" + metadata.getName() + "\")");
        columnMeta.append(".withIndex(" + metadata.getIndex() + ")");
        if (metadata.hasJdbcType()) {
            String type = String.valueOf(metadata.getJdbcType());
            if (typeConstants.containsKey(metadata.getJdbcType())) {
                type = "Types." + typeConstants.get(metadata.getJdbcType());
            }
            columnMeta.append(".ofType(" + type + ")");
        }
        if (metadata.hasSize()) {
            columnMeta.append(".withSize(" + metadata.getSize() + ")");
        }
        if (metadata.getDigits() > 0) {
            columnMeta.append(".withDigits(" + metadata.getDigits() + ")");
        }
        if (!metadata.isNullable()) {
            columnMeta.append(".notNull()");
        }
        writer.line("addMetadata(", name, ", ", columnMeta.toString(), ");");
    }
    writer.end();
    super.outro(model, writer);
}
Also used : ColumnMetadata(com.querydsl.sql.ColumnMetadata)

Example 2 with ColumnMetadata

use of com.querydsl.sql.ColumnMetadata in project querydsl by querydsl.

the class OrdinalPositionComparator method compare.

@Override
public int compare(Property property1, Property property2) {
    Integer comparison = null;
    for (Property property : Arrays.asList(property1, property2)) {
        Map<Object, Object> data = property.getData();
        ColumnMetadata columnMetadata = (ColumnMetadata) data.get("COLUMN");
        int index = columnMetadata.getIndex();
        comparison = comparison == null ? index : comparison - index;
    }
    return comparison;
}
Also used : ColumnMetadata(com.querydsl.sql.ColumnMetadata) Property(com.querydsl.codegen.Property)

Aggregations

ColumnMetadata (com.querydsl.sql.ColumnMetadata)2 Property (com.querydsl.codegen.Property)1