org.mybatis.generator.api.GeneratedXmlFile Java Examples

The following examples show how to use org.mybatis.generator.api.GeneratedXmlFile. 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: IntrospectedTableMyBatis3Impl.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
	// 让isMergeable属性可配置 add by wushuai begin
	String isMergeableStr = context.getSqlMapGeneratorConfiguration().getProperty("isMergeable");
	boolean isMergeable = false;
	if ("true".equalsIgnoreCase(isMergeableStr)) {
		isMergeable = true;
	}
	// 让isMergeable属性可配置 add by wushuai end
	List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();

	if (xmlMapperGenerator != null) {
		Document document = xmlMapperGenerator.getDocument();
		GeneratedXmlFile gxf = new GeneratedXmlFile(document, getMyBatis3XmlMapperFileName(), getMyBatis3XmlMapperPackage(), context.getSqlMapGeneratorConfiguration().getTargetProject(),isMergeable, context.getXmlFormatter());
		if (context.getPlugins().sqlMapGenerated(gxf, this)) {
			answer.add(gxf);
		}
	}

	return answer;
}
 
Example #2
Source File: IntrospectedTableMyBatis3Impl.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();

    if (xmlMapperGenerator != null) {
        Document document = xmlMapperGenerator.getDocument();
        GeneratedXmlFile gxf = new GeneratedXmlFile(document,
            getMyBatis3XmlMapperFileName(), getMyBatis3XmlMapperPackage(),
            context.getSqlMapGeneratorConfiguration().getTargetProject(),
            true, context.getXmlFormatter());
        if (context.getPlugins().sqlMapGenerated(gxf, this)) {
            answer.add(gxf);
        }
    }

    return answer;
}
 
Example #3
Source File: IntrospectedTableIbatis2Java2Impl.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
	// 让isMergeable属性可配置 add by wushuai begin
	String isMergeableStr = context.getSqlMapGeneratorConfiguration().getProperty("isMergeable");
	boolean isMergeable = false;
	if ("true".equalsIgnoreCase(isMergeableStr)) {
		isMergeable = true;
	}
	// 让isMergeable属性可配置 add by wushuai end

	List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();

	Document document = sqlMapGenerator.getDocument();
	GeneratedXmlFile gxf = new GeneratedXmlFile(document, getIbatis2SqlMapFileName(), getIbatis2SqlMapPackage(), context.getSqlMapGeneratorConfiguration().getTargetProject(), isMergeable,context.getXmlFormatter());
	if (context.getPlugins().sqlMapGenerated(gxf, this)) {
		answer.add(gxf);
	}

	return answer;
}
 
Example #4
Source File: IntrospectedTableMyBatis3Impl.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<>();

    if (xmlMapperGenerator != null) {
        Document document = xmlMapperGenerator.getDocument();
        GeneratedXmlFile gxf = new GeneratedXmlFile(document,
                getMyBatis3XmlMapperFileName(), getMyBatis3XmlMapperPackage(),
                context.getSqlMapGeneratorConfiguration().getTargetProject(),
                true, context.getXmlFormatter());
        if (context.getPlugins().sqlMapGenerated(gxf, this)) {
            answer.add(gxf);
        }
    }

    return answer;
}
 
Example #5
Source File: CommentsWavePlugin.java    From dolphin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
  try {
    // use reflect to fix the root comment
    Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true);
    ExtendedDocument extendedDocument = new ExtendedDocument(document);
    FieldUtils.writeDeclaredField(sqlMap, "document", extendedDocument, true);
    if (context.getCommentGenerator() instanceof CommentGenerator) {
      CommentGenerator cg = (CommentGenerator) context.getCommentGenerator();
      cg.addSqlMapFileComment(extendedDocument);
    }
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  }
  return true;
}
 
Example #6
Source File: ContentMergePlugin.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: SqlMapConfigPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    StringBuilder sb = new StringBuilder();
    sb.append(sqlMap.getTargetPackage());
    sb.append('.');
    String temp = sb.toString();
    sb.setLength(0);
    sb.append(temp.replace('.', '/'));
    sb.append(sqlMap.getFileName());
    sqlMapFiles.add(sb.toString());

    return true;
}
 
Example #8
Source File: XMLMergePlugin.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: MapperConfigPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    StringBuilder sb = new StringBuilder();
    sb.append(sqlMap.getTargetPackage());
    sb.append('.');
    String temp = sb.toString();
    sb.setLength(0);
    sb.append(temp.replace('.', '/'));
    sb.append(sqlMap.getFileName());
    mapperFiles.add(sb.toString());

    return true;
}
 
Example #10
Source File: IntrospectedTableIbatis2Java2Impl.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();

    Document document = sqlMapGenerator.getDocument();
    GeneratedXmlFile gxf = new GeneratedXmlFile(document,
            getIbatis2SqlMapFileName(), getIbatis2SqlMapPackage(), context
                    .getSqlMapGeneratorConfiguration().getTargetProject(),
            true, context.getXmlFormatter());
    if (context.getPlugins().sqlMapGenerated(gxf, this)) {
        answer.add(gxf);
    }

    return answer;
}
 
Example #11
Source File: MapperOverwriteEnablePlugin.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
  try {
    isMergeable.set(sqlMap, false);
  } catch (IllegalArgumentException | IllegalAccessException e) {
    e.printStackTrace();
  }
  return true;
}
 
Example #12
Source File: Context.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public void generateFiles(ProgressCallback callback, List<GeneratedJavaFile> generatedJavaFiles, List<GeneratedXmlFile> generatedXmlFiles, List<String> warnings) throws InterruptedException {

		pluginAggregator = new PluginAggregator();
		for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
			Plugin plugin = ObjectFactory.createPlugin(this, pluginConfiguration);
			if (plugin.validate(warnings)) {
				pluginAggregator.addPlugin(plugin);
			}
			else {
				warnings.add(getString("Warning.24", //$NON-NLS-1$
						pluginConfiguration.getConfigurationType(), id));
			}
		}

		if (introspectedTables != null) {
			for (IntrospectedTable introspectedTable : introspectedTables) {
				callback.checkCancel();

				introspectedTable.initialize();
				introspectedTable.calculateGenerators(warnings, callback);
				generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles());
				generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles());

				generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles(introspectedTable));
				generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles(introspectedTable));
			}
		}

		generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles());
		generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles());


		//每个表自定义包路径
		setJavaFilesCustomTargetPackage(generatedJavaFiles);
		setXmlFilesCustomTargetPackage(generatedJavaFiles);
	}
 
Example #13
Source File: PluginAggregator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
	List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
	for (Plugin plugin : plugins) {
		List<GeneratedXmlFile> temp = plugin.contextGenerateAdditionalXmlFiles();
		if (temp != null) {
			answer.addAll(temp);
		}
	}
	return answer;
}
 
Example #14
Source File: PluginAggregator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
	boolean rc = true;

	for (Plugin plugin : plugins) {
		if (!plugin.sqlMapGenerated(sqlMap, introspectedTable)) {
			rc = false;
			break;
		}
	}

	return rc;
}
 
Example #15
Source File: PluginAggregator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(IntrospectedTable introspectedTable) {
	List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
	for (Plugin plugin : plugins) {
		List<GeneratedXmlFile> temp = plugin.contextGenerateAdditionalXmlFiles(introspectedTable);
		if (temp != null) {
			answer.addAll(temp);
		}
	}
	return answer;
}
 
Example #16
Source File: SqlMapConfigPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    StringBuilder sb = new StringBuilder();
    sb.append(sqlMap.getTargetPackage());
    sb.append('.');
    String temp = sb.toString();
    sb.setLength(0);
    sb.append(temp.replace('.', '/'));
    sb.append(sqlMap.getFileName());
    sqlMapFiles.add(sb.toString());

    return true;
}
 
Example #17
Source File: MapperConfigPlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    StringBuilder sb = new StringBuilder();
    sb.append(sqlMap.getTargetPackage());
    sb.append('.');
    String temp = sb.toString();
    sb.setLength(0);
    sb.append(temp.replace('.', '/'));
    sb.append(sqlMap.getFileName());
    mapperFiles.add(sb.toString());

    return true;
}
 
Example #18
Source File: DAOPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * contextGenerateAdditionalXmlFiles:. <br/>
 *
 * @author Hongbin Yuan
 * @param introspectedTable
 * @return
 * @see PluginAdapter#contextGenerateAdditionalXmlFiles(IntrospectedTable)
 */
@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(
		IntrospectedTable introspectedTable) {
	// 设置文件类型,DAO 的xml文件, 原命名空间,用设置的值替换
	String  xmlMapperNamespace = introspectedTable.getMyBatis3SqlMapNamespace();
	String typeNameProp = this.getProperties().getProperty("typeName");
	if(typeNameProp == null || "".equals(typeNameProp.trim())){
		typeNameProp = typeName;
	}
	xmlMapperNamespace = xmlMapperNamespace.replaceAll("Mapper$",typeNameProp);
	
	// 创建mapper文件,
	Document document = new Document(
                XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
                XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
	// 创建根 root元素
	XmlElement root = new XmlElement("mapper"); //$NON-NLS-1$
       root.addAttribute(new Attribute("namespace", //$NON-NLS-1$
       		xmlMapperNamespace));
       
       context.getCommentGenerator().addRootComment(root);
       document.setRootElement(root);

       // 像root添加一个空元素
       root.addElement(new TextElement("\n"));
       
       String xmlMapperName = introspectedTable.getMyBatis3XmlMapperFileName();
       xmlMapperName = xmlMapperName.replaceAll("Mapper.xml$",typeNameProp+".xml");
	GeneratedXmlFile gxf = new GeneratedXmlFile(document,
			xmlMapperName, introspectedTable.getMyBatis3XmlMapperPackage(),
               context.getSqlMapGeneratorConfiguration().getTargetProject(),
               true, context.getXmlFormatter());
	List<GeneratedXmlFile>  gxfList = new ArrayList<GeneratedXmlFile>();
       
	gxfList.add(gxf);
       
	return gxfList;
}
 
Example #19
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedXmlFile> temp = plugin
                .contextGenerateAdditionalXmlFiles();
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example #20
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.sqlMapGenerated(sqlMap, introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example #21
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(
        IntrospectedTable introspectedTable) {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedXmlFile> temp = plugin
                .contextGenerateAdditionalXmlFiles(introspectedTable);
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example #22
Source File: PluginAggregator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(
        IntrospectedTable introspectedTable) {
    List<GeneratedXmlFile> answer = new ArrayList<>();
    for (Plugin plugin : plugins) {
        List<GeneratedXmlFile> temp = plugin.contextGenerateAdditionalXmlFiles(introspectedTable);
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example #23
Source File: OverIsMergeablePlugin.java    From bootshiro with MIT License 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
    try {
        Field field = sqlMap.getClass().getDeclaredField("isMergeable");
        field.setAccessible(true);
        field.setBoolean(sqlMap, false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
 
Example #24
Source File: MyShellCallback.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public String mergeXmlFile(GeneratedXmlFile gxf, File targetFile) throws ShellException {

    try {
        return getMergedSource(new InputSource(new StringReader(gxf.getFormattedContent())),
                new InputSource(new InputStreamReader(new FileInputStream(targetFile), StandardCharsets.UTF_8)),
                targetFile.getName());
    } catch (IOException | SAXException | ParserConfigurationException e) {
        throw new ShellException(getString("Warning.13",
                targetFile.getName()), e);
    }
}
 
Example #25
Source File: MapperConfigPlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    StringBuilder sb = new StringBuilder();
    sb.append(sqlMap.getTargetPackage());
    sb.append('.');
    String temp = sb.toString();
    sb.setLength(0);
    sb.append(temp.replace('.', '/'));
    sb.append(sqlMap.getFileName());
    mapperFiles.add(sb.toString());

    return true;
}
 
Example #26
Source File: Context.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public void generateFiles(ProgressCallback callback,
        List<GeneratedJavaFile> generatedJavaFiles,
        List<GeneratedXmlFile> generatedXmlFiles, List<String> warnings)
        throws InterruptedException {

    pluginAggregator = new PluginAggregator();
    for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
        Plugin plugin = ObjectFactory.createPlugin(this, pluginConfiguration);
        if (plugin.validate(warnings)) {
            pluginAggregator.addPlugin(plugin);
        } else {
            warnings.add(getString("Warning.24",
                    pluginConfiguration.getConfigurationType(), id));
        }
    }

    if (introspectedTables != null) {
        for (IntrospectedTable introspectedTable : introspectedTables) {
            callback.checkCancel();

            introspectedTable.initialize();
            introspectedTable.calculateGenerators(warnings, callback);
            generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles());
            generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles());

            generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles(introspectedTable));
            generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles(introspectedTable));
        }
    }

    generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles());
    generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles());
}
 
Example #27
Source File: XmlFileMergerJaxp.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public static String getMergedSource(GeneratedXmlFile generatedXmlFile,
        File existingFile) throws ShellException {

    try {
        return getMergedSource(new InputSource(new StringReader(generatedXmlFile.getFormattedContent())),
            new InputSource(new InputStreamReader(new FileInputStream(existingFile), StandardCharsets.UTF_8)),
            existingFile.getName());
    } catch (IOException | SAXException | ParserConfigurationException e) {
        throw new ShellException(getString("Warning.13",
                existingFile.getName()), e);
    }
}
 
Example #28
Source File: PluginAggregator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap,
        IntrospectedTable introspectedTable) {
    boolean rc = true;

    for (Plugin plugin : plugins) {
        if (!plugin.sqlMapGenerated(sqlMap, introspectedTable)) {
            rc = false;
            break;
        }
    }

    return rc;
}
 
Example #29
Source File: PluginAggregator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<>();
    for (Plugin plugin : plugins) {
        List<GeneratedXmlFile> temp = plugin.contextGenerateAdditionalXmlFiles();
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example #30
Source File: UnmergeableXmlMappersPlugin.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
    sqlMap.setMergeable(false);
    return true;
}