Search in sources :

Example 1 with CustomType

use of com.querydsl.sql.codegen.support.CustomType in project querydsl by querydsl.

the class AntMetaDataExporter method getCustomTypes.

/**
 * Gets a list of custom types
 * @return a list of custom types
 * @deprecated Use addCustomType instead
 */
public String[] getCustomTypes() {
    String[] customTypes = new String[this.customTypes.size()];
    for (int i = 0; i < this.customTypes.size(); i++) {
        CustomType customType = this.customTypes.get(i);
        customTypes[i] = customType.getClassName();
    }
    return customTypes;
}
Also used : CustomType(com.querydsl.sql.codegen.support.CustomType)

Example 2 with CustomType

use of com.querydsl.sql.codegen.support.CustomType 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);
            }
        }
    }
}
Also used : CustomType(com.querydsl.sql.codegen.support.CustomType) BeanSerializer(com.querydsl.codegen.BeanSerializer) Configuration(com.querydsl.sql.Configuration) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SimpleType(com.querydsl.codegen.utils.model.SimpleType) NumericMapping(com.querydsl.sql.codegen.support.NumericMapping) RenameMapping(com.querydsl.sql.codegen.support.RenameMapping) TypeMapping(com.querydsl.sql.codegen.support.TypeMapping) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) MetaDataExporter(com.querydsl.sql.codegen.MetaDataExporter)

Example 3 with CustomType

use of com.querydsl.sql.codegen.support.CustomType in project querydsl by querydsl.

the class AntMetaDataExporter method setCustomTypes.

/**
 * Sets a list of custom types
 * @param strings a list of custom types
 * @deprecated Use addCustomType instead
 */
public void setCustomTypes(String[] strings) {
    this.customTypes.clear();
    for (String string : strings) {
        CustomType customType = new CustomType();
        customType.setClassName(string);
        this.customTypes.add(customType);
    }
}
Also used : CustomType(com.querydsl.sql.codegen.support.CustomType)

Aggregations

CustomType (com.querydsl.sql.codegen.support.CustomType)3 BeanSerializer (com.querydsl.codegen.BeanSerializer)1 SimpleType (com.querydsl.codegen.utils.model.SimpleType)1 Configuration (com.querydsl.sql.Configuration)1 MetaDataExporter (com.querydsl.sql.codegen.MetaDataExporter)1 NumericMapping (com.querydsl.sql.codegen.support.NumericMapping)1 RenameMapping (com.querydsl.sql.codegen.support.RenameMapping)1 TypeMapping (com.querydsl.sql.codegen.support.TypeMapping)1 File (java.io.File)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 BuildException (org.apache.tools.ant.BuildException)1