1. tbrugz
  2. sqldump

Commits

tbrugz  committed b17e9e4

sqldump: jdbcgrabber: added tablefilter ; added maxlevel for recursive table grabbing

  • Participants
  • Parent commits 98c5ad4
  • Branches default

Comments (0)

Files changed (2)

File sqldump.template.properties

View file
 # schema names to dump
 sqldump.dumpschemapattern=<DW, SA, EMPDEPT>
 
+# filter tables by name
+sqldump.schemagrab.tablefilter=TABLE_X, TABLE_Y
+
 # exclude table filters (regex), splitted by "|"
 #sqldump.schemadump.tablename.excludes=EMPT.* | .*_OLD | ZZZ_.* 
 
-# recursive dump (grab) of tables based on FKs, defaults below
+# recursive dump (grab) of tables based on FKs, defaults below (default maxlevel is null)
 #sqldump.doschemadump.recursivedumpbasedonfks=false
 #sqldump.doschemadump.recursivedumpbasedonfks.exportedfks=false
+#sqldump.doschemadump.recursivedumpbasedonfks.maxlevel=3
 #sqldump.doschemadump.recursivedumpbasedonfks.deep=false
 
 #

File src/tbrugz/sqldump/JDBCSchemaGrabber.java

View file
 	
 	static final String PROP_DO_SCHEMADUMP_RECURSIVEDUMP = "sqldump.doschemadump.recursivedumpbasedonfks";
 	static final String PROP_DO_SCHEMADUMP_RECURSIVEDUMP_DEEP = "sqldump.doschemadump.recursivedumpbasedonfks.deep";
+	static final String PROP_DO_SCHEMADUMP_RECURSIVEDUMP_MAXLEVEL = "sqldump.doschemadump.recursivedumpbasedonfks.maxlevel";
 	static final String PROP_DO_SCHEMADUMP_RECURSIVEDUMP_EXPORTEDFKS = "sqldump.doschemadump.recursivedumpbasedonfks.exportedfks";
 
 	static final String PROP_SCHEMADUMP_DOMAINTABLES = "sqldump.schemainfo.domaintables";
+	static final String PROP_SCHEMADUMP_TABLEFILTER = "sqldump.schemagrab.tablefilter";
 	static final String PROP_SCHEMADUMP_EXCLUDETABLES = "sqldump.schemadump.tablename.excludes";
 	
 	static final String PROP_DUMP_DBSPECIFIC = "sqldump.usedbspecificfeatures";
 			doSchemaGrabIndexes = false,
 			doSchemaGrabDbSpecific = false;
 	
+	Long maxLevel = null;
+	
 	@Override
 	public void procProperties(Properties prop) {
 		log.info("init JDBCSchemaGrabber...");
 		doSchemaGrabGrants = Utils.getPropBool(papp, PROP_DO_SCHEMADUMP_GRANTS, doSchemaGrabGrants);
 		doSchemaGrabIndexes = Utils.getPropBool(papp, PROP_DO_SCHEMADUMP_INDEXES, doSchemaGrabIndexes);
 		doSchemaGrabDbSpecific = Utils.getPropBool(papp, PROP_DUMP_DBSPECIFIC, doSchemaGrabDbSpecific);
+		maxLevel = Utils.getPropLong(papp, PROP_DO_SCHEMADUMP_RECURSIVEDUMP_MAXLEVEL);
 
 		/*try {
 			dbmsSpecificResource.load(JDBCSchemaGrabber.class.getClassLoader().getResourceAsStream(SQLDump.DBMS_SPECIFIC_RESOURCE));
 		
 		schemaModel.setSqlDialect(DBMSResources.instance().dbid());
 
+		List<String> tablePatterns = Utils.getStringListFromProp(papp, PROP_SCHEMADUMP_TABLEFILTER, ","); 
 		for(String schemaName: schemasList) {
-			grabRelations(schemaModel, dbmd, feats, schemaName, null, false);
+			if(tablePatterns==null) {
+				grabRelations(schemaModel, dbmd, feats, schemaName, null, false);
+			}
+			else {
+				for(String tableName: tablePatterns) {
+					grabRelations(schemaModel, dbmd, feats, schemaName, tableName, false);
+				}
+			}
 		}
 		
 		boolean recursivedump = Utils.getPropBool(papp, PROP_DO_SCHEMADUMP_RECURSIVEDUMP, false);
 		if(recursivedump) {
 			boolean grabExportedFKsAlso = Utils.getPropBool(papp, PROP_DO_SCHEMADUMP_RECURSIVEDUMP_EXPORTEDFKS, false);
 			int lastTableCount = schemaModel.getTables().size();
-			log.info("grabbing tables recursively: #ini:"+lastTableCount);
+			int level = 0;
+			log.info("grabbing tables recursively["+level+"]: #ini:"+lastTableCount
+					+(maxLevel!=null?" [maxlevel="+maxLevel+"]":" [maxlevel not defined]"));
 			while(true) {
+				level++;
 				grabTablesRecursivebasedOnFKs(dbmd, feats, schemaModel, schemaPattern, grabExportedFKsAlso);
+				
 				int newTableCount = schemaModel.getTables().size();
-				if(newTableCount <= lastTableCount) { break; }
-				log.info("grabbing tables recursively: #last:"+lastTableCount+" #now:"+newTableCount);
+				boolean wontGrowMore = (newTableCount <= lastTableCount);
+				boolean maxLevelReached = (maxLevel!=null && level>=maxLevel);
+				log.info("grabbing tables recursively["+level+"]: #last:"+lastTableCount+" #now:"+newTableCount
+						+(wontGrowMore?" [won't grow more]":"")
+						+(maxLevelReached?" [maxlevel reached]":"")
+						);
+				if(wontGrowMore || maxLevelReached) { break; }
 				lastTableCount = newTableCount;
 			}
 		}