use of com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator in project sql-boot by sql-boot.
the class FsResourceTypes method walk.
/**
* @param path
* @return
*/
private List<ResourceType> walk(final String path) {
File[] files = new File(path).listFiles();
if (files == null)
return null;
List<ResourceType> list = new ArrayList<>();
for (File f : files) {
if (f.isDirectory()) {
File sqlFile = new File(f, "README.md");
list.addAll(walk(f.getAbsolutePath()));
final ResourceType jdbcResourceType;
switch(f.getName()) {
case "schema":
jdbcResourceType = new SchemaJdbcResourceType(dataSource);
break;
case "table":
jdbcResourceType = new TableJdbcResourceType(dataSource);
break;
case "child":
jdbcResourceType = new ChildTableJdbcResourceType(dataSource);
break;
case "parent":
jdbcResourceType = new ParentTableJdbcResourceType(dataSource);
break;
case "pk":
jdbcResourceType = new PkJdbcResourceType(dataSource);
break;
case "index":
jdbcResourceType = new IndexJdbcResourceType(dataSource);
break;
case "fk":
jdbcResourceType = new FkJdbcResourceType(dataSource);
break;
case "view":
jdbcResourceType = new ViewJdbcResourceType(dataSource);
break;
case "column":
jdbcResourceType = new ColumnJdbcResourceType(dataSource);
break;
case "function":
jdbcResourceType = new FunctionJdbcResourceType(dataSource);
break;
case "procedure":
jdbcResourceType = new ProcedureJdbcResourceType(dataSource);
break;
default:
jdbcResourceType = null;
}
String sql = null;
try {
MarkdownFile markdownFile = new MarkdownFile(readFileToString(sqlFile, UTF_8));
Map<String, String> parse = markdownFile.parse();
Iterator<Map.Entry<String, String>> iterator = parse.entrySet().iterator();
if (iterator.hasNext()) {
sql = iterator.next().getValue();
}
} catch (IOException e) {
// TODO catch and process this exception
}
final ResourceType baseResourceType;
if (sqlFile.exists() && sql != null) {
baseResourceType = new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), singletonList(f.getName()));
} else if (jdbcResourceType != null) {
baseResourceType = jdbcResourceType;
} else {
baseResourceType = null;
}
final ResourceType resourceType = new SelectWrapper(// new SqlBodyWrapper(
new TemplateBodyWrapper(new PageWrapper(new LimitWrapper(// new WhereWrapper(
baseResourceType)), new GroovyTemplateGenerator("EMPTY BODY ...")));
if (baseResourceType != null) {
list.add(resourceType);
}
}
}
return list;
}
use of com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator in project sql-boot by sql-boot.
the class JdbcSqlQueryTest method medataData.
@Test
public void medataData() throws Exception {
SqlQuery sqlQuery = new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator("select name /* name */, email /* email */ from main_schema.users"));
final Map<String, String> metadata = sqlQuery.metaData();
System.out.println(metadata);
assertEquals("email", metadata.get("email"));
assertEquals("name", metadata.get("name"));
}
use of com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator in project sql-boot by sql-boot.
the class SqlResourceTypeTest method read2.
@Test
public void read2() {
final String sql = "select * from (select table_schema as \"@table_schema\", table_name as \"@table_name\", column_name as \"@column_name\"" + "from information_schema.columns)";
ResourceType type = new WhereWrapper(new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("column")));
assertEquals(8, type.read(new DbUri("column/main_schema.users")).count());
}
use of com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator in project sql-boot by sql-boot.
the class SqlResourceTypeTest method read.
@Test
public void read() throws Exception {
final String sql = "select * from (select table_schema as \"@table_schema\", table_name as \"@table_name\" " + "from information_schema.tables)";
final ResourceType type = new WhereWrapper(new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("table")));
assertEquals(3, type.read(new DbUri("table/m.column")).count());
}
use of com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator in project sql-boot by sql-boot.
the class SqlResourceTypeTest method path.
@Test
public void path() {
final String sql = "select _schema, _table, _column from (select table_schema as \"_schema\", table_name as \"_table\", column_name as \"_column\"" + "from information_schema.columns)";
final ResourceType type = new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("column"));
final List<String> path = type.path();
assertEquals("schema", path.get(0));
assertEquals("table", path.get(1));
assertEquals("column", path.get(2));
}
Aggregations