Search in sources :

Example 1 with SimpleType

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));
}
Also used : EntityType(com.querydsl.codegen.EntityType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) EntityType(com.querydsl.codegen.EntityType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Before(org.junit.Before)

Example 2 with SimpleType

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);
        }
    }
}
Also used : PrimaryKeyData(com.querydsl.sql.codegen.support.PrimaryKeyData) SimpleType(com.querydsl.codegen.utils.model.SimpleType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) InverseForeignKeyData(com.querydsl.sql.codegen.support.InverseForeignKeyData) Collection(java.util.Collection) ForeignKeyData(com.querydsl.sql.codegen.support.ForeignKeyData) InverseForeignKeyData(com.querydsl.sql.codegen.support.InverseForeignKeyData)

Example 3 with SimpleType

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);
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Before(org.junit.Before)

Example 4 with SimpleType

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));
    }
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 5 with SimpleType

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\"));"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) JavaWriter(com.querydsl.codegen.utils.JavaWriter) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Aggregations

SimpleType (com.querydsl.codegen.utils.model.SimpleType)35 Type (com.querydsl.codegen.utils.model.Type)17 Test (org.junit.Test)17 ClassType (com.querydsl.codegen.utils.model.ClassType)15 JavaWriter (com.querydsl.codegen.utils.JavaWriter)8 StringWriter (java.io.StringWriter)6 EntityType (com.querydsl.codegen.EntityType)5 Parameter (com.querydsl.codegen.utils.model.Parameter)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Before (org.junit.Before)5 File (java.io.File)3 Writer (java.io.Writer)3 Map (java.util.Map)3 BeanSerializer (com.querydsl.codegen.BeanSerializer)2 Configuration (com.querydsl.sql.Configuration)2 MetaDataExporter (com.querydsl.sql.codegen.MetaDataExporter)2 NumericMapping (com.querydsl.sql.codegen.support.NumericMapping)2 RenameMapping (com.querydsl.sql.codegen.support.RenameMapping)2 TypeMapping (com.querydsl.sql.codegen.support.TypeMapping)2 Connection (java.sql.Connection)2