Commits

tbrugz  committed 93bc49b

datadump: narrowing DumpSyntax & its subclasses & SQLUtils throws clause

  • Participants
  • Parent commits 1ee0949

Comments (0)

Files changed (11)

File src/tbrugz/sqldump/SQLUtils.java

 		public static final String SUFFIX_ASKFORPASSWD_GUI = ".askforpasswordgui";
 		public static final String SUFFIX_INITSQL = ".initsql";
 
-		public static Connection initDBConnection(String propsPrefix, Properties papp) throws Exception {
+		public static Connection initDBConnection(String propsPrefix, Properties papp) throws ClassNotFoundException, SQLException {
 			return initDBConnection(propsPrefix, papp, false);
 		}
 
-		public static Connection initDBConnection(String propsPrefix, Properties papp, boolean autoCommit) throws Exception {
+		public static Connection initDBConnection(String propsPrefix, Properties papp, boolean autoCommit) throws ClassNotFoundException, SQLException {
 			//init database
 			log.debug("initDBConnection...");
 			

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

 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
 import java.sql.Blob;
 
 	@Override
 	public void initDump(String tableName, List<String> pkCols,
-			ResultSetMetaData md) throws Exception {
+			ResultSetMetaData md) throws SQLException {
 		this.tableName = tableName;
 		this.pkCols = pkCols;
 		
 	}
 
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) {
 	}
 	
 	//XX: prop for setting ROWID_JOINER
 	public static String ROWID_JOINER = "_";
 	
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer writer) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer writer) throws IOException, SQLException {
 		if(pkCols==null) { return; }
 		
 		List<String> pkVals = new ArrayList<String>();
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) {
 	}
 	
 	@Override

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

 import java.io.Writer;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 	}
 	
 	@Override
-	public void initDump(String tableName, List<String> pkCols, ResultSetMetaData md) throws Exception {
+	public void initDump(String tableName, List<String> pkCols, ResultSetMetaData md) throws SQLException {
 		this.tableName = tableName;
 		this.md = md;
 		numCol = md.getColumnCount();		
 	}
 
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) throws IOException {
 		//headers
 		if(doTableNameHeaderDump) {
 			out("[table "+tableName+"]", fos, recordDelimiter);
 		if(doColumnNamesHeaderDump) {
 			StringBuffer sb = new StringBuffer();
 			for(int i=0;i<numCol;i++) {
-				sb.append( (i!=0?columnDelimiter:"") + md.getColumnName(i+1));
+				sb.append( (i!=0?columnDelimiter:"") + lsColNames.get(i));
 			}
 			out(sb.toString(), fos, recordDelimiter);
 		}
 	static boolean resultSetWarned = false;
 	
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		StringBuffer sb = new StringBuffer();
 		List vals = SQLUtils.getRowObjectListFromRS(rs, lsColTypes, numCol);
 		for(int i=0;i<lsColTypes.size();i++) {
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) {
 		//do nothing
 	}
 	

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

 package tbrugz.sqldump.datadump;
 
+import java.io.IOException;
 import java.io.Writer;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 		return buffer.toString();
 	}
 
-	public static void dumpRS(DumpSyntax ds, ResultSetMetaData rsmd, ResultSet rs, String tableName, Writer writer, boolean resetRS) throws Exception {
+	public static void dumpRS(DumpSyntax ds, ResultSetMetaData rsmd, ResultSet rs, String tableName, Writer writer, boolean resetRS) throws IOException, SQLException {
 		//int ncol = rsmd.getColumnCount();
 		ds.initDump(tableName, null, rsmd);
 		ds.dumpHeader(writer);

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

 package tbrugz.sqldump.datadump;
 
+import java.io.IOException;
 import java.io.Writer;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
 import java.text.DateFormat;
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 		return getSyntaxId();
 	}
 	
-	public abstract void initDump(String tableName, List<String> pkCols, ResultSetMetaData md) throws Exception;
+	public abstract void initDump(String tableName, List<String> pkCols, ResultSetMetaData md) throws SQLException;
 	
-	public abstract void dumpHeader(Writer fos) throws Exception;
+	public abstract void dumpHeader(Writer fos) throws IOException;
 
-	public abstract void dumpRow(ResultSet rs, long count, Writer fos) throws Exception;
+	public abstract void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException;
 
-	public abstract void dumpFooter(Writer fos) throws Exception;
+	public abstract void dumpFooter(Writer fos) throws IOException;
 
-	public void flushBuffer(Writer fos) throws Exception {}
+	public void flushBuffer(Writer fos) throws IOException {}
 	
 	/**
 	 * Should return true if responsable for creating output files

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

 	List<Boolean> leftAlignField = new ArrayList<Boolean>();
 	
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) {
 		setColMaxLenghtForColNames();
 	}
 	
 	static boolean resultSetWarned = false;
 	
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		//first count is equal 0
 		if(count%lineGroupSize==0) {
 			dumpBuffer(fos);
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) throws IOException {
 		//setColMaxLenghtForColNames();
 		dumpBuffer(fos);
 	}
 	
 	@Override
-	public void flushBuffer(Writer fos) throws Exception {
+	public void flushBuffer(Writer fos) throws IOException {
 		if(valuesBuffer.size()<=0) { return; } //not needed now: dumpBuffer() already does it
 		dumpBuffer(fos);
 	}

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

 	}
 	
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) throws IOException {
 		if(prepend!=null) { out(prepend, fos); }
 		out("<table class='"+tableName+"'>", fos);
 		StringBuffer sb = new StringBuffer();
 	}
 
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		StringBuffer sb = new StringBuffer();
 		sb.append("\t"+"<tr>");
 		List vals = SQLUtils.getRowObjectListFromRS(rs, lsColTypes, numCol, true);
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) throws IOException {
 		out("</table>", fos);
 		if(append!=null) { out(append, fos); }
 	}

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

 	}
 
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		List vals = SQLUtils.getRowObjectListFromRS(rs, lsColTypes, numCol);
 		out("insert into "+tableName+" "+
 			colNames+" values ("+
 	}
 
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) {
 		//do nothing
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) {
 		//do nothing
 	}
 

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

  *      http://msdn.microsoft.com/en-us/library/bb299886.aspx 
  *      
  * TODO: option to output as hash (using pkcols)
+ * TODO: add prepend/append (JSONP option) / ?callback=xxx
  */
 public class JSONDataDump extends DumpSyntax {
 
 	}
 	
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) throws IOException {
 		if(tableName!=null) {
 			outNoPadding("{ \""+tableName+"\": "
 				+(this.pkCols!=null?"{":"[")
 	}
 
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		StringBuffer sb = new StringBuffer();
 		sb.append("\t"+(count==0?"":","));
 		if(this.pkCols!=null) {
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) throws IOException {
 		if(tableName!=null) {
 			out((usePK?"}":"]")+"}",fos);
 		}

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

 package tbrugz.sqldump.datadump;
 
+import java.io.IOException;
 import java.io.Writer;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 	}
 	
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		if(pkCols==null) { return; }
 		
 		List<String> vals = (List<String>) DataDumpUtils.values4sql( SQLUtils.getRowObjectListFromRS(rs, lsColTypes, numCol), dateFormatter );

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

 	}
 	
 	@Override
-	public void dumpHeader(Writer fos) throws Exception {
+	public void dumpHeader(Writer fos) throws IOException {
 		//XXX: add xml declaration? optional? e.g.: <?xml version="1.0" encoding="UTF-8" ?>
 		//see http://www.w3.org/TR/REC-xml/#NT-XMLDecl
 		//    http://www.ibm.com/developerworks/xml/library/x-tipdecl/index.html
 	}
 
 	@Override
-	public void dumpRow(ResultSet rs, long count, Writer fos) throws Exception {
+	public void dumpRow(ResultSet rs, long count, Writer fos) throws IOException, SQLException {
 		StringBuffer sb = new StringBuffer();
 		//XXX: option to define 'row' xml-element
 		sb.append("\t"+"<row>");
 	}
 
 	@Override
-	public void dumpFooter(Writer fos) throws Exception {
+	public void dumpFooter(Writer fos) throws IOException {
 		out("</"+tableName+">", fos);
 	}