本文整理汇总了Java中org.mybatis.generator.api.dom.xml.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于org.mybatis.generator.api.dom.xml包,在下文中一共展示了Document类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toDocument
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
/**
* Builds an XML representation of this configuration. This can be used to
* persist a programmatically generated configuration.
*
* @return the XML representation of this configuration
*/
public Document toDocument() {
// note that this method will not reconstruct a properties
// element - that element is only used in XML parsing
Document document = new Document(
XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID,
XmlConstants.MYBATIS_GENERATOR_CONFIG_SYSTEM_ID);
XmlElement rootElement = new XmlElement("generatorConfiguration"); //$NON-NLS-1$
document.setRootElement(rootElement);
for (String classPathEntry : classPathEntries) {
XmlElement cpeElement = new XmlElement("classPathEntry"); //$NON-NLS-1$
cpeElement.addAttribute(new Attribute("location", classPathEntry)); //$NON-NLS-1$
rootElement.addElement(cpeElement);
}
for (Context context : contexts) {
rootElement.addElement(context.toXmlElement());
}
return document;
}
示例2: getGeneratedXmlFiles
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@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;
}
示例3: testThatFilesAreTheSameAfterMerge
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@Test
public void testThatFilesAreTheSameAfterMerge() throws Exception {
DefaultXmlFormatter xmlFormatter = new DefaultXmlFormatter();
Properties p = new Properties();
p.setProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE, "true");
CommentGenerator commentGenerator = new DefaultCommentGenerator();
commentGenerator.addConfigurationProperties(p);
Document document = new Document(XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
document.setRootElement(getSqlMapElement(commentGenerator));
GeneratedXmlFile generatedFile1 = new GeneratedXmlFile(document, "TestMapper.xml", "org.mybatis.test", "src",
true, xmlFormatter);
InputSource is1 = new InputSource(new StringReader(generatedFile1.getFormattedContent()));
GeneratedXmlFile generatedFile2 = new GeneratedXmlFile(document, "TestMapper.xml", "org.mybatis.test", "src",
true, xmlFormatter);
InputSource is2 = new InputSource(new StringReader(generatedFile2.getFormattedContent()));
String mergedSource = XmlFileMergerJaxp.getMergedSource(is1, is2, "TestMapper.xml");
assertEquals(generatedFile1.getFormattedContent(), mergedSource);
}
示例4: generateSqlBaseColumns
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
/**
* 生成包含全部列的 sql 元素
*/
private void generateSqlBaseColumns(Document document, IntrospectedTable introspectedTable) {
// 新建 sql 元素标签
XmlElement sqlElement = new XmlElement("sql");
// 新建 sql 元素属性
Attribute attr = new Attribute("id", id);
sqlElement.addAttribute(attr);
// 新建 sql 元素内容,填写注释
sqlElement.addElement(new TextElement(Constants.WARNING));
// 获取全部列名称
StringBuilder columnsBuilder = new StringBuilder();
List<IntrospectedColumn> columnList = introspectedTable.getAllColumns();
for (IntrospectedColumn column : columnList) {
columnsBuilder.append(MyBatis3FormattingUtilities.getSelectListPhrase(column)).append(", ");
}
// 删除最后一个逗号
String columns = columnsBuilder.substring(0, columnsBuilder.length() - 2);
// 新建 sql 元素内容,填写列名称
sqlElement.addElement(new TextElement(columns));
// 将 sql 元素放到根元素下
XmlElement rootElement = document.getRootElement();
rootElement.addElement(new TextElement(""));
rootElement.addElement(sqlElement);
rootElement.addElement(new TextElement(""));
}
示例5: getGeneratedXmlFiles
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@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;
}
示例6: contextGenerateAdditionalXmlFiles
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
Document document = new Document("-//mybatis.org//DTD Config 3.0//EN", "http://mybatis" +
".org/dtd/mybatis-3-config.dtd");
XmlElement root = new XmlElement("configuration");
document.setRootElement(root);
root.addElement(new TextElement("<!--"));
root.addElement(new TextElement(" This file is generated by MyBatis Generator."));
root.addElement(new TextElement("-->"));
XmlElement mappers = new XmlElement("mappers");
root.addElement(mappers);
Iterator var6 = this.mapperFiles.iterator();
while (var6.hasNext()) {
String mapperFile = (String) var6.next();
XmlElement mapper = new XmlElement("mapper");
mapper.addAttribute(new Attribute("resource", mapperFile));
mappers.addElement(mapper);
}
GeneratedXmlFile gxf = new GeneratedXmlFile(document, this.properties.getProperty("fileName", "MapperConfig" +
".xml"), this.properties.getProperty("targetPackage"), this.properties.getProperty("targetProject"),
false, this.context.getXmlFormatter());
List<GeneratedXmlFile> answer = new ArrayList(1);
answer.add(gxf);
return answer;
}
示例7: sqlMapDocumentGenerated
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
public boolean sqlMapDocumentGenerated(Document document,
IntrospectedTable introspectedTable) {
boolean rc = true;
for (Plugin plugin : plugins) {
if (!plugin.sqlMapDocumentGenerated(document, introspectedTable)) {
rc = false;
break;
}
}
return rc;
}
示例8: getGeneratedXmlFiles
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@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;
}
示例9: getDocument
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@Override
public Document getDocument() {
Document document = new Document(
XmlConstants.IBATIS2_SQL_MAP_PUBLIC_ID,
XmlConstants.IBATIS2_SQL_MAP_SYSTEM_ID);
document.setRootElement(getSqlMapElement());
if (!context.getPlugins().sqlMapDocumentGenerated(document,
introspectedTable)) {
document = null;
}
return document;
}
示例10: getDocument
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@Override
public Document getDocument() {
Document document = new Document(
XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
document.setRootElement(getSqlMapElement());
if (!context.getPlugins().sqlMapDocumentGenerated(document,
introspectedTable)) {
document = null;
}
return document;
}
示例11: sqlMapDocumentGenerated
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
/**
* We'll override this method and add any new elements generated by
* previous calls
*/
@Override
public boolean sqlMapDocumentGenerated(Document document,
IntrospectedTable introspectedTable) {
List<XmlElement> elements = elementsToAdd.get(introspectedTable.getFullyQualifiedTable());
if (elements != null) {
for (XmlElement element : elements) {
document.getRootElement().addElement(element);
}
}
return true;
}
示例12: sqlMapDocumentGenerated
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
@Override
public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
XmlElement element = new XmlElement("cache"); //$NON-NLS-1$
context.getCommentGenerator().addComment(element);
for (CacheProperty cacheProperty : CacheProperty.values()) {
addAttributeIfExists(element, introspectedTable, cacheProperty);
}
document.getRootElement().addElement(element);
return true;
}
示例13: addBatchUpdateXml
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
public void addBatchUpdateXml(Document document, IntrospectedTable introspectedTable) {
List<IntrospectedColumn> columns = introspectedTable.getAllColumns();
String keyColumn=introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName();
XmlElement insertBatchElement = new XmlElement("update");
insertBatchElement.addAttribute(new Attribute("id", "updateBatchByPrimaryKeySelective"));
insertBatchElement.addAttribute(new Attribute("parameterType", "java.util.List"));
XmlElement foreach=new XmlElement("foreach");
foreach.addAttribute(new Attribute("collection","list"));
foreach.addAttribute(new Attribute("item","item"));
foreach.addAttribute(new Attribute("index","index"));
foreach.addAttribute(new Attribute("separator",";"));
foreach.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
XmlElement trim1Element = new XmlElement("set");
for (IntrospectedColumn introspectedColumn : columns) {
String columnName = introspectedColumn.getActualColumnName();
if(!columnName.toUpperCase().equalsIgnoreCase(keyColumn)){//不是自增字段的才会出现在批量插入中
XmlElement ifxml=new XmlElement("if");
ifxml.addAttribute(new Attribute("test", "item."+introspectedColumn.getJavaProperty()+"!=null"));
ifxml.addElement(new TextElement(columnName+"=#{item."+introspectedColumn.getJavaProperty()+",jdbcType="+introspectedColumn.getJdbcTypeName() + "},"));
trim1Element.addElement(ifxml);
}
}
foreach.addElement(trim1Element);
foreach.addElement(new TextElement("where "));
int index=0;
for(IntrospectedColumn i:introspectedTable.getPrimaryKeyColumns()){
foreach.addElement(new TextElement((index>0?" AND ":"")+i.getActualColumnName()+" = #{item."+i.getJavaProperty()+",jdbcType="+i.getJdbcTypeName()+"}"));
}
insertBatchElement.addElement(foreach);
document.getRootElement().addElement(insertBatchElement);
}
示例14: testGenerateWithTemplate
import org.mybatis.generator.api.dom.xml.Document; //导入依赖的package包/类
/**
* 测试配置了模板参数转换
*/
@Test
public void testGenerateWithTemplate() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator.xml");
MyBatisGenerator myBatisGenerator = tool.generate();
// java中的注释
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
if (file.getFileName().equals("Tb.java")) {
TopLevelClass topLevelClass = (TopLevelClass) file.getCompilationUnit();
// addJavaFileComment
Assert.assertEquals(topLevelClass.getFileCommentLines().get(0), "TestAddJavaFileComment:Tb:" + new SimpleDateFormat("yyyy-MM").format(new Date()));
// addFieldComment 同时测试 if 判断和 mbg
Field id = topLevelClass.getFields().get(0);
Assert.assertEquals(id.getJavaDocLines().get(0), "注释1");
Assert.assertEquals(id.getJavaDocLines().get(1), MergeConstants.NEW_ELEMENT_TAG);
// addGeneralMethodComment
Method cons = topLevelClass.getMethods().get(0);
Assert.assertEquals(cons.getJavaDocLines().get(0), "addGeneralMethodComment:Tb:tb");
// addSetterComment
Method setter = topLevelClass.getMethods().get(5);
Assert.assertEquals(setter.getJavaDocLines().get(0), "addSetterComment:field1:field1");
}
}
// xml注释
ObjectUtil xml = new ObjectUtil(myBatisGenerator.getGeneratedXmlFiles().get(0));
Document doc = (Document) xml.get("document");
List<Element> els = ((XmlElement) (doc.getRootElement().getElements().get(0))).getElements();
String comment = ((TextElement) els.get(0)).getContent();
Assert.assertEquals(comment, "addComment:BaseResultMap");
}