Connection connection = udc.getConnection();
if (connection == null || name == null)
throw new IllegalArgumentException("connection or name is empty.");
Function sp = new Function(name);
ResultSet rs = null;
try {
String catalog = sp.getCatalog();
String schema = sp.getSchema();
String api = sp.getApi();
DBAdapter dba = DBAdapterFactory.getInstance().getAdapter(udc.getConnectionName());
boolean foundPlSqlRecord = false;//will skip all output columns when a PL/SQL record is found.//TODO: This code is tied to Oracle. Change it.
boolean startToRecord = false;
int previousIndex = -1;
DatabaseMetaData dbmd = connection.getMetaData();
String vendor = getDatabaseVendor(dbmd);
rs = dbmd.getProcedureColumns(toUpperCaseIfAllowed(dba, catalog),
toUpperCaseIfAllowed(dba, schema), toUpperCaseIfAllowed(dba, api), null);
while (rs.next()) {
catalog = rs.getString("PROCEDURE_CAT");
schema = rs.getString("PROCEDURE_SCHEM");
int index = rs.getInt("SEQUENCE");
String columnName = rs.getString("COLUMN_NAME");
String mode = rs.getString("COLUMN_TYPE");
int sqlDataType = rs.getInt("DATA_TYPE");
String sqlDataTypeName = rs.getString("TYPE_NAME");
// turn on foundPlSqlRecord
if (Parameter.MODE_OUT.equals(mode) &&
Types.OTHER == sqlDataType && //cursor type
columnName == null &&
"PL/SQL RECORD".equals(sqlDataTypeName)) {//TODO: This code is tied to Oracle. Change it.
foundPlSqlRecord = true;
}
// The next few rows are definition of this ref cursor
// ignore it as there is no way to detect the end of this
// cursor columns exactly.
// will get the output cursor info in other place.
if (foundPlSqlRecord) {
if (Parameter.MODE_OUT.equals(mode)) {
continue;
}
else {
// turn off foundPlSqlRecord
foundPlSqlRecord = false;
}
}
//check if start to record
if (index == 1 && Parameter.MODE_RETURN.equals(mode)) {
startToRecord = true;
previousIndex = -1;//clear position
}
if (index <= previousIndex) {
startToRecord = false;
}
if (startToRecord) {
Parameter p = ParameterFactory.getInstance().createParameter(vendor, index, columnName, mode, sqlDataType, sqlDataTypeName);
p.setCatalog(catalog);
p.setSchema(schema);
sp.addParameter(p);
}
previousIndex = index;
}
sp.setCataloge(catalog);
sp.setSchema(schema);
rs.close();
}
catch(SQLException sqlEx) {
throw new UnsupportedStoredProcedureAPINameException(sqlEx);