/** * helper function to create a WHERE clause to search the DB for matching rows. If the col number * is < 0, then the colValue is ignored and the WHERE clause is constructed using only the * values[]. */ private List<IWhereClausePart> getWhereClause( Object[] values, ColumnDisplayDefinition[] colDefs, int col, Object colValue) { try { // For tables that have a lot of columns, the user may have limited the set of columns // to use in the where clause, so see if there is a table of col names HashMap<String, String> colNames = (EditWhereCols.get(getFullTableName())); ColumnDisplayDefinition editedCol = null; if (-1 != col) { editedCol = colDefs[col]; } List<IWhereClausePart> clauseParts = new ArrayList<IWhereClausePart>(); for (int i = 0; i < colDefs.length; i++) { if (i != col && null != editedCol && colDefs[i] .getFullTableColumnName() .equalsIgnoreCase(editedCol.getFullTableColumnName())) { // The edited column is in the resultset twice (example: SELECT MyName,* FROM MyTable). // We won't add the this col to the where clause. continue; } // if the user has said to not use this column, then skip it if (colNames != null) { // the user has restricted the set of columns to use. // If this name is NOT in the list, then skip it; otherwise we fall through // and use the column in the WHERE clause if (colNames.get(colDefs[i].getColumnName()) == null) continue; // go on to the next item } // for the column that is being changed, use the value // passed in by the caller (which may be either the // current value or the new replacement value) Object value = values[i]; if (i == col) value = colValue; // convert user representation of null into an actual null if (value != null && value.toString().equals("<null>")) value = null; // do different things depending on data type ISQLDatabaseMetaData md = _session.getMetaData(); IWhereClausePart clausePart = CellComponentFactory.getWhereClauseValue(colDefs[i], value, md); if (clausePart.shouldBeUsed()) // Now we know that the part should not we ignoredshould clauseParts.add(clausePart); } return clauseParts; } catch (Exception e) { throw new RuntimeException(e); } }
/** Constructor - save the data needed by this data type. */ public DataTypeByte(JTable table, ColumnDisplayDefinition colDef) { _table = table; _colDef = colDef; _isNullable = colDef.isNullable(); _isSigned = colDef.isSigned(); _scale = colDef.getScale(); }
/** Constructor - save the data needed by this data type. */ public DataTypeTime(JTable table, ColumnDisplayDefinition colDef) { _table = table; _colDef = colDef; _isNullable = colDef.isNullable(); loadProperties(); }
@Before public void setUp() { mockColumn = mockHelper.createMock(ColumnDisplayDefinition.class); expect(mockColumn.getColumnName()).andStubReturn("myCol"); mockPstmt = mockHelper.createMock(PreparedStatement.class); mockHelper.replayAll(); classUnderTest = new IsNullWhereClausePart(mockColumn); }
private Cell getXlsCell(ColumnDisplayDefinition colDef, int colIdx, int curRow, Object cellObj) { Row row = sheet.getRow(curRow); if (row == null) { row = sheet.createRow(curRow); } Cell retVal = row.createCell(colIdx); if (null == cellObj || null == colDef) { retVal.setCellValue(getDataXLSAsString(cellObj)); return retVal; } int colType = colDef.getSqlType(); switch (colType) { case Types.BIT: case Types.BOOLEAN: if (null == cellObj) { // retVal.setCellValue((Boolean)null); } else { retVal.setCellValue((Boolean) cellObj); } break; case Types.INTEGER: if (null == cellObj) { // retVal.setCellValue((Integer)null); } else { retVal.setCellValue(((Number) cellObj).intValue()); } break; case Types.SMALLINT: case Types.TINYINT: if (null == cellObj) { // retVal.setCellValue(((Short) null)); } else { retVal.setCellValue(((Number) cellObj).shortValue()); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.FLOAT: case Types.DOUBLE: case Types.REAL: if (null == cellObj) { // retVal.setCellValue((Double) null); } else { retVal.setCellValue(((Number) cellObj).doubleValue()); } break; case Types.BIGINT: if (null == cellObj) { // retVal.setCellValue((Long)null); } else { retVal.setCellValue(Long.parseLong(cellObj.toString())); } break; case Types.DATE: makeTemporalCell(retVal, (Date) cellObj, "m/d/yy"); break; case Types.TIMESTAMP: makeTemporalCell(retVal, (Date) cellObj, "m/d/yy h:mm"); break; case Types.TIME: makeTemporalCell(retVal, (Date) cellObj, "h:mm"); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: cellObj = CellComponentFactory.renderObject(cellObj, colDef); retVal.setCellValue(getDataXLSAsString(cellObj)); break; default: cellObj = CellComponentFactory.renderObject(cellObj, colDef); retVal.setCellValue(getDataXLSAsString(cellObj)); } return retVal; }