Java Code Examples for org.apache.ibatis.jdbc.SQL

The following examples show how to use org.apache.ibatis.jdbc.SQL. These examples are extracted from open source projects. 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 Project: efo   Source File: FileSqlProvider.java    License: MIT License 6 votes vote down vote up
private String getBaseSql(boolean isDownloaded) {
    return new SQL() {{
        SELECT("distinct f.id,f.user_id,u.username,u.avatar,f.name file_name,f.size,f.create_time,c.name " +
                "category_name,f"
                + ".description,f.tag,f.check_times,f.download_times,f.visit_url,f.is_uploadable,f.is_deletable,"
                + "f.is_updatable,f.is_downloadable,f.is_visible");
        if (isDownloaded) {
            SELECT("d.create_time download_time");
        }
        FROM("file f");
        JOIN("user u on u.id=f.user_id");
        JOIN("category c on c.id=f.category_id");
        if (isDownloaded) {
            JOIN("download d on d.file_id=f.id");
        } else {
            JOIN("auth a on a.file_id=f.id");
        }
    }}.toString();
}
 
Example 2
Source Project: efo   Source File: UserSqlProvider.java    License: MIT License 6 votes vote down vote up
public String getUserBy(@Param("permission") int permission, @Param("condition") String condition, @Param
        ("offset") int offset) {
    String sql = new SQL() {{
        SELECT("*");
        FROM("user");
        if (permission == DefaultValues.THREE_INT) {
            WHERE("permission<3");
        } else if (permission == DefaultValues.TWO_INT) {
            WHERE("permission<2");
        } else {
            WHERE("permission<0");
        }
        if (Checker.isNotEmpty(condition)) {
            WHERE("username like '%" + condition + "%' or email like '%" + condition + "%' or real_name like '" +
                    condition + "'");
        }
        ORDER_BY(EfoApplication.settings.getStringUseEval(ConfigConsts.USER_ORDER_BY_OF_SETTINGS));
    }}.toString();
    int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.USER_PAGE_SIZE_OF_SETTINGS);
    return sql + " limit " + (offset * size) + "," + size;
}
 
Example 3
Source Project: efo   Source File: AuthSqlProvider.java    License: MIT License 6 votes vote down vote up
public String getAuthBy(@Param("id") long id, @Param("userId") int userId, @Param("fileId") long fileId, @Param
        ("fileName") String fileName, @Param("offset") int offset) {
    String sql = new SQL() {{
        SELECT("a.id,a.user_id,a.file_id,u.username,f.name file_name,f.local_url,a.is_downloadable,a" + "" + "" +
                ".is_uploadable,a.is_deletable,a.is_updatable,a.is_visible,a.create_time");
        FROM("auth a");
        JOIN("user u on u.id=a.user_id");
        JOIN("file f on f.id=a.file_id");
        if (id > 0) {
            WHERE("a.id=#{id}");
        }
        if (userId > 0) {
            WHERE("u.id=#{userId}");
        }
        if (fileId > 0) {
            WHERE("f.id=#{fileId}");
        } else if (Checker.isNotEmpty(fileName)) {
            WHERE("f.local_url like '%" + fileName + "%'");
        }
        ORDER_BY("a." + EfoApplication.settings.getStringUseEval(ConfigConsts.AUTH_ORDER_BY_OF_SETTINGS));
    }}.toString();
    int size = EfoApplication.settings.getIntegerUseEval(ConfigConsts.AUTH_PAGE_SIZE_OF_SETTINGS);
    return sql + " limit " + (offset * size) + "," + size;
}
 
Example 4
Source Project: tutorial   Source File: InsertUpdateSqlProvider.java    License: MIT License 6 votes vote down vote up
/**
 * id如果传入了值,会被insert使用;如果id为null,不会被insert的columns列出
 */
public static String insert(Object obj) {
    Map<String, String> map;
    try {
        map = getFieldsMap(obj, true);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    return new SQL() {
        {
            INSERT_INTO(getTableName(obj));
            for (String col : map.keySet()) {
                VALUES(col, map.get(col));
            }
        }
    }.toString();
}
 
Example 5
Source Project: maintain   Source File: InvtDeliverySqlProvide.java    License: MIT License 6 votes vote down vote up
public String comparisonDeliveryByLogisticsNoSql(final String logisticsCode, final String logisticsNo, final String headGuid) {
	return new SQL() {{
		this.SELECT("cih.head_guid as invt_head_guid");
		this.SELECT("cdh.head_guid as delivery_head_guid");
		this.SELECT("cdh.cop_no");
		this.SELECT("cdh.voyage_no as delivery_voyage_no");
		this.SELECT("cih.voyage_no as invt_voyage_no");
		this.SELECT("cdh.bill_no as delivery_bill_no");
		this.SELECT("cih.bill_no as invt_bill_no");
		this.SELECT("cdh.traf_mode as delivery_traf_mode");
		this.SELECT("cih.traf_mode as invt_traf_mode");
		this.SELECT("cdh.traf_no as delivery_traf_no");
		this.SELECT("cih.traf_no as invt_traf_no");
		this.SELECT("cih.logistics_code");
		this.SELECT("cih.logistics_no");
		this.FROM("ceb2_invt_head cih");
		this.INNER_JOIN("ceb2_delivery_head cdh on cih.logistics_code = cih.logistics_code");
		this.INNER_JOIN("ceb2_delivery_list cdl on cih.logistics_no = cdl.logistics_no and cdh.head_guid = cdl.head_guid");
		this.WHERE("cih.head_guid = '" + headGuid + "'");
		this.WHERE("cih.logistics_code = '" + logisticsCode + "'");
		this.WHERE("cih.logistics_no = '" + logisticsNo + "'");
		this.ORDER_BY("cdh.head_guid");
	}}.toString();
}
 
Example 6
Source Project: SpringbootMybatis   Source File: UserSqlProvider.java    License: 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 7
Source Project: maintain   Source File: ImpPayHeadSqlProvide.java    License: MIT License 6 votes vote down vote up
public String getImpPayHeadListSql(final ImpPayHead impPayHead) {
	return new SQL() {{
		this.SELECT("guid");
		this.SELECT("app_time");
		this.SELECT("app_status");
		this.SELECT("pay_code");
		this.SELECT("pay_name");
		this.SELECT("pay_transaction_id");
		this.SELECT("pay_time");
		this.SELECT("uuid");
		this.FROM("imp_pay_head");
		
		OracleTool.where(this, "guid", impPayHead.getGuid());
		OracleTool.where(this, "pay_code", impPayHead.getPayCode());
		OracleTool.where(this, "pay_name", impPayHead.getPayName(), true);
		OracleTool.where(this, "pay_transaction_id", impPayHead.getPayTransactionId(), true);
		OracleTool.where(this, "uuid", impPayHead.getUuid());
		OracleTool.orderBy(this, impPayHead.getOrderBy());
		
	}}.toString();
}
 
Example 8
Source Project: maintain   Source File: InvtHeadSqlProvide.java    License: MIT License 6 votes vote down vote up
public String getDeclareTopTenSql(final InvtHead invtHead) {
	return new SQL() {{
		this.SELECT("ebc_name");
		this.SELECT("count(1) as count");
		
		if (!StringUtils.isEmpty(invtHead.getAppStatus())) {
			this.SELECT("round(count(1) / (select count(1) from ceb2_invt_head where app_status = '" +
					invtHead.getAppStatus() + "') * 100, 2) as percentage");
			this.SELECT("(select count(1) from ceb2_invt_head where app_status = '" +
					invtHead.getAppStatus() + "') as total");
		} else {
			this.SELECT("round(count(1) / (select count(1) from ceb2_invt_head) * 100, 2) as percentage");
			this.SELECT("(select count(1) from ceb2_invt_head) as total");
		}
		this.FROM("ceb2_invt_head");
		
		if (!StringUtils.isEmpty(invtHead.getAppStatus())) {
			this.WHERE("app_status = '" + invtHead.getAppStatus() + "'");
		}
		
		this.GROUP_BY("ebc_name");
		this.ORDER_BY("count(1) desc");
	}}.toString();
}
 
Example 9
Source Project: maintain   Source File: ImpInvtHeadSqlProvide.java    License: MIT License 6 votes vote down vote up
public String getInvtHeadListByCopNoSql(final String copNo) {
	return new SQL() {{
		this.SELECT("guid");
		this.SELECT("pre_no");
		this.SELECT("invt_no");
		this.SELECT("detailscode");
		this.SELECT("applycode");
		this.SELECT("audit_state");
		this.SELECT("bw_name");
		this.SELECT("apply_date");
		this.SELECT("payecode");
		this.SELECT("payename");
		this.FROM("imp_invt_head");
		
		if (!StringUtils.isEmpty(copNo)) {
			this.WHERE("cop_no = '" + copNo + "'");
		} else {
			this.WHERE("1 = 2");
		}
	}}.toString();
}
 
Example 10
Source Project: maintain   Source File: UserUserSqlProvide.java    License: MIT License 6 votes vote down vote up
public String getUsersSql(final UserUser user) {
	return new SQL() {{
		this.SELECT("user_id, login_name, user_name");
		this.FROM("user_user");
		this.WHERE("1 = 1");
		if (!StringUtils.isEmpty(user.getUserId())) {
			this.WHERE("user_id = '" + user.getUserId() + "'");
		}
		
		if (!StringUtils.isEmpty(user.getLoginName())) {
			this.WHERE("login_name like '%" + user.getLoginName() + "%'");
		}
		
		if (!StringUtils.isEmpty(user.getUserName())) {
			this.WHERE("user_name = '" + user.getUserName() + "'");
		}
		
		this.ORDER_BY("oper_time");
	}}.toString();
}
 
Example 11
Source Project: RCT   Source File: RDBAnalyzeProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String updateRdbAnalyze(@Param("rdbAnalyze") RDBAnalyze rdbAnalyze) {
    return new SQL(){{
        UPDATE(TABLE_NAME);
        SET("auto_analyze = #{rdbAnalyze.autoAnalyze}");
        SET("schedule = #{rdbAnalyze.schedule}");
        SET("dataPath = #{rdbAnalyze.dataPath}");
        SET("prefixes = #{rdbAnalyze.prefixes}");
        SET("is_report = #{rdbAnalyze.report}");
        SET("mailTo = #{rdbAnalyze.mailTo}");
        SET("analyzer = #{rdbAnalyze.analyzer}");
        WHERE("id = #{rdbAnalyze.id}");
    }}.toString();
}
 
Example 12
Source Project: mybatis-action   Source File: SysPrivilegeProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String selectById(final Long id) {
    return new SQL() {
        {
            SELECT("id,privilege_name,privilege_url");
            FROM("sys_privilege");
            WHERE("id = #{id}");
        }
    }.toString();
}
 
Example 13
Source Project: efo   Source File: CommonSqlProvider.java    License: MIT License 5 votes vote down vote up
public static String updateAuthById(String table) {
    return new SQL() {{
        UPDATE(table);
        SET("is_downloadable=#{isDownloadable}");
        SET("is_uploadable=#{isUploadable}");
        SET("is_deletable=#{isDeletable}");
        SET("is_updatable=#{isUpdatable}");
        SET("is_visible=#{isVisible}");
        WHERE("id=#{id}");
    }}.toString();
}
 
Example 14
Source Project: maintain   Source File: InvtHeadSqlProvide.java    License: MIT License 5 votes vote down vote up
public String getInvtHeadListByRepeatInvtNoSql() {
	return new SQL() {{
		this.SELECT("head_guid");
		this.FROM("ceb2_invt_head");
		this.WHERE("invt_no in (SELECT invt_no FROM ceb2_invt_head WHERE (invt_no is not null AND app_status = '800') GROUP BY invt_no HAVING (count(1) > 1))");
	}}.toString();
}
 
Example 15
Source Project: QuickProject   Source File: BaseSQLProvider.java    License: 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 16
Source Project: QuickProject   Source File: BaseSQLProvider.java    License: 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 17
Source Project: QuickProject   Source File: BaseSQLProvider.java    License: Apache License 2.0 5 votes vote down vote up
private SQL WHERE(SQL sql, T findParams, String operator) {
    if (findParams == null) {
        return sql;
    }

    Map<String, Property> properties = ModelUtils.getProperties(findParams, ColumnTarget.WHERE);

    for (Property property : properties.values()) {
        if (operator.equalsIgnoreCase(OPERATOR_LIKE)) {
        }
        sql.WHERE(property.getColumnName() + operator + "#{findParams." + property.getName() + "}");
    }
    return sql;
}
 
Example 18
Source Project: cola-cloud   Source File: SysOrganizationBuilder.java    License: MIT License 5 votes vote down vote up
/**
 * 构建组织机构详情SQL语句
 *
 * @param params
 * @return
 */
public String buildGetOrganizationSql(Map<String, Object> params) {
    return new SQL() {{
        SELECT("ado.id,ado.name,ado.description,ado.code,ado.parent,ado.deleted,ado.status");
        SELECT("adop.code as pcode,adop.name as pname");
        FROM("cola_sys_organization ado");
        LEFT_OUTER_JOIN("cola_sys_organization adop on adop.id = ado.parent");
        WHERE("ado.id = " + params.get("id"));
    }}.toString();
}
 
Example 19
Source Project: cola-cloud   Source File: SysTenantSqlBuilder.java    License: MIT License 5 votes vote down vote up
public String buildTenantListSql(Map<String,Object> params){
   return new SQL(){{
       SELECT("t.id,t.`name`,t.code,t.description,t.status,su.username as administrator");
       FROM("cola_sys_tenant t");
       LEFT_OUTER_JOIN("cola_sys_user su on su.id = t.administrator");
       if (Objects.nonNull(params.get("name"))) {
           WHERE("t.name like #{name}");
       }
       if (Objects.nonNull(params.get("code"))) {
           WHERE("t.code  like #{code}");
       }
   }}.toString();
}
 
Example 20
Source Project: maintain   Source File: OrderListSqlProvide.java    License: MIT License 5 votes vote down vote up
public String getOrderListBySearchTextSql(final String headGuid, final String searchText) {
	return new SQL() {{
		this.SELECT("head_guid");
		this.SELECT("g_num");
		this.SELECT("item_no");
		this.SELECT("item_name");
		this.SELECT("item_describe");
		this.SELECT("bar_code");
		this.SELECT("unit");
		this.SELECT("qty");
		this.SELECT("price");
		this.SELECT("total_price");
		this.SELECT("currency");
		this.SELECT("country");
		this.SELECT("note");
		this.SELECT("sys_date");
		
		this.FROM("ceb2_ord_list");
		
		if (!StringUtils.isEmpty(headGuid)) {
			OracleTool.where(this, "head_guid", headGuid);
		} else {
			this.WHERE("1 = 2");
		}
		
		if (!StringUtils.isEmpty(searchText)) {
			String orSql = "(unit like '%" + searchText + "%'";
			orSql += " OR lower(item_name) like '%' || lower('" + searchText + "') || '%'";
			orSql += " OR lower(item_no) like '%' || lower('" + searchText + "') || '%'";
			orSql += " OR qty like '%" + searchText + "%'";
			orSql += " OR price like '%" + searchText + "%'";
			orSql += " OR total_price like '%" + searchText + "%'";
			orSql += " OR country like '%" + searchText + "%'";
			orSql += " OR currency like '%" + searchText + "%')";
			this.WHERE(orSql);
		}
		
	}}.toString();
}
 
Example 21
Source Project: maintain   Source File: CurrSqlProvide.java    License: MIT License 5 votes vote down vote up
public String getCurrByCodeSql(final String code) {
	return new SQL() {{
		this.SELECT("curr_code");
		this.SELECT("curr_name");
		this.FROM("curr");
		
		if (!StringUtils.isEmpty(code)) {
			this.WHERE("curr_code = '" + code + "'");
		} else {
			this.WHERE("1 = 2");
		}
	}}.toString();
}
 
Example 22
Source Project: redis-manager   Source File: RDBAnalyzeProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String updateRdbAnalyze(@Param("rdbAnalyze") RDBAnalyze rdbAnalyze) {
    return new SQL(){{
        UPDATE(TABLE_NAME);
        SET("auto_analyze = #{rdbAnalyze.autoAnalyze}");
        SET("schedule = #{rdbAnalyze.schedule}");
        SET("dataPath = #{rdbAnalyze.dataPath}");
        SET("prefixes = #{rdbAnalyze.prefixes}");
        SET("is_report = #{rdbAnalyze.report}");
        SET("mailTo = #{rdbAnalyze.mailTo}");
        SET("analyzer = #{rdbAnalyze.analyzer}");
        WHERE("id = #{rdbAnalyze.id}");
    }}.toString();
}
 
Example 23
Source Project: Okra   Source File: BusInfoSqlProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String selectSql(final long uid) {
    return new SQL() {{
        SELECT("*");
        FROM(TABLE_NAME);
        WHERE("uid=#{uid}");
    }}.toString();
}
 
Example 24
Source Project: mybatis-jpa   Source File: InsertSqlTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String parseSQL(final Class<?> type) {
  return new SQL() {
    {
      INSERT_INTO(PersistentUtil.getTableName(type));
      for (Field field : PersistentUtil.getPersistentFields(type)) {
        if (PersistentUtil.insertable(field)) {
          VALUES(PersistentUtil.getColumnName(field),
              ColumnMetaResolver.resolveSqlPlaceholder(field));
        }
      }
    }
  }.toString();
}
 
Example 25
Source Project: Okra   Source File: BusProgressSqlProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String insertSql() {
    return new SQL() {{
        INSERT_INTO(TABLE_NAME);
        VALUES("uid", "#{uid}");
        VALUES("busId", "#{busId}");
        VALUES("targetKey", "#{targetKey}");
        VALUES("targetValue", "#{targetValue}");
    }}.toString();
}
 
Example 26
Source Project: SpringbootMybatis   Source File: UserSqlProvider.java    License: 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 27
Source Project: maintain   Source File: InvtHeadSqlProvide.java    License: MIT License 5 votes vote down vote up
public String getInvtHeadMonthCountSql() {
	return new SQL() {{
		this.SELECT("to_char(sys_date, 'yyyy-mm') as ebc_name");
		this.SELECT("count(1) as count");
		this.FROM("ceb2_invt_head");
		this.GROUP_BY("to_char(sys_date, 'yyyy-mm')");
		this.ORDER_BY("to_char(sys_date, 'yyyy-mm')");
	}}.toString();
}
 
Example 28
Source Project: Okra   Source File: BusListenerSqlProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String selectByEventSql() {
    return new SQL() {{
        SELECT("*");
        FROM(TABLE_NAME);
        WHERE("uid=#{uid} AND event=#{event}");
    }}.toString();
}
 
Example 29
Source Project: maintain   Source File: InvtHeadSqlProvide.java    License: MIT License 5 votes vote down vote up
public String getInvtHeadByHeadGuidSql(final String headGuid) {
	final InvtHeadSqlProvide self = this;
	return new SQL() {{
		for(String field : self.selectField()) {
			this.SELECT(field);
		}
		this.SELECT("app_type");
		this.SELECT("port_code");
		this.SELECT("ebp_code");
		this.SELECT("ebp_name");
		this.SELECT("ie_date");
		this.SELECT("loct_no");
		this.SELECT("ems_no");
		this.SELECT("buyer_name");
		this.SELECT("country");
		this.SELECT("traf_no");
		this.SELECT("wrap_type");
		this.SELECT("pack_no");
		this.SELECT("buyer_id_type");
		this.SELECT("consignee_address");
		this.SELECT("voyage_no");
		this.SELECT("assure_code");
		this.SELECT("gross_weight");
		this.SELECT("buyer_id_number");
		this.SELECT("license_no");
		this.SELECT("bill_no");
		this.SELECT("insured_fee");
		this.SELECT("net_weight");
		this.SELECT("buyer_telephone");
		this.SELECT("traf_mode");
		this.SELECT("freight");
		this.SELECT("currency");
		this.SELECT("note");
		this.FROM("ceb2_invt_head");
		this.WHERE("head_guid = '" + headGuid + "'");
		
	}}.toString();
}
 
Example 30
Source Project: jeesuite-libs   Source File: SelectByPrimaryKeyBuilder.java    License: 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();
	
	return new SQL()
	   .SELECT("*")
	   .FROM(tableMapper.getName())
	   .WHERE(idColumn.getColumn() + "=#{" + idColumn.getProperty() + "}")
	   .toString();
}