com.gitee.hengboy.builder.core.database.model.Table Java Examples
The following examples show how to use
com.gitee.hengboy.builder.core.database.model.Table.
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: AbstractDataBase.java From code-builder with Apache License 2.0 | 6 votes |
/** * 获取数据库内的所有表 * * @param tableNamePattern 表名表达式 * @return 数据表列表结果集 */ public List<Table> getTables(String tableNamePattern) { try { // 获取该数据库内的所有表 ResultSet resultSet = connection.getMetaData().getTables(connection.getCatalog(), codeBuilderProperties.getDbUserName(), tableNamePattern, new String[]{"TABLE"}); List<Table> tables = new ArrayList<Table>(); while (resultSet.next()) { // 获取表名 String tableName = resultSet.getString(TableMetaDataEnum.TABLE_NAME.getValue()); // 获取表格基本信息 tables.add(getTable(tableName)); } return tables; } catch (Exception e) { e.printStackTrace(); } throw new CodeBuilderException(ErrorEnum.NOT_GET_TABLE); }
Example #2
Source File: FreemarkerEngineImpl.java From code-builder with Apache License 2.0 | 5 votes |
/** * 构建指定表的实体 * * @param table 数据表对象 */ public void process(Table table) { try { // 获取配置 BuilderConfiguration builderConfiguration = getConfiguration(); // 遍历生成文件 for (TemplateConfiguration templateConfiguration : builderConfiguration.getTemplates()) { // 创建package loopCreatePackage(templateConfiguration); // freemarker模板 Template template = configuration.getTemplate(templateConfiguration.getName()); // 创建文件 File file = new File(getTemplateNewFileName(templateConfiguration, table.getEntityName())); // 写入freemarker模板内容 Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), DEFAULT_ENCODING)); /* * 构建数据模型实体 * 1. 设置当前模板创建类的包名 * 2. 设置当前模板创建类的类名 * 3. 设置数据表格对象 */ DataModelEntity dataModelEntity = DataModelEntity.builder() .packageName(getTemplatePackageName(templateConfiguration)) .className(getTemplateClassName(templateConfiguration, table.getEntityName())) .table(table) .build(); // 执行生成 template.process(dataModelEntity, out); } } catch (Exception e) { e.printStackTrace(); } }
Example #3
Source File: AbstractDataBase.java From code-builder with Apache License 2.0 | 5 votes |
/** * 获取数据表基本信息 * * @param tableName 表名 * @return 数据表对象实例 */ public Table getTable(String tableName) { // 构建数据表对象 Table.TableBuilder tableBuilder = Table.builder(); try { ResultSet resultSet = getConnection().getMetaData().getTables(null, null, tableName, new String[]{"TABLE"}); if (resultSet.next()) { tableBuilder // 表名 .tableName(tableName) // 实体类名称 .entityName(StringUtil.getCamelCaseString(tableName, true)) // 表类别 .catalog(resultSet.getString(TableMetaDataEnum.TABLE_CAT.getValue())) // 表模式 .schema(resultSet.getString(TableMetaDataEnum.TABLE_SCHEMA.getValue())) // 表类型 .tableType(resultSet.getString(TableMetaDataEnum.TABLE_TYPE.getValue())) // 获取备注信息 .remark(getTableComment(tableName)) // 所有列,排除主键 .columns(getColumns(tableName)) // 主键列表 .primaryKeys(getPrimaryKeys(tableName)); } } catch (SQLException e) { e.printStackTrace(); } return tableBuilder.build().buildAfterSetting(codeBuilderProperties); }
Example #4
Source File: DynamicEntityClassBuilder.java From beihu-boot with Apache License 2.0 | 4 votes |
/** * generator dynamic entity * * @return */ @Override public String getClassContent() { try { StringWriter stringWriter = new StringWriter(); CodeWriter writer = new JavaWriter(stringWriter); // current table Table table = getWrapper().getTable(); // package writer.packageDecl(getWrapper().getPackageName()); writer.imports(ColumnExpression.class, TableExpression.class); // formatter super class name String superClassName = String.format(TABLE_EXPRESSION, getEntityName(getWrapper().getTableCamelName())); // java doc writer.javadoc(table.getRemark(), AUTHOR); // begin class writer.beginClass(new SimpleType(getWrapper().getTableCamelName(), EnhanceCodegenConstant.EMPTY_STRING, getWrapper().getTableCamelName()), new SimpleType(superClassName, EnhanceCodegenConstant.EMPTY_STRING, superClassName)); // constructor writer.beginConstructor(new Parameter(CONSTRUCTOR_PARAMETER_NAME, Types.STRING)); writer.line(String.format(SUPER_CONSTRUCTOR, CONSTRUCTOR_PARAMETER_NAME)); writer.end(); // dsl method writer.beginStaticMethod(new SimpleType(getWrapper().getTableCamelName(), EnhanceCodegenConstant.EMPTY_STRING, getWrapper().getTableCamelName()), DYNAMIC_METHOD_NAME); writer.line(String.format(DYNAMIC_INSTANCE, getWrapper().getTableCamelName(), table.getTableName())); writer.end(); StringBuffer columns = new StringBuffer(); // column expression for (int i = 0; i < table.getColumns().size(); i++) { Column column = table.getColumns().get(i); // column java doc writer.javadoc(column.getRemark()); writer.line(String.format(COLUMN_EXPRESSION, formatterJavaPropertyName(column.getColumnName()), column.getColumnName())); columns.append(formatterJavaPropertyName(column.getColumnName())); columns.append(i == table.getColumns().size() - 1 ? EnhanceCodegenConstant.EMPTY_STRING : ", "); } // getColumns method writer.annotation(Override.class); writer.beginPublicMethod(new SimpleType(COLUMN_EXPRESSION_ARRAY, EnhanceCodegenConstant.EMPTY_STRING, COLUMN_EXPRESSION_ARRAY), GET_COLUMN_METHOD_NAME); writer.line(String.format(COLUMN_EXPRESSION_ARRAY_INSTANCE, columns.toString())); writer.end(); // end class writer.end(); return stringWriter.toString(); } catch (Exception e) { return null; } }
Example #5
Source File: DynamicEntityClassBuilder.java From api-boot with Apache License 2.0 | 4 votes |
/** * generator dynamic entity * * @return */ @Override public String getClassContent() { try { StringWriter stringWriter = new StringWriter(); CodeWriter writer = new JavaWriter(stringWriter); // current table Table table = getWrapper().getTable(); // package writer.packageDecl(getWrapper().getPackageName()); writer.imports(ColumnExpression.class, TableExpression.class); // formatter super class name String superClassName = String.format(TABLE_EXPRESSION, getEntityName(getWrapper().getTableCamelName())); // java doc writer.javadoc(table.getRemark(), AUTHOR); // begin class writer.beginClass(new SimpleType(getWrapper().getTableCamelName(), EnhanceCodegenConstant.EMPTY_STRING, getWrapper().getTableCamelName()), new SimpleType(superClassName, EnhanceCodegenConstant.EMPTY_STRING, superClassName)); // constructor writer.beginConstructor(new Parameter(CONSTRUCTOR_PARAMETER_NAME, Types.STRING)); writer.line(String.format(SUPER_CONSTRUCTOR, CONSTRUCTOR_PARAMETER_NAME)); writer.end(); // dsl method writer.beginStaticMethod(new SimpleType(getWrapper().getTableCamelName(), EnhanceCodegenConstant.EMPTY_STRING, getWrapper().getTableCamelName()), DYNAMIC_METHOD_NAME); writer.line(String.format(DYNAMIC_INSTANCE, getWrapper().getTableCamelName(), table.getTableName())); writer.end(); StringBuffer columns = new StringBuffer(); // column expression for (int i = 0; i < table.getColumns().size(); i++) { Column column = table.getColumns().get(i); // column java doc writer.javadoc(column.getRemark()); writer.line(String.format(COLUMN_EXPRESSION, formatterJavaPropertyName(column.getColumnName()), column.getColumnName())); columns.append(formatterJavaPropertyName(column.getColumnName())); columns.append(i == table.getColumns().size() - 1 ? EnhanceCodegenConstant.EMPTY_STRING : ", "); } // getColumns method writer.annotation(Override.class); writer.beginPublicMethod(new SimpleType(COLUMN_EXPRESSION_ARRAY, EnhanceCodegenConstant.EMPTY_STRING, COLUMN_EXPRESSION_ARRAY), GET_COLUMN_METHOD_NAME); writer.line(String.format(COLUMN_EXPRESSION_ARRAY_INSTANCE, columns.toString())); writer.end(); // end class writer.end(); return stringWriter.toString(); } catch (Exception e) { return null; } }
Example #6
Source File: EngineTemplate.java From code-builder with Apache License 2.0 | 2 votes |
/** * 单个数据表生成文件 * * @param table 数据表对象 */ void process(Table table);
Example #7
Source File: DataBase.java From code-builder with Apache License 2.0 | 2 votes |
/** * 获取数据库内的所有数据表 * * @param tableNamePattern 表名称表达式过滤,如:sys_%,则仅仅查询出【sys_】开头的所有表 * @return 数据表列表 */ List<Table> getTables(String tableNamePattern);
Example #8
Source File: DataBase.java From code-builder with Apache License 2.0 | 2 votes |
/** * 根据表名获取数据表对象 * * @param tableName 表名 * @return 表对象实例 */ Table getTable(String tableName);