1. tbrugz
  2. sqldump

Commits

tbrugz  committed 6c98b27

dbfeatures: oracle: added getExportedKeys() ; better error logging on addFKSpecificFeatures()

  • Participants
  • Parent commits b17e9e4
  • Branches default

Comments (0)

Files changed (2)

File src/tbrugz/sqldump/dbmsfeatures/OracleDatabaseMetaData.java

View file
 		return st.executeQuery(sql);
 	}
 	
-	static boolean grabFKFromUK = false;
+	static boolean grabFKFromUK = true;
 	
 	/**
 	 * added a UK_CONSTRAINT_TYPE column, which returns: P - primary key, U - unique key
 	 */
 	@Override
-	public ResultSet getImportedKeys(String catalog, String schema, String table)
-			throws SQLException {
+	public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
+		return getKeys(catalog, schema, table, true);
+	}
+	
+	@Override
+	public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException {
+		return getKeys(catalog, schema, table, false);
+	}
+	
+	public ResultSet getKeys(String catalog, String schema, String table, boolean imported) throws SQLException {
 		//TODOne: do not grab FKs that do not reference a PK
-		
+
+		//TODO: if(grabFKFromUK==true) -> status, validated, rely are not returned! 
 		if(!grabFKFromUK) {
-			return super.getImportedKeys(catalog, schema, table);
+			if(imported) {
+				return super.getImportedKeys(catalog, schema, table);
+			}
+			else {
+				return super.getExportedKeys(catalog, schema, table);
+			}
 		}
 		
 		//XXX: this makes grabbing slower. prop option to use default method
 				+") ";
 
 		if(schema!=null) {
-			sql += "where FKTABLE_SCHEM = '"+schema+"' \n";
+			sql += "where "+(imported?"FKTABLE_SCHEM":"PKTABLE_SCHEM")+" = '"+schema+"' \n";
 		}
 		if(table!=null) {
 			if(schema!=null) {
 			else {
 				sql += "where ";
 			}
-			sql += "FKTABLE_NAME = '"+table+"' ";
+			sql += (imported?"FKTABLE_NAME":"PKTABLE_NAME")+" = '"+table+"' ";
 		}
 		sql += "order by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, KEY_SEQ ";
 		Statement st = conn.createStatement();

File src/tbrugz/sqldump/dbmsfeatures/OracleFeatures.java

View file
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import tbrugz.sqldump.SQLUtils;
 import tbrugz.sqldump.dbmodel.Column;
 import tbrugz.sqldump.dbmodel.Constraint;
 import tbrugz.sqldump.dbmodel.DBObject;
 		return new OracleFK();
 	}
 	
+	boolean grabXtraFKColumns = true;
+	
 	@Override
 	public void addFKSpecificFeatures(FK fk, ResultSet rs) {
 		if(fk instanceof OracleFK) {
-			OracleFK ofk = (OracleFK) fk;
 			try {
-				// acfk.status, acfk.validated, acfk.rely "
-				String status = rs.getString("STATUS");
-				if(status!=null && status.equals("DISABLED")) {
-					ofk.enabled = false; 
+				OracleFK ofk = (OracleFK) fk;
+				if(grabXtraFKColumns) {
+					// acfk.status, acfk.validated, acfk.rely
+					String status = rs.getString("STATUS");
+					if(status!=null && status.equals("DISABLED")) {
+						ofk.enabled = false; 
+					}
+					String validated = rs.getString("VALIDATED");
+					if(validated!=null && validated.equals("NOT VALIDATED")) {
+						ofk.validated = false; 
+					}
+					String rely = rs.getString("RELY");
+					if(rely!=null && !rely.equals("")) {
+						ofk.rely = false; 
+					}
 				}
-				String validated = rs.getString("VALIDATED");
-				if(validated!=null && validated.equals("NOT VALIDATED")) {
-					ofk.validated = false; 
+				//log.info("OracleFK: "+ofk);
+			} catch (SQLException e) {
+				grabXtraFKColumns = false;
+				log.warn("addFKSpecificFeatures: column 'STATUS', 'VALIDATED' or 'RELY' not avaiable [ex: "+e+"]");
+				if(log.isDebugEnabled()) {
+					try { log.debug("rowlist: "+SQLUtils.getColumnNames(rs.getMetaData()));	}
+					catch(SQLException ee) { ee.printStackTrace(); }
 				}
-				String rely = rs.getString("RELY");
-				if(rely!=null && !rely.equals("")) {
-					ofk.rely = false; 
-				}
-			} catch (SQLException e) {
-				log.warn("sql exception:", e);
 			}
-			//log.info("OracleFK: "+ofk);
 		}
 		else {
 			log.warn("FK "+fk+" should be instance of "+OracleFK.class.getSimpleName());