1 21 22 package org.apache.derby.impl.load; 23 24 import java.sql.Connection ; 25 import java.sql.ResultSet ; 26 import java.io.IOException ; 27 import java.sql.SQLException ; 28 import java.util.*; 29 30 35 public class Export extends ExportAbstract{ 36 37 private String outputFileName; 38 39 40 private void doExport() throws SQLException 41 { 42 try { 43 if (entityName == null && selectStatement == null) 44 throw LoadError.entityNameMissing(); 45 46 if (outputFileName == null) 47 throw LoadError.dataFileNull(); 48 try { 49 doAllTheWork(); 50 } catch (IOException iex) { 51 throw LoadError.errorWritingData(); 53 } 54 } catch (Exception ex) { 55 throw LoadError.unexpectedError(ex); 56 } 57 58 } 59 60 private Export(Connection con, String schemaName , 61 String tableName, String selectStatement , 62 String outputFileName, String characterDelimeter, 63 String columnDelimeter, String codeset) 64 throws SQLException { 65 this.con = con; 66 this.schemaName = schemaName; 67 this.entityName = tableName; 68 this.selectStatement = selectStatement; 69 this.outputFileName = outputFileName; 70 try{ 71 controlFileReader = new ControlInfo(); 72 controlFileReader.setControlProperties(characterDelimeter, 73 columnDelimeter, codeset); 74 }catch(Exception ex) 75 { 76 throw LoadError.unexpectedError(ex); 77 } 78 } 79 80 92 93 public static void exportTable(Connection con, String schemaName, 94 String tableName, String outputFileName, 95 String columnDelimeter, String characterDelimeter, 96 String codeset) 97 throws SQLException { 98 99 Export fex = new Export(con, schemaName, tableName, null, 100 outputFileName, characterDelimeter, 101 columnDelimeter, codeset); 102 103 fex.doExport(); 104 } 105 106 107 118 public static void exportQuery(Connection con, String selectStatement, 119 String outputFileName, String columnDelimeter, 120 String characterDelimeter, String codeset) 121 throws SQLException { 122 123 Export fex = new Export(con, null, null, selectStatement, 124 outputFileName,characterDelimeter, 125 columnDelimeter, codeset); 126 fex.doExport(); 127 } 128 129 130 134 protected ExportWriteDataAbstract getExportWriteData() throws Exception { 136 return new ExportWriteData(outputFileName, controlFileReader); 137 } 138 } 139 140 141 142 143 144 145 | Popular Tags |