use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class AntMetaDataExporter method execute.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void execute() {
if (targetFolder == null) {
throw new BuildException("targetFolder is a mandatory property");
}
Connection dbConn = null;
try {
Class.forName(jdbcDriver).newInstance();
dbConn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
Configuration configuration = new Configuration(SQLTemplates.DEFAULT);
MetaDataExporter exporter = new MetaDataExporter();
if (namePrefix != null) {
exporter.setNamePrefix(namePrefix);
}
if (nameSuffix != null) {
exporter.setNameSuffix(nameSuffix);
}
if (beanPrefix != null) {
exporter.setBeanPrefix(beanPrefix);
}
if (beanSuffix != null) {
exporter.setBeanSuffix(beanSuffix);
}
if (beansTargetFolder != null) {
exporter.setBeansTargetFolder(new File(beansTargetFolder));
}
exporter.setPackageName(packageName);
exporter.setBeanPackageName(beanPackageName);
exporter.setTargetFolder(new File(targetFolder));
exporter.setNamingStrategy((NamingStrategy) Class.forName(namingStrategyClass).newInstance());
exporter.setInnerClassesForKeys(innerClassesForKeys);
exporter.setSchemaPattern(schemaPattern);
exporter.setTableNamePattern(tableNamePattern);
exporter.setColumnAnnotations(columnAnnotations);
exporter.setValidationAnnotations(validationAnnotations);
exporter.setSchemaToPackage(schemaToPackage);
exporter.setLowerCase(lowerCase);
exporter.setExportTables(exportTables);
exporter.setExportViews(exportViews);
exporter.setExportAll(exportAll);
exporter.setTableTypesToExport(tableTypesToExport);
exporter.setExportPrimaryKeys(exportPrimaryKeys);
exporter.setExportForeignKeys(exportForeignKeys);
exporter.setExportDirectForeignKeys(exportDirectForeignKeys);
exporter.setExportInverseForeignKeys(exportInverseForeignKeys);
exporter.setSpatial(spatial);
if (imports != null && imports.length > 0) {
exporter.setImports(imports);
}
if (exportBeans) {
BeanSerializer serializer = (BeanSerializer) Class.forName(beanSerializerClass).newInstance();
if (beanInterfaces != null) {
for (String iface : beanInterfaces) {
int sepIndex = iface.lastIndexOf('.');
if (sepIndex < 0) {
serializer.addInterface(new SimpleType(iface));
} else {
String packageName = iface.substring(0, sepIndex);
String simpleName = iface.substring(sepIndex + 1);
serializer.addInterface(new SimpleType(iface, packageName, simpleName));
}
}
}
serializer.setAddFullConstructor(beanAddFullConstructor);
serializer.setAddToString(beanAddToString);
serializer.setPrintSupertype(beanPrintSupertype);
exporter.setBeanSerializer(serializer);
}
if (sourceEncoding != null) {
exporter.setSourceEncoding(sourceEncoding);
}
if (customTypes != null) {
for (CustomType customType : customTypes) {
configuration.register((Type<?>) Class.forName(customType.getClassName()).newInstance());
}
}
if (typeMappings != null) {
for (TypeMapping mapping : typeMappings) {
mapping.apply(configuration);
}
}
if (numericMappings != null) {
for (NumericMapping mapping : numericMappings) {
mapping.apply(configuration);
}
}
if (renameMappings != null) {
for (RenameMapping mapping : renameMappings) {
mapping.apply(configuration);
}
}
if (columnComparatorClass != null) {
exporter.setColumnComparatorClass((Class) Class.forName(this.columnComparatorClass).asSubclass(Comparator.class));
}
exporter.setConfiguration(configuration);
exporter.export(dbConn.getMetaData());
} catch (RuntimeException | SQLException | ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new BuildException(e);
} finally {
if (dbConn != null) {
try {
dbConn.close();
} catch (SQLException e2) {
throw new BuildException(e2);
}
}
}
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class SpatialSupport method registerTypes.
private static void registerTypes(TypeMappings typeMappings) {
Map<String, String> additions = new HashMap<>();
additions.put("Geometry", "GeometryPath");
additions.put("GeometryCollection", "GeometryCollectionPath");
additions.put("LinearRing", "LinearRingPath");
additions.put("LineString", "LineStringPath");
additions.put("MultiLineString", "MultiLineStringPath");
additions.put("MultiPoint", "MultiPointPath");
additions.put("MultiPolygon", "MultiPolygonPath");
additions.put("Point", "PointPath");
additions.put("Polygon", "PolygonPath");
for (Map.Entry<String, String> entry : additions.entrySet()) {
typeMappings.register(new SimpleType("org.geolatte.geom." + entry.getKey()), new SimpleType("com.querydsl.spatial." + entry.getValue()));
}
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class JPADomainExporter method handleProperty.
private void handleProperty(EntityType entityType, Class<?> cl, Attribute<?, ?> p) throws NoSuchMethodException, ClassNotFoundException {
Class<?> clazz = Object.class;
try {
clazz = p.getJavaType();
} catch (MappingException e) {
// ignore
}
Type propertyType = getType(cl, clazz, p.getName());
AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
propertyType = getTypeOverride(propertyType, annotated);
if (propertyType == null) {
return;
}
if (p.isCollection()) {
if (p instanceof MapAttribute) {
MapAttribute<?, ?, ?> map = (MapAttribute<?, ?, ?>) p;
Type keyType = typeFactory.get(map.getKeyJavaType());
Type valueType = typeFactory.get(map.getElementType().getJavaType());
valueType = getPropertyType(p, valueType);
propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType));
} else {
Type valueType = typeFactory.get(((PluralAttribute<?, ?, ?>) p).getElementType().getJavaType());
valueType = getPropertyType(p, valueType);
propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), valueType));
}
} else {
propertyType = getPropertyType(p, propertyType);
}
Property property = createProperty(entityType, p.getName(), propertyType, annotated);
entityType.addProperty(property);
}
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\"));"));
}
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));
}
}
Aggregations