org.mybatis.generator.api.IntrospectedTable Java Examples
The following examples show how to use
org.mybatis.generator.api.IntrospectedTable.
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: SerializablePlugin.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (addGWTInterface) { topLevelClass.addImportedType(gwtSerializable); topLevelClass.addSuperInterface(gwtSerializable); } if (!suppressJavaInterface) { topLevelClass.addImportedType(serializable); topLevelClass.addSuperInterface(serializable); Field field = new Field(); field.setFinal(true); field.setInitializationString("1L"); //$NON-NLS-1$ field.setName("serialVersionUID"); //$NON-NLS-1$ field.setStatic(true); field.setType(new FullyQualifiedJavaType("long")); //$NON-NLS-1$ field.setVisibility(JavaVisibility.PRIVATE); context.getCommentGenerator().addFieldComment(field, introspectedTable); topLevelClass.addField(field); } }
Example #2
Source File: MySQLCommentGenerator.java From mbg-comment with MIT License | 6 votes |
@Override public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { String author = properties.getProperty("author"); String dateFormat = properties.getProperty("dateFormat", "yyyy-MM-dd"); SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat); // 获取表注释 String remarks = introspectedTable.getRemarks(); topLevelClass.addJavaDocLine("/**"); topLevelClass.addJavaDocLine(" * " + remarks); topLevelClass.addJavaDocLine(" *"); topLevelClass.addJavaDocLine(" * @author " + author); topLevelClass.addJavaDocLine(" * @date " + dateFormatter.format(new Date())); topLevelClass.addJavaDocLine(" */"); }
Example #3
Source File: SerializablePlugin.java From feiqu-opensource with Apache License 2.0 | 6 votes |
/** * 添加给Example类序列化的方法 * @param topLevelClass * @param introspectedTable * @return */ @Override public boolean modelExampleClassGenerated(TopLevelClass topLevelClass,IntrospectedTable introspectedTable){ makeSerializable(topLevelClass, introspectedTable); for (InnerClass innerClass : topLevelClass.getInnerClasses()) { if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) { innerClass.addSuperInterface(serializable); } if ("Criteria".equals(innerClass.getType().getShortName())) { innerClass.addSuperInterface(serializable); } if ("Criterion".equals(innerClass.getType().getShortName())) { innerClass.addSuperInterface(serializable); } } return true; }
Example #4
Source File: SerializablePlugin.java From feiqu-opensource with Apache License 2.0 | 6 votes |
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if(this.addGWTInterface) { topLevelClass.addImportedType(this.gwtSerializable); topLevelClass.addSuperInterface(this.gwtSerializable); } if(!this.suppressJavaInterface) { topLevelClass.addImportedType(this.serializable); topLevelClass.addSuperInterface(this.serializable); Field field = new Field(); field.setFinal(true); field.setInitializationString("1L"); field.setName("serialVersionUID"); field.setStatic(true); field.setType(new FullyQualifiedJavaType("long")); field.setVisibility(JavaVisibility.PRIVATE); this.context.getCommentGenerator().addFieldComment(field, introspectedTable); topLevelClass.addField(field); } }
Example #5
Source File: MapperCommentGenerator.java From Mapper with MIT License | 6 votes |
/** * getter方法注释 * * @param method * @param introspectedTable * @param introspectedColumn */ @Override public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { StringBuilder sb = new StringBuilder(); method.addJavaDocLine("/**"); if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) { sb.append(" * 获取"); sb.append(introspectedColumn.getRemarks()); method.addJavaDocLine(sb.toString()); method.addJavaDocLine(" *"); } sb.setLength(0); sb.append(" * @return "); sb.append(introspectedColumn.getActualColumnName()); if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) { sb.append(" - "); sb.append(introspectedColumn.getRemarks()); } method.addJavaDocLine(sb.toString()); method.addJavaDocLine(" */"); }
Example #6
Source File: DatabaseIntrospector.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
/** * Calls database metadata to retrieve extra information about the table * such as remarks associated with the table and the type. * * <p>If there is any error, we just add a warning and continue. * * @param introspectedTable the introspected table to enhance */ private void enhanceIntrospectedTable(IntrospectedTable introspectedTable) { try { FullyQualifiedTable fqt = introspectedTable.getFullyQualifiedTable(); ResultSet rs = databaseMetaData.getTables(fqt.getIntrospectedCatalog(), fqt.getIntrospectedSchema(), fqt.getIntrospectedTableName(), null); if (rs.next()) { String remarks = rs.getString("REMARKS"); String tableType = rs.getString("TABLE_TYPE"); introspectedTable.setRemarks(remarks); introspectedTable.setTableType(tableType); } closeResultSet(rs); } catch (SQLException e) { warnings.add(getString("Warning.27", e.getMessage())); } }
Example #7
Source File: RenameExampleClassAndMethodsPluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldRenameElementOfSqlMapUpdateByExampleSelective() throws Exception { RenameExampleClassAndMethodsPlugin plugin = spy(this.plugin); // Given willReturn(true).given(plugin).renameElement(element); willDoNothing().given(plugin).removeIdColumns(any(IntrospectedTable.class), any(XmlElement.class)); // When boolean ok = plugin.sqlMapUpdateByExampleSelectiveElementGenerated(element, introspectedTable); // Then assertThat(ok).isTrue(); verify(plugin).removeIdColumns(eq(introspectedTable), eq(element)); verify(plugin).renameElement(eq(element)); }
Example #8
Source File: CommentGenerator.java From HIS with Apache License 2.0 | 6 votes |
/** * 给字段添加注释 */ @Override public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { String remarks = introspectedColumn.getRemarks(); //根据参数和备注信息判断是否添加备注信息 if(addRemarkComments&&StringUtility.stringHasValue(remarks)){ // addFieldJavaDoc(field, remarks); //数据库中特殊字符需要转义 if(remarks.contains("\"")){ remarks = remarks.replace("\"","'"); } //给model的字段添加swagger注解 field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")"); } }
Example #9
Source File: PluginAggregator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles( IntrospectedTable introspectedTable) { List<GeneratedJavaFile> answer = new ArrayList<>(); for (Plugin plugin : plugins) { List<GeneratedJavaFile> temp = plugin .contextGenerateAdditionalJavaFiles(introspectedTable); if (temp != null) { answer.addAll(temp); } } return answer; }
Example #10
Source File: IncrementsPlugin.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * Model builder class 生成 * @param topLevelClass * @param builderClass * @param columns * @param introspectedTable * @return */ @Override public boolean modelBuilderClassGenerated(TopLevelClass topLevelClass, InnerClass builderClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable) { if (this.support()) { if (this.incEnum == null) { this.incEnum = this.generatedIncEnum(introspectedTable); this.incEnumBuilder = builderClass; // 增加枚举 builderClass.addInnerEnum(this.incEnum); // topLevel class 添加必要的操作方法 this.addIncMethodToTopLevelClass(topLevelClass, builderClass, introspectedTable, false); } // Builder 中 添加字段支持 for (IntrospectedColumn column : columns) { if (this.supportIncrement(column)) { Field field = JavaBeansUtil.getJavaBeansField(column, context, introspectedTable); // 增加方法 Method mIncrements = JavaElementGeneratorTools.generateMethod( field.getName(), JavaVisibility.PUBLIC, builderClass.getType(), new Parameter(field.getType(), field.getName()), new Parameter(this.getIncEnum(builderClass, introspectedTable), "inc") ); commentGenerator.addSetterComment(mIncrements, introspectedTable, column); Method setterMethod = JavaBeansUtil.getJavaBeansSetter(column, context, introspectedTable); mIncrements.addBodyLine("obj." + IncrementsPlugin.FIELD_INC_MAP + ".put(\"" + column.getActualColumnName() + "\", inc);"); mIncrements.addBodyLine("obj." + setterMethod.getName() + "(" + field.getName() + ");"); mIncrements.addBodyLine("return this;"); FormatTools.addMethodWithBestPosition(builderClass, mIncrements); } } } return true; }
Example #11
Source File: CommentsWavePlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //System.out.println(topLevelClass.getFormattedContent()); //System.out.println(context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING)); return true; }
Example #12
Source File: CachePlugin.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
private void addAttributeIfExists(XmlElement element, IntrospectedTable introspectedTable, CacheProperty cacheProperty) { String property = introspectedTable.getTableConfigurationProperty(cacheProperty.getPropertyName()); if (property == null) { property = properties.getProperty(cacheProperty.getPropertyName()); } if (StringUtility.stringHasValue(property)) { element.addAttribute(new Attribute(cacheProperty.getAttributeName(), property)); } }
Example #13
Source File: ExtendedDAOMethodNameCalculator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
public String getDeleteByPrimaryKeyMethodName( IntrospectedTable introspectedTable) { StringBuilder sb = new StringBuilder(); sb.append("delete"); //$NON-NLS-1$ sb.append(introspectedTable.getFullyQualifiedTable() .getDomainObjectName()); sb.append("ByPrimaryKey"); //$NON-NLS-1$ return sb.toString(); }
Example #14
Source File: DefaultCommentGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { if (suppressAllComments || !addRemarkComments) { return; } StringBuilder sb = new StringBuilder(); topLevelClass.addJavaDocLine("/**"); //$NON-NLS-1$ String remarks = introspectedTable.getRemarks(); if (addRemarkComments && StringUtility.stringHasValue(remarks)) { topLevelClass.addJavaDocLine(" * Database Table Remarks:"); String[] remarkLines = remarks.split(System.getProperty("line.separator")); //$NON-NLS-1$ for (String remarkLine : remarkLines) { topLevelClass.addJavaDocLine(" * " + remarkLine); //$NON-NLS-1$ } } topLevelClass.addJavaDocLine(" *"); //$NON-NLS-1$ topLevelClass .addJavaDocLine(" * This class was generated by MyBatis Generator."); //$NON-NLS-1$ sb.append(" * This class corresponds to the database table "); //$NON-NLS-1$ sb.append(introspectedTable.getFullyQualifiedTable()); topLevelClass.addJavaDocLine(sb.toString()); addJavadocTag(topLevelClass, true); topLevelClass.addJavaDocLine(" */"); //$NON-NLS-1$ }
Example #15
Source File: PluginAggregator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
public boolean providerUpdateByExampleWithBLOBsMethodGenerated( Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { boolean rc = true; for (Plugin plugin : plugins) { if (!plugin.providerUpdateByExampleWithBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { rc = false; break; } } return rc; }
Example #16
Source File: PluginAggregator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public boolean clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { boolean rc = true; for (Plugin plugin : plugins) { if (!plugin.clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) { rc = false; break; } } return rc; }
Example #17
Source File: LombokPlugin.java From mybatis-generator-lombok-plugin with Apache License 2.0 | 5 votes |
@Override public boolean clientGenerated( Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable ) { interfaze.addImportedType(new FullyQualifiedJavaType( "org.apache.ibatis.annotations.Mapper")); interfaze.addAnnotation("@Mapper"); return true; }
Example #18
Source File: MybatisGeneratorPlugin.java From java-master with Apache License 2.0 | 5 votes |
private boolean addGenerateKey(XmlElement element, IntrospectedTable introspectedTable) { List<IntrospectedColumn> columns = introspectedTable.getPrimaryKeyColumns(); if (columns.size() == 1) { element.addAttribute(new Attribute("useGeneratedKeys", "true")); element.addAttribute(new Attribute("keyProperty", columns.get(0).getJavaProperty())); } return super.sqlMapInsertElementGenerated(element, introspectedTable); }
Example #19
Source File: DatabaseIntrospector.java From mybatis-generator-plus 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()) == 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())); } } }
Example #20
Source File: PluginAggregator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public boolean sqlMapBaseColumnListElementGenerated(XmlElement element, IntrospectedTable introspectedTable) { boolean rc = true; for (Plugin plugin : plugins) { if (!plugin.sqlMapBaseColumnListElementGenerated(element, introspectedTable)) { rc = false; break; } } return rc; }
Example #21
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 #22
Source File: DefaultCommentGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) { imports.add(new FullyQualifiedJavaType("javax.annotation.Generated")); String comment = "Source field: " + introspectedTable.getFullyQualifiedTable().toString() + "." + introspectedColumn.getActualColumnName(); method.addAnnotation(getGeneratedAnnotation(comment)); }
Example #23
Source File: PluginAggregator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public boolean providerInsertSelectiveMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { boolean rc = true; for (Plugin plugin : plugins) { if (!plugin.providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { rc = false; break; } } return rc; }
Example #24
Source File: SerializablePlugin.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { final boolean serializable = Boolean.parseBoolean(introspectedTable.getTableConfigurationProperty("jdkSerializable")); if (!serializable) { return; } if (addGWTInterface) { topLevelClass.addImportedType(gwtSerializable); topLevelClass.addSuperInterface(gwtSerializable); } if (!suppressJavaInterface) { topLevelClass.addImportedType(this.serializable); topLevelClass.addSuperInterface(this.serializable); Field field = new Field("serialVersionUID", new FullyQualifiedJavaType("long")); field.setFinal(true); field.setInitializationString("1L"); field.setStatic(true); field.setVisibility(JavaVisibility.PRIVATE); if (introspectedTable.getTargetRuntime() == TargetRuntime.MYBATIS3_DSQL) { context.getCommentGenerator().addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes()); } else { context.getCommentGenerator().addFieldComment(field, introspectedTable); } topLevelClass.addField(field); } }
Example #25
Source File: PluginAggregator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated( XmlElement element, IntrospectedTable introspectedTable) { boolean rc = true; for (Plugin plugin : plugins) { if (!plugin.sqlMapSelectByExampleWithoutBLOBsElementGenerated( element, introspectedTable)) { rc = false; break; } } return rc; }
Example #26
Source File: TemplateCommentGenerator.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * Adds the field comment. * @param field the field * @param introspectedTable the introspected table */ @Override public void addFieldComment(Field field, IntrospectedTable introspectedTable) { Map<String, Object> map = new HashMap<>(); map.put("mgb", MergeConstants.NEW_ELEMENT_TAG); map.put("field", field); map.put("introspectedTable", introspectedTable); // 添加评论 addJavaElementComment(field, map, EnumNode.ADD_FIELD_COMMENT); }
Example #27
Source File: AbstractPaginationPlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { List<Field> fields = new ArrayList<>(); // add field, getter, setter for limit clause Field field = generateFieldDeclarationWithGetterSetterFor(LIMIT_NAME, new FullyQualifiedJavaType(Integer.class.getCanonicalName()), topLevelClass); fields.add(field); field = generateFieldDeclarationWithGetterSetterFor(OFFSET_NAME, new FullyQualifiedJavaType(Integer.class.getCanonicalName()), topLevelClass); fields.add(field); generateBuilderFor(BOUND_BUILDER_NAME, topLevelClass, fields); return true; }
Example #28
Source File: ContentMergePlugin.java From dolphin with Apache License 2.0 | 5 votes |
@Override public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) { SqlMapGeneratorConfiguration smgc = context.getSqlMapGeneratorConfiguration(); try { Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true); File targetFile = getTargetFile(smgc.getTargetPackage(), sqlMap.getFileName()); if (!targetFile.exists()) { // 第一次生成直接使用当前生成的文件 return true; } visitAndMerge(document, targetFile); } catch (ShellException | IOException | IllegalAccessException | DocumentException e) { e.printStackTrace(); } return true; }
Example #29
Source File: PluginAggregator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public boolean clientInsertSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { boolean rc = true; for (Plugin plugin : plugins) { if (!plugin.clientInsertSelectiveMethodGenerated(method, interfaze, introspectedTable)) { rc = false; break; } } return rc; }
Example #30
Source File: MybatisPageTools.java From DouBiNovel with Apache License 2.0 | 5 votes |
@Override public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) { XmlElement isParameterPresenteElemen = element;//(XmlElement) element.getElements().get(element.getElements().size()); XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$ isNotNullElement.addAttribute(new Attribute("test", "limitStart > -1")); //$NON-NLS-1$ //$NON-NLS-2$ isNotNullElement.addElement(new TextElement("limit ${limitStart} , ${limitEnd}")); isParameterPresenteElemen.addElement(isNotNullElement); return super.sqlMapUpdateByExampleWithoutBLOBsElementGenerated(element, introspectedTable); }