}
private void getProcedures(MetadataFactory metadataFactory,
DatabaseMetaData metadata) throws SQLException, TranslatorException {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "JDBCMetadataProcessor - Importing procedures"); //$NON-NLS-1$
ResultSet procedures = metadata.getProcedures(catalog, schemaPattern, procedureNamePattern);
int rsColumns = procedures.getMetaData().getColumnCount();
while (procedures.next()) {
String procedureCatalog = procedures.getString(1);
String procedureSchema = procedures.getString(2);
String procedureName = procedures.getString(3);
String nameInSource = procedureName;
if (useProcedureSpecificName && rsColumns >= 9) {
procedureName = procedures.getString(9);
if (procedureName == null) {
procedureName = nameInSource;
}
}
String fullProcedureName = getFullyQualifiedName(procedureCatalog, procedureSchema, procedureName);
Procedure procedure = metadataFactory.addProcedure(useFullSchemaName?fullProcedureName:procedureName);
procedure.setNameInSource(getFullyQualifiedName(procedureCatalog, procedureSchema, nameInSource, true));
ResultSet columns = metadata.getProcedureColumns(catalog, procedureSchema, procedureName, null);
while (columns.next()) {
String columnName = columns.getString(4);
short columnType = columns.getShort(5);
int sqlType = columns.getInt(6);
String typeName = columns.getString(7);
sqlType = checkForUnsigned(sqlType, typeName);
if (columnType == DatabaseMetaData.procedureColumnUnknown) {
continue; //there's a good chance this won't work
}
BaseColumn record = null;
int precision = columns.getInt(8);
String runtimeType = getRuntimeType(sqlType, typeName, precision);
if (columnType == DatabaseMetaData.procedureColumnResult) {
Column column = metadataFactory.addProcedureResultSetColumn(columnName, runtimeType, procedure);
record = column;
column.setNativeType(typeName);
} else {
record = metadataFactory.addProcedureParameter(columnName, runtimeType, Type.values()[columnType], procedure);
}
record.setPrecision(columns.getInt(8));
record.setLength(columns.getInt(9));
record.setScale(columns.getInt(10));
record.setRadix(columns.getInt(11));
record.setNullType(NullType.values()[columns.getShort(12)]);
record.setAnnotation(columns.getString(13));
}
}
procedures.close();
}