<commit_before>package com.founder.fix.fixflow.expand.database.pagination;

import com.founder.fix.apputil.util.StringUtil;
import com.founder.fix.fixflow.core.db.pagination.Pagination;

public class DB2PaginationImpl implements Pagination{
	protected static final String SQL_END_DELIMITER = ";";

	public String getPaginationSql(String sql, int firstResult, int maxResults, String fields) {
		sql = trim(sql);
    	String inFiled = fields;
    	if(StringUtil.isNotEmpty(fields)){
    		fields="*";
    		inFiled="A.*";
    	}
        StringBuffer sb = new StringBuffer(sql.length() + 20);
        sb.append("(");
        sb.append("SELECT "+fields+" FROM (SELECT "+inFiled+", rownumber() over() as RN_ FROM (");
        sb.append(sql);
        sb.append(" )A");
        sb.append(" )b WHERE b.RN_ <=");
        sb.append(maxResults);
        sb.append(" and b.RN_ >=");
        if (firstResult >= 0) {
            sb.append(firstResult);
         } 
        sb.append(")");
        
        return sb.toString();
	}

	public String getIsNullLocalismSql(String sql) {
		return "COALESCE("+sql+")";
	}

	public String getDateSql() {
		return "current date";
	}

	public String getCurrentDateSql() {
		return "current timestamp";
	}

	public String getCastConvertSql(String sql, String type) {
		return "cast("+sql+" as "+ type +")";
	}

	public String getLocalismSql(String localismKey, String localismValue) {

		if(localismKey.equals("processperformance")){
			return "COALESCE(end_time-start_time)";
		}
		
		if(localismKey.equals("datediffconvert")) {
			return "avg(end_time-create_time)";
		}
		
		if(localismKey.equals("datediffconvertorg")) {
			return "avg(x.end_time-x.create_time)";
		}
		
		return null;
	}

	private String trim(String sql) {
        sql = sql.trim();
        if (sql.endsWith(SQL_END_DELIMITER)) {
            sql = sql.substring(0, sql.length() - 1
                    - SQL_END_DELIMITER.length());
        }<commit_msg>修正DB2分页实现类<commit_after>package com.founder.fix.fixflow.expand.database.pagination;

import com.founder.fix.apputil.util.StringUtil;
import com.founder.fix.fixflow.core.db.pagination.Pagination;

public class DB2PaginationImpl implements Pagination{
	protected static final String SQL_END_DELIMITER = ";";

	public String getPaginationSql(String sql, int firstResult, int maxResults, String fields) {
		sql = trim(sql);
    	String inFiled = fields;
    	if(StringUtil.isNotEmpty(fields)){
    		fields="*";
    		inFiled="A.*";
    	}
        StringBuffer sb = new StringBuffer(sql.length() + 20);
        sb.append("(");
        sb.append("SELECT "+fields+" FROM (SELECT "+inFiled+", rownumber() over() as RN_ FROM (");
        sb.append(sql);
        sb.append(" )A");
        sb.append(" )b WHERE b.RN_ <=");
        sb.append(maxResults);
        sb.append(" and b.RN_ >=");
        if (firstResult >= 0) {
            sb.append(firstResult);
         } 
        sb.append(")");
        
        return sb.toString();
	}

	public String getIsNullLocalismSql(String sql) {
		return "COALESCE("+sql+")";
	}

	public String getDateSql() {
		return "current date";
	}

	public String getCurrentDateSql() {
		return "current timestamp";
	}

	public String getCastConvertSql(String sql, String type) {
		return "cast("+sql+" as "+ type +")";
	}

	public String getLocalismSql(String localismKey, String localismValue) {

		if(localismKey.equals("processperformance")){
			return "COALESCE(TIMESTAMPDIFF(8,end_time-start_time),0)";
		}
		
		if(localismKey.equals("datediffconvert")) {
			return "avg(TIMESTAMPDIFF(8,end_time-create_time))";
		}
		
		if(localismKey.equals("datediffconvertorg")) {
			return "avg(TIMESTAMPDIFF(8,x.end_time-x.create_time))";
		}
		
		return null;
	}

	private String trim(String sql) {
        sql = sql.trim();
        if (sql.endsWith(SQL_END_DELIMITER)) {
            sql = sql.substring(0, sql.length() - 1
                    - SQL_END_DELIMITER.length());
        }
{'fraction_non_alphanumeric': 0.1437246963562753, 'fraction_numerical': 0.00430161943319838, 'mean_word_length': 3.113423517169615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '264164', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1305, 'n_words': 252}