Skip to content

[doc] add example of getting mybatis generated DOClass info #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/godel_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches: [ main ]
paths:
- godel-script/**
workflow_dispatch:

jobs:
mac-aarch64-build:
Expand Down Expand Up @@ -47,6 +48,9 @@ jobs:
run: |
git config --global user.name "$(git log -n 1 --pretty=format:%an)"
git config --global user.email "$(git log -n 1 --pretty=format:%ae)"
- name: Install Package
run: |
apt-get install sqlite3 libsqlite3-dev
- name: Build
run: |
cd godel-script
Expand Down
42 changes: 42 additions & 0 deletions example/java/GetMybatisDOClass.gdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// script
use coref::java::*
use coref::xml::*

fn default_xml_db() -> XmlDB { return XmlDB::load("coref_xml_src.db") }
fn default_java_db() -> JavaDB { return JavaDB::load("coref_java_src.db") }

schema DBElement extends XmlElement {}

impl DBElement {
// find XmlElement with name "resultMap"
pub fn __all__(db: XmlDB) -> *Self {
for (x in XmlElement(db)) {
if (x.getElementName() = "resultMap") {
yield DBElement { ..x }
}
}
}

// get attribute "type" from XmlElement "resultMap"
pub fn getType(self) -> string {
for (a in self.getAttribute()) {
if (a.getName() = "type") {
return a.getValue()
}
}
}
}

// if DBElement's type name equals to Java Class name, then collect this Class info
fn getDOClassFromResultMap() -> *Class {
for (c in Class(default_java_db()), e in DBElement(default_xml_db())) {
if (c.getQualifiedName() = e.getType()) {
yield c
}
}
}

// example query, just get the class name, you could do other queries
query do_class
from c in getDOClassFromResultMap()
select c.getQualifiedName() as do_class_name
Loading