use of com.mysema.codegen.model.TypeCategory in project querydsl by querydsl.
the class TypeElementHandler method getType.
private Type getType(VariableElement element) {
Type rv = typeFactory.getType(element.asType(), true);
if (element.getAnnotation(QueryType.class) != null) {
QueryType qt = element.getAnnotation(QueryType.class);
if (qt.value() != PropertyType.NONE) {
TypeCategory typeCategory = TypeCategory.valueOf(qt.value().name());
rv = rv.as(typeCategory);
}
}
return rv;
}
use of com.mysema.codegen.model.TypeCategory 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);
}
use of com.mysema.codegen.model.TypeCategory 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");
}
use of com.mysema.codegen.model.TypeCategory in project querydsl by querydsl.
the class TypeElementHandler method toProperty.
private Property toProperty(EntityType entityType, String name, TypeMirror type, Annotations annotations) {
// type
Type propertyType = typeFactory.getType(type, true);
if (annotations.isAnnotationPresent(QueryType.class)) {
PropertyType propertyTypeAnn = annotations.getAnnotation(QueryType.class).value();
if (propertyTypeAnn != PropertyType.NONE) {
TypeCategory typeCategory = TypeCategory.valueOf(annotations.getAnnotation(QueryType.class).value().name());
if (typeCategory == null) {
return null;
}
propertyType = propertyType.as(typeCategory);
} else {
return null;
}
}
// inits
List<String> inits = Collections.emptyList();
if (annotations.isAnnotationPresent(QueryInit.class)) {
inits = ImmutableList.copyOf(annotations.getAnnotation(QueryInit.class).value());
}
return new Property(entityType, name, propertyType, inits);
}
Aggregations