• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Element类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mybatis.generator.api.dom.xml.Element的典型用法代码示例。如果您正苦于以下问题:Java Element类的具体用法?Java Element怎么用?Java Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Element类属于org.mybatis.generator.api.dom.xml包,在下文中一共展示了Element类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generatedWithSelective

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * 有Selective代码生成
 * @param element
 */
private void generatedWithSelective(XmlElement element, IntrospectedTable introspectedTable, boolean hasPrefix) {
    if (incTools.support()) {
        // 查找 set->if->text
        List<XmlElement> sets = XmlElementGeneratorTools.findXmlElements(element, "set");
        if (sets.size() > 0) {
            List<XmlElement> ifs = XmlElementGeneratorTools.findXmlElements(sets.get(0), "if");
            if (ifs.size() > 0) {
                for (XmlElement xmlElement : ifs) {
                    // 下面为if的text节点
                    List<Element> textEles = xmlElement.getElements();
                    TextElement textEle = (TextElement) textEles.get(0);
                    String[] strs = textEle.getContent().split("=");
                    String columnName = strs[0].trim();
                    IntrospectedColumn introspectedColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, columnName);
                    // 查找是否需要进行增量操作
                    if (incTools.supportColumn(introspectedColumn)) {
                        xmlElement.getElements().clear();
                        xmlElement.getElements().addAll(incTools.generatedIncrementsElement(introspectedColumn, hasPrefix, true));
                    }
                }
            }
        }
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:29,代码来源:IncrementsPlugin.java


示例2: getSelectKey

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * This method should return an XmlElement for the select key used to
 * automatically generate keys.
 * @param introspectedColumn the column related to the select key statement
 * @param generatedKey       the generated key for the current table
 * @return the selectKey element
 */
public static Element getSelectKey(IntrospectedColumn introspectedColumn, GeneratedKey generatedKey) {
    String identityColumnType = introspectedColumn
            .getFullyQualifiedJavaType().getFullyQualifiedName();

    XmlElement answer = new XmlElement("selectKey");
    answer.addAttribute(new Attribute("resultType", identityColumnType));
    answer.addAttribute(new Attribute(
            "keyProperty", introspectedColumn.getJavaProperty()));
    answer.addAttribute(new Attribute("order",
            generatedKey.getMyBatis3Order()));

    answer.addElement(new TextElement(generatedKey
            .getRuntimeSqlStatement()));

    return answer;
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:24,代码来源:XmlElementGeneratorTools.java


示例3: adaptInsertSelective

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * 在单条插入动态sql中增加查询序列,以实现oracle主键自增
 *
 * @author 吴帅
 * @parameter @param element
 * @parameter @param introspectedTable
 * @createDate 2015年9月29日 下午12:00:37
 */
@Override
public void adaptInsertSelective(XmlElement element, IntrospectedTable introspectedTable) {
    TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
    Properties properties = tableConfiguration.getProperties();
    String incrementFieldName = properties.getProperty("incrementField");
    if (incrementFieldName != null) {// 有自增字段的配置
        List<Element> elements = element.getElements();
        XmlElement selectKey = new XmlElement("selectKey");
        selectKey.addAttribute(new Attribute("keyProperty", incrementFieldName));
        selectKey.addAttribute(new Attribute("resultType", "java.lang.Long"));
        selectKey.addAttribute(new Attribute("order", "BEFORE"));
        selectKey.addElement(new TextElement("select "));
        XmlElement includeSeq = new XmlElement("include");
        includeSeq.addAttribute(new Attribute("refid", "TABLE_SEQUENCE"));
        selectKey.addElement(includeSeq);
        selectKey.addElement(new TextElement(" from dual"));
        elements.add(0, selectKey);
    }
}
 
开发者ID:handosme,项目名称:mybatis-generator-plus,代码行数:28,代码来源:OracleSupport.java


示例4: removeIdColumns

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * Remove the id columns from the sql statement. Useful when the generated update statement is trying to update an
 * id column.
 * 
 * @param updates
 *            the update statements
 * @param element
 *            the element
 * @param parent
 *            the parent element
 * @param index
 *            the index of the element in the parent list
 */
void removeIdColumns(List<String> updates, Element element, XmlElement parent, int index) {
	log.debug("element type: {}", element.getClass().getSimpleName());
	log.debug("element: {}", element.getFormattedContent(0));

	if (element instanceof TextElement) {
		TextElement textElement = (TextElement) element;
		for (String update : updates) {
			if (textElement.getContent().contains(update)) {
				TextElement newElement = new TextElement(textElement.getContent().replace(update, ""));
				parent.getElements().set(index, newElement);
			}
		}
	} else if (element instanceof XmlElement) {
		XmlElement xmlElement = (XmlElement) element;
		for (int i = 0; i < xmlElement.getElements().size(); i++) {
			Element e = xmlElement.getElements().get(i);
			removeIdColumns(updates, e, xmlElement, i);
		}
	}
}
 
开发者ID:dcendents,项目名称:mybatis-generator-plugins,代码行数:34,代码来源:RenameExampleClassAndMethodsPlugin.java


示例5: shouldIgnoreTablesWithoutIdColumns

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
@Test
public void shouldIgnoreTablesWithoutIdColumns() throws Exception {
	RenameExampleClassAndMethodsPlugin plugin = spy(this.plugin);

	// Given
	willDoNothing().given(plugin).removeIdColumns(anyListOf(String.class), any(Element.class),
			any(XmlElement.class), anyInt());
	given(introspectedTable.getPrimaryKeyColumns()).willReturn(new ArrayList<IntrospectedColumn>());

	// When
	plugin.removeIdColumns(introspectedTable, element);

	// Then
	verify(plugin, times(0)).removeIdColumns(anyListOf(String.class), any(Element.class),
			any(XmlElement.class), anyInt());
}
 
开发者ID:dcendents,项目名称:mybatis-generator-plugins,代码行数:17,代码来源:RenameExampleClassAndMethodsPluginTest.java


示例6: shouldRemoveIdUpdatesFromTextElements

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
@Test
public void shouldRemoveIdUpdatesFromTextElements() throws Exception {
	String update = "alias.actual_name = #{record.someProperty,jdbcType=DOUBLE},";
	List<String> updates = new ArrayList<>();
	updates.add(update);
	
	List<Element> elements = new ArrayList<>();
	elements.add(textElement);
	
	String textContent = "some content with " + update + " and some more";
	
	// Given
	given(textElement.getContent()).willReturn(textContent);
	given(element.getElements()).willReturn(elements);
	
	// When
	plugin.removeIdColumns(updates, textElement, element, 0);

	// Then
	verify(element, times(1)).getElements();
	assertThat(elements).hasSize(1);

	TextElement newTextElement = (TextElement) elements.get(0);
	assertThat(newTextElement).isNotSameAs(textElement);
	assertThat(newTextElement.getContent()).isEqualTo("some content with  and some more");
}
 
开发者ID:dcendents,项目名称:mybatis-generator-plugins,代码行数:27,代码来源:RenameExampleClassAndMethodsPluginTest.java


示例7: shouldProcessAllChildrenOfAnXmlElement

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
@Test
public void shouldProcessAllChildrenOfAnXmlElement() throws Exception {
	RenameExampleClassAndMethodsPlugin plugin = spy(this.plugin);
	
	List<Element> elements = new ArrayList<>();
	elements.add(textElement);
	
	// Given
	willDoNothing().given(plugin).removeIdColumns(anyListOf(String.class), any(Element.class),
			eq(element), anyInt());
	given(element.getElements()).willReturn(elements);
	
	// When
	plugin.removeIdColumns(null, element, null, -1);

	// Then
	verify(plugin, times(1)).removeIdColumns(anyListOf(String.class), eq(textElement),
			eq(element), eq(0));
}
 
开发者ID:dcendents,项目名称:mybatis-generator-plugins,代码行数:20,代码来源:RenameExampleClassAndMethodsPluginTest.java


示例8: updateSourceMethods

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
private void updateSourceMethods(XmlElement mapper) {
	Iterator<Element> eleIterator = mapper.getElements().iterator();
	while (eleIterator.hasNext()) {
		XmlElement xmlEle = (XmlElement) eleIterator.next();
		Attribute idAttr = getEleAttr(xmlEle, "id");

		if (idAttr.getValue().equals("selectByPrimaryKey")) {
			Reflects.setField(idAttr, "value", "getById");
		}
		else if (idAttr.getValue().equals("deleteByPrimaryKey")) {
			Reflects.setField(idAttr, "value", "delById");
		}
		else if (idAttr.getValue().equals("insert")) {
			Reflects.setField(idAttr, "value", "save");
		}
		else if (idAttr.getValue().equals("insertSelective")) {
			eleIterator.remove();
		}
		else if (idAttr.getValue().equals("updateByPrimaryKey")) {
			Reflects.setField(idAttr, "value", "modify");
		}
		else if (idAttr.getValue().equals("updateByPrimaryKeySelective")) {
			Reflects.setField(idAttr, "value", "modifySelective");
		}
	}
}
 
开发者ID:haogrgr,项目名称:haogrgr-projects,代码行数:27,代码来源:MapperPlugin.java


示例9: getFormattedContent

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
@Override
public String getFormattedContent(Document document) {
	XmlElement mapper = document.getRootElement();

	//按自己的喜好排序
	Collections.sort(mapper.getElements(), new Comparator<Element>() {
		@Override
		public int compare(Element o1, Element o2) {
			String o1Id = getEleAttr(o1, "id").getValue();
			String o2Id = getEleAttr(o2, "id").getValue();
			return weightMap.get(o1Id).intValue() - weightMap.get(o2Id).intValue();
		}
	});

	//每个sql元素后插入空行
	int size = mapper.getElements().size();
	for (int i = 0, offset = 1, index = 1; i < size - 1; i++, offset++, index = i + offset) {
		mapper.addElement(index, new TextElement(""));
	}

	String xml = super.getFormattedContent(document);

	return xml;
}
 
开发者ID:haogrgr,项目名称:haogrgr-projects,代码行数:25,代码来源:SortedXmlFormatter.java


示例10: findMatchedElementIn

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * 从MBG生成的DOM文档结构中找到与element代表同一节点的元素对象
 *
 * @param document generate xml dom tree
 * @param element  The dom4j element
 * @return The xml element correspond to dom4j element
 */
protected XmlElement findMatchedElementIn(Document document, org.dom4j.Element element) {
  org.dom4j.Attribute id = element.attribute("id");
  String idName = id.getName();
  String idValue = id.getValue();
  for (Element me : document.getRootElement().getElements()) {
    if (me instanceof XmlElement) {
      XmlElement xe = (XmlElement) me;
      for (Attribute ab : xe.getAttributes()) {
        if (StringUtils.equals(idName, ab.getName()) && StringUtils.equals(idValue, ab.getValue())) {
          return xe;
        }
      }
    }
  }
  return null;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:24,代码来源:XMLMergePlugin.java


示例11: sqlMapExampleWhereClauseElementGenerated

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
public boolean sqlMapExampleWhereClauseElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
    traverse(element, new FindElements() {
        @Override
        public boolean process(XmlElement parent, Element self, int position) {
            XmlElement foreach = ancestor(0);
            XmlElement trim = ancestor(1);
            if (indexOf(trim, foreach) != indexOf(trim, "foreach")) return false;

            XmlElement choose = traverse(trim, new CopyXml());
            traverse(choose, new ReplaceText(new TextReplacer("criterion\\.", "citem\\."), new TextReplacer("criterion(?=\\.|$)", "citem")));
            traverse(choose, new ReplaceText(new TextReplacer("criteria\\.", "criterion\\.subCriteria\\.")));
            traverse(choose, new ReplaceText(new TextReplacer("^\\s*and(?=\\s|\\(|$)", "or"), null));

            addLater((XmlElement)self, 0,
                e("when", a("test", "criterion.complex"),
                    "and", e("trim", a("prefix", "("), a("suffix", ")"), a("prefixOverrides", "or"),
                        new DocumentFragment(choose)
                    )
                )
            );
            return true;
        }
    }.when(ELEMENT.and(ancestorsAndSelf("where", "foreach", "if", "trim", "foreach", "choose"))));
    return true;
}
 
开发者ID:vsl1978,项目名称:mybatis-generator-pluginsplus,代码行数:26,代码来源:SimpleOrCriteriaPlugin.java


示例12: modifyXml

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
@Override
public boolean modifyXml(XmlElement element, IntrospectedTable introspectedTable, boolean baseFields, boolean blobFields) {
    traverse(element, new FindElements() {
        private boolean first = true;

        @Override
        public boolean process(XmlElement parent, Element self, int position) {
            if (!(self instanceof TextElement)) return false;
            if (!first) return false;
            String s = ((TextElement) self).getFormattedContent(0).trim();
            if (SELECT.matcher(s).matches()) {
                first = false;
                addLater(parent, position + 1,
                    e("if", a("test", "orderByClause != null and limit != null"),
                        "FIRST ${limit}",
                        e("if", a("test", "offset != null"), "SKIP ${offset}")
                    )
                );
                return true;
            }
            return false;
        }
    }.when(TEXT_NODE.and(depth(2, 2)).and(skipComments()) ));
    return true;
}
 
开发者ID:vsl1978,项目名称:mybatis-generator-pluginsplus,代码行数:26,代码来源:PaginationPlugin.java


示例13: traverse0

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
private static void traverse0(XmlElement root, XmlTraverser<?> walker) {
    XmlElement parent = root;
    if (parent == null) return;
    walker.start(root);
    try {
        for (Element e : parent.getElements()) {
            if (e instanceof XmlElement) {
                traverse0((XmlElement) e, walker);
            } else if (e instanceof TextElement) {
                walker.text((TextElement)e);
            }
        }
    } finally {
        walker.finish(root);
    }
}
 
开发者ID:vsl1978,项目名称:mybatis-generator-pluginsplus,代码行数:17,代码来源:MBGenerator.java


示例14: ancestorsAndSelf

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
public static BiPredicate<Stack<XmlElement>, Element> ancestorsAndSelf(final String ... namesFromTopAncestorToSelf) {
    return new AbstractBiPredicate<Stack<XmlElement>, Element>() {
        @Override
        public boolean test(Stack<XmlElement> xmlElements, Element element) {
            int pos = namesFromTopAncestorToSelf.length - 1;
            if (!(element instanceof XmlElement)) return false;
            if (!Objects.equals(namesFromTopAncestorToSelf[pos], ((XmlElement)element).getName()))
                return false;
            ListIterator<XmlElement> it = xmlElements.listIterator(xmlElements.size());
            while (it.hasPrevious() && pos > 0) {
                XmlElement e = it.previous();
                pos--;
                if (!Objects.equals(namesFromTopAncestorToSelf[pos], e.getName())) return false;
            }
            return pos == 0;
        }
    };
}
 
开发者ID:vsl1978,项目名称:mybatis-generator-pluginsplus,代码行数:19,代码来源:MBGenerator.java


示例15: skipComments

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
public static BiPredicate<Stack<XmlElement>, Element> skipComments() {
    return new AbstractBiPredicate<Stack<XmlElement>, Element>() {
        private boolean comment;
        @Override
        public boolean test(Stack<XmlElement> xmlElements, Element element) {
            if (!(element instanceof TextElement)) return true;
            TextElement text = (TextElement)element;
            String s = text.getFormattedContent(0).trim();
            if (!comment) {
                comment = s.indexOf("<!--") >= 0;
                return !comment;
            } else {
                comment = s.indexOf("-->") < 0;
                return false;
            }
        }
    };
}
 
开发者ID:vsl1978,项目名称:mybatis-generator-pluginsplus,代码行数:19,代码来源:MBGenerator.java


示例16: changeConditions

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
private XmlElement changeConditions(XmlElement e) {
    boolean update = "update".equals(e.getName());
    traverse(e,
        new FindElements() {
            @Override
            public boolean process(XmlElement parent, Element self, int position) {
                XmlElement _if = (XmlElement)self;
                Pair<String, String> field = Str.groups(getAttribute(_if, "test"), "^(.+\\.)?([^\\.]+?)\\s*!=\\s*null$", 1, 2);
                if (field.b() == null) return false;
                setAttribute(_if, "test", Objects.nvl(field.a(), "_parameter.")+getterName+"()."+field.b());
                return true;
            }
        }.when(ELEMENT.and(ancestorsAndSelf(update ? "set" : "trim", "if")))
    );
    return e;
}
 
开发者ID:vsl1978,项目名称:mybatis-generator-pluginsplus,代码行数:17,代码来源:SelectiveWithNullPlugin.java


示例17: getElementById

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * getElementById: 在指定的xmlElement的一级子元素中查找id值为指定value的Element. <br/>
 *
 * @author Hongbin Yuan
 * @param xmlElement	指定的xmlElement元素  <br/>
 * @param value			查找id值为指定value的Element  <br/>
 * @return
 * @since JDK 1.6
 */
public XmlElement getElementById(XmlElement xmlElement,String value){
	if(xmlElement == null){
		return null;
	}
	if(value == null || "".equals(value.trim())){
		return xmlElement;
	}
	List<Element> elementList = xmlElement.getElements();
	if(elementList != null && elementList.size() > 0){
		for(Element e : elementList){
			if(e instanceof XmlElement){
				XmlElement eXML = (XmlElement)e;
				List<Attribute> eXMLAttrList = eXML.getAttributes();
				for(Attribute a : eXMLAttrList){
					if(a!=null && "id".equals(a.getName()) && value.equals(a.getValue())){
						return eXML;
					}
				}
			}
		}
	}
	return null;
}
 
开发者ID:yuanmomo,项目名称:maven-archetype,代码行数:33,代码来源:AliasPlugin.java


示例18: generatedWithoutSelective

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * 无Selective代码生成
 * @param xmlElement
 * @param introspectedTable
 * @param hasPrefix
 */
private void generatedWithoutSelective(XmlElement xmlElement, IntrospectedTable introspectedTable, boolean hasPrefix) {
    if (incTools.support()) {
        List<Element> newEles = new ArrayList<>();
        for (Element ele : xmlElement.getElements()) {
            // 找到text节点且格式为 set xx = xx 或者 xx = xx
            if (ele instanceof TextElement) {
                String text = ((TextElement) ele).getContent().trim();
                if (text.matches("(^set\\s)?\\S+\\s?=.*")) {
                    // 清理 set 操作
                    text = text.replaceFirst("^set\\s", "").trim();
                    String columnName = text.split("=")[0].trim();
                    IntrospectedColumn introspectedColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, columnName);
                    // 查找判断是否需要进行节点替换
                    if (incTools.supportColumn(introspectedColumn)) {
                        newEles.addAll(incTools.generatedIncrementsElement(introspectedColumn, hasPrefix, text.endsWith(",")));

                        continue;
                    }
                }
            }
            newEles.add(ele);
        }

        // 替换节点
        xmlElement.getElements().clear();
        xmlElement.getElements().addAll(newEles);
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:35,代码来源:IncrementsPlugin.java


示例19: addElementWithBestPosition

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
/**
 * 在最佳位置添加节点
 *
 * @param rootElement
 * @param element
 */
public static void addElementWithBestPosition(XmlElement rootElement, XmlElement element){
    String id = getIdFromElement(element);
    if (id == null){
        rootElement.addElement(element);
    } else {
        List<Element> elements = rootElement.getElements();
        int index = -1;
        for (int i = 0; i < elements.size(); i++){
            Element ele = elements.get(i);
            if (ele instanceof XmlElement){
                String eleId = getIdFromElement((XmlElement) ele);
                if (eleId != null){
                    if (eleId.startsWith(id)){
                        if (index == - 1){
                            index = i;
                        }
                    } else if (id.startsWith(eleId)){
                        index = i + 1;
                    }
                }
            }
        }

        if (index == -1 || index >= elements.size()){
            rootElement.addElement(element);
        } else {
            elements.add(index, element);
        }
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:37,代码来源:FormatTools.java


示例20: getExampleIncludeElement

import org.mybatis.generator.api.dom.xml.Element; //导入依赖的package包/类
public static Element getExampleIncludeElement(IntrospectedTable introspectedTable) {
    XmlElement ifElement = new XmlElement("if");
    ifElement.addAttribute(new Attribute("test", "_parameter != null"));

    XmlElement includeElement = new XmlElement("include");
    includeElement.addAttribute(new Attribute("refid",
            introspectedTable.getExampleWhereClauseId()));
    ifElement.addElement(includeElement);

    return ifElement;
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:12,代码来源:XmlElementGeneratorTools.java



注:本文中的org.mybatis.generator.api.dom.xml.Element类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SlideInBottomAnimationAdapter类代码示例发布时间:2022-05-22
下一篇:
Java DataCollector类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap