本文整理汇总了Java中org.apache.ibatis.scripting.xmltags.WhereSqlNode类的典型用法代码示例。如果您正苦于以下问题:Java WhereSqlNode类的具体用法?Java WhereSqlNode怎么用?Java WhereSqlNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WhereSqlNode类属于org.apache.ibatis.scripting.xmltags包,在下文中一共展示了WhereSqlNode类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: select
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
/**
* 查询(dr = 0)
*
* @param ms
* @return SqlNode
*/
private SqlNode select(MappedStatement ms, Class<?> entityClass) {
List<SqlNode> sqlNodes = new LinkedList<SqlNode>();
//静态的sql部分:select column ... from table
sqlNodes.add(new StaticTextSqlNode("SELECT "
+ EntityHelper.getSelectColumns(entityClass)
+ " FROM "
+ tableName(entityClass)));
//将if添加到<where>
sqlNodes.add(new WhereSqlNode(ms.getConfiguration(), new StaticTextSqlNode(" dr = 0")));
String orderByClause = EntityHelper.getOrderByClause(entityClass);
if (orderByClause.length() > 0) {
sqlNodes.add(new StaticTextSqlNode("ORDER BY " + orderByClause));
}
return new MixedSqlNode(sqlNodes);
}
示例2: shouldTrimWHEREInsteadOfANDForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREInsteadOfANDForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "true"
),
new IfSqlNode(mixedContents(new TextSqlNode(" or NAME = ? ")), "false"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例3: shouldTrimWHEREANDWithLFForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public 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());
}
示例4: shouldTrimWHEREANDWithCRLFForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREANDWithCRLFForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \r\n ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and\r\n ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例5: shouldTrimWHEREANDWithTABForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREANDWithTABForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and\t ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例6: shouldTrimWHEREORWithLFForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREORWithLFForFirstCondition() 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(" or\n ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例7: shouldTrimWHEREORWithCRLFForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREORWithCRLFForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \r\n ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" or\r\n ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例8: shouldTrimWHEREORWithTABForFirstCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREORWithTABForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" or\t ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例9: shouldTrimWHEREInsteadOfORForSecondCondition
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREInsteadOfORForSecondCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE NAME = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "false"
),
new IfSqlNode(mixedContents(new TextSqlNode(" or NAME = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例10: shouldTrimWHEREInsteadOfANDForBothConditions
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimWHEREInsteadOfANDForBothConditions() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE ID = ? OR NAME = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "true"
),
new IfSqlNode(mixedContents(new TextSqlNode("OR NAME = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例11: shouldTrimNoWhereClause
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
@Test
public void shouldTrimNoWhereClause() throws Exception {
final String expected = "SELECT * FROM BLOG";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "false"
),
new IfSqlNode(mixedContents(new TextSqlNode("OR NAME = ? ")), "false"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例12: selectByIdList
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
public SqlNode selectByIdList(MappedStatement ms) {
Class<?> entityClass = getEntityClass(ms);
//修改返回值类型为实体类型
setResultType(ms, entityClass);
List<SqlNode> sqlNodes = new LinkedList<SqlNode>();
//静态的sql部分:select column ... from table
sqlNodes.add(new StaticTextSqlNode("SELECT "
+ EntityHelper.getSelectColumns(entityClass)
+ " FROM "
+ tableName(entityClass)));
List<SqlNode> whereNodes = new LinkedList<SqlNode>();
whereNodes.add(new StaticTextSqlNode(" dr = 0 "));
ForEachSqlNode forEachSqlNode = new ForEachSqlNode(ms.getConfiguration(),
new StaticTextSqlNode("#{item}"), "list", "index", "item", " and id in (", ")", ",");
whereNodes.add(forEachSqlNode);
sqlNodes.add(new WhereSqlNode(ms.getConfiguration(), new MixedSqlNode(whereNodes)));
String orderByClause = EntityHelper.getOrderByClause(entityClass);
if (orderByClause.length() > 0) {
sqlNodes.add(new StaticTextSqlNode("ORDER BY " + orderByClause));
}
return new MixedSqlNode(sqlNodes);
}
示例13: batchDelete
import org.apache.ibatis.scripting.xmltags.WhereSqlNode; //导入依赖的package包/类
public SqlNode batchDelete(MappedStatement ms) {
// 获取实体类型
Class<?> entityClass = getEntityClass(ms);
LOG.debug("要更新的实体类:"+entityClass.getName());
List<SqlNode> sqlNodes = new LinkedList<>();
// update table
sqlNodes.add(new StaticTextSqlNode("UPDATE " + tableName(entityClass)));
// 获取全部列
Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass);
EntityColumn drCol = null;
EntityColumn idCol = null;
for (EntityColumn entityColumn : columnList) {
if (DBConsts.FIELD_DR.equalsIgnoreCase(entityColumn.getColumn())) {
drCol = entityColumn;
}
if (entityColumn.isId()) {
idCol = entityColumn;
}
}
sqlNodes.add(new SetSqlNode(ms.getConfiguration(), new StaticTextSqlNode(drCol.getColumn() + " = 1 ")));
ForEachSqlNode forEachSqlNode = new ForEachSqlNode(ms.getConfiguration(),
new StaticTextSqlNode("#{item." + idCol.getProperty() + "}"), "list", "index", "item", " id in (", ")",
",");
sqlNodes.add(new WhereSqlNode(ms.getConfiguration(), forEachSqlNode));
return new MixedSqlNode(sqlNodes);
}