/** * Creates the column hint with given column definition and the old column hint. * * @param columnDefn the latest column definition * @param cachedColumnDefn the last (cached) column definition * @param oldHint the existing column hint in the data set handle * @return the newly created column hint */ static ColumnHint newROMColumnHintFromColumnDefinition( ColumnDefinition columnDefn, ColumnDefinition cachedColumnDefn, ColumnHint oldHint, OdaResultSetColumn resultSetColumn) { if (columnDefn == null) return null; String columnName = resultSetColumn == null ? null : resultSetColumn.getColumnName(); DataElementAttributes dataAttrs = columnDefn.getAttributes(); if (dataAttrs == null) return null; ColumnHint newHint = null; ColumnDefinition tmpCachedColumnDefn = cachedColumnDefn; if (oldHint == null) { newHint = StructureFactory.createColumnHint(); tmpCachedColumnDefn = null; } else newHint = (ColumnHint) oldHint.copy(); DataElementUIHints dataUIHints = dataAttrs.getUiHints(); OutputElementAttributes outputAttrs = columnDefn.getUsageHints(); AxisAttributes axisAttrs = columnDefn.getMultiDimensionAttributes(); boolean hasValue = hasColumnHintValue(dataUIHints, outputAttrs, axisAttrs); if (!hasValue) { if (oldHint == null) return null; return newHint; } DataElementAttributes cachedDataAttrs = tmpCachedColumnDefn == null ? null : tmpCachedColumnDefn.getAttributes(); updateColumnHintFromDataAttrs( columnDefn.getAttributes(), cachedDataAttrs, newHint, resultSetColumn); updateColumnHintFromUsageHints( outputAttrs, tmpCachedColumnDefn == null ? null : tmpCachedColumnDefn.getUsageHints(), newHint, resultSetColumn); updateColumnHintFromAxisAttrs( columnDefn.getMultiDimensionAttributes(), tmpCachedColumnDefn == null ? null : tmpCachedColumnDefn.getMultiDimensionAttributes(), newHint); newHint.setProperty(ColumnHint.COLUMN_NAME_MEMBER, columnName); return newHint; }
/** * Updates column hint values by given output element attributes. * * @param outputAttrs the latest output element attributes * @param cachedOutputAttrs the last(cached) output element attributes * @param newHint the column hint */ private static void updateColumnHintFromUsageHints( OutputElementAttributes outputAttrs, OutputElementAttributes cachedOutputAttrs, ColumnHint newHint, OdaResultSetColumn column) { if (outputAttrs == null) return; // help text and key Object oldValue = cachedOutputAttrs == null ? null : cachedOutputAttrs.getHelpText(); Object newValue = outputAttrs.getHelpText(); if (!CompareUtil.isEquals(oldValue, newValue)) { newHint.setProperty(ColumnHint.HELP_TEXT_MEMBER, newValue); } oldValue = cachedOutputAttrs == null ? null : cachedOutputAttrs.getHelpTextKey(); newValue = outputAttrs.getHelpTextKey(); if (!CompareUtil.isEquals(oldValue, newValue)) { newHint.setProperty(ColumnHint.HELP_TEXT_ID_MEMBER, newValue); } // m_label maps to heading oldValue = cachedOutputAttrs == null ? null : cachedOutputAttrs.getLabel(); newValue = outputAttrs.getLabel(); if (!CompareUtil.isEquals(oldValue, newValue)) { newHint.setProperty(ColumnHint.HEADING_MEMBER, newValue); } oldValue = cachedOutputAttrs == null ? null : cachedOutputAttrs.getLabelKey(); newValue = outputAttrs.getLabelKey(); if (!CompareUtil.isEquals(oldValue, newValue)) { newHint.setProperty(ColumnHint.HEADING_ID_MEMBER, newValue); } // for values in formatting. ValueFormatHints formatHints = outputAttrs.getFormattingHints(); if (formatHints == null) return; ValueFormatHints cachedFormatHints = cachedOutputAttrs == null ? null : cachedOutputAttrs.getFormattingHints(); oldValue = cachedFormatHints == null ? null : cachedFormatHints.getDisplayFormat(); // convert display format in oda to pattern part of value-format member newValue = formatHints.getDisplayFormat(); if (!CompareUtil.isEquals(oldValue, newValue)) { FormatValue format = (FormatValue) newHint.getProperty(null, ColumnHint.VALUE_FORMAT_MEMBER); if (format == null && newValue != null) { format = StructureFactory.newFormatValue(); newHint.setProperty(ColumnHint.VALUE_FORMAT_MEMBER, format); } // add logic to fix 32742: if the column is date-time, then do some // special handle for the format string in IO if (newValue != null && (column != null && DesignChoiceConstants.COLUMN_DATA_TYPE_DATETIME.equals(column.getDataType()))) { String formatValue = (String) newValue; newValue = formatValue.replaceFirst("mm/", "MM/"); // $NON-NLS-1$//$NON-NLS-2$ } if (format != null) format.setPattern((String) newValue); } // not support display length /* * newValue = formatHints.getDisplaySize( ); oldValue = * cachedFormatHints == null ? null : cachedFormatHints .getDisplaySize( * ); if ( oldValue == null || !oldValue.equals( newValue ) ) { * newHint.setProperty( ColumnHint.DISPLAY_LENGTH_MEMBER, newValue ); } */ newValue = formatHints.getHorizontalAlignment(); oldValue = cachedFormatHints == null ? null : cachedFormatHints.getHorizontalAlignment(); if (formatHints.isSetHorizontalAlignment() && !CompareUtil.isEquals(oldValue, newValue)) { newHint.setProperty( ColumnHint.HORIZONTAL_ALIGN_MEMBER, convertToROMHorizontalAlignment((HorizontalAlignment) newValue)); } // not support word-wrap /* * newValue = formatHints.getTextWrapType( ); oldValue = * cachedFormatHints == null ? null : cachedFormatHints * .getTextWrapType( ); * * if ( oldValue == null || !oldValue.equals( newValue ) ) { * newHint.setProperty( ColumnHint.WORD_WRAP_MEMBER, * convertToROMWordWrap( (TextWrapType) newValue ) ); } */ // cannot handle text format since two objects in ODA and ROM are // different. }
/** * @param dataSetHandle * @return * @throws BirtException */ IResultMetaData refreshMetaData(DataSetHandle dataSetHandle, boolean holdEvent) throws BirtException { IResultMetaData rsMeta = null; try { rsMeta = this.getDataSetMetaData(dataSetHandle, false); } catch (BirtException e1) { // clear cache meta data if (holdEvent || !dataSetHandle.canEdit()) { CompatibilityUtil.updateResultSetinCachedMetaData(dataSetHandle, new ArrayList()); } else { if (dataSetHandle.getCachedMetaDataHandle() != null) dataSetHandle.getCachedMetaDataHandle().getResultSet().clearValue(); else dataSetHandle.setCachedMetaData(StructureFactory.createCachedMetaData()); } throw e1; } if (needsSetCachedMetaData(dataSetHandle, rsMeta)) { List columnList = new ArrayList(); if (rsMeta != null && rsMeta.getColumnCount() != 0) { for (int i = 1; i <= rsMeta.getColumnCount(); i++) { ResultSetColumn rsc = StructureFactory.createResultSetColumn(); String columnName = getColumnName(rsMeta, i); if (columnName == null || columnName.trim().length() == 0) { // in some store procedure cases, column name is just empty, // then, we just use column name already saved in datasetHandle List list = dataSetHandle.getListProperty(IDataSetModel.RESULT_SET_PROP); ResultSetColumn column = (ResultSetColumn) list.get(i - 1); rsc.setColumnName(column.getColumnName()); } else { rsc.setColumnName(columnName); } if (rsMeta.getColumnType(i) != DataType.ANY_TYPE) rsc.setDataType(DataAdapterUtil.adapterToModelDataType(rsMeta.getColumnType(i))); rsc.setPosition(Integer.valueOf(i)); columnList.add(rsc); } } if (holdEvent || !dataSetHandle.canEdit()) { CompatibilityUtil.updateResultSetinCachedMetaData(dataSetHandle, columnList); } else { if (dataSetHandle.getCachedMetaDataHandle() != null) { List resultSetColumnHandles = getResultSetColumnHandles(dataSetHandle.getCachedMetaDataHandle()); int i = 0; for (; i < columnList.size(); i++) { ResultSetColumn rsc = (ResultSetColumn) columnList.get(i); if (i < resultSetColumnHandles.size()) { // update if needed, avoid writing "any" type to // Model if old report contains "any" type ResultSetColumnHandle rsh = (ResultSetColumnHandle) resultSetColumnHandles.get(i); if (!rsh.getColumnName().equals(rsc.getColumnName())) { rsh.setColumnName(rsc.getColumnName()); } if (!rsh.getDataType().equals(rsc.getDataType())) { rsh.setDataType(rsc.getDataType()); } } else { // some columns are to be added dataSetHandle.getCachedMetaDataHandle().getResultSet().addItem(rsc); } } if (i < resultSetColumnHandles.size()) { // some columns are to be removed List toRemoved = resultSetColumnHandles.subList(i, resultSetColumnHandles.size()); dataSetHandle.getCachedMetaDataHandle().getResultSet().removeItems(toRemoved); } } else { dataSetHandle.setCachedMetaData(StructureFactory.createCachedMetaData()); for (int i = 0; i < columnList.size(); i++) { dataSetHandle .getCachedMetaDataHandle() .getResultSet() .addItem((ResultSetColumn) columnList.get(i)); } } } } return rsMeta; }