use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class MetaDataSerializer method introDefaultInstance.
@Override
protected void introDefaultInstance(CodeWriter writer, EntityType entityType, String defaultName) throws IOException {
String variableName = !defaultName.isEmpty() ? defaultName : namingStrategy.getDefaultVariableName(entityType);
String alias = namingStrategy.getDefaultAlias(entityType);
Type queryType = typeMappings.getPathType(entityType, entityType, true);
writer.publicStaticFinal(queryType, variableName, NEW + queryType.getSimpleName() + "(\"" + alias + "\")");
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class MetaDataSerializer method serializeProperties.
@SuppressWarnings("unchecked")
@Override
protected void serializeProperties(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException {
Collection<PrimaryKeyData> primaryKeys = (Collection<PrimaryKeyData>) model.getData().get(PrimaryKeyData.class);
Collection<ForeignKeyData> foreignKeys = (Collection<ForeignKeyData>) model.getData().get(ForeignKeyData.class);
Collection<InverseForeignKeyData> inverseForeignKeys = (Collection<InverseForeignKeyData>) model.getData().get(InverseForeignKeyData.class);
if (innerClassesForKeys) {
Type primaryKeyType = new SimpleType(namingStrategy.getPrimaryKeysClassName());
Type foreignKeysType = new SimpleType(namingStrategy.getForeignKeysClassName());
// primary keys
if (primaryKeys != null) {
writer.beginClass(primaryKeyType);
serializePrimaryKeys(model, writer, primaryKeys);
writer.end();
}
// foreign keys
if (foreignKeys != null || inverseForeignKeys != null) {
writer.beginClass(foreignKeysType);
if (foreignKeys != null) {
serializeForeignKeys(model, writer, foreignKeys, false);
}
// inverse foreign keys
if (inverseForeignKeys != null) {
serializeForeignKeys(model, writer, inverseForeignKeys, true);
}
writer.end();
}
super.serializeProperties(model, config, writer);
if (primaryKeys != null) {
writer.publicFinal(primaryKeyType, namingStrategy.getPrimaryKeysVariable(model), "new " + primaryKeyType.getSimpleName() + "()");
}
if (foreignKeys != null || inverseForeignKeys != null) {
writer.publicFinal(foreignKeysType, namingStrategy.getForeignKeysVariable(model), "new " + foreignKeysType.getSimpleName() + "()");
}
} else {
super.serializeProperties(model, config, writer);
// primary keys
if (primaryKeys != null) {
serializePrimaryKeys(model, writer, primaryKeys);
}
// foreign keys
if (foreignKeys != null) {
serializeForeignKeys(model, writer, foreignKeys, false);
}
// inverse foreign keys
if (inverseForeignKeys != null) {
serializeForeignKeys(model, writer, inverseForeignKeys, true);
}
}
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class MetaDataSerializer method customField.
@Override
protected void customField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException {
Type queryType = typeMappings.getPathType(field.getType(), model, false);
if (queryType.getPackageName().startsWith("com.querydsl")) {
String localRawName = writer.getRawName(field.getType());
serialize(model, field, queryType, writer, "create" + field.getType().getSimpleName(), writer.getClassConstant(localRawName));
} else {
super.customField(model, field, config, writer);
}
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class MetaDataSerializer method introClassHeader.
@Override
protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException {
Type queryType = typeMappings.getPathType(model, model, true);
writer.line("@", generatedAnnotationClass.getSimpleName(), "(\"", getClass().getName(), "\")");
TypeCategory category = model.getOriginalCategory();
// serialize annotations only, if no bean types are used
if (model.equals(queryType)) {
for (Annotation annotation : model.getAnnotations()) {
writer.annotation(annotation);
}
}
writer.beginClass(queryType, new ClassType(category, entityPathType, model));
writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", String.valueOf(model.hashCode()));
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class GenericExporter method addProperties.
private void addProperties(Class<?> cl, EntityType type) {
Map<String, Type> types = new HashMap<>();
Map<String, Annotations> annotations = new HashMap<>();
PropertyHandling.Config config = propertyHandling.getConfig(cl);
// fields
if (config.isFields()) {
for (Field field : cl.getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers())) {
if (Modifier.isTransient(field.getModifiers()) && !field.isAnnotationPresent(QueryType.class)) {
continue;
}
AnnotatedElement annotated = ReflectionUtils.getAnnotatedElement(cl, field.getName(), field.getType());
Type propertyType = getPropertyType(cl, annotated, field.getType(), field.getGenericType());
Annotations ann = new Annotations(field);
types.put(field.getName(), propertyType);
annotations.put(field.getName(), ann);
}
}
}
// getters
if (config.isMethods()) {
for (Method method : cl.getDeclaredMethods()) {
String name = method.getName();
if (method.getParameterTypes().length == 0 && !Modifier.isStatic(method.getModifiers()) && !method.isBridge() && ((name.startsWith("get") && name.length() > 3) || (name.startsWith("is") && name.length() > 2))) {
String propertyName;
if (name.startsWith("get")) {
propertyName = BeanUtils.uncapitalize(name.substring(3));
} else {
propertyName = BeanUtils.uncapitalize(name.substring(2));
}
Type propertyType = getPropertyType(cl, method, method.getReturnType(), method.getGenericReturnType());
if (!types.containsKey(propertyName) || !useFieldTypes) {
types.put(propertyName, propertyType);
}
Annotations ann = annotations.get(propertyName);
if (ann == null) {
ann = new Annotations();
annotations.put(propertyName, ann);
}
ann.addAnnotations(method);
}
}
}
for (Map.Entry<String, Type> entry : types.entrySet()) {
Annotations ann = annotations.get(entry.getKey());
Property property = createProperty(type, entry.getKey(), entry.getValue(), ann);
if (property != null) {
type.addProperty(property);
}
}
}
Aggregations