本文整理汇总了Java中org.apache.ibatis.scripting.xmltags.MixedSqlNode类的典型用法代码示例。如果您正苦于以下问题:Java MixedSqlNode类的具体用法?Java MixedSqlNode怎么用?Java MixedSqlNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MixedSqlNode类属于org.apache.ibatis.scripting.xmltags包,在下文中一共展示了MixedSqlNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: select
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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: getInsertFileds
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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, ")", ",");
}
示例3: buildUpdate
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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);
}
示例4: getUpdateColumns
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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));
}
示例5: buildSelect
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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);
}
示例6: shouldDemonstrateSimpleExpectedTextWithNoLoopsOrConditionals
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
@Test
public 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());
}
示例7: createDynamicSqlSource
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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);
}
示例8: shouldMapNullStringsToEmptyStrings
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
@Test
public void shouldMapNullStringsToEmptyStrings() {
final String expected = "id=${id}";
final MixedSqlNode sqlNode = mixedContents(new TextSqlNode(expected));
final DynamicSqlSource source = new DynamicSqlSource(new Configuration(), sqlNode);
String sql = source.getBoundSql(new Bean(null)).getSql();
Assert.assertEquals("id=", sql);
}
示例9: selectByIdList
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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);
}
示例10: batchDelete
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的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);
}
示例11: buildInsert
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
private void buildInsert(String statementId) {
//
Integer fetchSize = null;
Integer timeout = null;
Class<?> parameterType = entityClass;
///~~~~~~~~~~
boolean flushCache = true;
boolean useCache = false;
boolean resultOrdered = false;
KeyGenerator keyGenerator = null;
String keyProperty = null;
String keyColumn = null;
Id id = AnnotationUtils.findDeclaredAnnotation(Id.class, entityClass);
if(id != null) {
String keyStatementId = entityClass.getName() + ".insert" + SelectKeyGenerator.SELECT_KEY_SUFFIX;
if (configuration.hasKeyGenerator(keyStatementId)) {
keyGenerator = configuration.getKeyGenerator(keyStatementId);
} else {
keyGenerator = id.generatedKeys() ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
}
keyProperty = idField.getName();
keyColumn = StringUtils.isBlank(id.column()) ? CaseFormatUtils.camelToUnderScore(idField.getName()) : id.column();
}
List<SqlNode> contents = new ArrayList<SqlNode>();
contents.add(this.getInsertSql());
SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED,
SqlCommandType.INSERT, fetchSize, timeout, null, parameterType, null, null,
ResultSetType.FORWARD_ONLY, flushCache, useCache, resultOrdered, keyGenerator,
keyProperty, keyColumn, databaseId, lang);
}
示例12: getInsertSql
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
private SqlNode getInsertSql() {
List<SqlNode> contents = new ArrayList<SqlNode>();
contents.add(new TextSqlNode("INSERT INTO " + tableName + " "));
contents.add(getInsertColumns());
contents.add(getInsertFileds());
return new MixedSqlNode(contents);
}
示例13: getInsertColumns
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
private TrimSqlNode getInsertColumns(){
List<SqlNode> contents = new ArrayList<SqlNode>();
for(Field field : columnFields){
List<SqlNode> sqlNodes = new ArrayList<SqlNode>();
sqlNodes.add(new TextSqlNode(getColumnNameByField(field) + ","));
contents.add(new IfSqlNode(new MixedSqlNode(sqlNodes), getTestByField(field)));
}
return new TrimSqlNode(configuration, new MixedSqlNode(contents), "(", null, ")", ",");
}
示例14: getUpdateSql
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
private SqlNode getUpdateSql(){
List<SqlNode> contents = new ArrayList<SqlNode>();
contents.add(new TextSqlNode("UPDATE " + tableName + " "));
contents.add(getUpdateColumns());
contents.add(new TextSqlNode(" WHERE " + getIdColumnName() + " = #{" + getIdFieldName() + "}" + getVersionSQL()));
return new MixedSqlNode(contents);
}
示例15: mixedContents
import org.apache.ibatis.scripting.xmltags.MixedSqlNode; //导入依赖的package包/类
private MixedSqlNode mixedContents(SqlNode... contents) {
return new MixedSqlNode(Arrays.asList(contents));
}