Commits

tbrugz committed a491aca

processor: SchemaModelTransformer: added suffix '.remove-views-definitions'

Comments (0)

Files changed (2)

sqldump.template.properties

 #sqldump.modeltransform.removeschemaname=false
 # removes tables with referencing FKs
 #sqldump.modeltransform.removetableswithfks=TABLE_A, TABLE_B
+# remove views' definitions (sql query)
+#sqldump.modeltransform.remove-views-definitions=true
 # removes FKs by name
 #sqldump.modeltransform.removefksbyname=FK1, EMP_DEPT_FK, ...
 # adds xtra FKs to table <fktable>

src/tbrugz/sqldump/processors/SchemaModelTransformer.java

 import tbrugz.sqldump.dbmodel.DBIdentifiable;
 import tbrugz.sqldump.dbmodel.FK;
 import tbrugz.sqldump.dbmodel.Table;
+import tbrugz.sqldump.dbmodel.View;
 import tbrugz.sqldump.def.AbstractSchemaProcessor;
 import tbrugz.sqldump.util.Utils;
 import tbrugz.util.LongFactory;
 	
 	static final String SUFFIX_REMOVE_SCHEMANAME = ".removeschemaname";
 	static final String SUFFIX_REMOVE_FKS_BYNAME = ".removefksbyname";
-	static final String SUFFIX_REMOVE_TABLES_WITH_FKS = ".removetableswithfks";
+	static final String SUFFIX_REMOVE_TABLES_WITH_FKS = ".removetableswithfks"; //remove tables with *their* fks
+	static final String SUFFIX_REMOVE_VIEWS_DEFINITIONS = ".remove-views-definitions";
 	
 	//XXX option to remove FKs that references non-existent tables?
 	//XXX option to remove FKs from/to table?
 	String prefix = DEFAULT_PREFIX;
 	
 	boolean doRemoveSchemaName = false;
+	boolean doRemoveViewsDefinitions = false;
 	
 	@Override
 	public void setProperties(Properties prop) {
 		super.setProperties(prop);
 		doRemoveSchemaName = Utils.getPropBool(prop, prefix+SUFFIX_REMOVE_SCHEMANAME, doRemoveSchemaName);
+		doRemoveViewsDefinitions = Utils.getPropBool(prop, prefix+SUFFIX_REMOVE_VIEWS_DEFINITIONS, doRemoveSchemaName);
 	}
 
 	@Override
 			removeTablesWithFKs(tablesToRemove);
 		}
 		
+		//views
+		if(doRemoveViewsDefinitions) {
+			removeViewsDefinitions();
+		}
+		//XXX prop to remove parameterCount, parameterValues?
+		
 		//fks
 		removeFKs();
 		addFKs();
 			log.info("remove: tables not found: "+removeTables);
 		}
 	}
+	
+	void removeViewsDefinitions() {
+		Set<View> views = model.getViews();
+		int count = 0;
+		for(View v: views) {
+			v.setQuery(null);
+			count++;
+		}
+		if(count>0) {
+			log.info(count+" views' definitions removed");
+		}
+	}
 }