Example usage for java.sql DatabaseMetaData importedKeyInitiallyImmediate

List of usage examples for java.sql DatabaseMetaData importedKeyInitiallyImmediate

Introduction

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

Prototype

int importedKeyInitiallyImmediate

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

Click Source Link

Document

Indicates deferrability.

Usage

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

/**
 * Dumps the foreign key columns of the indicated table to other tables.
 * //from  ww w .jav a 2s.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 tableName   The table name
 */
private void dumpFKs(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String tableName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getImportedKeys(catalogName, schemaName, tableName);
        }

        public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException {
            Set columns = getColumnsInResultSet(result);

            xmlWriter.writeElementStart(null, "foreignKey");

            addStringAttribute(xmlWriter, "name", result, columns, "FK_NAME");
            addStringAttribute(xmlWriter, "primaryKeyName", result, columns, "PK_NAME");
            addStringAttribute(xmlWriter, "column", result, columns, "PKCOLUMN_NAME");
            addStringAttribute(xmlWriter, "foreignCatalog", result, columns, "FKTABLE_CAT");
            addStringAttribute(xmlWriter, "foreignSchema", result, columns, "FKTABLE_SCHEM");
            addStringAttribute(xmlWriter, "foreignTable", result, columns, "FKTABLE_NAME");
            addStringAttribute(xmlWriter, "foreignColumn", result, columns, "FKCOLUMN_NAME");
            addShortAttribute(xmlWriter, "sequenceNumberInFK", result, columns, "KEY_SEQ");
            if (columns.contains("UPDATE_RULE")) {
                try {
                    switch (result.getShort("UPDATE_RULE")) {
                    case DatabaseMetaData.importedKeyNoAction:
                        xmlWriter.writeAttribute(null, "updateRule", "no action");
                        break;
                    case DatabaseMetaData.importedKeyCascade:
                        xmlWriter.writeAttribute(null, "updateRule", "cascade PK change");
                        break;
                    case DatabaseMetaData.importedKeySetNull:
                        xmlWriter.writeAttribute(null, "updateRule", "set FK to NULL");
                        break;
                    case DatabaseMetaData.importedKeySetDefault:
                        xmlWriter.writeAttribute(null, "updateRule", "set FK to default");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "updateRule", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the UPDATE_RULE value for a foreign key of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            if (columns.contains("DELETE_RULE")) {
                try {
                    switch (result.getShort("DELETE_RULE")) {
                    case DatabaseMetaData.importedKeyNoAction:
                    case DatabaseMetaData.importedKeyRestrict:
                        xmlWriter.writeAttribute(null, "deleteRule", "no action");
                        break;
                    case DatabaseMetaData.importedKeyCascade:
                        xmlWriter.writeAttribute(null, "deleteRule", "cascade PK change");
                        break;
                    case DatabaseMetaData.importedKeySetNull:
                        xmlWriter.writeAttribute(null, "deleteRule", "set FK to NULL");
                        break;
                    case DatabaseMetaData.importedKeySetDefault:
                        xmlWriter.writeAttribute(null, "deleteRule", "set FK to default");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "deleteRule", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the DELETE_RULE value for a foreign key of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            if (columns.contains("DEFERRABILITY")) {
                try {
                    switch (result.getShort("DEFERRABILITY")) {
                    case DatabaseMetaData.importedKeyInitiallyDeferred:
                        xmlWriter.writeAttribute(null, "deferrability", "initially deferred");
                        break;
                    case DatabaseMetaData.importedKeyInitiallyImmediate:
                        xmlWriter.writeAttribute(null, "deferrability", "immediately deferred");
                        break;
                    case DatabaseMetaData.importedKeyNotDeferrable:
                        xmlWriter.writeAttribute(null, "deferrability", "not deferred");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "deferrability", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the DEFERRABILITY value for a foreign key of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            xmlWriter.writeElementEnd();
        }

        public void handleError(SQLException ex) {
            log("Could not determine the foreign keys for table '" + tableName + "': " + ex.getStackTrace(),
                    Project.MSG_ERR);
        }
    });
}

From source file:org.executequery.databaseobjects.impl.TableColumnConstraint.java

private String translateDeferrabilityRule(Short value) {

    String translated = String.valueOf(value);
    if (isForeignKey()) {

        switch (value) {
        case DatabaseMetaData.importedKeyInitiallyDeferred:
            return translated + " - importedKeyInitiallyDeferred";

        case DatabaseMetaData.importedKeyInitiallyImmediate:
            return translated + " - importedKeyInitiallyImmediate";

        case DatabaseMetaData.importedKeyNotDeferrable:
            return translated + " - importedKeyNotDeferrable";
        }//w  ww .j  a v  a  2 s  . c o m

    }
    return translated;
}