use of com.querydsl.codegen.utils.model.SimpleType 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));
}
use of com.querydsl.codegen.utils.model.SimpleType 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.SimpleType in project querydsl by querydsl.
the class BeanSerializerTest method setUp.
@Before
public void setUp() {
typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
type = new EntityType(typeModel);
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class BeanSerializerTest method properties.
@Test
public void properties() throws IOException {
// property
type.addProperty(new Property(type, "entityField", type));
type.addProperty(new Property(type, "collection", new SimpleType(Types.COLLECTION, typeModel)));
type.addProperty(new Property(type, "listField", new SimpleType(Types.LIST, typeModel)));
type.addProperty(new Property(type, "setField", new SimpleType(Types.SET, typeModel)));
type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class)));
type.addProperty(new Property(type, "mapField", new SimpleType(Types.MAP, typeModel, typeModel)));
for (Class<?> cl : Arrays.<Class<?>>asList(Boolean.class, Comparable.class, Integer.class, Date.class, java.sql.Date.class, java.sql.Time.class)) {
Type classType = new ClassType(TypeCategory.get(cl.getName()), cl);
type.addProperty(new Property(type, StringUtils.uncapitalize(cl.getSimpleName()), classType));
}
BeanSerializer serializer = new BeanSerializer();
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
String str = writer.toString();
// System.err.println(str);
for (String prop : Arrays.asList("String[] arrayField;", "Boolean boolean$;", "Collection<DomainClass> collection;", "Comparable comparable;", "java.util.Date date;", "DomainClass entityField;", "Integer integer;", "List<DomainClass> listField;", "Map<DomainClass, DomainClass> mapField;", "Set<DomainClass> setField;", "java.sql.Time time;")) {
assertTrue(prop + " was not contained", str.contains(prop));
}
}
use of com.querydsl.codegen.utils.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\"));"));
}
Aggregations