Commits

tbrugz  committed 52efef4

datadump: added clone() to DumpSyntax ; fixed datadump for stateful dumpers (ffc)

  • Participants
  • Parent commits e516f0a

Comments (0)

Files changed (3)

File src/tbrugz/sqldump/datadump/DataDump.java

 				String filename = getDynamicFileName(prop, tableOrQueryId, ds.getSyntaxId());
 
 				//TODO: remove when multiple partition-patterns for stateful syntaxes is implemented
-				if(ds.isStateful()) {
+				/*if(ds.isStateful()) {
 					if(partitionByPatterns.length>1) {
 						log.warn("syntax "+ds.getSyntaxId()+" is stateful and not ready for dumping queries with multiple partition-patterns");
 						continue;
 					}
-				}
+				}*/
 				
 				if(filename==null) {
 					log.warn("no output file defined for syntax '"+ds.getSyntaxId()+"'");
 			}
 			
 			Map<String, String> lastPartitionIdByPartitionPattern = new HashMap<String, String>();
-			//Map<String, DumpSyntax> statefulDumpSyntaxes = new HashMap<String, DumpSyntax>();
-			Set<DumpSyntax> hasWarnedAboutNonimplementedStatefulness = new HashSet<DumpSyntax>();
+			Map<String, DumpSyntax> statefulDumpSyntaxes = new HashMap<String, DumpSyntax>();
+			//Set<DumpSyntax> hasWarnedAboutNonimplementedStatefulness = new HashSet<DumpSyntax>();
 			Map<String, Long> countInPartitionByPattern = new HashMap<String, Long>();
 			for(int partIndex = 0; partIndex<partitionByPatterns.length ; partIndex++) {
 				countInPartitionByPattern.put(partitionByPatterns[partIndex], 0l);
 							
 							if(ds.isStateful()) {
 								//TODO: implement dumping queries with multiple partition-patterns for stateful syntaxes 
-								if(partitionByPatterns.length>1) {
+								/*if(partitionByPatterns.length>1) {
 									if(!hasWarnedAboutNonimplementedStatefulness.contains(ds)) {
 										log.warn("syntax "+ds.getSyntaxId()+" is stateful and not ready for dumping queries with multiple partition-patterns");
 										hasWarnedAboutNonimplementedStatefulness.add(ds);
 									}
 									continue;
+								}*/
+								String dskey = ds.getSyntaxId()+"$"+partitionByPattern;
+								DumpSyntax ds2 = statefulDumpSyntaxes.get(dskey);
+								if(ds2==null) {
+									ds2 = (DumpSyntax) ds.clone();
+									statefulDumpSyntaxes.put(dskey, ds2);
 								}
-								/*DumpSyntax ds2 = statefulDumpSyntaxes.get(ds.getSyntaxId()+"$"+partitionByPattern);
-								if(ds2==null) {
-									//create/clone dumper... what abount header line?
-								}*/
+								ds = ds2;
 							}
 							
 							String finalFilename = getFinalFilenameForAbstractFilename(filenameList.get(i), partitionByStrId);

File src/tbrugz/sqldump/datadump/DumpSyntax.java

 		return false;
 	}
 	
+	@Override
+	public Object clone() throws CloneNotSupportedException {
+		return super.clone();
+	}
+	
+	public void copyPropsTo(DumpSyntax ds) {
+		ds.dateFormatter = this.dateFormatter;
+		ds.floatFormatter = this.floatFormatter;
+		ds.nullValueStr = this.nullValueStr;
+	}
+	
 	//XXX: methods dumpDocHeader, dumpDocFooter -- before dumpHeader/Footer, for dumps with multiple ResultSet
 	
 	//XXX: method supportResultSetDump()?

File src/tbrugz/sqldump/datadump/FFCDataDump.java

 /**
  * FFC: Formatted Fixed Column
  */
-public class FFCDataDump extends DumpSyntax {
+public class FFCDataDump extends DumpSyntax implements Cloneable {
 
 	static final String PROP_DATADUMP_FFC_COLUMNDELIMITER = "sqldump.datadump.ffc.columndelimiter";
 	static final String PROP_DATADUMP_FFC_LINEGROUPSIZE = "sqldump.datadump.ffc.linegroupsize";
 
 	static final String FFC_SYNTAX_ID = "ffc";
 	//static final String DEFAULT_NULL_VALUE = "";
-	static Log log = LogFactory.getLog(FFCDataDump.class);
+	static final Log log = LogFactory.getLog(FFCDataDump.class);
 	
 	static final String recordDemimiter = "\n";
 	
-	int numCol;
+	transient int numCol;
 	List<String> lsColNames = new ArrayList<String>();
 	List<Class> lsColTypes = new ArrayList<Class>();
 	boolean showColNames = true, showColNamesLines = true;
 	
 	int lineGroupSize = 20;
 	String separator = " | ";
-	//String nullValue = DEFAULT_NULL_VALUE;
-
-	//List<Integer> headersColsMaxLenght = new ArrayList<Integer>();
+	List<Boolean> leftAlignField = new ArrayList<Boolean>();
+	
+	//"stateful" props
 	List<Integer> colsMaxLenght = new ArrayList<Integer>();
 	List<List<String>> valuesBuffer = new ArrayList<List<String>>();
-	List<Boolean> leftAlignField = new ArrayList<Boolean>();
+	//end stateful props
 	
 	@Override
 	public void dumpHeader(Writer fos) {
 	public String getDefaultFileExtension() {
 		return "ffc.txt";
 	}
+	
+	@Override
+	public Object clone() throws CloneNotSupportedException {
+		FFCDataDump newffc = new FFCDataDump();
+		super.copyPropsTo(newffc);
+		
+		//procproperties props
+		newffc.lineGroupSize = this.lineGroupSize;
+		newffc.separator = this.separator;
+		newffc.showColNames = this.showColNames;
+		newffc.showColNamesLines = this.showColNamesLines;
+		//initDump props
+		newffc.numCol = this.numCol;
+		newffc.lsColNames = this.lsColNames;
+		newffc.lsColTypes = this.lsColTypes;
+		newffc.leftAlignField = this.leftAlignField;
+		//setup
+		newffc.clearBuffer();
+		
+		return newffc;
+	}
 
 	@Override
 	public String getMimeType() {