本文整理汇总了Java中org.apache.ibatis.scripting.xmltags.SqlNode类的典型用法代码示例。如果您正苦于以下问题:Java SqlNode类的具体用法?Java SqlNode怎么用?Java SqlNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlNode类属于org.apache.ibatis.scripting.xmltags包,在下文中一共展示了SqlNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: selectUnionAll
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
public SqlNode selectUnionAll(Configuration configuration, String conditions, String orderBy, LockMode lockMode) {
String sql = select(conditions, orderBy).toString();
StringBuffer sqlSb = new StringBuffer();
Matcher matcher = ARGUMENT_REGEX.matcher(sql);
while (matcher.find()) {
String name = matcher.group(1);
matcher.appendReplacement(sqlSb, "#{item." + name + "}");
}
matcher.appendTail(sqlSb);
if (lockMode == LockMode.UPGRADE) {
sqlSb.append(" FOR UPDATE");
} else if (lockMode == LockMode.UPGRADE_NOWAIT) {
sqlSb.append(" FOR UPDATE NOWAIT");
}
SqlNode contents = new TextSqlNode(sqlSb.toString());
String collectionExpression = "list";
String index = "index";
String item = "item";
String open = "";
String close = "";
String separator = " UNION ALL ";
return new ForEachSqlNode(configuration, contents, collectionExpression, index, item, open, close, separator);
}
示例2: select
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的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);
}
示例3: getInsertFileds
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
private SqlNode getInsertFileds() {
List<SqlNode> contents = new ArrayList<SqlNode>();
for(Field field : columnFields){
List<SqlNode> sqlNodes = new ArrayList<SqlNode>();
if(Date.class.isAssignableFrom(field.getType())
&& field.getAnnotation(Column.class) != null
&& field.getAnnotation(Column.class).sysdate() == true){
sqlNodes.add(new TextSqlNode("now(),"));
} else {
sqlNodes.add(new TextSqlNode("#{" + field.getName() + "},"));
}
contents.add(new IfSqlNode(new MixedSqlNode(sqlNodes), getTestByField(field)));
}
return new TrimSqlNode(configuration, new MixedSqlNode(contents), " VALUES (", null, ")", ",");
}
示例4: buildDelete
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
private void buildDelete(String statementId){
Integer timeout = null;
Class<?> parameterType = entityClass;
//~~~~~~~~~~~~~~~~~~~~~~~
boolean flushCache = true;
boolean useCache = false;
boolean resultOrdered = false;
KeyGenerator keyGenerator = new NoKeyGenerator();
SqlNode sqlNode = new TextSqlNode("DELETE FROM " + tableName + " WHERE " + getIdColumnName() + " = #{" + getIdFieldName() + "} " + getVersionSQL());
SqlSource sqlSource = new DynamicSqlSource(configuration, sqlNode);
assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED,
SqlCommandType.DELETE, null, timeout, null, parameterType, null, null, null,
flushCache, useCache, resultOrdered, keyGenerator, null, null, databaseId, lang);
}
示例5: buildUpdate
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
private void buildUpdate(String statementId){
Integer timeout = null;
Class<?> parameterType = entityClass;
//~~~~~~~~~~~~~
boolean flushCache = true;
boolean useCache = false;
boolean resultOrdered = false;
KeyGenerator keyGenerator = new NoKeyGenerator();
List<SqlNode> contents = new ArrayList<SqlNode>();
contents.add(this.getUpdateSql());
SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED,
SqlCommandType.UPDATE, null, timeout, null, parameterType, null, null, null,
flushCache, useCache, resultOrdered, keyGenerator, null, null, databaseId, lang);
}
示例6: getUpdateColumns
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
private SqlNode getUpdateColumns(){
List<SqlNode> contents = new ArrayList<SqlNode>();
for(Field field : columnFields){
List<SqlNode> sqlNodes = new ArrayList<SqlNode>();
if(Date.class.isAssignableFrom(field.getType())
&& field.getAnnotation(Column.class) != null
&& field.getAnnotation(Column.class).sysdate() == true){
sqlNodes.add(new TextSqlNode(getColumnNameByField(field) + " = now(),"));
} else {
sqlNodes.add(new TextSqlNode(getColumnNameByField(field) + " = #{" + field.getName() + "},"));
}
contents.add(new IfSqlNode(new MixedSqlNode(sqlNodes), getTestByField(field)));
}
return new SetSqlNode(configuration, new MixedSqlNode(contents));
}
示例7: buildSelect
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
private void buildSelect(String statementId){
Integer fetchSize = null;
Integer timeout = entity.timeout() == -1 ? null : entity.timeout();
Class<?> resultType = entityClass;
//~~~~~~~~~~~~~~~~~
boolean flushCache = entity.flushCache();
boolean useCache = entity.useCache();
boolean resultOrdered = false;
KeyGenerator keyGenerator = new NoKeyGenerator();
List<SqlNode> contents = new ArrayList<SqlNode>();
contents.add(this.getGetSql());
SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED,
SqlCommandType.SELECT, fetchSize, timeout, null, null, null, resultType, null,
flushCache, useCache, resultOrdered, keyGenerator, null, null, databaseId, lang);
}
示例8: selectUnionAll
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
public String selectUnionAll(Class<?> entityType, String condition, String orderBy, LockMode lockMode) {
String statementId = this.buildStatementId(entityType, "[email protected]" + condition + "|" + orderBy);
if (configuration.hasStatement(statementId)) {
return statementId;
}
ResultMap resultMap = resultMapBuilder.getDefault(entityType);
SqlNode rootSqlNode = new SqlBuilder(entityType).selectUnionAll(configuration, condition, orderBy, lockMode);
DynamicSqlSource sqlSource = new DynamicSqlSource(configuration, rootSqlNode);
MappedStatement statement = new MappedStatement.Builder(configuration, statementId, sqlSource,
SqlCommandType.SELECT).resultMaps(Arrays.asList(resultMap)).build();
StatementResultMapHelper.addMappedStatement(configuration, statement);
return statementId;
}
示例9: shouldConditionallyDefault
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
@Test
public void shouldConditionallyDefault() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = 'DEFAULT'";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new ChooseSqlNode(new ArrayList<SqlNode>() {{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "false"
));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "false"
));
}}, mixedContents(new TextSqlNode("WHERE CATEGORY = 'DEFAULT'"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例10: shouldConditionallyChooseFirst
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
@Test
public void shouldConditionallyChooseFirst() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new ChooseSqlNode(new ArrayList<SqlNode>() {{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "true"
));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "false"
));
}}, mixedContents(new TextSqlNode("WHERE CATEGORY = 'DEFAULT'"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例11: shouldConditionallyChooseSecond
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
@Test
public void shouldConditionallyChooseSecond() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = 'NONE'";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new ChooseSqlNode(new ArrayList<SqlNode>() {{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "false"
));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "true"
));
}}, mixedContents(new TextSqlNode("WHERE CATEGORY = 'DEFAULT'"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
示例12: createDynamicSqlSource
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
private DynamicSqlSource createDynamicSqlSource(SqlNode... contents) throws IOException, SQLException {
createBlogDataSource();
final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
final Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
Configuration configuration = sqlMapper.getConfiguration();
MixedSqlNode sqlNode = mixedContents(contents);
return new DynamicSqlSource(configuration, sqlNode);
}
示例13: selectPage
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的package包/类
public SqlNode selectPage(MappedStatement ms) {
Class<?> entityClass = getEntityClass(ms);
//修改返回值类型为实体类型
setResultType(ms, entityClass);
return select(ms, entityClass);
}
示例14: selectByIdList
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的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);
}
示例15: batchDelete
import org.apache.ibatis.scripting.xmltags.SqlNode; //导入依赖的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);
}