Changeset 4104
- Timestamp:
- Jan 28, 2008, 1:29:10 PM (15 years ago)
- Location:
- trunk/src/core/net/sf/basedb/util/parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/parser/ColFunction.java
r3911 r4104 66 66 private final ParsePosition pos; 67 67 private FlatFileParser.Data data; 68 private boolean ignoreNonExistingColumns = false; 68 69 69 70 public ColFunction(Map<String, Integer> columnHeaders, NumberFormat numberFormat) … … 138 139 if (column == null) 139 140 { 140 throw new BaseException("Column '" + colName + "' not found in column headers."); 141 } 142 value = data.get(column); 141 if (!ignoreNonExistingColumns) 142 { 143 throw new BaseException("Column '" + colName + "' not found in column headers."); 144 } 145 value = null; 146 } 147 else 148 { 149 value = data.get(column); 150 } 143 151 } 144 152 else … … 176 184 // ------------------------------------------- 177 185 186 /** 187 Set to TRUE to ignore non-existing columns. Set to FALSE to 188 throw an exception (default). 189 @since 2.6 190 */ 191 public void setIgnoreNonExistingColumns(boolean ignoreNonExistingColumns) 192 { 193 this.ignoreNonExistingColumns = ignoreNonExistingColumns; 194 } 195 178 196 public void setData(FlatFileParser.Data data) 179 197 { -
trunk/src/core/net/sf/basedb/util/parser/FlatFileParser.java
r4095 r4104 247 247 248 248 /** 249 If non-existing columns should be ignored (true) or result in an 250 exception (false) 251 */ 252 private boolean ignoreNonExistingColumns = false; 253 254 /** 249 255 If <code>null</code> should be returned for the string NULL (ignoring case) 250 256 or not. … … 849 855 850 856 /** 857 Specify if trying to create a mapper with one of the {@link #getMapper(String)} 858 methods for an expression which references a non-existing column should 859 result in an exception or be ignored. 860 @param ignoreNonExistingColumns TRUE to ignore, or FALSE to throw an exception 861 @since 2.6 862 */ 863 public void setIgnoreNonExistingColumns(boolean ignoreNonExistingColumns) 864 { 865 this.ignoreNonExistingColumns = ignoreNonExistingColumns; 866 } 867 868 /** 851 869 Get a mapper using the default number format. 852 870 @see #getMapper(String, NumberFormat, boolean) … … 917 935 else if (expression.startsWith("=")) 918 936 { 919 mapper = new JepMapper(expression.substring(1), columnHeaders, numberFormat );937 mapper = new JepMapper(expression.substring(1), columnHeaders, numberFormat, ignoreNonExistingColumns); 920 938 if (nullIfException) mapper = new NullIfExceptionMapper(mapper); 921 939 } … … 946 964 if (column == null) 947 965 { 948 throw new BaseException("Column '" + name + "' not found in column headers."); 966 if (!ignoreNonExistingColumns) 967 { 968 throw new BaseException("Column '" + name + "' not found in column headers."); 969 } 949 970 } 950 mappers.add(new ColumnMapper(column, name, numberFormat, nullIfException)); 971 else 972 { 973 mappers.add(new ColumnMapper(column, name, numberFormat, nullIfException)); 974 } 951 975 } 952 976 } … … 957 981 mappers.add(new ConstantMapper(expression.substring(nextStart), numberFormat, nullIfException)); 958 982 } 959 if (mappers.size() == 1) 983 if (mappers.size() == 0) 984 { 985 mapper = new ConstantMapper(emptyIsNull ? null : "", numberFormat, nullIfException); 986 } 987 else if (mappers.size() == 1) 960 988 { 961 989 mapper = mappers.get(0); -
trunk/src/core/net/sf/basedb/util/parser/JepMapper.java
r3675 r4104 70 70 public JepMapper(String expression, List<String> columnHeaders) 71 71 { 72 this(expression, columnHeaders, null );72 this(expression, columnHeaders, null, false); 73 73 } 74 74 75 75 public JepMapper(String expression, List<String> columnHeaders, NumberFormat numberFormat) 76 76 { 77 this(expression, columnHeaders, numberFormat, false); 78 } 79 80 public JepMapper(String expression, List<String> columnHeaders, NumberFormat numberFormat, 81 boolean ignoreNonExistingColumns) 82 { 77 83 this.expression = expression; 78 84 this.numberFormat = numberFormat; 79 85 this.colFunction = new ColFunction(columnHeaders, numberFormat); 86 colFunction.setIgnoreNonExistingColumns(ignoreNonExistingColumns); 80 87 this.lineNoFunction = expression.contains("lineNo()") ? new LineNoFunction() : null; 81 88 this.hasLineNo = lineNoFunction != null; … … 86 93 this.parser = Jep.newJep(expression, colFunction, lineNoFunction, dataNoFunction); 87 94 } 95 88 96 89 97 /*
Note: See TracChangeset
for help on using the changeset viewer.