1 21 22 package org.apache.derby.impl.load; 23 24 import java.sql.Connection ; 25 import java.sql.ResultSet ; 26 import java.sql.ResultSetMetaData ; 27 import java.sql.Types ; 28 import java.util.Date ; 29 30 34 abstract class ExportAbstract { 35 36 protected ControlInfo controlFileReader; 37 protected ExportResultSetForObject exportResultSetForObject; 38 protected ExportWriteDataAbstract exportWriteData; 39 protected Connection con; 40 protected String entityName; protected String schemaName; 42 protected String selectStatement ; 43 44 45 protected ResultSet resultSetForEntity() throws Exception { 47 exportResultSetForObject = new ExportResultSetForObject(con, schemaName, 48 entityName, 49 selectStatement); 50 51 ResultSet rs = exportResultSetForObject.getResultSet(); 52 return rs; 53 } 54 55 public String [] getOneRowAtATime(ResultSet rs) throws Exception { 57 int columnCount = exportResultSetForObject.getColumnCount(); 58 59 ResultSetMetaData rsm=rs.getMetaData(); 60 if (rs.next()){ 61 String [] rowObjects = new String [columnCount]; 62 for (int colNum = 0; colNum < columnCount; colNum++) { 63 rowObjects[colNum]=rs.getString(colNum + 1); 64 } 65 return rowObjects; 66 } 67 rs.close(); 68 exportResultSetForObject.close(); 69 return null; 70 } 71 72 protected ControlInfo getControlFileReader(){ 74 return controlFileReader; 75 } 76 77 protected abstract ExportWriteDataAbstract getExportWriteData() throws Exception ; 78 79 protected void doAllTheWork() throws Exception { 80 81 ResultSet rs = null; 82 try { 83 rs = resultSetForEntity(); 84 if (rs != null) { 85 ResultSetMetaData rsmeta = rs.getMetaData(); 86 int ncols = rsmeta.getColumnCount(); 87 boolean[] isNumeric = new boolean[ncols]; 88 for (int i = 0; i < ncols; i++) { 89 int ctype = rsmeta.getColumnType(i+1); 90 if (ctype == Types.BIGINT || ctype == Types.DECIMAL || ctype == Types.DOUBLE || 91 ctype == Types.FLOAT ||ctype == Types.INTEGER || ctype == Types.NUMERIC || 92 ctype == Types.REAL ||ctype == Types.SMALLINT || ctype == Types.TINYINT) 93 isNumeric[i] = true; 94 else 95 isNumeric[i] = false; 96 } 97 exportWriteData = getExportWriteData(); 98 exportWriteData.writeColumnDefinitionOptionally( 99 exportResultSetForObject.getColumnDefinition(), 100 exportResultSetForObject.getColumnTypes()); 101 exportWriteData.setColumnLengths(controlFileReader.getColumnWidths()); 102 103 String [] oneRow = getOneRowAtATime(rs); 105 while (oneRow != null) { 106 exportWriteData.writeData(oneRow, isNumeric); 107 oneRow = getOneRowAtATime(rs); 108 } 109 } 110 } finally { 111 if (exportWriteData != null) 113 exportWriteData.noMoreRows(); 114 if (rs != null) 115 rs.close(); 116 } 117 } 118 119 120 } 121 | Popular Tags |