List of usage examples for java.sql DatabaseMetaData importedKeyRestrict
int importedKeyRestrict
To view the source code for java.sql DatabaseMetaData importedKeyRestrict.
Click Source Link
UPDATE_RULE
, indicates that a primary key may not be updated if it has been imported by another table as a foreign key. From source file:org.executequery.sql.spi.LiquibaseStatementGenerator.java
private ForeignKeyConstraintType getForeignKeyConstraintType(short rule) { switch (rule) { case DatabaseMetaData.importedKeyCascade: return ForeignKeyConstraintType.importedKeyCascade; case DatabaseMetaData.importedKeySetNull: return ForeignKeyConstraintType.importedKeySetNull; case DatabaseMetaData.importedKeyRestrict: return ForeignKeyConstraintType.importedKeyRestrict; case DatabaseMetaData.importedKeySetDefault: return ForeignKeyConstraintType.importedKeySetDefault; case DatabaseMetaData.importedKeyNoAction: default:/*from w w w . ja v a 2 s . c om*/ return ForeignKeyConstraintType.importedKeyNoAction; } }
From source file:org.kuali.core.db.torque.KualiTorqueJDBCTransformTask.java
/** * Retrieves a list of foreign key columns for a given table. * * @param dbMeta JDBC metadata./* w w w . j a v a 2 s.c o m*/ * @param tableName Table from which to retrieve FK information. * @return A list of foreign keys in <code>tableName</code>. * @throws SQLException */ public Map<String, Object[]> getForeignKeys(DatabaseMetaData dbMeta, String tableName) throws SQLException { TreeMap<String, Object[]> fks = new TreeMap<String, Object[]>(); ResultSet foreignKeys = null; try { foreignKeys = dbMeta.getImportedKeys(null, dbSchema, tableName); while (foreignKeys.next()) { String refTableName = foreignKeys.getString(3); String fkName = foreignKeys.getString(12); int deleteRule = foreignKeys.getInt(11); String onDelete = "none"; if (deleteRule == DatabaseMetaData.importedKeyCascade) { onDelete = "cascade"; } else if (deleteRule == DatabaseMetaData.importedKeyRestrict) { onDelete = "restrict"; } else if (deleteRule == DatabaseMetaData.importedKeySetNull) { onDelete = "setnull"; } // if FK has no name - make it up (use tablename instead) if (fkName == null) { fkName = refTableName; } Object[] fk = (Object[]) fks.get(fkName); List<String[]> refs; if (fk == null) { fk = new Object[3]; fk[0] = refTableName; //referenced table name refs = new ArrayList<String[]>(); fk[1] = refs; fks.put(fkName, fk); fk[2] = onDelete; } else { refs = (ArrayList<String[]>) fk[1]; } String[] ref = new String[2]; ref[0] = foreignKeys.getString(8); //local column ref[1] = foreignKeys.getString(4); //foreign column refs.add(ref); } } catch (SQLException e) { // this seems to be happening in some db drivers (sybase) // when retrieving foreign keys from views. log("WARN: Could not read foreign keys for Table " + tableName + " : " + e.getMessage(), Project.MSG_WARN); } finally { if (foreignKeys != null) { foreignKeys.close(); } } return fks; }