1 21 22 package org.apache.derby.impl.load; 23 24 import java.sql.SQLException ; 25 import java.sql.SQLWarning ; 26 import java.sql.ResultSetMetaData ; 27 import org.apache.derby.vti.VTITemplate; 28 import java.util.ArrayList ; 29 30 34 abstract class ImportAbstract extends VTITemplate { 35 36 ControlInfo controlFileReader; 37 ImportReadData importReadData; 38 39 String [] columnNames; 40 int numberOfColumns; 41 int[] columnWidths; 42 43 String [] nextRow; 44 45 ResultSetMetaData importResultSetMetaData; 46 int noOfColumnsExpected; 47 48 private boolean wasNull; 49 50 static final String COLUMNNAMEPREFIX = "COLUMN"; 51 52 abstract ImportReadData getImportReadData() throws Exception ; 53 54 57 void doAllTheWork() throws Exception { 58 59 importReadData = getImportReadData(); 62 numberOfColumns = importReadData.getNumberOfColumns(); 63 if(numberOfColumns == 0) 64 { 65 this.numberOfColumns = noOfColumnsExpected; 68 } 69 70 columnWidths = controlFileReader.getColumnWidths(); 71 columnNames = new String [numberOfColumns]; 72 loadColumnNames(); 73 nextRow = new String [numberOfColumns]; 74 75 importResultSetMetaData = 77 new ImportResultSetMetaData(numberOfColumns, columnNames, columnWidths); 78 79 80 } 83 void loadColumnNames() { 85 for (int i=1; i<=numberOfColumns; i++) 86 columnNames[i-1] = COLUMNNAMEPREFIX + i; 87 } 88 89 90 93 public ResultSetMetaData getMetaData() { 94 return importResultSetMetaData; 95 } 96 97 101 public int getRow() throws SQLException { 102 return (importReadData.getCurrentRowNumber()); 103 } 104 105 public boolean next() throws SQLException { 106 try { 107 return (importReadData.readNextRow(nextRow)); 108 } catch (Exception ex) { 109 throw LoadError.unexpectedError(ex); 110 } 111 } 112 113 116 public void close() throws SQLException { 117 try { 118 if(importReadData!=null) 119 importReadData.closeStream(); 120 } catch (Exception ex) { 121 throw LoadError.unexpectedError(ex); 122 } 123 } 124 125 public boolean wasNull() { 126 return wasNull; 127 } 128 129 132 public String getString(int columnIndex) throws SQLException { 133 if (columnIndex <= numberOfColumns) { 134 135 String val = nextRow[columnIndex-1]; 136 wasNull = (val == null); 137 return val; 138 } 139 else { 140 throw LoadError.invalidColumnNumber(numberOfColumns); 141 } 142 } 143 } 144 | Popular Tags |