/** * @param meta * @throws BirtException */ private void addResultSetColumn(DataSetHandle dataSetHandle, IResultMetaData meta) throws BirtException { if (meta == null || !(dataSetHandle instanceof OdaDataSetHandle)) return; Set computedColumnNameSet = new HashSet(); Iterator computedIter = dataSetHandle.computedColumnsIterator(); while (computedIter.hasNext()) { ComputedColumnHandle handle = (ComputedColumnHandle) computedIter.next(); computedColumnNameSet.add(handle.getName()); } HashSet orgColumnNameSet = new HashSet(); HashSet uniqueColumnNameSet = new HashSet(); PropertyHandle handle = dataSetHandle.getPropertyHandle(DataSetHandle.RESULT_SET_PROP); for (int i = 1; i <= meta.getColumnCount(); i++) { OdaResultSetColumn rsColumn = new OdaResultSetColumn(); String uniqueName; if (!computedColumnNameSet.contains(meta.getColumnName(i))) { uniqueName = MetaDataPopulator.getUniqueName( orgColumnNameSet, uniqueColumnNameSet, meta.getColumnName(i), i - 1); rsColumn.setColumnName(uniqueName); if (meta.getColumnType(i) != DataType.ANY_TYPE) rsColumn.setDataType(DataAdapterUtil.adapterToModelDataType(meta.getColumnType(i))); rsColumn.setNativeName(meta.getColumnName(i)); rsColumn.setPosition(Integer.valueOf(i)); handle.addItem(rsColumn); uniqueColumnNameSet.add(uniqueName); } } }
DataSetHandle createSelectedDataSet() { DataSetHandle dataSetHandle = null; try { if (useODAV3) { dataSetHandle = createDataSetODAV3(); } else { dataSetHandle = createDataSetODAV2(); } if (nameEditor != null && !nameEditor.isDisposed()) dataSetHandle.setName(nameEditor.getText()); return dataSetHandle; } catch (SemanticException e) { ExceptionHandler.handle(e); return null; } catch (IllegalStateException e) { ExceptionHandler.handle(e); return null; } catch (OdaException e) { ExceptionHandler.handle(e); return null; } }
@SuppressWarnings("unchecked") private void prepareReportParams(RptProperties properties) { externalParams = new HashSet<String>(); reportParams = new LinkedHashMap< String, ReportParameter>(); // use LinkedHashMap // http://issues.m-g.ru/bugzilla/show_bug.cgi?id=4577 IGetParameterDefinitionTask paramTask = engine.createGetParameterDefinitionTask(design); try { Collection<IParameterDefnBase> paramsC = paramTask.getParameterDefns(true); for (IParameterDefnBase param : paramsC) { if (param instanceof IParameterGroupDefn) addGroupReportParameter( properties, param.getName(), (IParameterGroupDefn) param, paramTask); else if (param instanceof IScalarParameterDefn) addReportParameter( properties, param.getName(), (IScalarParameterDefn) param, null, paramTask.getDefaultValue(param)); } } finally { paramTask.close(); } /* * BIRT не даёт работать с поименованными параметрами, приходится * обходить */ List<DataSetHandle> dshL = (List<DataSetHandle>) design.getDesignHandle().getModuleHandle().getAllDataSets(); for (DataSetHandle dsH : dshL) { if (dsH instanceof OdaDataSetHandle && MERP_DATASET_ID.equals(((OdaDataSetHandle) dsH).getExtensionID())) { ArrayList<String> paramNames = new ArrayList<String>(); ArrayList<DataSetParameter> prms = (ArrayList<DataSetParameter>) dsH.getListProperty("parameters"); if (prms != null) { for (DataSetParameter prm : prms) paramNames.add(prm.getName()); datasetParams.put(dsH.getStringProperty(BAI_CODE), paramNames); } } } // *********************************************************// }
/** * clear unused column hints * * @throws BirtException */ private final void clearUnusedColumnHints(DataSetHandle dataSetHandle, IResultMetaData metaData) throws BirtException { PropertyHandle handle = dataSetHandle.getPropertyHandle(DataSetHandle.COLUMN_HINTS_PROP); if (handle != null && handle.getListValue() != null) { ArrayList list = handle.getListValue(); int count = list.size(); for (int n = count - 1; n >= 0; n--) { ColumnHint hint = (ColumnHint) list.get(n); String columnName = (String) hint.getProperty(handle.getModule(), ColumnHint.COLUMN_NAME_MEMBER); String alias = (String) hint.getProperty(handle.getModule(), ColumnHint.ALIAS_MEMBER); boolean found = false; if (!isEmpty(hint, handle.getModule().getModuleHandle())) { for (int m = 0; m < metaData.getColumnCount() && !found; m++) { String name = metaData.getColumnName(m + 1); if (name != null && (name.equals(columnName)) || name.equals(alias)) { found = true; break; } } if (!found) { try { // remove the item handle.removeItem(hint); } catch (PropertyValueException e) { } } } } } }
protected DynamicValuesQuery updateDynamicValueQuery( DataSetHandle setHandle, Object valueColumn, Object labelColumn, DataSetDesign dataSetDesign, boolean isEnabled) { DynamicValuesQuery valueQuery = null; if (setHandle instanceof OdaDataSetHandle && valueColumn != null) { valueQuery = designFactory.createDynamicValuesQuery(); if (dataSetDesign != null) { DataSetDesign targetDataSetDesign = (DataSetDesign) EcoreUtil.copy(dataSetDesign); if (!setHandle.getName().equals(dataSetDesign.getName())) targetDataSetDesign = new ModelOdaAdapter().createDataSetDesign((OdaDataSetHandle) setHandle); valueQuery.setDataSetDesign(targetDataSetDesign); } else { DataSetDesign targetDataSetDesign = new ModelOdaAdapter().createDataSetDesign((OdaDataSetHandle) setHandle); valueQuery.setDataSetDesign(targetDataSetDesign); } valueQuery.setDisplayNameColumn(AdapterUtil.extractColumnName(labelColumn)); valueQuery.setValueColumn(AdapterUtil.extractColumnName(valueColumn)); valueQuery.setEnabled(isEnabled); } return valueQuery; }
private IResultMetaData getRuntimeMetaData(DataSetHandle dataSetHandle) throws BirtException { Map dataSetBindingMap = new HashMap(); Map dataSourceBindingMap = new HashMap(); DataSetHandle handle = null; if (sessionContext.getModuleHandle() != null && sessionContext.getModuleHandle().getAllDataSets() != null) { for (Object o : sessionContext.getModuleHandle().getAllDataSets()) { DataSetHandle dsh = (DataSetHandle) o; if (dsh.getQualifiedName().equals(dataSetHandle.getQualifiedName())) { handle = dsh; break; } } } // First clear all property bindings so that the data set can be executed against design time // properties clearPropertyBindingMap(handle, dataSetBindingMap, dataSourceBindingMap); try { QueryDefinition query = new QueryDefinition(); query.setDataSetName(dataSetHandle.getQualifiedName()); query.setMaxRows(1); query.setAutoBinding(true); IResultMetaData metaData = new QueryExecutionHelper(dataEngine, modelAdaptor, sessionContext, false, this.session) .executeQuery(query) .getResultMetaData(); addResultSetColumn(dataSetHandle, metaData); if (MetaDataPopulator.needsUseResultHint(dataSetHandle, metaData)) { metaData = new QueryExecutionHelper(dataEngine, modelAdaptor, sessionContext, true, this.session) .executeQuery(query) .getResultMetaData(); } return metaData; } finally { // restore property bindings resetPropertyBinding(handle, dataSetBindingMap, dataSourceBindingMap); } }
/** * @param dataSetHandle * @param useCache * @return * @throws BirtException */ IResultMetaData getDataSetMetaData(DataSetHandle dataSetHandle, boolean useCache) throws BirtException { if (dataSetHandle == null) { throw new AdapterException(ResourceConstants.DATASETHANDLE_NULL_ERROR); } if (useCache) { return getCachedMetaData(dataSetHandle.getCachedMetaDataHandle()); } else { return getRealMetaData(dataSetHandle); } }
/** * @param dataSetHandle * @param rsMeta * @return * @throws BirtException */ private boolean needsSetCachedMetaData(DataSetHandle dataSetHandle, IResultMetaData rsMeta) throws BirtException { if (dataSetHandle.getCachedMetaDataHandle() == null || rsMeta == null || rsMeta.getColumnCount() == 0) return true; List list = getResultSetColumnHandles(dataSetHandle.getCachedMetaDataHandle()); if (list.size() != rsMeta.getColumnCount()) return true; for (int i = 1; i <= rsMeta.getColumnCount(); i++) { ResultSetColumnHandle handle = (ResultSetColumnHandle) list.get(i - 1); if (handle.getColumnName() == null || !handle.getColumnName().equals(getColumnName(rsMeta, i)) || !handle .getDataType() .equals(DataAdapterUtil.adapterToModelDataType(rsMeta.getColumnType(i)))) return true; } return false; }
/** * reset the property binding in dataset. * * @param dsHandle * @param dataSetMap * @param dataSourceMap * @throws SemanticException */ public static void resetPropertyBinding(DataSetHandle dsHandle, Map dataSetMap, Map dataSourceMap) throws SemanticException { if (dsHandle == null) { return; } if (dsHandle.getExtends() != null) { return; } if (dsHandle instanceof JointDataSetHandle) { Iterator iter = ((JointDataSetHandle) dsHandle).dataSetsIterator(); while (iter.hasNext()) { DataSetHandle ds = (DataSetHandle) iter.next(); if (dsHandle != null) { resetPropertyBinding(ds, dataSetMap, dataSourceMap); } } } else if (dsHandle instanceof DerivedDataSetHandle) { List<DataSetHandle> dataSets = ((DerivedDataSetHandle) dsHandle).getInputDataSets(); if (dataSets != null && dataSets.size() != 0) { for (int i = 0; i < dataSets.size(); i++) { DataSetHandle ds = dataSets.get(i); if (dsHandle != null) { resetPropertyBinding(ds, dataSetMap, dataSourceMap); } } } } else { if (dsHandle instanceof OdaDataSetHandle) { if (dataSetMap.get(dsHandle.getName()) != null) { List pList = (List) dataSetMap.get(dsHandle.getName()); for (int i = 0; i < pList.size(); i++) { PropertyBinding binding = (PropertyBinding) pList.get(i); dsHandle.setPropertyBinding(binding.getName(), binding.getValue()); } } if (dsHandle.getDataSource() != null && dataSourceMap.get(dsHandle.getDataSource().getName()) != null) { List pList = (List) dataSourceMap.get(dsHandle.getDataSource().getName()); for (int i = 0; i < pList.size(); i++) { PropertyBinding binding = (PropertyBinding) pList.get(i); dsHandle.getDataSource().setPropertyBinding(binding.getName(), binding.getValue()); } } } } }
/** * clear the property binding in dataset to disable it when run the query * * @param dsHandle * @param dataSetMap * @param dataSourceMap * @throws SemanticException */ public static void clearPropertyBindingMap( DataSetHandle dsHandle, Map dataSetMap, Map dataSourceMap) throws SemanticException { if (dsHandle == null) { return; } if (dsHandle.getExtends() != null) { return; } if (dsHandle instanceof JointDataSetHandle) { Iterator iter = ((JointDataSetHandle) dsHandle).dataSetsIterator(); while (iter.hasNext()) { DataSetHandle ds = (DataSetHandle) iter.next(); if (dsHandle != null) { clearPropertyBindingMap(ds, dataSetMap, dataSourceMap); } } } else if (dsHandle instanceof DerivedDataSetHandle) { List<DataSetHandle> dataSets = ((DerivedDataSetHandle) dsHandle).getInputDataSets(); if (dataSets != null && dataSets.size() != 0) { for (int i = 0; i < dataSets.size(); i++) { DataSetHandle ds = dataSets.get(i); if (dsHandle != null) { clearPropertyBindingMap(ds, dataSetMap, dataSourceMap); } } } } else if (dsHandle instanceof OdaDataSetHandle) { List dataSetBindingList = dsHandle.getPropertyBindings(); List dataSourceBindingList = dsHandle.getDataSource() == null ? new ArrayList() : dsHandle.getDataSource().getPropertyBindings(); if (!dataSetBindingList.isEmpty()) dataSetMap.put(dsHandle.getName(), dataSetBindingList); if (!dataSourceBindingList.isEmpty()) dataSourceMap.put(dsHandle.getDataSource().getName(), dataSourceBindingList); for (int i = 0; i < dataSetBindingList.size(); i++) { PropertyBinding binding = (PropertyBinding) dataSetBindingList.get(i); dsHandle.setPropertyBinding(binding.getName(), (Expression) null); } for (int i = 0; i < dataSourceBindingList.size(); i++) { PropertyBinding binding = (PropertyBinding) dataSourceBindingList.get(i); dsHandle.getDataSource().setPropertyBinding(binding.getName(), (Expression) null); } } }
/** * @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; }