public Map<String, DbParameterAccessor> getAllProcedureParameters(String procName) throws SQLException { String[] qualifiers = NameNormaliser.normaliseName(procName).split("\\."); String qry = " select type,param_list,returns from mysql.proc where "; if (qualifiers.length == 2) { qry += " lower(db)=? and lower(name)=? "; } else { qry += " (db=database() and lower(name)=?)"; } String type; String paramList; String returns; try (PreparedStatement dc = currentConnection.prepareStatement(qry)) { for (int i = 0; i < qualifiers.length; i++) { dc.setString(i + 1, NameNormaliser.normaliseName(qualifiers[i])); } ResultSet rs = dc.executeQuery(); if (!rs.next()) { throw new SQLException("Unknown procedure " + procName); } type = rs.getString(1); paramList = rs.getString(2); returns = rs.getString(3); rs.close(); } MySqlProcedureParametersParser parser = new MySqlProcedureParametersParser(); Map<String, DbParameterAccessor> allParams = new HashMap<String, DbParameterAccessor>(); int position = 0; for (ParamDescriptor pd : parser.parseParameters(paramList)) { DbParameterAccessor dbp = new DbParameterAccessor( pd.name, pd.direction, getSqlType(pd.type), getJavaClass(pd.type), position++); allParams.put(NameNormaliser.normaliseName(pd.name), dbp); } if ("FUNCTION".equals(type)) { ParamDescriptor rd = parser.parseReturnType(returns); allParams.put( "", new DbParameterAccessor( "", Direction.RETURN_VALUE, getSqlType(rd.type), getJavaClass(rd.type), -1)); } return allParams; }
private ParamDescriptor parseReturn(String returnTypeExpression) { return parser.parseReturnType(returnTypeExpression); }
private List<ParamDescriptor> parse(String parametersList) { params = parser.parseParameters(parametersList); return params; }