Java Code Examples for org.mybatis.generator.api.GeneratedXmlFile

The following examples show how to use org.mybatis.generator.api.GeneratedXmlFile. These examples are extracted from open source projects. 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
@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 2
@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
@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
@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 5
Source Project: dolphin   Source File: CommentsWavePlugin.java    License: 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 Project: mapper-generator-javafx   Source File: PluginAggregator.java    License: 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 7
Source Project: mapper-generator-javafx   Source File: PluginAggregator.java    License: 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 8
Source Project: mapper-generator-javafx   Source File: PluginAggregator.java    License: 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 9
Source Project: mapper-generator-javafx   Source File: XmlFileMergerJaxp.java    License: 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 10
Source Project: mapper-generator-javafx   Source File: Context.java    License: 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 11
@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 12
Source Project: mapper-generator-javafx   Source File: MyShellCallback.java    License: 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 13
Source Project: bootshiro   Source File: OverIsMergeablePlugin.java    License: 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 14
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 15
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 16
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 17
@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 18
@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 19
@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 20
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: 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 21
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: 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 22
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: 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 23
Source Project: mybatis-generator-plus   Source File: Context.java    License: 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 24
Source Project: mybatis-generator-plus   Source File: MapperConfigPlugin.java    License: 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 25
Source Project: mybatis-generator-plus   Source File: SqlMapConfigPlugin.java    License: 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 26
Source Project: dolphin   Source File: ContentMergePlugin.java    License: 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 27
Source Project: dolphin   Source File: XMLMergePlugin.java    License: 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 28
Source Project: dolphin   Source File: MapperOverwriteEnablePlugin.java    License: 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 29
/**
 * 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 30
Source Project: java-master   Source File: MybatisGeneratorPlugin.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
    // 重复生成xml文件时不合并已有文件
    sqlMap.setMergeable(false);
    return true;
}