Skip to content

Commit 4c68270

Browse files
committed
add example of get mybatis generated DOClass info
1 parent c4f905d commit 4c68270

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

example/java/GetMybatisDOClass.gdl

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// script
2+
use coref::java::*
3+
use coref::xml::*
4+
5+
fn default_xml_db() -> XmlDB { return XmlDB::load("coref_xml_src.db") }
6+
fn default_java_db() -> JavaDB { return JavaDB::load("coref_java_src.db") }
7+
8+
schema DBElement extends XmlElement {}
9+
10+
impl DBElement {
11+
// find XmlElement with name "resultMap"
12+
pub fn __all__(db: XmlDB) -> *Self {
13+
for (x in XmlElement(db)) {
14+
if (x.getElementName() = "resultMap") {
15+
yield DBElement { ..x }
16+
}
17+
}
18+
}
19+
20+
// get attribute "type" from XmlElement "resultMap"
21+
pub fn getType(self) -> string {
22+
for (a in self.getAttribute()) {
23+
if (a.getName() = "type") {
24+
return a.getValue()
25+
}
26+
}
27+
}
28+
}
29+
30+
// if DBElement's type name equals to Java Class name, then collect this Class info
31+
fn getDOClassFromResultMap() -> *Class {
32+
for (c in Class(default_java_db()), e in DBElement(default_xml_db())) {
33+
if (c.getQualifiedName() = e.getType()) {
34+
yield c
35+
}
36+
}
37+
}
38+
39+
// example query, just get the class name, you could do other queries
40+
query do_class
41+
from c in getDOClassFromResultMap()
42+
select c.getQualifiedName() as do_class_name

0 commit comments

Comments
 (0)