Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getAllColumns()
The following examples show how to use
org.mybatis.generator.api.IntrospectedTable#getAllColumns() .
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: PostgisGeoPlugin.java From dolphin with Apache License 2.0 | 6 votes |
@Override public void initialized(IntrospectedTable introspectedTable) { for(IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()){ if(introspectedColumn.getJdbcType() == Types.OTHER){ String typeName = fetchTypeName(introspectedColumn); //System.out.println("postgis type : "+typeName); switch(typeName.toLowerCase()){ case "geometry":{ introspectedColumn.setFullyQualifiedJavaType(new FullyQualifiedJavaType("org.geolatte.geom.Geometry")); //introspectedColumn.setJdbcTypeName(typeName.toUpperCase()); break; } } } } }
Example 2
Source File: HySwaggerMapperPlugin.java From jvue-admin with MIT License | 6 votes |
private void columnTypeAnnotation(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (this.columnTypeEnabled) { String columnType = "tk.mybatis.mapper.annotation.ColumnType"; String jdbcType = "org.apache.ibatis.type.JdbcType"; topLevelClass.addImportedType(columnType); topLevelClass.addImportedType(jdbcType); List<Field> fields = topLevelClass.getFields(); for (Field field : fields) { List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns(); for (IntrospectedColumn introspectedColumn : allColumns) if (field.getName().equals(introspectedColumn.getJavaProperty())) { String jdbcTypeName = introspectedColumn.getJdbcTypeName(); if(StringUtil.isEmpty(jdbcTypeName)){ continue; }else{ jdbcTypeName="JdbcType."+jdbcTypeName; } field.addAnnotation("@ColumnType(jdbcType=" + jdbcTypeName + ")"); } } } }
Example 3
Source File: DB2UpsertPlugin.java From dolphin with Apache License 2.0 | 6 votes |
protected void generateCopyForSetByPrefix(String fieldPrefix, String leftPrefix, String rightPrefix, boolean ifNullCheck, IntrospectedTable introspectedTable, XmlElement dynamicElement) { XmlElement trimElement = new XmlElement("trim"); trimElement.addAttribute(new Attribute("suffixOverrides", ",")); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { sb.setLength(0); String columnName = MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn); sb.append(leftPrefix + columnName); sb.append(" = "); sb.append(rightPrefix + columnName); sb.append(','); doIfNullCheck(fieldPrefix, ifNullCheck, trimElement, sb, introspectedColumn); } dynamicElement.addElement(trimElement); }
Example 4
Source File: HsqldbUpsertPlugin.java From dolphin with Apache License 2.0 | 6 votes |
protected void generateCopyForSetByPrefix(String fieldPrefix, String leftPrefix, String rightPrefix, boolean ifNullCheck, IntrospectedTable introspectedTable, XmlElement dynamicElement) { XmlElement trimElement = new XmlElement("trim"); trimElement.addAttribute(new Attribute("suffixOverrides", ",")); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { sb.setLength(0); String columnName = MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn); sb.append(leftPrefix + columnName); sb.append(" = "); sb.append(rightPrefix + columnName); sb.append(','); doIfNullCheck(fieldPrefix, ifNullCheck, trimElement, sb, introspectedColumn); } dynamicElement.addElement(trimElement); }
Example 5
Source File: IntrospectedTableTools.java From mybatis-generator-plugin with Apache License 2.0 | 6 votes |
/** * 获取生成model baseRecord的列 * @param introspectedTable * @return */ public static List<IntrospectedColumn> getModelBaseRecordClomns(IntrospectedTable introspectedTable) { List<IntrospectedColumn> introspectedColumns; if (includePrimaryKeyColumns(introspectedTable)) { if (includeBLOBColumns(introspectedTable)) { introspectedColumns = introspectedTable.getAllColumns(); } else { introspectedColumns = introspectedTable.getNonBLOBColumns(); } } else { if (includeBLOBColumns(introspectedTable)) { introspectedColumns = introspectedTable .getNonPrimaryKeyColumns(); } else { introspectedColumns = introspectedTable.getBaseColumns(); } } return introspectedColumns; }
Example 6
Source File: AbstractUpsertPlugin.java From dolphin with Apache License 2.0 | 5 votes |
/** * 创建根据传入的Array数组进行判断的sql语句 * * @param introspectedTable The metadata for database table * @return generated xml element for check input array params */ protected XmlElement buildSqlClause(IntrospectedTable introspectedTable) { XmlElement sql = new XmlElement("sql"); sql.addAttribute(new Attribute("id", IDENTIFIERS_ARRAY_CONDITIONS)); XmlElement foreach = new XmlElement("foreach"); foreach.addAttribute(new Attribute("collection", "array")); foreach.addAttribute(new Attribute("item", "item")); foreach.addAttribute(new Attribute("index", "index")); foreach.addAttribute(new Attribute("separator", " and ")); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { XmlElement isEqualElement = new XmlElement("if"); sb.setLength(0); sb.append("item == \'"); sb.append(introspectedColumn.getJavaProperty()); sb.append("\'"); isEqualElement.addAttribute(new Attribute("test", sb.toString())); foreach.addElement(isEqualElement); sb.setLength(0); sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn)); sb.append(" = "); sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, PROPERTY_PREFIX)); isEqualElement.addElement(new TextElement(sb.toString())); } sql.addElement(foreach); return sql; }
Example 7
Source File: HsqldbUpsertPlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override protected XmlElement buildSqlClause(IntrospectedTable introspectedTable) { XmlElement sql = new XmlElement("sql"); sql.addAttribute(new Attribute("id", IDENTIFIERS_ARRAY_CONDITIONS)); XmlElement foreach = new XmlElement("foreach"); foreach.addAttribute(new Attribute("collection", "array")); foreach.addAttribute(new Attribute("item", "item")); foreach.addAttribute(new Attribute("index", "index")); foreach.addAttribute(new Attribute("separator", " and ")); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) { XmlElement isEqualElement = new XmlElement("if"); sb.setLength(0); sb.append("item == \'"); sb.append(introspectedColumn.getJavaProperty()); sb.append("\'"); isEqualElement.addAttribute(new Attribute("test", sb.toString())); foreach.addElement(isEqualElement); sb.setLength(0); String columnName = MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn); sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime() + "." + columnName); sb.append(" = "); sb.append("temp." + columnName); isEqualElement.addElement(new TextElement(sb.toString())); } sql.addElement(foreach); return sql; }
Example 8
Source File: OptimisticLockingPlugin.java From mybatis-generator-plugins with Apache License 2.0 | 5 votes |
IntrospectedColumn getColumn(IntrospectedTable introspectedTable) { for (IntrospectedColumn column : introspectedTable.getAllColumns()) { if (lockColumn.equals(column.getActualColumnName())) { return column; } } return null; }
Example 9
Source File: EqualsHashCodePlugin.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns; if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { columns = introspectedTable.getNonBLOBColumns(); } else { columns = introspectedTable.getAllColumns(); } generateEquals(topLevelClass, columns, introspectedTable); generateHashCode(topLevelClass, columns, introspectedTable); return true; }
Example 10
Source File: DatabaseIntrospector.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Report introspection warnings. * * @param introspectedTable * the introspected table * @param tableConfiguration * the table configuration * @param table * the table */ private void reportIntrospectionWarnings( IntrospectedTable introspectedTable, TableConfiguration tableConfiguration, FullyQualifiedTable table) { // make sure that every column listed in column overrides // actually exists in the table for (ColumnOverride columnOverride : tableConfiguration .getColumnOverrides()) { if (introspectedTable.getColumn(columnOverride.getColumnName()) == null) { warnings.add(getString("Warning.3", //$NON-NLS-1$ columnOverride.getColumnName(), table.toString())); } } // make sure that every column listed in ignored columns // actually exists in the table for (String string : tableConfiguration.getIgnoredColumnsInError()) { warnings.add(getString("Warning.4", //$NON-NLS-1$ string, table.toString())); } GeneratedKey generatedKey = tableConfiguration.getGeneratedKey(); if (generatedKey != null && introspectedTable.getColumn(generatedKey.getColumn()) == null) { if (generatedKey.isIdentity()) { warnings.add(getString("Warning.5", //$NON-NLS-1$ generatedKey.getColumn(), table.toString())); } else { warnings.add(getString("Warning.6", //$NON-NLS-1$ generatedKey.getColumn(), table.toString())); } } for (IntrospectedColumn ic : introspectedTable.getAllColumns()) { if (JavaReservedWords.containsWord(ic.getJavaProperty())) { warnings.add(getString("Warning.26", //$NON-NLS-1$ ic.getActualColumnName(), table.toString())); } } }
Example 11
Source File: ModelBuilderPlugin.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
@Override public boolean modelBaseRecordBuilderClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { // 判断是否有生成Model的WithBLOBs类 List<IntrospectedColumn> columns = introspectedTable.getRules().generateRecordWithBLOBsClass() ? introspectedTable.getNonBLOBColumns() : introspectedTable.getAllColumns(); InnerClass innerClass = this.generateModelBuilder(topLevelClass, introspectedTable, columns); topLevelClass.addInnerClass(innerClass); return true; }
Example 12
Source File: DatabaseIntrospector.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
private void reportIntrospectionWarnings( IntrospectedTable introspectedTable, TableConfiguration tableConfiguration, FullyQualifiedTable table) { // make sure that every column listed in column overrides // actually exists in the table for (ColumnOverride columnOverride : tableConfiguration .getColumnOverrides()) { if (!introspectedTable.getColumn(columnOverride.getColumnName()).isPresent()) { warnings.add(getString("Warning.3", columnOverride.getColumnName(), table.toString())); } } // make sure that every column listed in ignored columns // actually exists in the table for (String string : tableConfiguration.getIgnoredColumnsInError()) { warnings.add(getString("Warning.4", string, table.toString())); } GeneratedKey generatedKey = tableConfiguration.getGeneratedKey(); if (generatedKey != null && !introspectedTable.getColumn(generatedKey.getColumn()).isPresent()) { if (generatedKey.isIdentity()) { warnings.add(getString("Warning.5", generatedKey.getColumn(), table.toString())); } else { warnings.add(getString("Warning.6", generatedKey.getColumn(), table.toString())); } } for (IntrospectedColumn ic : introspectedTable.getAllColumns()) { if (JavaReservedWords.containsWord(ic.getJavaProperty())) { warnings.add(getString("Warning.26", ic.getActualColumnName(), table.toString())); } } }
Example 13
Source File: PostgisGeoPlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns = new ArrayList<IntrospectedColumn>(); for(IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()){ if(introspectedColumn.getFullyQualifiedJavaType().getPackageName().equalsIgnoreCase("org.geolatte.geom")){ columns.add(introspectedColumn); } } if(columns.isEmpty()) return true; XmlElement xmlElement = document.getRootElement(); for(Element element : xmlElement.getElements()){ if(element instanceof XmlElement){ XmlElement xe = (XmlElement) element; switch (xe.getName().toLowerCase()) { case "sql": if(containsAttribute(xe, "id", introspectedTable.getBaseColumnListId())){ checkAndReplaceOutput(columns,xe); }else if(containsAttribute(xe, "id", AbstractUpsertPlugin.IDENTIFIERS_ARRAY_CONDITIONS)){ checkAndReplaceInput(columns, xe); } break; case "insert": case "update": checkAndReplaceInput(columns, xe); break; default: break; } } } return true; }
Example 14
Source File: EqualsHashCodePlugin.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns; if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { columns = introspectedTable.getNonBLOBColumns(); } else { columns = introspectedTable.getAllColumns(); } generateEquals(topLevelClass, columns, introspectedTable); generateHashCode(topLevelClass, columns, introspectedTable); return true; }
Example 15
Source File: PostgreBatchUpdatePlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 4 votes |
private void addSqlMapper(Document document, IntrospectedTable introspectedTable){ String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); List<IntrospectedColumn> columnList = introspectedTable.getAllColumns(); String primaryKeyName = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName(); //primaryKey的JAVA名字 String primaryKeyJavaName = introspectedTable.getPrimaryKeyColumns().get(0).getJavaProperty(); XmlElement updateElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.UPDATE, BATCH_UPDATE, FullyQualifiedJavaType.getNewListInstance()); XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME, "item", "index", ","); String baseSql = String.format("update %s", tableName); updateElement.addElement(new TextElement(baseSql)); XmlElement setElement = new XmlElement("set"); StringBuilder columnInfo = new StringBuilder(); StringBuilder valuesInfo = new StringBuilder(); StringBuilder columnInfoTotal = new StringBuilder(); for (int i = 0; i < columnList.size(); i++) { IntrospectedColumn introspectedColumn = columnList.get(i); columnInfo.append(introspectedColumn.getActualColumnName()); columnInfoTotal.append(introspectedColumn.getActualColumnName()); if (introspectedColumn.getFullyQualifiedJavaType().equals(FullyQualifiedJavaType.getDateInstance())){ valuesInfo.append("to_timestamp("); valuesInfo.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")); valuesInfo.append(",'yyyy-MM-dd hh24:mi:ss')"); }else { valuesInfo.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")); } String setSql = String.format(" %s = %s," ,columnInfo,"temp."+columnInfo); if (i == (columnList.size() - 1)) { setSql = setSql.substring(0, setSql.length() - 1); } if (!introspectedColumn.isIdentity() && !introspectedColumn.getActualColumnName().equals(primaryKeyName)) { setElement.addElement(new TextElement(setSql)); } if (i != (columnList.size() - 1)) { valuesInfo.append(","); columnInfo.append(","); columnInfoTotal.append(","); } columnInfo.delete(0, valuesInfo.length()); } foreachElement.addElement(new TextElement("(")); foreachElement.addElement(new TextElement(valuesInfo.toString())); foreachElement.addElement(new TextElement(")")); updateElement.addElement(setElement); updateElement.addElement(new TextElement("from (values")); updateElement.addElement(foreachElement); updateElement.addElement(new TextElement(String.format(") as temp (%s) where %s.%s=temp.%s;",columnInfoTotal,tableName,primaryKeyName,primaryKeyName))); //3.parent Add document.getRootElement().addElement(updateElement); }
Example 16
Source File: CustomCommentGenerator.java From BlogManagePlatform with Apache License 2.0 | 4 votes |
private void resolveImports(TopLevelClass klass, IntrospectedTable table) { addImport(klass, Data.class); addImport(klass, Id.class); addImport(klass, Table.class); addImport(klass, Column.class); addImport(klass, Entity.class); addImport(klass, ApiModel.class); addImport(klass, ApiModelProperty.class); boolean hasNullable = false; boolean hasNotNull = false; boolean hasNotBlank = false; boolean hasLength = false; for (IntrospectedColumn iter : table.getAllColumns()) { if (iter.isNullable()) { hasNullable = true; } else { if (iter.isStringColumn()) { hasNotBlank = true; } else { hasNotNull = true; } } if (iter.isStringColumn()) { if (iter.getLength() != 0) { hasLength = true; } } } if (hasNullable) { addImport(klass, Nullable.class); } if (hasNotNull) { addImport(klass, NotNull.class); } if (hasNotBlank) { addImport(klass, NotBlank.class); } if (hasLength) { addImport(klass, Length.class); } }
Example 17
Source File: OracleSupport.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
/** * 生成批量插入的动态sql代码 * * @author 吴帅 * @parameter @param document * @parameter @param introspectedTable * @createDate 2015年8月9日 下午6:57:43 */ @Override public void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns = introspectedTable.getAllColumns(); //获得要自增的列名 String incrementField = introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField"); if (incrementField != null) { incrementField = incrementField.toUpperCase(); } StringBuilder dbcolumnsName = new StringBuilder(); StringBuilder javaPropertyAndDbType = new StringBuilder(); for (IntrospectedColumn introspectedColumn : columns) { String columnName = introspectedColumn.getActualColumnName(); dbcolumnsName.append(columnName + ","); if (!columnName.toUpperCase().equals(incrementField)) {// 不设置id javaPropertyAndDbType.append("#{item." + introspectedColumn.getJavaProperty() + ",jdbcType=" + introspectedColumn.getJdbcTypeName() + "},"); } } XmlElement insertBatchElement = new XmlElement("insert"); insertBatchElement.addAttribute(new Attribute("id", "insertBatch")); insertBatchElement.addAttribute(new Attribute("parameterType", introspectedTable.getBaseRecordType())); insertBatchElement.addElement(new TextElement("insert into " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())); XmlElement trim1Element = new XmlElement("trim"); trim1Element.addAttribute(new Attribute("prefix", "(")); trim1Element.addAttribute(new Attribute("suffix", ")")); trim1Element.addAttribute(new Attribute("suffixOverrides", ",")); trim1Element.addElement(new TextElement(dbcolumnsName.toString())); insertBatchElement.addElement(trim1Element); insertBatchElement.addElement(new TextElement("select " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime() + "_SEQUENCE.nextval,A.* from(")); XmlElement foreachElement = new XmlElement("foreach"); foreachElement.addAttribute(new Attribute("collection", "list")); foreachElement.addAttribute(new Attribute("index", "index")); foreachElement.addAttribute(new Attribute("item", "item")); foreachElement.addAttribute(new Attribute("separator", "UNION ALL")); foreachElement.addElement(new TextElement("SELECT")); XmlElement trim2Element = new XmlElement("trim"); trim2Element.addAttribute(new Attribute("suffixOverrides", ",")); trim2Element.addElement(new TextElement(javaPropertyAndDbType.toString())); foreachElement.addElement(trim2Element); foreachElement.addElement(new TextElement("from dual")); insertBatchElement.addElement(foreachElement); insertBatchElement.addElement(new TextElement(") A")); document.getRootElement().addElement(insertBatchElement); }
Example 18
Source File: MysqlSupport.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
/** * 增加批量插入的xml配置 * * @author 吴帅 * @parameter @param document * @parameter @param introspectedTable * @createDate 2015年8月9日 下午6:57:43 */ @Override public void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns = introspectedTable.getAllColumns(); //获得要自增的列名 String incrementField = introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField"); if (incrementField != null) { incrementField = incrementField.toUpperCase(); } StringBuilder dbcolumnsName = new StringBuilder(); StringBuilder javaPropertyAndDbType = new StringBuilder(); for (IntrospectedColumn introspectedColumn : columns) { String columnName = introspectedColumn.getActualColumnName(); if (!columnName.toUpperCase().equals(incrementField)) {//不是自增字段的才会出现在批量插入中 dbcolumnsName.append(columnName + ","); javaPropertyAndDbType.append("#{item." + introspectedColumn.getJavaProperty() + ",jdbcType=" + introspectedColumn.getJdbcTypeName() + "},"); } } XmlElement insertBatchElement = new XmlElement("insert"); insertBatchElement.addAttribute(new Attribute("id", "insertBatch")); insertBatchElement.addAttribute(new Attribute("parameterType", introspectedTable.getBaseRecordType())); insertBatchElement.addElement(new TextElement("insert into " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())); XmlElement trim1Element = new XmlElement("trim"); trim1Element.addAttribute(new Attribute("prefix", "(")); trim1Element.addAttribute(new Attribute("suffix", ")")); trim1Element.addAttribute(new Attribute("suffixOverrides", ",")); trim1Element.addElement(new TextElement(dbcolumnsName.toString())); insertBatchElement.addElement(trim1Element); insertBatchElement.addElement(new TextElement("values")); XmlElement foreachElement = new XmlElement("foreach"); foreachElement.addAttribute(new Attribute("collection", "list")); foreachElement.addAttribute(new Attribute("index", "index")); foreachElement.addAttribute(new Attribute("item", "item")); foreachElement.addAttribute(new Attribute("separator", ",")); foreachElement.addElement(new TextElement("(")); XmlElement trim2Element = new XmlElement("trim"); trim2Element.addAttribute(new Attribute("suffixOverrides", ",")); trim2Element.addElement(new TextElement(javaPropertyAndDbType.toString())); foreachElement.addElement(trim2Element); foreachElement.addElement(new TextElement(")")); insertBatchElement.addElement(foreachElement); document.getRootElement().addElement(insertBatchElement); }
Example 19
Source File: SqlServerSupport.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
/** * 增加批量插入的xml配置 * * @author 吴帅 * @parameter @param document * @parameter @param introspectedTable * @createDate 2015年8月9日 下午6:57:43 */ @Override public void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns = introspectedTable.getAllColumns(); //获得要自增的列名 String incrementField = introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField"); if (incrementField != null) { incrementField = incrementField.toUpperCase(); } StringBuilder dbcolumnsName = new StringBuilder(); StringBuilder javaPropertyAndDbType = new StringBuilder(); for (IntrospectedColumn introspectedColumn : columns) { String columnName = introspectedColumn.getActualColumnName(); if (!columnName.toUpperCase().equals(incrementField)) {//不是自增字段的才会出现在批量插入中 dbcolumnsName.append(columnName + ","); javaPropertyAndDbType.append("#{item." + introspectedColumn.getJavaProperty() + ",jdbcType=" + introspectedColumn.getJdbcTypeName() + "},"); } } XmlElement insertBatchElement = new XmlElement("insert"); insertBatchElement.addAttribute(new Attribute("id", "insertBatch")); insertBatchElement.addAttribute(new Attribute("parameterType", introspectedTable.getBaseRecordType())); insertBatchElement.addElement(new TextElement("insert into " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())); XmlElement trim1Element = new XmlElement("trim"); trim1Element.addAttribute(new Attribute("prefix", "(")); trim1Element.addAttribute(new Attribute("suffix", ")")); trim1Element.addAttribute(new Attribute("suffixOverrides", ",")); trim1Element.addElement(new TextElement(dbcolumnsName.toString())); insertBatchElement.addElement(trim1Element); insertBatchElement.addElement(new TextElement("values")); XmlElement foreachElement = new XmlElement("foreach"); foreachElement.addAttribute(new Attribute("collection", "list")); foreachElement.addAttribute(new Attribute("index", "index")); foreachElement.addAttribute(new Attribute("item", "item")); foreachElement.addAttribute(new Attribute("separator", ",")); foreachElement.addElement(new TextElement("(")); XmlElement trim2Element = new XmlElement("trim"); trim2Element.addAttribute(new Attribute("suffixOverrides", ",")); trim2Element.addElement(new TextElement(javaPropertyAndDbType.toString())); foreachElement.addElement(trim2Element); foreachElement.addElement(new TextElement(")")); insertBatchElement.addElement(foreachElement); document.getRootElement().addElement(insertBatchElement); }
Example 20
Source File: HySwaggerMapperPlugin.java From jvue-admin with MIT License | 4 votes |
private void addFieldEnum(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (this.modelFieldEnum) { String enumName = "FieldEnum"; String javaFieldName = "javaFieldName"; String dbFieldName = "dbFieldName"; InnerEnum enum1 = new InnerEnum(new FullyQualifiedJavaType(enumName)); enum1.setVisibility(JavaVisibility.PUBLIC); StringBuilder enumConstant = new StringBuilder(); List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns(); int index = 0; for (IntrospectedColumn column : allColumns) { String dbName = column.getActualColumnName(); String javaName = column.getJavaProperty(); enumConstant.append(dbName.toUpperCase()).append("(\"").append(javaName).append("\",\"").append(dbName).append("\")"); if (++index < allColumns.size()) { enumConstant.append(",\n\t\t"); } } enum1.addEnumConstant(enumConstant.toString()); //java字段 Field field = new Field(); field.setVisibility(JavaVisibility.PRIVATE); field.setStatic(false); field.setType(new FullyQualifiedJavaType("String")); field.setName(javaFieldName); enum1.addField(field); //db字段 Field field1 = new Field(); field1.setVisibility(JavaVisibility.PRIVATE); field1.setStatic(false); field1.setType(new FullyQualifiedJavaType("String")); field1.setName(dbFieldName); enum1.addField(field1); //构造器 Method method = new Method(); method.setConstructor(true); method.setVisibility(JavaVisibility.DEFAULT); method.setStatic(false); method.setName(enumName); method.addParameter(new Parameter(new FullyQualifiedJavaType("String"), javaFieldName)); method.addParameter(new Parameter(new FullyQualifiedJavaType("String"), dbFieldName)); method.addBodyLine("this."+javaFieldName+" = "+javaFieldName+";"); method.addBodyLine("this."+dbFieldName+" = "+dbFieldName+";"); enum1.addMethod(method); //方法 Method getMethod = new Method(); getMethod.setConstructor(false); getMethod.setVisibility(JavaVisibility.PUBLIC); getMethod.setStatic(false); getMethod.setName(javaFieldName); getMethod.addBodyLine("return "+javaFieldName+";"); getMethod.setReturnType(new FullyQualifiedJavaType("String")); enum1.addMethod(getMethod); Method getMethod1 = new Method(); getMethod1.setConstructor(false); getMethod1.setVisibility(JavaVisibility.PUBLIC); getMethod1.setStatic(false); getMethod1.setName(dbFieldName); getMethod1.addBodyLine("return "+dbFieldName+";"); getMethod1.setReturnType(new FullyQualifiedJavaType("String")); enum1.addMethod(getMethod1); topLevelClass.addInnerEnum(enum1); } }