Example usage for java.sql DatabaseMetaData procedureNullable

List of usage examples for java.sql DatabaseMetaData procedureNullable

Introduction

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

Prototype

int procedureNullable

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

Click Source Link

Document

Indicates that NULL values are allowed.

Usage

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

/**
 * Dumps the contents of the indicated procedure.
 * //from w  w w  .  j av a  2  s.c om
 * @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);
        }
    });
}

From source file:org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider.java

/**
 * Process the procedure column metadata
 *///from   ww  w . ja  v a  2s  .c  o m
private void processProcedureColumns(DatabaseMetaData databaseMetaData, @Nullable String catalogName,
        @Nullable String schemaName, @Nullable String procedureName) {

    String metaDataCatalogName = metaDataCatalogNameToUse(catalogName);
    String metaDataSchemaName = metaDataSchemaNameToUse(schemaName);
    String metaDataProcedureName = procedureNameToUse(procedureName);
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieving metadata for " + metaDataCatalogName + '/' + metaDataSchemaName + '/'
                + metaDataProcedureName);
    }

    ResultSet procs = null;
    try {
        procs = databaseMetaData.getProcedures(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName);
        List<String> found = new ArrayList<>();
        while (procs.next()) {
            found.add(procs.getString("PROCEDURE_CAT") + '.' + procs.getString("PROCEDURE_SCHEM") + '.'
                    + procs.getString("PROCEDURE_NAME"));
        }
        procs.close();

        if (found.size() > 1) {
            throw new InvalidDataAccessApiUsageException(
                    "Unable to determine the correct call signature - multiple "
                            + "procedures/functions/signatures for '" + metaDataProcedureName + "': found "
                            + found);
        } else if (found.isEmpty()) {
            if (metaDataProcedureName != null && metaDataProcedureName.contains(".")
                    && !StringUtils.hasText(metaDataCatalogName)) {
                String packageName = metaDataProcedureName.substring(0, metaDataProcedureName.indexOf("."));
                throw new InvalidDataAccessApiUsageException(
                        "Unable to determine the correct call signature for '" + metaDataProcedureName
                                + "' - package name should be specified separately using '.withCatalogName(\""
                                + packageName + "\")'");
            } else if ("Oracle".equals(databaseMetaData.getDatabaseProductName())) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Oracle JDBC driver did not return procedure/function/signature for '"
                            + metaDataProcedureName + "' - assuming a non-exposed synonym");
                }
            } else {
                throw new InvalidDataAccessApiUsageException(
                        "Unable to determine the correct call signature - no "
                                + "procedure/function/signature for '" + metaDataProcedureName + "'");
            }
        }

        procs = databaseMetaData.getProcedureColumns(metaDataCatalogName, metaDataSchemaName,
                metaDataProcedureName, null);
        while (procs.next()) {
            String columnName = procs.getString("COLUMN_NAME");
            int columnType = procs.getInt("COLUMN_TYPE");
            if (columnName == null && (columnType == DatabaseMetaData.procedureColumnIn
                    || columnType == DatabaseMetaData.procedureColumnInOut
                    || columnType == DatabaseMetaData.procedureColumnOut)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Skipping metadata for: " + columnType + " " + procs.getInt("DATA_TYPE") + " "
                            + procs.getString("TYPE_NAME") + " " + procs.getInt("NULLABLE")
                            + " (probably a member of a collection)");
                }
            } else {
                CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType,
                        procs.getInt("DATA_TYPE"), procs.getString("TYPE_NAME"),
                        procs.getInt("NULLABLE") == DatabaseMetaData.procedureNullable);
                this.callParameterMetaData.add(meta);
                if (logger.isDebugEnabled()) {
                    logger.debug("Retrieved metadata: " + meta.getParameterName() + " "
                            + meta.getParameterType() + " " + meta.getSqlType() + " " + meta.getTypeName() + " "
                            + meta.isNullable());
                }
            }
        }
    } catch (SQLException ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Error while retrieving metadata for procedure columns: " + ex);
        }
    } finally {
        try {
            if (procs != null) {
                procs.close();
            }
        } catch (SQLException ex) {
            if (logger.isWarnEnabled()) {
                logger.warn("Problem closing ResultSet for procedure column metadata: " + ex);
            }
        }
    }
}