本文整理汇总了Java中ro.nextreports.engine.util.QueryUtil类的典型用法代码示例。如果您正苦于以下问题:Java QueryUtil类的具体用法?Java QueryUtil怎么用?Java QueryUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryUtil类属于ro.nextreports.engine.util包,在下文中一共展示了QueryUtil类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllColumnTypesForReport
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
public static List<String> getAllColumnTypesForReport(String sql) throws Exception {
List<String> columnTypes = new ArrayList<String>();
Connection con = null;
String md5Key = Cache.getColumnsKey(sql);
List<NameType> result = Cache.getColumns(md5Key);
if (result != null) {
return ReportUtil.getColumnTypes(result);
}
try {
con = Globals.createTempConnection(
DefaultDataSourceManager.getInstance().getConnectedDataSource());
QueryUtil qu = new QueryUtil(con, Globals.getDialect());
// get parameters definition from system
Map<String, QueryParameter> params = new HashMap<String, QueryParameter>();
ParameterManager paramManager = ParameterManager.getInstance();
List<String> paramNames = paramManager.getParameterNames();
for (String paramName : paramNames) {
QueryParameter param = paramManager.getParameter(paramName);
if (param == null) {
throw new Exception(I18NSupport.getString("parameter.undefined", paramName));
}
params.put(paramName, param);
}
List <NameType> columns = qu.getColumns(sql, params);
columnTypes = ReportUtil.getColumnTypes(columns);
Cache.setColumns(md5Key, columns);
} finally {
if (con != null) {
con.close();
}
}
return columnTypes;
}
示例2: getAllColumnsForReport
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
public static List<NameType> getAllColumnsForReport(String sql) throws Exception {
List<NameType> columnTypes = new ArrayList<NameType>();
String md5Key = Cache.getColumnsKey(sql);
List<NameType> result = Cache.getColumns(md5Key);
if (result != null) {
return result;
}
Connection con = null;
try {
con = Globals.createTempConnection(
DefaultDataSourceManager.getInstance().getConnectedDataSource());
QueryUtil qu = new QueryUtil(con, Globals.getDialect());
// get parameters definition from system
Map<String, QueryParameter> params = new HashMap<String, QueryParameter>();
ParameterManager paramManager = ParameterManager.getInstance();
List<String> paramNames = paramManager.getParameterNames();
for (String paramName : paramNames) {
QueryParameter param = paramManager.getParameter(paramName);
if (param == null) {
throw new Exception(I18NSupport.getString("parameter.undefined", paramName));
}
params.put(paramName, param);
}
columnTypes = qu.getColumns(sql, params);
Cache.setColumns(md5Key, columnTypes);
} finally {
if (con != null) {
con.close();
}
}
return columnTypes;
}
示例3: getColumnTypeForReportColumn
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
public static String getColumnTypeForReportColumn(String sql, String column) throws Exception {
Connection con = null;
String md5Key = Cache.getColumnsKey(sql);
List<NameType> result = Cache.getColumns(md5Key);
if (result != null) {
return getColumnTypeByName(column, result);
}
try {
con = Globals.createTempConnection(
DefaultDataSourceManager.getInstance().getConnectedDataSource());
QueryUtil qu = new QueryUtil(con, Globals.getDialect());
// get parameters definition from system
Map<String, QueryParameter> params = new HashMap<String, QueryParameter>();
ParameterManager paramManager = ParameterManager.getInstance();
List<String> paramNames = paramManager.getParameterNames();
for (String paramName : paramNames) {
QueryParameter param = paramManager.getParameter(paramName);
if (param == null) {
throw new Exception(I18NSupport.getString("parameter.undefined", paramName));
}
params.put(paramName, param);
}
List<NameType> columns = qu.getColumns(sql, params);
Cache.setColumns(md5Key, columns);
return getColumnTypeByName(column, columns);
} finally {
if (con != null) {
con.close();
}
}
}
示例4: setDynamicColumns
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
private void setDynamicColumns() throws Exception {
if (chart.getYColumnQuery() != null) {
QueryUtil qu = new QueryUtil(connection, DialectUtil.getDialect(connection));
List<NameType> list = qu.executeQueryForDynamicColumn(chart.getYColumnQuery());
List<String> columns = new LinkedList<String>();
List<String> legends = new LinkedList<String>();
for (NameType nt : list) {
columns.add(nt.getName());
legends.add(nt.getType());
}
chart.setYColumns(columns);
chart.setYColumnsLegends(legends);
}
}
示例5: executeQuery
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
/**
* Execute query This method is useful in case you are not interested about
* report layout, but only query and you want to make your own business.
*
* @return QueryResult object
*
* @throws ReportRunnerException
* if Runner object is not correctly configured
* @throws InterruptedException
* if process was interrupted
*/
public QueryResult executeQuery() throws ReportRunnerException, InterruptedException {
if (connection == null) {
throw new ReportRunnerException("Connection is null!");
}
if (report == null) {
throw new ReportRunnerException("Report is null!");
}
String sql = getSql();
// retrieves the report parameters
Map<String, QueryParameter> parameters = getReportParameters();
if (QueryUtil.restrictQueryExecution(sql)) {
throw new ReportRunnerException("You are not allowed to execute queries that modify the database!");
}
if (QueryUtil.isProcedureCall(sql)) {
if (!QueryUtil.isValidProcedureCall(sql, dialect)) {
throw new ReportRunnerException("Invalid procedure call! Must be of form 'call (${P1}, ?)'");
}
}
QueryResult queryResult = null;
try {
Query query = getQuery(sql);
QueryExecutor executor = new QueryExecutor(query, parameters, parameterValues, connection, count, true,
csv);
executor.setMaxRows(0);
executor.setTimeout(queryTimeout);
queryResult = executor.execute();
return queryResult;
} catch (Exception e) {
throw new ReportRunnerException(e);
}
}
示例6: setOutParametersValues
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
private void setOutParametersValues(PreparedStatement pstmt) throws SQLException, DialectException {
Dialect dialect = DialectUtil.getDialect(conn);
if (QueryUtil.isProcedureCall(query.getText())) {
if (dialect.hasProcedureWithCursor()) {
((CallableStatement) pstmt).registerOutParameter(outputParameterPosition,dialect.getCursorSqlType());
}
}
}
示例7: getValueClassName
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
public static String getValueClassName(StorageService storageService, DataSource ds, String sql) throws Exception {
try {
if ((sql != null) && !sql.trim().equals("")) {
Connection con = null;
try {
con = ConnectionUtil.createConnection(storageService, ds);
int index = sql.toLowerCase().indexOf("where");
int index2 = sql.indexOf("${");
String newSql = sql;
if ((index > 0) && (index2 > 0)) {
newSql = sql.substring(0, index) + " where 1 = 0";
}
QueryUtil qu = new QueryUtil(con, DialectUtil.getDialect(con));
List<NameType> list = qu.executeQueryForColumnNames(newSql);
//System.out.println("*** newType=" + list.get(0).getType());
return list.get(0).getType();
} finally {
ConnectionUtil.closeConnection(con);
}
}
} catch (Exception ex) {
ex.printStackTrace();
LOG.error(ex.getMessage(), ex);
throw ex;
}
return null;
}
示例8: createQueryString
import ro.nextreports.engine.util.QueryUtil; //导入依赖的package包/类
/**
* Parse query and return a string query that will be passed to prepared
* statement(substitute parameter with '?' char).
*/
private String createQueryString() {
QueryChunk[] chunks = query.getChunks();
if ((chunks == null) || (chunks.length == 0)) {
// no query chunks
return "";
}
StringBuffer sb = new StringBuffer();
QueryChunk chunk = null;
int position = 1;
for (int i = 0; i < chunks.length; i++) {
chunk = chunks[i];
//System.out.println("chunk = " + chunk);
switch (chunk.getType()) {
case QueryChunk.PARAMETER_TYPE: {
position++;
String paramName = chunk.getText();
QueryParameter param = parameters.get(paramName);
if (QueryParameter.MULTIPLE_SELECTION.equals(param.getSelection())) {
if (QueryUtil.isProcedureCall(query.getText())) {
sb.append("?");
} else {
Object[] paramValue = (Object[]) parameterValues.get(paramName);
sb.append('(');
for (int j = 0; j < paramValue.length; j++) {
if (j > 0) {
sb.append(',');
}
sb.append('?');
}
sb.append(')');
}
} else {
sb.append("?");
}
break;
}
case QueryChunk.TEXT_TYPE:
if (chunk.getText().contains("?")) {
outputParameterPosition = position;
}
default: {
sb.append(chunk.getText());
break;
}
}
}
return sb.toString();
}