1. tbrugz
  2. sqldump

Commits

tbrugz  committed 48506b5

model: FK: added get/set

  • Participants
  • Parent commits 01563ca
  • Branches default

Comments (0)

Files changed (9)

File src/tbrugz/sqldump/JDBCSchemaGrabber.java

View file
 		Set<DBObjectId> ids = new HashSet<DBObjectId>();
 		for(FK fk: schemaModel.getForeignKeys()) {
 			DBObjectId dbid = new DBObjectId();
-			dbid.setName(fk.pkTable);
-			dbid.setSchemaName(fk.pkTableSchemaName);
+			dbid.setName(fk.getPkTable());
+			dbid.setSchemaName(fk.getPkTableSchemaName());
 			ids.add(dbid);
 	
 			//Exported FKs
 			if(grabExportedFKsAlso) {
 				DBObjectId dbidFk = new DBObjectId();
-				dbidFk.setName(fk.fkTable);
-				dbidFk.setSchemaName(fk.fkTableSchemaName);
+				dbidFk.setName(fk.getFkTable());
+				dbidFk.setSchemaName(fk.getFkTableSchemaName());
 				ids.add(dbidFk);
 			}
 			
 				fk.setName(fkName);
 				fks.put(fkName, fk);
 			}
-			if(fk.pkTable==null) {
-				fk.pkTable = fkrs.getString("PKTABLE_NAME");
-				fk.fkTable = fkrs.getString("FKTABLE_NAME");
-				fk.pkTableSchemaName = fkrs.getString("PKTABLE_SCHEM");
-				fk.fkTableSchemaName = fkrs.getString("FKTABLE_SCHEM");
+			if(fk.getPkTable()==null) {
+				fk.setPkTable(fkrs.getString("PKTABLE_NAME"));
+				fk.setFkTable(fkrs.getString("FKTABLE_NAME"));
+				fk.setPkTableSchemaName(fkrs.getString("PKTABLE_SCHEM"));
+				fk.setFkTableSchemaName(fkrs.getString("FKTABLE_SCHEM"));
 				String pkTableCatalog = fkrs.getString("PKTABLE_CAT");
 				String fkTableCatalog = fkrs.getString("FKTABLE_CAT");
 				String updateRule = fkrs.getString("UPDATE_RULE");
 				//log.debug("fk: "+fkName+" :: rules: "+updateRule+"|"+fk.updateRule+" / "+deleteRule+"|"+fk.deleteRule+"");
 				
 				//for MySQL
-				if(fk.pkTableSchemaName==null && pkTableCatalog!=null) { fk.pkTableSchemaName = pkTableCatalog; }
-				if(fk.fkTableSchemaName==null && fkTableCatalog!=null) { fk.fkTableSchemaName = fkTableCatalog; }
+				if(fk.getPkTableSchemaName()==null && pkTableCatalog!=null) { fk.setPkTableSchemaName(pkTableCatalog); }
+				if(fk.getFkTableSchemaName()==null && fkTableCatalog!=null) { fk.setFkTableSchemaName(fkTableCatalog); }
 				
 				if(askForUkType) {
 					try {
 					}
 					catch(SQLException e) {
 						askForUkType = false;
-						log.debug("resultset has no 'UK_CONSTRAINT_TYPE' column [fkTable='"+fk.fkTable+"'; ukTable='"+fk.pkTable+"']");
+						log.debug("resultset has no 'UK_CONSTRAINT_TYPE' column [fkTable='"+fk.getFkTable()+"'; ukTable='"+fk.getPkTable()+"']");
 					}
 				}
 				dbmsfeatures.addFKSpecificFeatures(fk, fkrs);
 			}
-			fk.fkColumns.add(fkrs.getString("FKCOLUMN_NAME"));
-			fk.pkColumns.add(fkrs.getString("PKCOLUMN_NAME"));
+			fk.getFkColumns().add(fkrs.getString("FKCOLUMN_NAME"));
+			fk.getPkColumns().add(fkrs.getString("PKCOLUMN_NAME"));
 			log.debug("fk: "+fkName+" - "+fk);
 		}
 		List<FK> ret = new ArrayList<FK>();

File src/tbrugz/sqldump/SchemaModelScriptDumper.java

View file
 			//FK outside table, with referencing table
 			if(dumpFKsWithReferencingTable && !dumpFKsInsideTable) {
 				for(FK fk: schemaModel.getForeignKeys()) {
-					if(fk.fkTable.equals(table.getName())) {
+					if(fk.getFkTable().equals(table.getName())) {
 						String fkscript = fkScriptWithAlterTable(fk, dumpDropStatements, dumpWithSchemaName);
 						categorizedOut(table.getSchemaName(), table.getName(), DBObjectType.TABLE, fkscript);
 					}
 	}
 	
 	public static String fkScriptWithAlterTable(FK fk, boolean dumpDropStatements, boolean dumpWithSchemaName) {
-		String fkTableName = (dumpWithSchemaName?DBObject.getFinalIdentifier(fk.fkTableSchemaName)+".":"")+DBObject.getFinalIdentifier(fk.fkTable);
+		String fkTableName = (dumpWithSchemaName?DBObject.getFinalIdentifier(fk.getFkTableSchemaName())+".":"")+DBObject.getFinalIdentifier(fk.getFkTable());
 		return
 			(dumpDropStatements?"--alter table "+fkTableName+" drop constraint "+fk.getName()+";\n":"")
 			+"alter table "+fkTableName

File src/tbrugz/sqldump/dbmodel/FK.java

View file
 	
 	private static final long serialVersionUID = 1L;
 	//String name;
-	public String pkTable;
-	public String fkTable;
-	public String pkTableSchemaName;
-	public String fkTableSchemaName;
+	String pkTable;
+	String fkTable;
+	String pkTableSchemaName;
+	String fkTableSchemaName;
 	public Boolean fkReferencesPK; //FK references a PK? true. references a UK (unique key)? false
 	public UpdateRule updateRule;
 	public UpdateRule deleteRule;
 
-	public List<String> pkColumns = new ArrayList<String>();
-	public List<String> fkColumns = new ArrayList<String>();
+	List<String> pkColumns = new ArrayList<String>();
+	List<String> fkColumns = new ArrayList<String>();
 	
 	@Override
 	public String toString() {
 		return fkSimpleScript(" ", true);
 	}
 	
+	public String getPkTable() {
+		return pkTable;
+	}
+
+	public void setPkTable(String pkTable) {
+		this.pkTable = pkTable;
+	}
+
+	public String getFkTable() {
+		return fkTable;
+	}
+
+	public void setFkTable(String fkTable) {
+		this.fkTable = fkTable;
+	}
+
+	public String getPkTableSchemaName() {
+		return pkTableSchemaName;
+	}
+
+	public void setPkTableSchemaName(String pkTableSchemaName) {
+		this.pkTableSchemaName = pkTableSchemaName;
+	}
+
+	public String getFkTableSchemaName() {
+		return fkTableSchemaName;
+	}
+
+	public void setFkTableSchemaName(String fkTableSchemaName) {
+		this.fkTableSchemaName = fkTableSchemaName;
+	}
+
+	public List<String> getPkColumns() {
+		return pkColumns;
+	}
+
+	public void setPkColumns(List<String> pkColumns) {
+		this.pkColumns = pkColumns;
+	}
+
+	public List<String> getFkColumns() {
+		return fkColumns;
+	}
+
+	public void setFkColumns(List<String> fkColumns) {
+		this.fkColumns = fkColumns;
+	}
+
 	@Override
 	public boolean equals(Object obj) {
 		if(obj instanceof FK) {

File src_diff/tbrugz/sqldiff/model/SchemaDiff.java

View file
 	static Set<FK> getFKsFromTable(Set<FK> fks, String table) {
 		Set<FK> retfks = new HashSet<FK>();
 		for(FK fk: fks) {
-			if(fk.fkTable.equals(table)) { retfks.add(fk); }
+			if(fk.getFkTable().equals(table)) { retfks.add(fk); }
 		}
 		return retfks;
 	}

File src_graphml/tbrugz/sqldump/graph/Schema2GraphML.java

View file
 			boolean isRoot = true;
 			boolean isLeaf = true;
 			for(FK fk: schemaModel.getForeignKeys()) {
-				if(fk.pkTable.equals(t.getName())) {
+				if(fk.getPkTable().equals(t.getName())) {
 					isRoot = false;
 				}
-				if(fk.fkTable.equals(t.getName())) {
+				if(fk.getFkTable().equals(t.getName())) {
 					isLeaf = false;
 				}
 			}
 			case FK: 
 				l.setName(fk.getName()); break;
 			case COLUMNS: 
-				l.setName("("+fk.fkColumns+" -> "+fk.pkColumns+")"); break;
+				l.setName("("+fk.getFkColumns()+" -> "+fk.getPkColumns()+")"); break;
 			case FKANDCOLUMNS:
 				//fk label: fk name + columns involved
-				l.setName(fk.getName()+" ("+fk.fkColumns+" -> "+fk.pkColumns+")"); break;
+				l.setName(fk.getName()+" ("+fk.getFkColumns()+" -> "+fk.getPkColumns()+")"); break;
 			case NONE:
 			default:
 				l.setName(""); break;
 		}
 		l.referencesPK = fk.fkReferencesPK;
-		l.composite = fk.fkColumns.size()>1;
+		l.composite = fk.getFkColumns().size()>1;
 		l.setSource(getSourceId(fk));
 		l.setTarget(getTargetId(fk));
 		
 	}
 	
 	public static String getSourceId(FK fk) {
-		return fk.pkTableSchemaName+"."+fk.pkTable;
+		return fk.getPkTableSchemaName()+"."+fk.getPkTable();
 	}
 
 	public static String getTargetId(FK fk) {
-		return fk.fkTableSchemaName+"."+fk.fkTable;
+		return fk.getFkTableSchemaName()+"."+fk.getFkTable();
 	}
 	
 	@Override

File src_mondrian/tbrugz/sqldump/mondrianschema/MondrianSchemaDumper.java

View file
 				}
 				FK fk = new FK();
 				log.debug("new FK: "+newfkstr+"; parts.len: "+parts.length);
-				fk.fkTable = t.getName();
-				fk.fkTableSchemaName = t.getSchemaName();
-				fk.fkColumns = Utils.newStringList(parts[0]);
+				fk.setFkTable(t.getName());
+				fk.setFkTableSchemaName(t.getSchemaName());
+				fk.setFkColumns(Utils.newStringList(parts[0]));
 				if(parts[1].contains(".")) {
 					String[] pkTableParts = parts[1].split("\\.");
 					log.debug("FKschema: "+parts[1]+"; pkTable.len: "+pkTableParts.length);
-					fk.pkTableSchemaName = pkTableParts[0];
+					fk.setPkTableSchemaName(pkTableParts[0]);
 					parts[1] = pkTableParts[1];
 				}
-				fk.pkTable = parts[1];
-				fk.pkColumns = Utils.newStringList(parts[2]);
+				fk.setPkTable(parts[1]);
+				fk.setPkColumns(Utils.newStringList(parts[2]));
 				if(parts.length>3) {
 					fk.setName(parts[3]);
 				}
 				else {
-					fk.setName(fk.fkTable + "_" + fk.pkTable + "_FK"); //XXX: suggestAcronym?
+					fk.setName(fk.getFkTable() + "_" + fk.getPkTable() + "_FK"); //XXX: suggestAcronym?
 				}
 				
 				//TODO: changing model... should clone() first
 			boolean isRoot = true;
 			boolean isLeaf = true;
 			for(FK fk: schemaModel.getForeignKeys()) {
-				if(fk.pkTable.equals(t.getName())) {
+				if(fk.getPkTable().equals(t.getName())) {
 					isRoot = false;
 				}
-				if(fk.fkTable.equals(t.getName())) {
+				if(fk.getFkTable().equals(t.getName())) {
 					isLeaf = false;
 					fks.add(fk);
 				}
 		boolean ok = true;
 		
 		for(FK fk: fks) {
-			if(fk.fkColumns.contains(c.getName())) {
+			if(fk.getFkColumns().contains(c.getName())) {
 				log.debug("column '"+c.getName()+"' belongs to FK. ignoring (as measure)");
 				ok = false; break;
 				//continue columnloop;
 	}
 	
 	void procDimension(Schema.Cube cube, FK fk, List<String> degenerateDimCandidates, SchemaModel schemaModel) {
-		if(fk.fkColumns.size()>1) {
+		if(fk.getFkColumns().size()>1) {
 			log.debug("fk "+fk+" is composite. ignoring");
 			return;
 		}
 		//pkTable.setSchema(fk.schemaName);
 		//pkTable.setName(fk.pkTable);
 		
-		String dimName = fk.pkTable;
+		String dimName = fk.getPkTable();
 		if(false) {
 			dimName = fk.getName();
 		}
 			return;
 		}
 
-		degenerateDimCandidates.remove(fk.fkColumns.get(0));
+		degenerateDimCandidates.remove(fk.getFkColumns().get(0));
 		procHierRecursiveInit(schemaModel, cube, fk, dimName);
 		
 		/*PrivateDimension dim = new PrivateDimension();
 	void procHierRecursiveInit(SchemaModel schemaModel, Schema.Cube cube, FK fk, String dimName) {
 		PrivateDimension dim = new PrivateDimension();
 		dim.setName(dimName);
-		dim.setForeignKey(sqlIdDecorator.get( fk.fkColumns.iterator().next() ));
+		dim.setForeignKey(sqlIdDecorator.get( fk.getFkColumns().iterator().next() ));
 		dim.setType("StandardDimension");
 		
 		List<HierarchyLevelData> levels = new ArrayList<HierarchyLevelData>();
-		procHierRecursive(schemaModel, cube, dim, fk, fk.getSchemaName(), fk.pkTable, levels);
+		procHierRecursive(schemaModel, cube, dim, fk, fk.getSchemaName(), fk.getPkTable(), levels);
 		
 		if(oneHierarchyPerDim && dim.getHierarchy().size() > 1) {
 			for(int i=dim.getHierarchy().size()-1; i >= 0; i--) {
 		thisLevels.addAll(levelsData);
 		boolean isLevelLeaf = true;
 
-		Table pkTable = DBIdentifiable.getDBIdentifiableByTypeSchemaAndName(schemaModel.getTables(), DBObjectType.TABLE, schemaName, fk.pkTable);
+		Table pkTable = DBIdentifiable.getDBIdentifiableByTypeSchemaAndName(schemaModel.getTables(), DBObjectType.TABLE, schemaName, fk.getPkTable());
 		if(pkTable==null) {
-			log.warn("table not found: "+schemaName+"."+fk.pkTable);
+			log.warn("table not found: "+schemaName+"."+fk.getPkTable());
 		}
 		
 		HierarchyLevelData level = new HierarchyLevelData();
 				level.levelNameColumn = levelNameColumn;
 			}
 			else {
-				log.warn("levelName column not found: "+levelNameColumn+" [table = "+schemaName+"."+fk.pkTable+"]");
+				log.warn("levelName column not found: "+levelNameColumn+" [table = "+schemaName+"."+fk.getPkTable()+"]");
 			}
 		}
 		else if(preferredLevelNameColumns!=null) {
 				}
 			}
 			else {
-				log.warn("table not found [2]: "+schemaName+"."+fk.pkTable);
+				log.warn("table not found [2]: "+schemaName+"."+fk.getPkTable());
 			}
 		}
-		level.levelColumn = fk.pkColumns.iterator().next();
+		level.levelColumn = fk.getPkColumns().iterator().next();
 		level.levelType = "Regular";
-		level.joinLeftKey = fk.fkColumns.iterator().next();
-		level.joinRightKey = fk.pkColumns.iterator().next();
+		level.joinLeftKey = fk.getFkColumns().iterator().next();
+		level.joinRightKey = fk.getPkColumns().iterator().next();
 		//level.joinPKTable = fk.pkTable;
-		level.levelTable = fk.pkTable;
+		level.levelTable = fk.getPkTable();
 		
 		log.debug("fkk: "+fk.toStringFull());
 		
 		//levels.add(level);
 
 		for(FK fkInt: schemaModel.getForeignKeys()) {
-			if(fkInt.fkTable.equals(pkTableName) && (fkInt.fkColumns.size()==1)) {
+			if(fkInt.getFkTable().equals(pkTableName) && (fkInt.getFkColumns().size()==1)) {
 				isLevelLeaf = false;
-				procHierRecursive(schemaModel, cube, dim, fkInt, schemaName, fkInt.pkTable, thisLevels);
+				procHierRecursive(schemaModel, cube, dim, fkInt, schemaName, fkInt.getPkTable(), thisLevels);
 				//isLeaf = false;
 				//fks.add(fkInt);
 			}

File src_xtra/tbrugz/sqldump/xtradumpers/AlterSchemaSuggester.java

View file
 			for(Table t: schemaModel.getTables()) {
 				boolean pkTable = false;
 				boolean fkTable = false;
-				if(t.getName().equals(fk.pkTable)) { pkTable = true; }
-				if(t.getName().equals(fk.fkTable)) { fkTable = true; }
+				if(t.getName().equals(fk.getPkTable())) { pkTable = true; }
+				if(t.getName().equals(fk.getFkTable())) { fkTable = true; }
 				if(! (pkTable || fkTable)) { continue; }
 				
 				//Index
 				for(Index idx: schemaModel.getIndexes()) {
-					if(! (idx.tableName.equals(fk.pkTable) || idx.tableName.equals(fk.fkTable))) { continue; }
+					if(! (idx.tableName.equals(fk.getPkTable()) || idx.tableName.equals(fk.getFkTable()))) { continue; }
 
 					Set<String> cols = new HashSet<String>();
 					cols.addAll(idx.columns);
-					if(idx.tableName.equals(fk.pkTable)) {
-						if(stringCollectionEquals(cols,fk.pkColumns)) { pkTableHasIndex = true; }
+					if(idx.tableName.equals(fk.getPkTable())) {
+						if(stringCollectionEquals(cols,fk.getPkColumns())) { pkTableHasIndex = true; }
 						//if(cols.equals(fk.pkColumns)) { pkTableHasIndex = true; }
 						//log.info("cols["+idx.tableName+"/pkt]: "+cols+" fk.pkCols: "+fk.pkColumns+"; hasI: "+pkTableHasIndex+"/"+stringCollectionEquals(cols, fk.pkColumns));
 					}
-					if(idx.tableName.equals(fk.fkTable)) { 
-						if(stringCollectionEquals(cols,fk.fkColumns)) { fkTableHasIndex = true; }
+					if(idx.tableName.equals(fk.getFkTable())) { 
+						if(stringCollectionEquals(cols,fk.getFkColumns())) { fkTableHasIndex = true; }
 						//if(cols.equals(fk.fkColumns)) { fkTableHasIndex = true; }
 						//log.info("cols["+idx.tableName+"/fkt]: "+cols+" fk.fkCols: "+fk.fkColumns+"; hasI: "+fkTableHasIndex+"/"+stringCollectionEquals(cols, fk.fkColumns));
 					}
 			
 			if(!pkTableHasIndex && !dumpFKIndexesOnly) {
 				Index idx = new Index();
-				idx.tableName = fk.pkTable;
-				idx.setSchemaName(fk.pkTableSchemaName);
+				idx.tableName = fk.getPkTable();
+				idx.setSchemaName(fk.getPkTableSchemaName());
 				idx.unique = false;
-				idx.columns.addAll(fk.pkColumns);
-				idx.setName(fk.pkTable + "_" + suggestAcronym(idx.columns) + "_UKI"); //_" + (indexes.size()+1);
+				idx.columns.addAll(fk.getPkColumns());
+				idx.setName(fk.getPkTable() + "_" + suggestAcronym(idx.columns) + "_UKI"); //_" + (indexes.size()+1);
 				addIndex(indexes, idx);
 			}
 
 			if(!fkTableHasIndex) {
 				Index idx = new Index();
-				idx.tableName = fk.fkTable;
-				idx.setSchemaName(fk.fkTableSchemaName);
+				idx.tableName = fk.getFkTable();
+				idx.setSchemaName(fk.getFkTableSchemaName());
 				idx.unique = false;
-				idx.columns.addAll(fk.fkColumns);
-				idx.setName(fk.fkTable + "_" + suggestAcronym(idx.columns) + "_FKI");
+				idx.columns.addAll(fk.getFkColumns());
+				idx.setName(fk.getFkTable() + "_" + suggestAcronym(idx.columns) + "_FKI");
 				//idx.name = fk.fkTable + "_FKI";
 				//idx.name = fk.fkTable + "_FKI_" + idx.hashCode();
 				//idx.name = fk.fkTable + "_FKI_" + (++fkIndexCounter);
 						
 						//Create FK
 						FK fk = new FK();
-						fk.pkTable = table.getName();
-						fk.pkTableSchemaName = table.getSchemaName();
-						fk.pkColumns.addAll(cons.uniqueColumns);
-						fk.fkTable = otherT.getName();
-						fk.fkTableSchemaName = otherT.getSchemaName();
-						fk.fkColumns.addAll(cons.uniqueColumns);
+						fk.setPkTable( table.getName() );
+						fk.setPkTableSchemaName( table.getSchemaName() );
+						fk.getPkColumns().addAll(cons.uniqueColumns);
+						fk.setFkTable( otherT.getName() );
+						fk.setFkTableSchemaName( otherT.getSchemaName() );
+						fk.getFkColumns().addAll(cons.uniqueColumns);
 						fk.fkReferencesPK = (cons.type==ConstraintType.PK);
-						fk.setName(suggestAcronym(fk.fkTable) + "_" + suggestAcronym(fk.pkTable) + "_FK");
+						fk.setName(suggestAcronym(fk.getFkTable()) + "_" + suggestAcronym(fk.getFkTable()) + "_FK");
 
 						//Test if FK already exists
 						boolean fkAlreadyExists = false;
 	int writeFKs(Set<FK> fks, CategorizedOut fos) throws IOException {
 		int dumpCounter = 0;
 		for(FK fk: fks) {
-			if(schemasToAlter==null || (schemasToAlter!=null && schemasToAlter.contains(fk.fkTableSchemaName))) {
+			if(schemasToAlter==null || (schemasToAlter!=null && schemasToAlter.contains(fk.getFkTableSchemaName()))) {
 				fos.categorizedOut(SchemaModelScriptDumper.fkScriptWithAlterTable(fk, false, true), fk.getSchemaName(), DBObjectType.FK.toString() );
 				//fos.write( fk.getDefinition(true)+";\n\n" );
 				dumpCounter++;

File src_xtra/tbrugz/sqldump/xtradumpers/DropScriptDumper.java

View file
 	public void dumpDropFKs(SchemaModel schemaModel, CategorizedOut co) throws IOException {
 		String fkcat = DBObjectType.FK.toString();
 		for(FK fk: schemaModel.getForeignKeys()) {
-			String script = "alter table "+fk.fkTable+" drop constraint "+fk.getName()+";\n";
+			String script = "alter table "+fk.getFkTable()+" drop constraint "+fk.getName()+";\n";
 			co.categorizedOut(script, fk.getSchemaName(), fkcat);
 		}
 	}

File src_xtra/tbrugz/sqldump/xtraproc/ModelSQLIdTransformer.java

View file
 		}
 		for(FK fk: model.getForeignKeys()) {
 			fk.setName( identifierDecorator.get(fk.getName()) );
-			fk.pkTable = identifierDecorator.get( fk.pkTable );
-			fk.fkTable = identifierDecorator.get( fk.fkTable );
-			procList(fk.fkColumns, identifierDecorator);
-			procList(fk.pkColumns, identifierDecorator);
+			fk.setPkTable( identifierDecorator.get( fk.getPkTable() ) );
+			fk.setFkTable( identifierDecorator.get( fk.getFkTable() ) );
+			procList(fk.getFkColumns(), identifierDecorator);
+			procList(fk.getPkColumns(), identifierDecorator);
 		}
 		for(Index i: model.getIndexes()) {
 			i.setName( identifierDecorator.get(i.getName()) );