Commits

tbrugz committed a71bab6

sqldump/queries: added query-specific dump syntax prop: 'sqldump.query.<query-id>.dumpsyntaxes'

  • Participants
  • Parent commits c9139a2

Comments (0)

Files changed (3)

sqldump.template.properties

 #sqldump.query.table_x.rowlimit=10000
 #sqldump.query.table_x.keycols=ID
 #sqldump.query.table_x.param.1=3
+# query dump syntaxes takes precedence over default datadump syntaxes (sqldump.datadump.dumpsyntaxes)
+#sqldump.query.table_x.dumpsyntaxes=csv, json, xml
 
 #sqldump.query.q2.sqlfile=c:/xxx/query2.sql
 #sqldump.query.q2.name=query_2

src/tbrugz/sqldump/SQLDump.java

  * XXXxx: error dumping blobs
  * XXXxx: add support for blobs (BlobDataDump)
  * XXXxx: add support for cursor in sql (ResultSet as a column type): [x] xml, [x] html, [x] json dumpers
- * XXX: option for queries (or specific queries) to have specific syntax-dumpers
+ * XXX: option for queries to have specific syntax-dumpers
+ * XXXdone: option for specific queries to have specific syntax-dumpers
  * XXX: filter tables/executables/trigger (/index/view/mv/sequence ?) by name (include only/exclude)
  * TODO: output ffc with optional trimming
  * TODO: use sql quote when names are equal to sql keywords or have invalid characters (" ", "-", ...) - SchemaModelScriptDumper, AlterSchemaSuggestion

src/tbrugz/sqldump/datadump/SQLQueries.java

 		Long globalRowLimit = Utils.getPropLong(prop, DataDump.PROP_DATADUMP_ROWLIMIT);
 		String charset = prop.getProperty(DataDump.PROP_DATADUMP_CHARSET, DataDump.CHARSET_DEFAULT);
 		//boolean dumpInsertInfoSyntax = false, dumpCSVSyntax = false, dumpXMLSyntax = false, dumpJSONSyntax = false;
-		String syntaxes = prop.getProperty(DataDump.PROP_DATADUMP_SYNTAXES);
-		if(syntaxes==null) {
-			log.warn("no datadump syntax defined");
-			return;
-		}
-		String[] syntaxArr = syntaxes.split(",");
-		List<DumpSyntax> syntaxList = new ArrayList<DumpSyntax>();
-		for(String syntax: syntaxArr) {
-			boolean syntaxAdded = false;
-			for(Class<? extends DumpSyntax> dsc: DumpSyntax.getSyntaxes()) {
-				DumpSyntax ds = (DumpSyntax) Utils.getClassInstance(dsc);
-				if(ds!=null && ds.getSyntaxId().equals(syntax.trim())) {
-					ds.procProperties(prop);
-					syntaxList.add(ds);
-					syntaxAdded = true;
-				}
-			}
-			if(!syntaxAdded) {
-				log.warn("unknown datadump syntax: "+syntax.trim());
-			}
-		}
-
+		
 		String queriesStr = prop.getProperty(PROP_QUERIES);
 		if(queriesStr==null) {
 			log.warn("prop '"+PROP_QUERIES+"' not defined");
 		int i=0;
 		for(String qid: queriesArr) {
 			qid = qid.trim();
+			
+			String queryName = prop.getProperty("sqldump.query."+qid+".name");
+			List<DumpSyntax> syntaxList = getQuerySyntexes(qid);
+			if(syntaxList==null) {
+				log.warn("no dump syntax defined for query "+queryName+" [id="+qid+"]");
+				continue;
+			}
 			//replace strings
 			int replaceCount = 1;
 			//List<String> replacers = new ArrayList<String>();
 				//replace props! XXX: replaceProps(): should be activated by a prop?
 				sql = ParametrizedProperties.replaceProps(sql, prop);
 			}
-			String queryName = prop.getProperty("sqldump.query."+qid+".name");
 			if(sql==null || queryName==null) { break; }
 			//params
 			int paramCount = 1;
 		log.info(i+" queries runned");
 	}
 	
+	List<DumpSyntax> getQuerySyntexes(String qid) {
+		String syntaxes = prop.getProperty("sqldump.query."+qid+".dumpsyntaxes");
+		if(syntaxes==null) {
+			syntaxes = prop.getProperty(DataDump.PROP_DATADUMP_SYNTAXES);
+		}
+		if(syntaxes==null) {
+			return null;
+		}
+		String[] syntaxArr = syntaxes.split(",");
+		List<DumpSyntax> syntaxList = new ArrayList<DumpSyntax>();
+		for(String syntax: syntaxArr) {
+			boolean syntaxAdded = false;
+			for(Class<? extends DumpSyntax> dsc: DumpSyntax.getSyntaxes()) {
+				DumpSyntax ds = (DumpSyntax) Utils.getClassInstance(dsc);
+				if(ds!=null && ds.getSyntaxId().equals(syntax.trim())) {
+					ds.procProperties(prop);
+					syntaxList.add(ds);
+					syntaxAdded = true;
+				}
+			}
+			if(!syntaxAdded) {
+				log.warn("unknown datadump syntax: "+syntax.trim());
+			}
+		}
+		return syntaxList;
+	}
+	
 }