當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.getParameterNames方法代碼示例

本文整理匯總了Java中ro.nextreports.engine.queryexec.Query.getParameterNames方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.getParameterNames方法的具體用法?Java Query.getParameterNames怎麽用?Java Query.getParameterNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ro.nextreports.engine.queryexec.Query的用法示例。


在下文中一共展示了Query.getParameterNames方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parametersAreDefined

import ro.nextreports.engine.queryexec.Query; //導入方法依賴的package包/類
/**
 * Test if all parameters used in sql are defined
 * @param sql sql
 * @throws ro.nextreports.engine.util.ParameterNotFoundException if a parameter used in the sql is not defined
 */
public void parametersAreDefined(String sql) throws ParameterNotFoundException {
    String[] paramNames;
    Query query = new Query(sql);
    paramNames = query.getParameterNames();

    List<QueryParameter> parameters = getParameters();

    for (String paramName : paramNames) {
        QueryParameter param = null;
        for (QueryParameter p : parameters) {
            if (paramName.equals(p.getName())) {
                param = p;
            }
        }
        if (param == null) {
            throw new ParameterNotFoundException(paramName);
        }
    }
}
 
開發者ID:nextreports,項目名稱:nextreports-designer,代碼行數:25,代碼來源:ParameterManager.java

示例2: checkSqlHasParametersDefined

import ro.nextreports.engine.queryexec.Query; //導入方法依賴的package包/類
public void checkSqlHasParametersDefined(String sql, Map<String,QueryParameter> params)
        throws Exception {
    // create the query object
    Query query = new Query(sql);

    // get parameter names
    String[] paramNames = query.getParameterNames();

    // execute query if no parameters
    if (paramNames.length == 0) {
        return;
    }

    for (String name : paramNames) {
         QueryParameter param = params.get(name);
            if (param == null) {
                throw new Exception(I18NSupport.getString("run.parameter.not.defined", name));
            }
    }
}
 
開發者ID:nextreports,項目名稱:nextreports-designer,代碼行數:21,代碼來源:QueryWizardPanel.java

示例3: parametersAreDefined

import ro.nextreports.engine.queryexec.Query; //導入方法依賴的package包/類
/**
 * Test if all parameters used in the report are defined
 *
 * @param report report object
 * @throws ParameterNotFoundException if a parameter used in the report is not defined
 */
public void parametersAreDefined(Report report) throws ParameterNotFoundException {
    String[] paramNames;
    String sql = report.getSql();
    if (sql == null) {
        sql = report.getQuery().toString();
    }
    Query query = new Query(sql);
    paramNames = query.getParameterNames();

    List<QueryParameter> parameters = report.getParameters();

    for (String paramName : paramNames) {
        QueryParameter param = null;
        for (QueryParameter p : parameters) {
            if (paramName.equals(p.getName())) {
                param = p;
            }
        }
        if (param == null) {
            throw new ParameterNotFoundException(paramName);
        }
    }
}
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:30,代碼來源:ParameterUtil.java

示例4: getUsedParametersMap

import ro.nextreports.engine.queryexec.Query; //導入方法依賴的package包/類
private static Map<String, QueryParameter> getUsedParametersMap(Report report, boolean withHidden, boolean onlyHidden) {  
 	if (report == null) {
 		return new HashMap<String, QueryParameter>();
 	}
     String sql = report.getSql();
     if (sql == null) {
         sql = report.getQuery().toString();
     }
     Query query = new Query(sql);

     String[] paramNames = query.getParameterNames();
     LinkedHashMap<String, QueryParameter> params = new LinkedHashMap<String, QueryParameter>();
     for (QueryParameter qp : report.getParameters()) {
         String name = qp.getName();
         boolean found = false;
         for (String pName : paramNames) {
             if (pName.equals(name)) {
             	if (onlyHidden) {
             		if (qp.isHidden()) {
             			found = true;
             			break;
             		}
             	} else if (!qp.isHidden() || (qp.isHidden() && withHidden)) {
                     found = true;
                     break;
                 }
             }
         }
         // parameter is not used inside query but it is used inside other parameter
         if (!found) {
         	if (getChildDependentParameters(report, qp).size() > 0) {
         		found = true;            	
         	} 
         }
         
         if (onlyHidden) {
         	if  (found) {
         		params.put(name, qp);
         	}
} else {
	if (found || (qp.isHidden() && withHidden)) {
		params.put(name, qp);
	}
}
     }
     return params;
 }
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:48,代碼來源:ParameterUtil.java

示例5: getColumns

import ro.nextreports.engine.queryexec.Query; //導入方法依賴的package包/類
public List<NameType> getColumns(String sql, Map<String, QueryParameter> params, List<NameType> cachedColumns) throws Exception {
	if (cachedColumns != null) {
		return cachedColumns;
	}
	
	// create the query object
	Query query = new Query(sql);

	// get parameter names
	String[] paramNames = query.getParameterNames();

	// execute query if no parameters
	if (paramNames.length == 0) {
		return executeQueryForColumnNames(sql);
	}

	// init the sql without parameters
	StringWriter sqlWithoutParameters = new StringWriter(100);

	// subtitute paramters with default value
	QueryChunk[] chunks = query.getChunks();
	for (QueryChunk chunk : chunks) {
		int chunckType = chunk.getType();
		if (QueryChunk.TEXT_TYPE == chunckType) {
			sqlWithoutParameters.append(chunk.getText());
		} else if (QueryChunk.PARAMETER_TYPE == chunckType) {
			String paramName = chunk.getText();
			QueryParameter param = params.get(paramName);
			if (param == null) {
				// do not internationalize strings in engine package!!!
				throw new Exception("Parameter '" + paramName + "' not defined.");
			}
			boolean afterIn = sqlWithoutParameters.getBuffer().toString().trim().toLowerCase()
					.endsWith(QueryExecutor.IN.toLowerCase());
			if (afterIn) {
				sqlWithoutParameters.append("(");
			}
			sqlWithoutParameters.append(getDummyValueForParameter(param));
			if (afterIn) {
				sqlWithoutParameters.append(")");
			}
		}
	}
	return executeQueryForColumnNames(sqlWithoutParameters.toString());
}
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:46,代碼來源:QueryUtil.java


注:本文中的ro.nextreports.engine.queryexec.Query.getParameterNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。