use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldDemonstrateSimpleExpectedTextWithNoLoopsOrConditionals.
@Test
void shouldDemonstrateSimpleExpectedTextWithNoLoopsOrConditionals() throws Exception {
final String expected = "SELECT * FROM BLOG";
final MixedSqlNode sqlNode = mixedContents(new TextSqlNode(expected));
DynamicSqlSource source = createDynamicSqlSource(sqlNode);
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldHandleOgnlExpression.
@Test
void shouldHandleOgnlExpression() throws Exception {
final HashMap<String, String> parameterObject = new HashMap<String, String>() {
{
put("name", "Steve");
}
};
final String expected = "Expression test: 3 / yes.";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("Expression test: ${name.indexOf('v')} / ${name in {'Bob', 'Steve'\\} ? 'yes' : 'no'}."));
BoundSql boundSql = source.getBoundSql(parameterObject);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldDemonstrateMultipartExpectedTextWithNoLoopsOrConditionals.
@Test
void shouldDemonstrateMultipartExpectedTextWithNoLoopsOrConditionals() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new TextSqlNode("WHERE ID = ?"));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREANDWithLFForFirstCondition.
@Test
void shouldTrimWHEREANDWithLFForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \n ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and\n ID = ? ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project qiuyj-code by qiuyuanjun.
the class ReturnValueWrapper method generateSqlSource.
/**
* 生成对应的SqlSource,这里仅仅会生成DynamicSqlSource和StaticSqlSource
*/
public SqlSource generateSqlSource(Configuration configuration) {
if (Objects.isNull(sqlNode)) {
throw new IllegalArgumentException("SqlNode can not be null");
} else {
SqlSource sqlSource;
if (generateStaticSqlSource) {
DynamicContext context = new DynamicContext(configuration, null);
sqlNode.apply(context);
sqlSource = new StaticSqlSource(configuration, context.getSql(), parameterMappings);
} else {
sqlSource = new DynamicSqlSource(configuration, sqlNode);
}
return new MapperSqlSource(sqlSource);
}
}
Aggregations