本文整理汇总了Java中org.mybatis.generator.api.dom.xml.Element类的典型用法代码示例。如果您正苦于以下问题:Java Element类的具体用法?Java Element怎么用?Java Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Element类属于org.mybatis.generator.api.dom.xml包,在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
}
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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");
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
};
}
示例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;
}
}
};
}