Java Code Examples for org.apache.ibatis.jdbc.SQL#toString()

The following examples show how to use org.apache.ibatis.jdbc.SQL#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 6 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String insertSelective(User record) {
    SQL sql = new SQL();
    sql.INSERT_INTO("user");
    
    if (record.getId() != null) {
        sql.VALUES("id", "#{id,jdbcType=INTEGER}");
    }
    
    if (record.getUsername() != null) {
        sql.VALUES("username", "#{username,jdbcType=VARCHAR}");
    }
    
    if (record.getPsw() != null) {
        sql.VALUES("psw", "#{psw,jdbcType=VARCHAR}");
    }
    
    return sql.toString();
}
 
Example 2
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 6 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String selectByExample(UserCriteria example) {
    SQL sql = new SQL();
    if (example != null && example.isDistinct()) {
        sql.SELECT_DISTINCT("id");
    } else {
        sql.SELECT("id");
    }
    sql.SELECT("username");
    sql.SELECT("psw");
    sql.FROM("user");
    applyWhere(sql, example, false);
    
    if (example != null && example.getOrderByClause() != null) {
        sql.ORDER_BY(example.getOrderByClause());
    }
    
    return sql.toString();
}
 
Example 3
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 6 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String updateByExampleSelective(Map<String, Object> parameter) {
    User record = (User) parameter.get("record");
    UserCriteria example = (UserCriteria) parameter.get("example");
    
    SQL sql = new SQL();
    sql.UPDATE("user");
    
    if (record.getId() != null) {
        sql.SET("id = #{record.id,jdbcType=INTEGER}");
    }
    
    if (record.getUsername() != null) {
        sql.SET("username = #{record.username,jdbcType=VARCHAR}");
    }
    
    if (record.getPsw() != null) {
        sql.SET("psw = #{record.psw,jdbcType=VARCHAR}");
    }
    
    applyWhere(sql, example, true);
    return sql.toString();
}
 
Example 4
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 6 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String updateByPrimaryKeySelective(User record) {
    SQL sql = new SQL();
    sql.UPDATE("user");
    
    if (record.getUsername() != null) {
        sql.SET("username = #{username,jdbcType=VARCHAR}");
    }
    
    if (record.getPsw() != null) {
        sql.SET("psw = #{psw,jdbcType=VARCHAR}");
    }
    
    sql.WHERE("id = #{id,jdbcType=INTEGER}");
    
    return sql.toString();
}
 
Example 5
Source File: CountByExampleProvider.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public String countByExample(Object example) throws Exception {
	EntityMapper entityMapper = EntityHelper.getEntityMapper(example.getClass());
	Set<ColumnMapper> columns = entityMapper.getColumnsMapper();
	SQL sql = new SQL().SELECT("COUNT(1)").FROM(entityMapper.getTableMapper().getName());
	Object value;
	StringBuilder whereBuilder = new StringBuilder();
	for (ColumnMapper column : columns) {
		value = EntityHelper.getEntityField(column.getProperty()).get(example);
		if(value == null)continue;
		appendWhere(whereBuilder,column,value);
	}
	if(whereBuilder.length() == 0)throw new IllegalArgumentException("至少包含一个查询条件");
	
	sql.WHERE(whereBuilder.toString());
	return sql.toString();
}
 
Example 6
Source File: SelectByExampleProvider.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public String selectByExample(Object example) throws Exception {
		EntityMapper entityMapper = EntityHelper.getEntityMapper(example.getClass());
		Set<ColumnMapper> columns = entityMapper.getColumnsMapper();
		SQL sql = new SQL().SELECT("*").FROM(entityMapper.getTableMapper().getName());
		Object value;
		StringBuilder whereBuilder = new StringBuilder();
		for (ColumnMapper column : columns) {
			value = EntityHelper.getEntityField(column.getProperty()).get(example);
			if(value == null)continue;
			appendWhere(whereBuilder,column,value);
		}
		if(whereBuilder.length() == 0)throw new IllegalArgumentException("至少包含一个查询条件");
		//
//		if(DbType.MYSQL.name().equalsIgnoreCase(MybatisConfigs.getDbType("default"))){
//			whereBuilder.append(" LIMIT 20000");
//		}
		sql.WHERE(whereBuilder.toString());
		return sql.toString();
	}
 
Example 7
Source File: DeleteByPrimaryKeyBuilder.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
@Override
String buildSQL(EntityMapper entityMapper, boolean selective) {
	// 从表注解里获取表名等信息
	TableMapper tableMapper = entityMapper.getTableMapper();
	ColumnMapper idColumn = entityMapper.getIdColumn();
	SQL sql = new SQL().DELETE_FROM(tableMapper.getName()).WHERE(idColumn.getColumn() + "=#{" + idColumn.getProperty() + "}");
	return sql.toString();
}
 
Example 8
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
public String query(Map<String, Object> dataMap) {
    List<Sort> sortList = (List<Sort>) dataMap.get("sortList");
    initFromThreadLocal();
    SQL sql = SELECT_FROM();
    sql = WHERE_CUSTOM(sql, dataMap);
    return sql.toString();
}
 
Example 9
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
public String find(Map<String, Object> dataMap) {
    T findParams = (T) dataMap.get("findParams");
    fixParamsValueToLike(findParams);
    initFromThreadLocal();

    SQL sql = SELECT_FROM();
    sql = WHERE(sql, findParams, OPERATOR_LIKE);
    return sql.toString();
}
 
Example 10
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
public String countFind(Map<String, Object> dataMap) {
    T findParams = (T) dataMap.get("findParams");
    fixParamsValueToLike(findParams);
    initFromThreadLocal();

    SQL sql = COUNT_FROM();
    sql = WHERE(sql, findParams, OPERATOR_LIKE);
    return sql.toString();
}
 
Example 11
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
public String get(Map<String, Object> dataMap) {
    T findParams = (T) dataMap.get("findParams");
    initFromThreadLocal();
    SQL sql = SELECT_FROM();
    sql = WHERE(sql, findParams, OPERATOR_EQUAL);
    return sql.toString();
}
 
Example 12
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
public String countGet(Map<String, Object> dataMap) {
    T findParams = (T) dataMap.get("findParams");
    initFromThreadLocal();
    SQL sql = COUNT_FROM();
    sql = WHERE(sql, findParams, OPERATOR_EQUAL);
    return sql.toString();
}
 
Example 13
Source File: BrowseNodeDAOQueryBuilder.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public String findChildrenQuery(
    @Param("path") final String path,
    @Param("maxNodes") final int maxNodes,
    @Param("contentSelectors") final List<String> contentSelectors,
    final ProviderContext providerContext)
{
  final String tableName = getFormatName(providerContext) + "_browse_node B";

  SQL sql = new SQL()
      .SELECT("B.*, L.parent_id IS NULL as leaf")
      .FROM(tableName)
      .LEFT_OUTER_JOIN("(SELECT DISTINCT parent_id FROM " + tableName + ") L ON B.browse_node_id = L.parent_id");

  if (path != null) {
    String innerTable = new SQL()
        .SELECT_DISTINCT("browse_node_id")
        .FROM(tableName)
        .WHERE("repository_id = #{repository.repositoryId}")
        .WHERE("path = #{path}")
        .toString();

    sql.WHERE("B.parent_id = (" + innerTable + ")");
  }
  else {
    sql.WHERE(" B.parent_id IS NULL")
       .WHERE(" B.repository_id = #{repository.repositoryId}");
  }

  if (contentSelectors != null && !contentSelectors.isEmpty()) {
    sql.AND();
    sql.WHERE(contentSelectors.stream().collect(joining(") or (", "(", ")")));
  }

  sql.LIMIT(maxNodes);

  return sql.toString();
}
 
Example 14
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 5 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String countByExample(UserCriteria example) {
    SQL sql = new SQL();
    sql.SELECT("count(*)").FROM("user");
    applyWhere(sql, example, false);
    return sql.toString();
}
 
Example 15
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 5 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String updateByExample(Map<String, Object> parameter) {
    SQL sql = new SQL();
    sql.UPDATE("user");
    
    sql.SET("id = #{record.id,jdbcType=INTEGER}");
    sql.SET("username = #{record.username,jdbcType=VARCHAR}");
    sql.SET("psw = #{record.psw,jdbcType=VARCHAR}");
    
    UserCriteria example = (UserCriteria) parameter.get("example");
    applyWhere(sql, example, true);
    return sql.toString();
}
 
Example 16
Source File: UserSqlProvider.java    From SpringbootMybatis with Apache License 2.0 5 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table user
 *
 * @mbg.generated
 */
public String deleteByExample(UserCriteria example) {
    SQL sql = new SQL();
    sql.DELETE_FROM("user");
    applyWhere(sql, example, false);
    return sql.toString();
}
 
Example 17
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 4 votes vote down vote up
public String getById() {
    initFromThreadLocal();
    SQL sql = SELECT_FROM().WHERE(parseIdColumn() + " = #{id}");
    return sql.toString();
}
 
Example 18
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 4 votes vote down vote up
public String getAll() {
    initFromThreadLocal();
    SQL sql = SELECT_FROM();
    return sql.toString();
}
 
Example 19
Source File: BaseSQLProvider.java    From QuickProject with Apache License 2.0 4 votes vote down vote up
public String countQuery(Map<String, Object> customQueryParams) {
    initFromThreadLocal();
    SQL sql = COUNT_FROM();
    sql = WHERE_CUSTOM(sql, customQueryParams);
    return sql.toString();
}