Java Code Examples for com.gitee.hengboy.builder.common.util.StringUtil#isNotEmpty()

The following examples show how to use com.gitee.hengboy.builder.common.util.StringUtil#isNotEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractEngineTemplate.java    From code-builder with Apache License 2.0 6 votes vote down vote up
/**
 * 获取生成目标目录 + package目录格式化后的根地址
 *
 * @return 存在包名的目录根路径
 */
protected String getBasePackageTargetDir() {
    // 获取builder配置信息
    BuilderConfiguration builderConfiguration = codeBuilderProperties.getBuilder();
    StringBuffer basePackageDir = new StringBuffer();
    // 生成文件的目标根路径
    basePackageDir.append(getBaseTargetDir());

    // 是否存在自定义的package前缀
    // 存在前缀添加到路径内
    if (StringUtil.isNotEmpty(builderConfiguration.getDiffSysPackagePrefix())) {
        basePackageDir.append(builderConfiguration.getDiffSysPackagePrefix());
    }
    // 系统分隔符
    basePackageDir.append(SEPARATOR);
    return basePackageDir.toString();
}
 
Example 2
Source File: AbstractEngineTemplate.java    From code-builder with Apache License 2.0 6 votes vote down vote up
/**
 * 获取新文件的全名称
 * 如:XxxEntity.java
 *
 * @param templateConfiguration 模板配置对象
 * @param entityName            数据表对应的实体名称
 * @return 新文件名称
 */
protected String getTemplateNewFileName(TemplateConfiguration templateConfiguration, String entityName) {
    StringBuffer fileName = new StringBuffer();
    // 目标package的根目录
    fileName.append(getBasePackageTargetDir());

    // 是否配置了模板创建文件后所属的package目录
    if (StringUtil.isNotEmpty(templateConfiguration.getPackageName())) {
        fileName.append(templateConfiguration.getPackageName());
        fileName.append(SEPARATOR);
    }
    // 类名
    fileName.append(getTemplateClassName(templateConfiguration, entityName));
    // 文件扩展名
    fileName.append(FILE_SUFFIX);
    return fileName.toString();
}
 
Example 3
Source File: Table.java    From code-builder with Apache License 2.0 6 votes vote down vote up
/**
 * 构建对象后设置是否存在特殊类型的字段
 * 如:java.math.BigDecimal、java.sql.TimeStamp等
 *
 * @param codeBuilderProperties 参数对象
 * @return Table实例
 */
public Table buildAfterSetting(CodeBuilderProperties codeBuilderProperties) {
    for (Column column : columns) {
        // 是否存在bigDecimal的列
        if (JavaTypeEnum.TYPE_BIG_DECIMAL.getFullName().equals(column.getFullJavaType())) {
            this.hasBigDecimal = true;
        }
        // 是否存在timeStamp的列
        if (JavaTypeEnum.TYPE_TIMESTAMP.getFullName().equals(column.getFullJavaType())) {
            this.hasTimeStamp = true;
        }
        // 是否存在java.sql.Date的列
        if (JavaTypeEnum.TYPE_DATE.getFullName().equals(column.getFullJavaType())) {
            this.hasSqlDate = true;
        }
    }
    // 自动忽略前缀
    if (StringUtil.isNotEmpty(codeBuilderProperties.getIgnoreClassPrefix())) {
        entityName = entityName.replaceFirst(codeBuilderProperties.getIgnoreClassPrefix(), "");
    }
    return this;
}
 
Example 4
Source File: CodeBuilderInvoke.java    From code-builder with Apache License 2.0 6 votes vote down vote up
/**
 * 获取需要自动生成的表列表
 *
 * @param dataBase 数据库对象实例
 * @return
 */
private static List<String> getTables(DataBase dataBase, CodeBuilderProperties codeBuilderProperties) {
    List<String> tables = codeBuilderProperties.getTables();
    String generatorByPattern = codeBuilderProperties.getGeneratorByPattern();
    /*
     * 根据配置tables参数表名进行构建生成
     * 优先级高于generatorByPattern
     */
    if (null != tables && tables.size() > 0) {
        logger.info("Using table name to generate code automatically, please wait...");
        return tables;
    }
    /*
     * 如果配置generatorByPattern参数,优先级高于tables
     */
    else if (StringUtil.isNotEmpty(generatorByPattern)) {
        logger.info("Using expression method to generate code automatically, please wait...");
        return dataBase.getTableNames(generatorByPattern);
    }
    throw new CodeBuilderException(ErrorEnum.NO_BUILDER_TABLE);
}
 
Example 5
Source File: AbstractEngineTemplate.java    From code-builder with Apache License 2.0 5 votes vote down vote up
/**
 * 获取模板创建文件后的包名
 *
 * @param templateConfiguration 模板配置对象
 * @return 包名
 */
protected String getTemplatePackageName(TemplateConfiguration templateConfiguration) {
    // 包名前缀
    StringBuffer packageName = new StringBuffer(codeBuilderProperties.getBuilder().getPackagePrefix());
    // 默认包名
    if (StringUtil.isNotEmpty(templateConfiguration.getPackageName())) {
        packageName.append(PACKAGE_SPLIT);
        // 转换为小写
        packageName.append(templateConfiguration.getPackageName().toLowerCase());
    }
    return packageName.toString();
}
 
Example 6
Source File: AbstractEngineTemplate.java    From code-builder with Apache License 2.0 5 votes vote down vote up
/**
 * 获取模板生成文件后的类名
 *
 * @param templateConfiguration 默认配置信息
 * @param entityName            数据表对应的实体名称
 * @return Class 名称
 */
protected String getTemplateClassName(TemplateConfiguration templateConfiguration, String entityName) {
    StringBuffer className = new StringBuffer();
    // 追加文件前缀名
    if (StringUtil.isNotEmpty(templateConfiguration.getFilePrefix())) {
        className.append(StringUtil.getCamelCaseString(templateConfiguration.getFilePrefix(), true));
    }
    // 实体类名称
    className.append(entityName);
    // 追加文件后缀名
    if (StringUtil.isNotEmpty(templateConfiguration.getFileSuffix())) {
        className.append(StringUtil.getCamelCaseString(templateConfiguration.getFileSuffix(), true));
    }
    return className.toString();
}
 
Example 7
Source File: AbstractEngineTemplate.java    From code-builder with Apache License 2.0 5 votes vote down vote up
/**
 * 循环创建package
 * 根据builder.yml配置文件内的参数packagePrefix进行自动创建package包名的文件夹
 * 如:com.code.builder
 * 则自动创建com/code/builder文件夹
 *
 * @param templateConfiguration 模板配置
 */
protected void loopCreatePackage(TemplateConfiguration templateConfiguration) {
    // 目录地址
    StringBuffer basePackagePath = new StringBuffer();
    // 目标根地址
    basePackagePath.append(getBasePackageTargetDir());
    // 模板生成文件目标独有的package
    if (StringUtil.isNotEmpty(templateConfiguration.getPackageName())) {
        basePackagePath.append(templateConfiguration.getPackageName());
    }
    // 执行创建目录
    File basePackage = new File(basePackagePath.toString());
    basePackage.mkdirs();
}
 
Example 8
Source File: AbstractDataBase.java    From code-builder with Apache License 2.0 5 votes vote down vote up
/**
 * 获取数据库连接对象
 *
 * @return 数据库连接对象
 */
public Connection getConnection() {
    try {
        /*
         * 连接不存在 || 连接失效
         * 重新获取连接
         */
        if (connection == null || connection.isClosed()) {
            // spring-boot-starter方式获取数据库连接
            if (codeBuilderProperties.getDataSource() != null) {
                connection = codeBuilderProperties.getDataSource().getConnection();
            }
            // maven-plugin插件形式获取数据库连接
            else {
                // 默认使用数据库驱动类型内的限定类名
                String driverClassName = codeBuilderProperties.getDbType().getValue();
                // 存在自定义的驱动限定类名时使用自定义来实例化驱动对象
                if (StringUtil.isNotEmpty(codeBuilderProperties.getDbDriverClassName())) {
                    driverClassName = codeBuilderProperties.getDbDriverClassName();
                }
                //加载驱动程序
                Class.forName(driverClassName);
                // 获取数据库连接
                connection = DriverManager.getConnection(codeBuilderProperties.getDbUrl(), codeBuilderProperties.getDbUserName(), codeBuilderProperties.getDbPassword());
            }
        }
        return connection;
    } catch (Exception e) {
        e.printStackTrace();
    }
    throw new CodeBuilderException(ErrorEnum.NOT_GET_CONNECTION);
}
 
Example 9
Source File: BuilderConfiguration.java    From code-builder with Apache License 2.0 5 votes vote down vote up
/**
 * 获取不同系统的package转换目录分割后的路径
 *
 * @return 获取不同系统格式化后的包名路径
 */
public String getDiffSysPackagePrefix() {
    if (!StringUtil.isNotEmpty(packagePrefix)) {
        return packagePrefix;
    }
    return packagePrefix.replace(".", File.separator);
}