Example usage for java.sql DatabaseMetaData procedureNoNulls

List of usage examples for java.sql DatabaseMetaData procedureNoNulls

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData procedureNoNulls.

Prototype

int procedureNoNulls

To view the source code for java.sql DatabaseMetaData procedureNoNulls.

Click Source Link

Document

Indicates that NULL values are not allowed.

Usage

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

/**
 * Dumps the contents of the indicated procedure.
 * /*from w ww.jav  a 2  s.  c  o  m*/
 * @param xmlWriter     The xml writer to write to
 * @param metaData      The database metadata
 * @param catalogName   The catalog name
 * @param schemaName    The schema name
 * @param procedureName The procedure name
 */
private void dumpProcedure(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String procedureName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getProcedureColumns(catalogName, schemaName, procedureName, _columnPattern);
        }

        public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException {
            Set columns = getColumnsInResultSet(result);
            String columnName = result.getString("COLUMN_NAME");

            if ((columnName != null) && (columnName.length() > 0)) {
                xmlWriter.writeElementStart(null, "column");
                xmlWriter.writeAttribute(null, "name", columnName);
                if (columns.contains("COLUMN_TYPE")) {
                    try {
                        switch (result.getShort("COLUMN_TYPE")) {
                        case DatabaseMetaData.procedureColumnIn:
                            xmlWriter.writeAttribute(null, "type", "in parameter");
                            break;
                        case DatabaseMetaData.procedureColumnInOut:
                            xmlWriter.writeAttribute(null, "type", "in/out parameter");
                            break;
                        case DatabaseMetaData.procedureColumnOut:
                            xmlWriter.writeAttribute(null, "type", "out parameter");
                            break;
                        case DatabaseMetaData.procedureColumnReturn:
                            xmlWriter.writeAttribute(null, "type", "return value");
                            break;
                        case DatabaseMetaData.procedureColumnResult:
                            xmlWriter.writeAttribute(null, "type", "result column in ResultSet");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "type", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the COLUMN_TYPE value for the column '" + columnName
                                + "' of procedure '" + procedureName + "' from the result set: "
                                + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }

                addIntAttribute(xmlWriter, "typeCode", result, columns, "DATA_TYPE");
                addStringAttribute(xmlWriter, "type", result, columns, "TYPE_NAME");
                addIntAttribute(xmlWriter, "length", result, columns, "LENGTH");
                addIntAttribute(xmlWriter, "precision", result, columns, "PRECISION");
                addShortAttribute(xmlWriter, "short", result, columns, "SCALE");
                addShortAttribute(xmlWriter, "radix", result, columns, "RADIX");
                if (columns.contains("NULLABLE")) {
                    try {
                        switch (result.getInt("NULLABLE")) {
                        case DatabaseMetaData.procedureNoNulls:
                            xmlWriter.writeAttribute(null, "nullable", "false");
                            break;
                        case DatabaseMetaData.procedureNullable:
                            xmlWriter.writeAttribute(null, "nullable", "true");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "nullable", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the NULLABLE value for the column '" + columnName
                                + "' of procedure '" + procedureName + "' from the result set: "
                                + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }
                addStringAttribute(xmlWriter, "remarks", result, columns, "REMARKS");
            }
        }

        public void handleError(SQLException ex) {
            log("Could not read the columns for procedure '" + procedureName + "' from the result set: "
                    + ex.getStackTrace(), Project.MSG_ERR);
        }
    });
}