diff --git a/wizards/com/sun/star/wizards/db/CommandMetaData.java b/wizards/com/sun/star/wizards/db/CommandMetaData.java index ad54020e8645..1819d3485994 100644 --- a/wizards/com/sun/star/wizards/db/CommandMetaData.java +++ b/wizards/com/sun/star/wizards/db/CommandMetaData.java @@ -24,7 +24,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package com.sun.star.wizards.db; import com.sun.star.lang.XMultiServiceFactory; @@ -39,25 +38,39 @@ import com.sun.star.lang.Locale; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XIndexAccess; import com.sun.star.container.XNameAccess; -import com.sun.star.embed.EntryInitModes; import com.sun.star.wizards.common.Helper; import com.sun.star.wizards.common.JavaTools; import com.sun.star.wizards.common.NumberFormatter; import com.sun.star.wizards.common.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.Vector; public class CommandMetaData extends DBMetaData { + public Map FieldTitleSet = new HashMap(); - public String[] m_aAllFieldNames = new String[]{}; - public FieldColumn[] FieldColumns = new FieldColumn[]{}; - public String[] GroupFieldNames = new String[] {}; - private String[][] SortFieldNames = new String[][] {}; - private String[] RecordFieldNames = new String[] {}; - public String[][] AggregateFieldNames = new String[][] {}; - public String[] NumericFieldNames = new String[] {}; + public String[] m_aAllFieldNames = new String[] + { + }; + public FieldColumn[] FieldColumns = new FieldColumn[] + { + }; + public String[] GroupFieldNames = new String[] + { + }; + private String[][] SortFieldNames = new String[][] + { + }; + private String[] RecordFieldNames = new String[] + { + }; + public String[][] AggregateFieldNames = new String[][] + { + }; + public String[] NumericFieldNames = new String[] + { + }; public String[] NonAggregateFieldNames; private int CommandType; private String Command; @@ -65,442 +78,417 @@ public class CommandMetaData extends DBMetaData String sCatalogSep = ""; String sIdentifierQuote = ""; boolean bCommandComposerAttributesalreadyRetrieved = false; - - private XIndexAccess xIndexKeys; public CommandMetaData(XMultiServiceFactory xMSF, Locale _aLocale, NumberFormatter oNumberFormatter) - { - super(xMSF, _aLocale, oNumberFormatter); - } + { + super(xMSF, _aLocale, oNumberFormatter); + } public CommandMetaData(XMultiServiceFactory xMSF) - { - super(xMSF); - } - + { + super(xMSF); + } public void initializeFieldColumns(boolean _bgetDefaultValue, String _CommandName, String[] _FieldNames) + { + this.setCommandName(_CommandName); + FieldColumns = new FieldColumn[_FieldNames.length]; + for (int i = 0; i < _FieldNames.length; i++) { - this.setCommandName(_CommandName); - FieldColumns = new FieldColumn[_FieldNames.length]; - for (int i = 0; i < _FieldNames.length; i++) - { - FieldColumns[i] = new FieldColumn(this, _FieldNames[i], this.getCommandName(), false); + FieldColumns[i] = new FieldColumn(this, _FieldNames[i], this.getCommandName(), false); // if (_bgetDefaultValue) // { // FieldColumns[i].getDefaultValue(); // } - } } - + } public void initializeFieldColumns(String[] _FieldNames, XNameAccess _xColumns) + { + FieldColumns = new FieldColumn[_FieldNames.length]; + for (int i = 0; i < _FieldNames.length; i++) { - FieldColumns = new FieldColumn[_FieldNames.length]; - for (int i = 0; i < _FieldNames.length; i++) - { - FieldColumns[i] = new FieldColumn(this,_xColumns, _FieldNames[i] ); - } + FieldColumns[i] = new FieldColumn(this, _xColumns, _FieldNames[i]); } - + } public void initializeFieldColumns(String[] _FieldNames, String _CommandName) + { + this.setCommandName(_CommandName); + FieldColumns = new FieldColumn[_FieldNames.length]; + for (int i = 0; i < _FieldNames.length; i++) { - this.setCommandName(_CommandName); - FieldColumns = new FieldColumn[_FieldNames.length]; - for (int i = 0; i < _FieldNames.length; i++) + FieldColumns[i] = new FieldColumn(this, _FieldNames[i], _CommandName, false); + if (FieldTitleSet != null && FieldTitleSet.containsKey(_FieldNames[i])) { - FieldColumns[i] = new FieldColumn(this, _FieldNames[i], _CommandName, false); - if (FieldTitleSet != null) + FieldColumns[i].setFieldTitle((String) FieldTitleSet.get(_FieldNames[i])); + if (FieldColumns[i].getFieldTitle() == null) { - if (FieldTitleSet.containsKey(_FieldNames[i])) - { - FieldColumns[i].setFieldTitle( (String) FieldTitleSet.get(_FieldNames[i]) ); - if (FieldColumns[i].getFieldTitle() == null) - { - FieldColumns[i].setFieldTitle( _FieldNames[i] ); - FieldTitleSet.put(_FieldNames[i], _FieldNames[i]); - } - } + FieldColumns[i].setFieldTitle(_FieldNames[i]); + FieldTitleSet.put(_FieldNames[i], _FieldNames[i]); } } } + } public Map getFieldTitleSet() - { - return FieldTitleSet; - } - + { + return FieldTitleSet; + } public XPropertySet getColumnObjectByFieldName(String _FieldName, boolean _bgetByDisplayName) + { + try { - try + FieldColumn CurFieldColumn = null; + if (_bgetByDisplayName) { - FieldColumn CurFieldColumn = null; - if (_bgetByDisplayName) - { - CurFieldColumn = this.getFieldColumnByDisplayName(_FieldName); - } - else - { - CurFieldColumn = this.getFieldColumnByFieldName(_FieldName); - } - String CurCommandName = CurFieldColumn.getCommandName(); - CommandObject oCommand = getTableByName(CurCommandName); - Object oColumn = oCommand.getColumns().getByName(CurFieldColumn.getFieldName()); - XPropertySet xColumn = UnoRuntime.queryInterface( XPropertySet.class, oColumn ); - return xColumn; + CurFieldColumn = this.getFieldColumnByDisplayName(_FieldName); } - catch (Exception exception) + else { - exception.printStackTrace(System.out); - return null; + CurFieldColumn = this.getFieldColumnByFieldName(_FieldName); } + String CurCommandName = CurFieldColumn.getCommandName(); + CommandObject oCommand = getTableByName(CurCommandName); + Object oColumn = oCommand.getColumns().getByName(CurFieldColumn.getFieldName()); + XPropertySet xColumn = UnoRuntime.queryInterface(XPropertySet.class, oColumn); + return xColumn; } - + catch (Exception exception) + { + exception.printStackTrace(System.out); + return null; + } + } // @SuppressWarnings("unchecked") public void prependSortFieldNames(String[] _fieldnames) + { + ArrayList aSortFields = new ArrayList(); + for (int i = 0; i < _fieldnames.length; i++) { - Vector aSortFields = new Vector(); - for (int i = 0; i < _fieldnames.length; i++) + String[] sSortFieldName = new String[2]; + sSortFieldName[0] = _fieldnames[i]; + int index = JavaTools.FieldInTable(SortFieldNames, _fieldnames[i]); + if (index > -1) { - String[] sSortFieldName = new String[2]; - sSortFieldName[0] = _fieldnames[i]; - int index = JavaTools.FieldInTable(SortFieldNames, _fieldnames[i]); - if (index > -1) - - { - sSortFieldName[1] = SortFieldNames[index][1]; - } - else - - { - sSortFieldName[1] = "ASC"; - } - aSortFields.add(sSortFieldName); + sSortFieldName[1] = SortFieldNames[index][1]; } - for (int i = 0; i < SortFieldNames.length; i++) + else { - if (JavaTools.FieldInList(_fieldnames, SortFieldNames[i][0]) == -1) - { - aSortFields.add(SortFieldNames[i]); - } + sSortFieldName[1] = "ASC"; } - SortFieldNames = new String[aSortFields.size()][2]; - aSortFields.toArray(SortFieldNames); + aSortFields.add(sSortFieldName); } + for (int i = 0; i < SortFieldNames.length; i++) + { + if (JavaTools.FieldInList(_fieldnames, SortFieldNames[i][0]) == -1) + { + aSortFields.add(SortFieldNames[i]); + } + } + SortFieldNames = new String[aSortFields.size()][2]; + aSortFields.toArray(SortFieldNames); + } public String[][] getSortFieldNames() - { - return SortFieldNames; - } + { + return SortFieldNames; + } + public void setSortFieldNames(String[][] aNewListList) - { - SortFieldNames = aNewListList; - } + { + SortFieldNames = aNewListList; + } public FieldColumn getFieldColumn(String _FieldName, String _CommandName) + { + for (int i = 0; i < FieldColumns.length; i++) { - if (FieldColumns.length > 0) + if (FieldColumns[i].getFieldName().equals(_FieldName) && FieldColumns[i].getCommandName().equals(_CommandName)) { - for (int i = 0; i < FieldColumns.length; i++) - { - if (FieldColumns[i].getFieldName().equals(_FieldName)) - - { - if (FieldColumns[i].getCommandName().equals(_CommandName)) - { - return FieldColumns[i]; - } - } - } + return FieldColumns[i]; } - return null; } - - + return null; + } public FieldColumn getFieldColumnByFieldName(String _FieldName) + { + for (int i = 0; i < FieldColumns.length; i++) { - for (int i = 0; i < FieldColumns.length; i++) + String sFieldName = FieldColumns[i].getFieldName(); + if (sFieldName.equals(_FieldName)) { - String sFieldName = FieldColumns[i].getFieldName(); - if (sFieldName.equals(_FieldName)) + return FieldColumns[i]; + } + if (_FieldName.indexOf('.') == -1) + { + String sCompound = Command + "." + _FieldName; + if (sFieldName.equals(sCompound)) { return FieldColumns[i]; } - if (_FieldName.indexOf('.') == -1) - { - String sCompound = Command + "." + _FieldName; - if (sFieldName.equals(sCompound)) - { - return FieldColumns[i]; - } - } } - throw new com.sun.star.uno.RuntimeException(); } - + throw new com.sun.star.uno.RuntimeException(); + } public FieldColumn getFieldColumnByDisplayName(String _DisplayName) + { + String identifierQuote = getIdentifierQuote(); + for (int i = 0; i < FieldColumns.length; i++) { - for (int i = 0; i < FieldColumns.length; i++) + String sDisplayName = FieldColumns[i].getDisplayFieldName(); + if (sDisplayName.equals(_DisplayName)) { - String sDisplayName = FieldColumns[i].getDisplayFieldName(); - if (sDisplayName.equals(_DisplayName)) + return FieldColumns[i]; + } + if (_DisplayName.indexOf('.') == -1) + { + String sCompound = Command + "." + _DisplayName; + if (sDisplayName.equals(sCompound)) { return FieldColumns[i]; } - if (_DisplayName.indexOf('.') == -1) - { - String sCompound = Command + "." + _DisplayName; - if (sDisplayName.equals(sCompound)) - { - return FieldColumns[i]; - } - } } - throw new com.sun.star.uno.RuntimeException(); + String quotedName = new StringBuilder(CommandName.quoteName(FieldColumns[i].getCommandName(), identifierQuote)).append('.').append(CommandName.quoteName(FieldColumns[i].getFieldName(), identifierQuote)).toString(); + if (quotedName.equals(_DisplayName)) + { + return FieldColumns[i]; + } } - + throw new com.sun.star.uno.RuntimeException(); + } public FieldColumn getFieldColumnByTitle(String _FieldTitle) + { + for (int i = 0; i < FieldColumns.length; i++) { - for (int i = 0; i < FieldColumns.length; i++) + if (FieldColumns[i].getFieldTitle().equals(_FieldTitle)) { - if (FieldColumns[i].getFieldTitle().equals(_FieldTitle)) - { - return FieldColumns[i]; - } + return FieldColumns[i]; } - // throw new com.sun.star.uno.RuntimeException(); - // LLA: Group works with fields direct - for (int i = 0; i < FieldColumns.length; i++) - { - if (FieldColumns[i].getFieldName().equals(_FieldTitle)) - { - return FieldColumns[i]; - } - } - throw new com.sun.star.uno.RuntimeException(); } - + // throw new com.sun.star.uno.RuntimeException(); + // LLA: Group works with fields direct + for (int i = 0; i < FieldColumns.length; i++) + { + if (FieldColumns[i].getFieldName().equals(_FieldTitle)) + { + return FieldColumns[i]; + } + } + throw new com.sun.star.uno.RuntimeException(); + } public boolean getFieldNamesOfCommand(String _commandname, int _commandtype, boolean _bAppendMode) + { + try { - try + // Object oField; + java.util.ArrayList ResultFieldNames = new java.util.ArrayList(10); + String[] FieldNames; + CommandObject oCommand = this.getCommandByName(_commandname, _commandtype); + FieldNames = oCommand.getColumns().getElementNames(); + if (FieldNames.length > 0) { - // Object oField; - java.util.Vector ResultFieldNames = new java.util.Vector(10); - String[] FieldNames; - CommandObject oCommand = this.getCommandByName(_commandname, _commandtype); - FieldNames = oCommand.getColumns().getElementNames(); - if (FieldNames.length > 0) + for (int n = 0; n < FieldNames.length; n++) { - for (int n = 0; n < FieldNames.length; n++) + final String sFieldName = FieldNames[n]; + Object oField = oCommand.getColumns().getByName(sFieldName); + int iType = AnyConverter.toInt(Helper.getUnoPropertyValue(oField, "Type")); + // BinaryFieldTypes are not included in the WidthList + if (JavaTools.FieldInIntTable(WidthList, iType) >= 0) { - final String sFieldName = FieldNames[n]; - Object oField = oCommand.getColumns().getByName(sFieldName); - int iType = AnyConverter.toInt(Helper.getUnoPropertyValue(oField, "Type")); - // BinaryFieldTypes are not included in the WidthList - if (JavaTools.FieldInIntTable(WidthList, iType) >= 0) - { // if (_bAppendMode) // ResultFieldNames.addElement(_commandname + "." + FieldNames[n]); // else - ResultFieldNames.addElement(sFieldName); - } - else if (JavaTools.FieldInIntTable(BinaryTypes, iType) >= 0) - { - ResultFieldNames.addElement(sFieldName); - } + ResultFieldNames.add(sFieldName); + } + else if (JavaTools.FieldInIntTable(BinaryTypes, iType) >= 0) + { + ResultFieldNames.add(sFieldName); } - // FieldNames = new String[FieldNames.length]; - // FieldTypes = new int[FieldNames.length]; - m_aAllFieldNames = new String[ResultFieldNames.size()]; - ResultFieldNames.copyInto(m_aAllFieldNames); - return true; } + // FieldNames = new String[FieldNames.length]; + // FieldTypes = new int[FieldNames.length]; + m_aAllFieldNames = new String[ResultFieldNames.size()]; + m_aAllFieldNames = ResultFieldNames.toArray(m_aAllFieldNames); + return true; } - catch (Exception exception) - { - exception.printStackTrace(System.out); - } - Resource oResource = new Resource(xMSF, "Database", "dbw"); - String sMsgNoFieldsFromCommand = oResource.getResText(RID_DB_COMMON + 45); - sMsgNoFieldsFromCommand = JavaTools.replaceSubString(sMsgNoFieldsFromCommand, _commandname, "%NAME"); - showMessageBox("ErrorBox", VclWindowPeerAttribute.OK, sMsgNoFieldsFromCommand); - return false; } - - - - - + catch (Exception exception) + { + exception.printStackTrace(System.out); + } + Resource oResource = new Resource(xMSF, "Database", "dbw"); + String sMsgNoFieldsFromCommand = oResource.getResText(RID_DB_COMMON + 45); + sMsgNoFieldsFromCommand = JavaTools.replaceSubString(sMsgNoFieldsFromCommand, _commandname, "%NAME"); + showMessageBox("ErrorBox", VclWindowPeerAttribute.OK, sMsgNoFieldsFromCommand); + return false; + } public String[] getOrderableColumns(String[] _fieldnames) + { + ArrayList aOrderableColumns = new ArrayList(); + int ncount = 0; + for (int i = 0; i < _fieldnames.length; i++) { - Vector aOrderableColumns = new Vector(); - int ncount = 0; - for (int i = 0; i < _fieldnames.length; i++) + FieldColumn ofieldcolumn = getFieldColumnByFieldName(_fieldnames[i]); + if (getDBDataTypeInspector().isColumnOrderable(ofieldcolumn.getXColumnPropertySet())) { - FieldColumn ofieldcolumn = getFieldColumnByFieldName(_fieldnames[i]); - if (getDBDataTypeInspector().isColumnOrderable(ofieldcolumn.getXColumnPropertySet())) - { - aOrderableColumns.addElement(_fieldnames[i]); - ncount++; - } + aOrderableColumns.add(_fieldnames[i]); + ncount++; } - String[] sretfieldnames = new String[ncount]; - aOrderableColumns.toArray(sretfieldnames); - return sretfieldnames; } - + String[] sretfieldnames = new String[ncount]; + aOrderableColumns.toArray(sretfieldnames); + return sretfieldnames; + } /** * @return Returns the command. */ public String getCommandName() - { - return Command; - } + { + return Command; + } + /** * @param _command The command to set. */ public void setCommandName(String _command) - { - Command = _command; - } + { + Command = _command; + } /** * @return Returns the commandType. */ public int getCommandType() - { - return CommandType; - } + { + return CommandType; + } /** * @param _commandType The commandType to set. */ public void setCommandType(int _commandType) - { - CommandType = _commandType; - } - + { + CommandType = _commandType; + } public boolean isnumeric(FieldColumn _oFieldColumn) + { + try { - try + CommandObject oTable = super.getTableByName(_oFieldColumn.getCommandName()); + Object oField = oTable.getColumns().getByName(_oFieldColumn.getFieldName()); + int iType = AnyConverter.toInt(Helper.getUnoPropertyValue(oField, "Type")); + int ifound = java.util.Arrays.binarySearch(NumericTypes, iType); + if ((ifound < NumericTypes.length) && (ifound > 0)) { - CommandObject oTable = super.getTableByName(_oFieldColumn.getCommandName()); - Object oField = oTable.getColumns().getByName(_oFieldColumn.getFieldName()); - int iType = AnyConverter.toInt(Helper.getUnoPropertyValue(oField, "Type")); - int ifound = java.util.Arrays.binarySearch(NumericTypes, iType); - if ((ifound < NumericTypes.length) && (ifound > 0)) - { - return (NumericTypes[ifound] == iType); - } - else - { - return false; - } + return (NumericTypes[ifound] == iType); } - catch (Exception exception) + else { - exception.printStackTrace(System.out); return false; } } + catch (Exception exception) + { + exception.printStackTrace(System.out); + return false; + } + } public String[] setNumericFields() + { + try { - try + ArrayList numericfieldsvector = new java.util.ArrayList(); + for (int i = 0; i < FieldColumns.length; i++) { - Vector numericfieldsvector = new java.util.Vector(); - for (int i = 0; i < FieldColumns.length; i++) + if (isnumeric(FieldColumns[i])) { - if (isnumeric(FieldColumns[i])) - { - numericfieldsvector.addElement(FieldColumns[i].getDisplayFieldName()); - } + numericfieldsvector.add(FieldColumns[i].getDisplayFieldName()); } - NumericFieldNames = new String[numericfieldsvector.size()]; - numericfieldsvector.toArray(NumericFieldNames); - return NumericFieldNames; - } - catch (Exception exception) - { - exception.printStackTrace(System.out); - return new String[]{}; } + NumericFieldNames = new String[numericfieldsvector.size()]; + numericfieldsvector.toArray(NumericFieldNames); + return NumericFieldNames; } + catch (Exception exception) + { + exception.printStackTrace(System.out); + return new String[] + { + }; + } + } public String[] getFieldNames(String[] _sDisplayFieldNames, String _sCommandName) + { + ArrayList sFieldNamesVector = new java.util.ArrayList(); + for (int i = 0; i < FieldColumns.length; i++) { - Vector sFieldNamesVector = new java.util.Vector(); - for (int i = 0; i < FieldColumns.length; i++) + if (_sCommandName.equals(FieldColumns[i].getCommandName()) && JavaTools.FieldInList(_sDisplayFieldNames, FieldColumns[i].getDisplayFieldName()) > -1) { - if (_sCommandName.equals(FieldColumns[i].getCommandName())) - { - if (JavaTools.FieldInList(_sDisplayFieldNames, FieldColumns[i].getDisplayFieldName()) > -1) - { - sFieldNamesVector.addElement(FieldColumns[i].getFieldName()); - } - } + sFieldNamesVector.add(FieldColumns[i].getFieldName()); } - String[] sFieldNames = new String[sFieldNamesVector.size()]; - sFieldNamesVector.toArray(sFieldNames); - return sFieldNames; } - - + String[] sFieldNames = new String[sFieldNamesVector.size()]; + sFieldNamesVector.toArray(sFieldNames); + return sFieldNames; + } public String[] getFieldNames() + { + String[] sFieldNames = new String[FieldColumns.length]; + for (int i = 0; i < FieldColumns.length; i++) { - String[] sFieldNames = new String[FieldColumns.length]; - for (int i = 0; i < FieldColumns.length; i++) - { - sFieldNames[i] = FieldColumns[i].getFieldName(); - } - return sFieldNames; + sFieldNames[i] = FieldColumns[i].getFieldName(); } + return sFieldNames; + } public String[] getDisplayFieldNames() + { + String[] sDisplayFieldNames = new String[FieldColumns.length]; + for (int i = 0; i < FieldColumns.length; i++) { - String[] sDisplayFieldNames = new String[FieldColumns.length]; - for (int i = 0; i < FieldColumns.length; i++) - { - sDisplayFieldNames[i] = FieldColumns[i].getDisplayFieldName(); - } - return sDisplayFieldNames; + sDisplayFieldNames[i] = FieldColumns[i].getDisplayFieldName(); } - + return sDisplayFieldNames; + } public String[] setNonAggregateFieldNames() + { + try { - try + ArrayList nonaggregatefieldsvector = new java.util.ArrayList(); + for (int i = 0; i < FieldColumns.length; i++) { - Vector nonaggregatefieldsvector = new java.util.Vector(); - for (int i = 0; i < FieldColumns.length; i++) + if (JavaTools.FieldInTable(AggregateFieldNames, FieldColumns[i].getDisplayFieldName()) == -1) { - if (JavaTools.FieldInTable(AggregateFieldNames, FieldColumns[i].getDisplayFieldName()) == -1) - { - nonaggregatefieldsvector.addElement(FieldColumns[i].getDisplayFieldName()); - } + nonaggregatefieldsvector.add(FieldColumns[i].getDisplayFieldName()); } - NonAggregateFieldNames = new String[nonaggregatefieldsvector.size()]; - nonaggregatefieldsvector.toArray(NonAggregateFieldNames); - return NonAggregateFieldNames; - } - catch (Exception exception) - { - exception.printStackTrace(System.out); - return new String[]{}; } + NonAggregateFieldNames = new String[nonaggregatefieldsvector.size()]; + nonaggregatefieldsvector.toArray(NonAggregateFieldNames); + return NonAggregateFieldNames; } + catch (Exception exception) + { + exception.printStackTrace(System.out); + return new String[] + { + }; + } + } /** * the fieldnames passed over are not necessarily the ones that are defined in the class @@ -508,108 +496,103 @@ public class CommandMetaData extends DBMetaData * @return */ public boolean hasNumericalFields(String[] _DisplayFieldNames) - + { + if (_DisplayFieldNames != null && _DisplayFieldNames.length > 0) { - if (_DisplayFieldNames != null) + for (int i = 0; i < _DisplayFieldNames.length; i++) { - if (_DisplayFieldNames.length > 0) + if (isnumeric(getFieldColumnByDisplayName(_DisplayFieldNames[i]))) { - for (int i = 0; i < _DisplayFieldNames.length; i++) - { - if (isnumeric(getFieldColumnByDisplayName(_DisplayFieldNames[i]))) - { - return true; - } - } + return true; } } - return false; } + return false; + } public String getFieldTitle(String FieldName) + { + String FieldTitle = FieldName; + if (this.FieldTitleSet != null) { - String FieldTitle = FieldName; - if (this.FieldTitleSet != null) + FieldTitle = (String) this.FieldTitleSet.get(FieldName); //FieldTitles[TitleIndex]; + if (FieldTitle == null) { - FieldTitle = (String) this.FieldTitleSet.get(FieldName); //FieldTitles[TitleIndex]; - if (FieldTitle == null) - { - return FieldName; - } + return FieldName; } - return FieldTitle; } - + return FieldTitle; + } public void setFieldTitles(String[] sFieldTitles) + { + int nFieldColLength = FieldColumns.length; + for (int i = 0; i < sFieldTitles.length; i++) { - int nFieldColLength = FieldColumns.length; - for (int i = 0; i < sFieldTitles.length; i++) + if (i < nFieldColLength) { - if (i < nFieldColLength) - { - FieldColumns[i].setFieldTitle(sFieldTitles[i]); - } - + FieldColumns[i].setFieldTitle(sFieldTitles[i]); } - } + } + } public String[] getFieldTitles() + { + String[] sFieldTitles = new String[FieldColumns.length]; + for (int i = 0; i < FieldColumns.length; i++) { - String[] sFieldTitles = new String[FieldColumns.length]; - for (int i = 0; i < FieldColumns.length; i++) - { - sFieldTitles[i] = FieldColumns[i].getFieldTitle(); - } - return sFieldTitles; + sFieldTitles[i] = FieldColumns[i].getFieldTitle(); } - + return sFieldTitles; + } public void setGroupFieldNames(String[] GroupFieldNames) - { - this.GroupFieldNames = GroupFieldNames; - } - + { + this.GroupFieldNames = GroupFieldNames; + } public String[] getGroupFieldNames() - { - return GroupFieldNames; - } + { + return GroupFieldNames; + } public void createRecordFieldNames() - { - String CurFieldName; - int GroupFieldCount; - int TotFieldCount = FieldColumns.length; - // int SortFieldCount = SortFieldNames[0].length; - GroupFieldCount = JavaTools.getArraylength(GroupFieldNames); - RecordFieldNames = new String[TotFieldCount - GroupFieldCount]; + { + String CurFieldName; + int GroupFieldCount; + int TotFieldCount = FieldColumns.length; + // int SortFieldCount = SortFieldNames[0].length; + GroupFieldCount = JavaTools.getArraylength(GroupFieldNames); + RecordFieldNames = new String[TotFieldCount - GroupFieldCount]; - int a = 0; - for (int i = 0; i < TotFieldCount; i++) + int a = 0; + for (int i = 0; i < TotFieldCount; i++) + { + CurFieldName = FieldColumns[i].getFieldName(); + if (JavaTools.FieldInList(GroupFieldNames, CurFieldName) < 0) { - CurFieldName = FieldColumns[i].getFieldName(); - if (JavaTools.FieldInList(GroupFieldNames, CurFieldName) < 0) - { - RecordFieldNames[a] = CurFieldName; - // a += 1; - ++a; - } + RecordFieldNames[a] = CurFieldName; + // a += 1; + ++a; } } - public void setRecordFieldNames(String [] _aNewList) - { - RecordFieldNames = _aNewList; - } - public String[] getRecordFieldNames() - { - return RecordFieldNames; - } - public String getRecordFieldName(int i) - { - return RecordFieldNames[i]; - } + } + + public void setRecordFieldNames(String[] _aNewList) + { + RecordFieldNames = _aNewList; + } + + public String[] getRecordFieldNames() + { + return RecordFieldNames; + } + + public String getRecordFieldName(int i) + { + return RecordFieldNames[i]; + } /**@deprecated use 'RelationController' class instead * @@ -618,46 +601,45 @@ public class CommandMetaData extends DBMetaData * @return */ public String[] getReferencedTables(String _stablename, int _ncommandtype) + { + String[] sTotReferencedTables = new String[] { - String[] sTotReferencedTables = new String[]{}; - try + }; + try + { + if (_ncommandtype == com.sun.star.sdb.CommandType.TABLE && xDBMetaData.supportsIntegrityEnhancementFacility()) { - if (_ncommandtype == com.sun.star.sdb.CommandType.TABLE) + java.util.ArrayList TableVector = new java.util.ArrayList(); + Object oTable = getTableNamesAsNameAccess().getByName(_stablename); + XKeysSupplier xKeysSupplier = UnoRuntime.queryInterface(XKeysSupplier.class, oTable); + xIndexKeys = xKeysSupplier.getKeys(); + for (int i = 0; i < xIndexKeys.getCount(); i++) { - if (xDBMetaData.supportsIntegrityEnhancementFacility()) + XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xIndexKeys.getByIndex(i)); + int curtype = AnyConverter.toInt(xPropertySet.getPropertyValue("Type")); + if (curtype == KeyType.FOREIGN) { - java.util.Vector TableVector = new java.util.Vector(); - Object oTable = getTableNamesAsNameAccess().getByName(_stablename); - XKeysSupplier xKeysSupplier = UnoRuntime.queryInterface( XKeysSupplier.class, oTable ); - xIndexKeys = xKeysSupplier.getKeys(); - for (int i = 0; i < xIndexKeys.getCount(); i++) + // getImportedKeys (RelationController.cxx /source/ui/relationdesign) /Zeile 475 + String sreftablename = AnyConverter.toString(xPropertySet.getPropertyValue("ReferencedTable")); + if (getTableNamesAsNameAccess().hasByName(sreftablename)) { - XPropertySet xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, xIndexKeys.getByIndex( i ) ); - int curtype = AnyConverter.toInt(xPropertySet.getPropertyValue("Type")); - if (curtype == KeyType.FOREIGN) - { - // getImportedKeys (RelationController.cxx /source/ui/relationdesign) /Zeile 475 - String sreftablename = AnyConverter.toString(xPropertySet.getPropertyValue("ReferencedTable")); - if (getTableNamesAsNameAccess().hasByName(sreftablename)) - { - TableVector.addElement(sreftablename); - } - } - } - if (TableVector.size() > 0) - { - sTotReferencedTables = new String[TableVector.size()]; - TableVector.copyInto(sTotReferencedTables); + TableVector.add(sreftablename); } } } + if (TableVector.size() > 0) + { + sTotReferencedTables = new String[TableVector.size()]; + TableVector.toArray(sTotReferencedTables); + } } - catch (Exception e) - { - e.printStackTrace(System.out); - } - return sTotReferencedTables; } + catch (Exception e) + { + e.printStackTrace(System.out); + } + return sTotReferencedTables; + } /**@deprecated use 'RelationController' class instead * @@ -665,108 +647,95 @@ public class CommandMetaData extends DBMetaData * @return */ public String[][] getKeyColumns(String _sreferencedtablename) + { + String[][] skeycolumnnames = null; + try { - String[][] skeycolumnnames = null; - try + for (int i = 0; i < xIndexKeys.getCount(); i++) { - for (int i = 0; i < xIndexKeys.getCount(); i++) + XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xIndexKeys.getByIndex(i)); + int curtype = AnyConverter.toInt(xPropertySet.getPropertyValue("Type")); + if (curtype == KeyType.FOREIGN) { - XPropertySet xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, xIndexKeys.getByIndex( i ) ); - int curtype = AnyConverter.toInt(xPropertySet.getPropertyValue("Type")); - if (curtype == KeyType.FOREIGN) + String scurreftablename = AnyConverter.toString(xPropertySet.getPropertyValue("ReferencedTable")); + if (getTableNamesAsNameAccess().hasByName(scurreftablename)) { - String scurreftablename = AnyConverter.toString(xPropertySet.getPropertyValue("ReferencedTable")); - if (getTableNamesAsNameAccess().hasByName(scurreftablename)) + if (scurreftablename.equals(_sreferencedtablename)) { - if (scurreftablename.equals(_sreferencedtablename)) + XColumnsSupplier xColumnsSupplier = UnoRuntime.queryInterface(XColumnsSupplier.class, xPropertySet); + String[] smastercolnames = xColumnsSupplier.getColumns().getElementNames(); + skeycolumnnames = new String[2][smastercolnames.length]; + skeycolumnnames[0] = smastercolnames; + skeycolumnnames[1] = new String[smastercolnames.length]; + for (int n = 0; n < smastercolnames.length; n++) { - XColumnsSupplier xColumnsSupplier = UnoRuntime.queryInterface( XColumnsSupplier.class, xPropertySet ); - String[] smastercolnames = xColumnsSupplier.getColumns().getElementNames(); - skeycolumnnames = new String[2][smastercolnames.length]; - skeycolumnnames[0] = smastercolnames; - skeycolumnnames[1] = new String[smastercolnames.length]; - for (int n = 0; n < smastercolnames.length; n++) - { - XPropertySet xcolPropertySet = UnoRuntime.queryInterface( XPropertySet.class, xColumnsSupplier.getColumns().getByName( smastercolnames[n] ) ); - skeycolumnnames[1][n] = AnyConverter.toString(xcolPropertySet.getPropertyValue("RelatedColumn")); - } - return skeycolumnnames; + XPropertySet xcolPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xColumnsSupplier.getColumns().getByName(smastercolnames[n])); + skeycolumnnames[1][n] = AnyConverter.toString(xcolPropertySet.getPropertyValue("RelatedColumn")); } + return skeycolumnnames; } } } } - catch (Exception e) - { - e.printStackTrace(); - } - return skeycolumnnames; } - + catch (Exception e) + { + e.printStackTrace(); + } + return skeycolumnnames; + } public void openFormDocument(boolean _bReadOnly) - { - try - { - Object oEmbeddedFactory = super.xMSF.createInstance("com.sun.star.embed.OOoEmbeddedObjectFactory"); - int iEntryInitMode = EntryInitModes.DEFAULT_INIT; //TRUNCATE_INIT??? - } - catch (Exception e) - { - e.printStackTrace(System.out); - } - } - + { + } public void setCommandComposingAttributes() + { + try { - try - { - boolean bCatalogAtStart2 = xDBMetaData.isCatalogAtStart(); - sCatalogSep = xDBMetaData.getCatalogSeparator(); - sIdentifierQuote = xDBMetaData.getIdentifierQuoteString(); - bCommandComposerAttributesalreadyRetrieved = true; - } - catch (SQLException e) - { - e.printStackTrace(System.out); - } + sCatalogSep = xDBMetaData.getCatalogSeparator(); + sIdentifierQuote = xDBMetaData.getIdentifierQuoteString(); + bCommandComposerAttributesalreadyRetrieved = true; } - + catch (SQLException e) + { + e.printStackTrace(System.out); + } + } /** * @return Returns the bCatalogAtStart. */ public boolean isCatalogAtStart() + { + if (!bCommandComposerAttributesalreadyRetrieved) { - if (!bCommandComposerAttributesalreadyRetrieved) - { - setCommandComposingAttributes(); - } - return bCatalogAtStart; + setCommandComposingAttributes(); } + return bCatalogAtStart; + } /** * @return Returns the sCatalogSep. */ public String getCatalogSeparator() + { + if (!bCommandComposerAttributesalreadyRetrieved) { - if (!bCommandComposerAttributesalreadyRetrieved) - { - setCommandComposingAttributes(); - } - return sCatalogSep; + setCommandComposingAttributes(); } + return sCatalogSep; + } /** * @return Returns the sIdentifierQuote. */ public String getIdentifierQuote() + { + if (!bCommandComposerAttributesalreadyRetrieved) { - if (!bCommandComposerAttributesalreadyRetrieved) - { - setCommandComposingAttributes(); - } - return sIdentifierQuote; + setCommandComposingAttributes(); } + return sIdentifierQuote; + } } diff --git a/wizards/com/sun/star/wizards/db/CommandName.java b/wizards/com/sun/star/wizards/db/CommandName.java index aa8a4f9c7ea9..3c6686868ff3 100644 --- a/wizards/com/sun/star/wizards/db/CommandName.java +++ b/wizards/com/sun/star/wizards/db/CommandName.java @@ -205,9 +205,7 @@ public class CommandName { sName = ""; } - String ReturnQuote = ""; - ReturnQuote = _sIdentifierQuote + sName + _sIdentifierQuote; - return ReturnQuote; + return new StringBuilder(_sIdentifierQuote).append(sName).append(_sIdentifierQuote).toString(); } public void setAliasName(String _AliasName) diff --git a/wizards/com/sun/star/wizards/db/QueryMetaData.java b/wizards/com/sun/star/wizards/db/QueryMetaData.java index bad14c2faa20..5fe6cd55c3a9 100644 --- a/wizards/com/sun/star/wizards/db/QueryMetaData.java +++ b/wizards/com/sun/star/wizards/db/QueryMetaData.java @@ -101,9 +101,10 @@ public class QueryMetaData extends CommandMetaData // FieldColumns = LocFieldColumns; // } // } + public void addSeveralFieldColumns(String[] _FieldNames, String _sCommandName) { - Vector oToBeAddedFieldColumns = new Vector(); + ArrayList oToBeAddedFieldColumns = new ArrayList(); for (int i = 0; i < _FieldNames.length; i++) { FieldColumn oFieldColumn = getFieldColumn(_FieldNames[i], _sCommandName); @@ -119,7 +120,7 @@ public class QueryMetaData extends CommandMetaData System.arraycopy(FieldColumns, 0, LocFieldColumns, 0, nOldFieldCount); for (int i = 0; i < oToBeAddedFieldColumns.size(); i++) { - LocFieldColumns[nOldFieldCount + i] = (FieldColumn) oToBeAddedFieldColumns.elementAt(i); + LocFieldColumns[nOldFieldCount + i] = oToBeAddedFieldColumns.get(i); } FieldColumns = LocFieldColumns; } @@ -138,7 +139,7 @@ public class QueryMetaData extends CommandMetaData public void removeSeveralFieldColumnsByDisplayFieldName(String[] _DisplayFieldNames) { - Vector oRemainingFieldColumns = new Vector(); + ArrayList oRemainingFieldColumns = new ArrayList(); int a = 0; for (int n = 0; n < FieldColumns.length; n++) { @@ -161,13 +162,10 @@ public class QueryMetaData extends CommandMetaData FieldColumn[] LocFieldColumns = new FieldColumn[FieldColumns.length - 1]; for (int i = 0; i < FieldColumns.length; i++) { - if (!FieldColumns[i].getFieldName().equals(_sFieldName)) + if (!FieldColumns[i].getFieldName().equals(_sFieldName) && !FieldColumns[i].getCommandName().equals(_sCommandName)) { - if (!FieldColumns[i].getCommandName().equals(_sCommandName)) - { - LocFieldColumns[a] = FieldColumns[i]; - a++; - } + LocFieldColumns[a] = FieldColumns[i]; + a++; } } FieldColumns = LocFieldColumns; @@ -177,7 +175,7 @@ public class QueryMetaData extends CommandMetaData public String[] getIncludedCommandNames() { // FieldColumn CurQueryField; - Vector CommandNamesV = new Vector(1); + ArrayList CommandNamesV = new ArrayList(1); // String CurCommandName; for (int i = 0; i < FieldColumns.length; i++) { @@ -185,7 +183,7 @@ public class QueryMetaData extends CommandMetaData final String CurCommandName = CurQueryField.getCommandName(); if (!CommandNamesV.contains(CurCommandName)) { - CommandNamesV.addElement(CurCommandName); + CommandNamesV.add(CurCommandName); } } String[] sIncludedCommandNames = new String[CommandNamesV.size()]; @@ -195,7 +193,7 @@ public class QueryMetaData extends CommandMetaData public static String[] getIncludedCommandNames(String[] _FieldNames) { - Vector CommandNames = new Vector(1); + ArrayList CommandNames = new ArrayList(1); for (int i = 0; i < _FieldNames.length; i++) { String CurCommandName = ""; @@ -208,7 +206,7 @@ public class QueryMetaData extends CommandMetaData } if (!CommandNames.contains(CurCommandName)) { - CommandNames.addElement(CurCommandName); + CommandNames.add(CurCommandName); } } } @@ -257,7 +255,7 @@ public class QueryMetaData extends CommandMetaData public String[] getUniqueAggregateFieldNames() { - Vector UniqueAggregateFieldVector = new Vector(0); + ArrayList UniqueAggregateFieldVector = new ArrayList(); for (int i = 0; i < AggregateFieldNames.length; i++) { if (!UniqueAggregateFieldVector.contains(AggregateFieldNames[i][0])) @@ -291,10 +289,13 @@ public class QueryMetaData extends CommandMetaData } return iAggregate; } + public SQLQueryComposer getSQLQueryComposer() { - if ( oSQLQueryComposer == null ) + if (oSQLQueryComposer == null) + { oSQLQueryComposer = new SQLQueryComposer(this); + } return oSQLQueryComposer; } } diff --git a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java index 038f00a58bd7..e088fb75641f 100644 --- a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java +++ b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java @@ -26,7 +26,6 @@ ************************************************************************/ package com.sun.star.wizards.db; -import java.util.Vector; // import com.sun.star.lang.IllegalArgumentException; // import com.sun.star.lang.WrappedTargetException; @@ -37,7 +36,6 @@ import com.sun.star.container.XIndexAccess; // import com.sun.star.container.XNameAccess; import com.sun.star.sdbcx.XColumnsSupplier; // import com.sun.star.sdb.XColumn; -import com.sun.star.sdb.XSQLQueryComposerFactory; import com.sun.star.sdb.XSingleSelectQueryComposer; import com.sun.star.sdb.XSingleSelectQueryAnalyzer; import com.sun.star.ui.dialogs.XExecutableDialog; @@ -50,6 +48,7 @@ import com.sun.star.awt.XWindow; import com.sun.star.sdb.SQLFilterOperator; import com.sun.star.wizards.common.*; +import java.util.ArrayList; public class SQLQueryComposer { @@ -60,7 +59,7 @@ public class SQLQueryComposer // String m_sSelectClause; // String m_sFromClause; public XSingleSelectQueryAnalyzer m_xQueryAnalyzer; - Vector composedCommandNames = new Vector(1); + ArrayList composedCommandNames = new ArrayList(1); private XSingleSelectQueryComposer m_queryComposer; XMultiServiceFactory xMSF; boolean bincludeGrouping = true; @@ -74,9 +73,6 @@ public class SQLQueryComposer final Object oQueryComposer = xMSF.createInstance("com.sun.star.sdb.SingleSelectQueryComposer"); m_xQueryAnalyzer = (XSingleSelectQueryAnalyzer) UnoRuntime.queryInterface(XSingleSelectQueryAnalyzer.class, oQueryComposer); m_queryComposer = (XSingleSelectQueryComposer) UnoRuntime.queryInterface(XSingleSelectQueryComposer.class, m_xQueryAnalyzer); - XSQLQueryComposerFactory xSQLComposerFactory; - xSQLComposerFactory = (XSQLQueryComposerFactory) UnoRuntime.queryInterface(XSQLQueryComposerFactory.class, CurDBMetaData.DBConnection); - // /* XSQLQueryComposer */ xSQLQueryComposer = xSQLComposerFactory.createQueryComposer(); } catch (Exception exception) { @@ -86,18 +82,9 @@ public class SQLQueryComposer private boolean addtoSelectClause(String DisplayFieldName) throws SQLException { - if (bincludeGrouping) + if (bincludeGrouping && CurDBMetaData.xDBMetaData.supportsGroupByUnrelated() && CurDBMetaData.GroupFieldNames != null && JavaTools.FieldInList(CurDBMetaData.GroupFieldNames, DisplayFieldName) > -1) { - if (CurDBMetaData.xDBMetaData.supportsGroupByUnrelated()) - { - if (CurDBMetaData.GroupFieldNames != null) - { - if (JavaTools.FieldInList(CurDBMetaData.GroupFieldNames, DisplayFieldName) > -1) - { - return false; - } - } - } + return false; } return true; } @@ -234,7 +221,6 @@ public class SQLQueryComposer } // just for debug! sOrder = m_queryComposer.getOrder(); - int dummy = 0; } public void appendGroupByColumns(boolean _baddAliasFieldNames) throws SQLException @@ -244,7 +230,6 @@ public class SQLQueryComposer XPropertySet xColumn = CurDBMetaData.getColumnObjectByFieldName(CurDBMetaData.GroupFieldNames[i], _baddAliasFieldNames); m_queryComposer.appendGroupByColumn(xColumn); } - String s = m_xQueryAnalyzer.getQuery(); } public void setDBMetaData(QueryMetaData _oDBMetaData) @@ -269,19 +254,19 @@ public class SQLQueryComposer return m_xQueryAnalyzer.getQuery(); } - public String getFromClause() + public StringBuilder getFromClause() { - String sFromClause = "FROM"; + StringBuilder sFromClause = new StringBuilder("FROM"); composedCommandNames.clear(); String[] sCommandNames = CurDBMetaData.getIncludedCommandNames(); for (int i = 0; i < sCommandNames.length; i++) { CommandName curCommandName = new CommandName(CurDBMetaData, sCommandNames[i]); //(setComposedCommandName) curCommandName.setAliasName(getuniqueAliasName(curCommandName.getTableName())); - sFromClause += " " + curCommandName.getComposedName() + " " + quoteName(curCommandName.getAliasName()); + sFromClause.append(" ").append(curCommandName.getComposedName()).append(" ").append(quoteName(curCommandName.getAliasName())); if (i < sCommandNames.length - 1) { - sFromClause += ", "; + sFromClause.append(", "); } // fill composedCommandNames composedCommandNames.add(curCommandName); @@ -291,30 +276,25 @@ public class SQLQueryComposer public boolean setQueryCommand(XWindow _xParentWindow, boolean _bincludeGrouping, boolean _baddAliasFieldNames) { - return setQueryCommand(_xParentWindow,_bincludeGrouping, _baddAliasFieldNames,true); + return setQueryCommand(_xParentWindow, _bincludeGrouping, _baddAliasFieldNames, true); } + public boolean setQueryCommand(XWindow _xParentWindow, boolean _bincludeGrouping, boolean _baddAliasFieldNames, boolean addQuery) { try { - String s; bincludeGrouping = _bincludeGrouping; - if ( addQuery ) + if (addQuery) { - String sFromClause = getFromClause(); String sSelectClause = getSelectClause(_baddAliasFieldNames); - String queryclause = sSelectClause + " " + sFromClause; - m_xQueryAnalyzer.setQuery(queryclause); - if (CurDBMetaData.getFilterConditions() != null) + StringBuilder queryclause = new StringBuilder(sSelectClause).append(" ").append(getFromClause()); + m_xQueryAnalyzer.setQuery(queryclause.toString()); + if (CurDBMetaData.getFilterConditions() != null && CurDBMetaData.getFilterConditions().length > 0) { - if (CurDBMetaData.getFilterConditions().length > 0) - { - CurDBMetaData.setFilterConditions(replaceConditionsByAlias(CurDBMetaData.getFilterConditions())); - m_queryComposer.setStructuredFilter(CurDBMetaData.getFilterConditions()); - } + CurDBMetaData.setFilterConditions(replaceConditionsByAlias(CurDBMetaData.getFilterConditions())); + m_queryComposer.setStructuredFilter(CurDBMetaData.getFilterConditions()); } } - s = m_xQueryAnalyzer.getQuery(); if (_bincludeGrouping) { appendGroupByColumns(_baddAliasFieldNames); @@ -325,7 +305,6 @@ public class SQLQueryComposer } appendSortingcriteria(_baddAliasFieldNames); - s = m_xQueryAnalyzer.getQuery(); return true; } catch (Exception exception) @@ -340,8 +319,10 @@ public class SQLQueryComposer { FieldColumn CurFieldColumn = CurDBMetaData.getFieldColumnByDisplayName(_fieldname); CommandName curComposedCommandName = getComposedCommandByDisplayName(CurFieldColumn.getCommandName()); - if ( curComposedCommandName == null ) + if (curComposedCommandName == null) + { return _fieldname; + } String curAliasName = curComposedCommandName.getAliasName(); return quoteName(curAliasName) + "." + quoteName(CurFieldColumn.getFieldName()); } @@ -350,13 +331,11 @@ public class SQLQueryComposer { if (composedCommandNames != null) { - CommandName curComposedName; - for (int i = 0; i < composedCommandNames.size(); i++) + for (CommandName commandName : composedCommandNames) { - curComposedName = (CommandName) composedCommandNames.elementAt(i); - if (curComposedName.getAliasName().equals(_AliasName)) + if (commandName.getAliasName().equals(_AliasName)) { - return curComposedName; + return commandName; } } } @@ -367,13 +346,11 @@ public class SQLQueryComposer { if (composedCommandNames != null) { - CommandName curComposedName; - for (int i = 0; i < composedCommandNames.size(); i++) + for (CommandName commandName : composedCommandNames) { - curComposedName = (CommandName) composedCommandNames.elementAt(i); - if (curComposedName.getDisplayName().equals(_DisplayName)) + if (commandName.getDisplayName().equals(_DisplayName)) { - return curComposedName; + return commandName; } } } @@ -420,7 +397,7 @@ public class SQLQueryComposer rDispatchArguments[2] = Properties.createProperty("SQLException", _exception); xInitialize.initialize(rDispatchArguments); xExecute.execute(); - //TODO dispose??? + //TODO dispose??? } catch (Exception typeexception) { @@ -443,38 +420,40 @@ public class SQLQueryComposer public PropertyValue[][] getNormalizedStructuredFilter() { final PropertyValue[][] structuredFilter = m_queryComposer.getStructuredFilter(); - for ( int i=0; i 0) { - if (_filterconditions.length > 0) + String sconditions = ""; + String sStart = oResource.getResText(_InitResID); + String BaseString = oResource.getResText(RID_QUERY + 96); + if (_filterconditions.length == 1) { - String sconditions = ""; - String sStart = oResource.getResText(_InitResID); - String BaseString = oResource.getResText(RID_QUERY + 96); - if (_filterconditions.length == 1) + PropertyValue[] curfilterconditions = _filterconditions[0]; + for (int i = 0; i < curfilterconditions.length; i++) { - PropertyValue[] curfilterconditions = _filterconditions[0]; - for (int i = 0; i < curfilterconditions.length; i++) - { - sconditions += FilterComponent.getDisplayCondition(BaseString, _filterconditions[0][i], this); - sconditions = appendClauseSeparator(sconditions, " " + sAnd + " ", i, curfilterconditions.length); - } + sconditions += FilterComponent.getDisplayCondition(BaseString, _filterconditions[0][i], this); + sconditions = appendClauseSeparator(sconditions, " " + sAnd + " ", i, curfilterconditions.length); } - else - { - - for (int i = 0; i < _filterconditions.length; i++) - { - sconditions += FilterComponent.getDisplayCondition(BaseString, _filterconditions[i][0], this); - sconditions = appendClauseSeparator(sconditions, " " + sOr + " ", i, _filterconditions.length); - } - } - String sreturn = sStart + sconditions; - return sreturn; } + else + { + + for (int i = 0; i < _filterconditions.length; i++) + { + sconditions += FilterComponent.getDisplayCondition(BaseString, _filterconditions[i][0], this); + sconditions = appendClauseSeparator(sconditions, " " + sOr + " ", i, _filterconditions.length); + } + } + String sreturn = sStart + sconditions; + return sreturn; } return oResource.getResText(_AlternativeResID); } @@ -173,14 +161,12 @@ public class QuerySummary extends QueryMetaData return _basestring; } // TODO: How can you merge the following two methods to a single one in a smarter way?? + public String combinePartString(int _InitResID, String[] _FieldNames, int _AlternativeResID) { - if (_FieldNames != null) + if (_FieldNames != null && _FieldNames.length > 0) { - if (_FieldNames.length > 0) - { - return ArrayFieldsToString(_InitResID, _FieldNames); - } + return ArrayFieldsToString(_InitResID, _FieldNames); } return oResource.getResText(_AlternativeResID); } @@ -202,12 +188,9 @@ public class QuerySummary extends QueryMetaData public String combinePartString(int _InitResID, String[][] _FieldNames, int _AlternativeResID, int _BaseStringID, String[] _ReplaceTags) { - if (_FieldNames != null) + if (_FieldNames != null && _FieldNames.length > 0) { - if (_FieldNames.length > 0) - { - return ArrayFieldsToString(_InitResID, _FieldNames, _BaseStringID, _ReplaceTags); - } + return ArrayFieldsToString(_InitResID, _FieldNames, _BaseStringID, _ReplaceTags); } return oResource.getResText(_AlternativeResID); } diff --git a/wizards/com/sun/star/wizards/query/QueryWizard.java b/wizards/com/sun/star/wizards/query/QueryWizard.java index c31315b965a0..a0696a435e77 100644 --- a/wizards/com/sun/star/wizards/query/QueryWizard.java +++ b/wizards/com/sun/star/wizards/query/QueryWizard.java @@ -53,6 +53,7 @@ import com.sun.star.wizards.ui.TitlesComponent; public class QueryWizard extends DatabaseObjectWizard { + public static final String SFILLUPFIELDSLISTBOX = "fillUpFieldsListbox"; private static final int SOFIELDSELECTION_PAGE = 1; private static final int SOSORTING_PAGE = 2; @@ -81,16 +82,19 @@ public class QueryWizard extends DatabaseObjectWizard private String resmsgNonNumericAsGroupBy; private String m_createdQuery; - public QueryWizard( XMultiServiceFactory xMSF, PropertyValue[] i_wizardContext ) + public QueryWizard(XMultiServiceFactory xMSF, PropertyValue[] i_wizardContext) { - super( xMSF, 40970, i_wizardContext ); + super(xMSF, 40970, i_wizardContext); addResourceHandler("QueryWizard", "dbw"); m_DBMetaData = new QuerySummary(xMSF, m_oResource); } public static void main(String i_args[]) { - final String settings[] = new String[] { null, null, null }; + final String settings[] = new String[] + { + null, null, null + }; final int IDX_PIPE_NAME = 0; final int IDX_LOCATION = 1; final int IDX_DSN = 2; @@ -98,28 +102,28 @@ public class QueryWizard extends DatabaseObjectWizard // some simple parsing boolean failure = false; int settingsIndex = -1; - for ( int i=0; i= 0 ) + if (settingsIndex >= 0) { - settings[ settingsIndex ] = i_args[i]; + settings[ settingsIndex] = i_args[i]; settingsIndex = -1; continue; } - if ( i_args[i].equals( "--pipe-name" ) ) + if (i_args[i].equals("--pipe-name")) { settingsIndex = IDX_PIPE_NAME; continue; } - if ( i_args[i].equals( "--database-location" ) ) + if (i_args[i].equals("--database-location")) { settingsIndex = IDX_LOCATION; continue; } - if ( i_args[i].equals( "--data-source-name" ) ) + if (i_args[i].equals("--data-source-name")) { settingsIndex = IDX_DSN; continue; @@ -128,18 +132,22 @@ public class QueryWizard extends DatabaseObjectWizard failure = true; } - if ( settings[ IDX_PIPE_NAME ] == null ) - failure = true; - - if ( ( settings[ IDX_DSN ] == null ) && ( settings[ IDX_LOCATION ] == null ) ) - failure = true; - - if ( failure ) + if (settings[ IDX_PIPE_NAME] == null) { - System.err.println( "supported arguments: " ); - System.err.println( " --pipe-name : specifies the name of the pipe to connect to the running OOo instance" ); - System.err.println( " --database-location : specifies the URL of the database document to work with" ); - System.err.println( " --data-source-name : specifies the name of the data source to work with" ); + failure = true; + } + + if ((settings[ IDX_DSN] == null) && (settings[ IDX_LOCATION] == null)) + { + failure = true; + } + + if (failure) + { + System.err.println("supported arguments: "); + System.err.println(" --pipe-name : specifies the name of the pipe to connect to the running OOo instance"); + System.err.println(" --database-location : specifies the URL of the database document to work with"); + System.err.println(" --data-source-name : specifies the name of the data source to work with"); return; } @@ -150,12 +158,16 @@ public class QueryWizard extends DatabaseObjectWizard if (serviceFactory != null) { PropertyValue[] curproperties = new PropertyValue[1]; - if ( settings[ IDX_LOCATION ] != null ) - curproperties[0] = Properties.createProperty( "DatabaseLocation", settings[ IDX_LOCATION ] ); + if (settings[ IDX_LOCATION] != null) + { + curproperties[0] = Properties.createProperty("DatabaseLocation", settings[ IDX_LOCATION]); + } else - curproperties[0] = Properties.createProperty( "DataSourceName", settings[ IDX_DSN ] ); + { + curproperties[0] = Properties.createProperty("DataSourceName", settings[ IDX_DSN]); + } - QueryWizard CurQueryWizard = new QueryWizard( serviceFactory, curproperties ); + QueryWizard CurQueryWizard = new QueryWizard(serviceFactory, curproperties); CurQueryWizard.startQueryWizard(); } } @@ -174,7 +186,7 @@ public class QueryWizard extends DatabaseObjectWizard { try { - if ( m_DBMetaData.getConnection( m_wizardContext ) ) + if (m_DBMetaData.getConnection(m_wizardContext)) { reslblFields = m_oResource.getResText(UIConsts.RID_QUERY + 4); reslblFieldHeader = m_oResource.getResText(UIConsts.RID_QUERY + 19); //Fielnames in AliasComponent @@ -196,13 +208,13 @@ public class QueryWizard extends DatabaseObjectWizard setRightPaneHeaders(m_oResource, UIConsts.RID_QUERY + 70, 8); this.setMaxStep(8); buildSteps(); - this.m_DBCommandFieldSelectio.preselectCommand( m_wizardContext, false ); + this.m_DBCommandFieldSelectio.preselectCommand(m_wizardContext, false); - XWindowPeer windowPeer = UnoRuntime.queryInterface( XWindowPeer.class, m_frame.getContainerWindow() ); + XWindowPeer windowPeer = UnoRuntime.queryInterface(XWindowPeer.class, m_frame.getContainerWindow()); createWindowPeer(windowPeer); m_DBMetaData.setWindowPeer(this.xControl.getPeer()); insertQueryRelatedSteps(); - executeDialog( m_frame.getContainerWindow().getPosSize() ); + executeDialog(m_frame.getContainerWindow().getPosSize()); } } catch (java.lang.Exception jexception) @@ -310,8 +322,8 @@ public class QueryWizard extends DatabaseObjectWizard try { m_DBCommandFieldSelectio = new CommandFieldSelection( - this, m_DBMetaData, 120, reslblFields, reslblSelFields, reslblTables, - m_DBMetaData.supportsQueriesInFrom(), 40850); + this, m_DBMetaData, 120, reslblFields, reslblSelFields, reslblTables, + m_DBMetaData.supportsQueriesInFrom(), 40850); m_DBCommandFieldSelectio.setAppendMode(true); m_DBCommandFieldSelectio.addFieldSelectionListener(new FieldSelectionListener()); m_sortingComponent = new SortingComponent(this, SOSORTING_PAGE, 95, 27, 210, 40865); @@ -341,14 +353,13 @@ public class QueryWizard extends DatabaseObjectWizard public boolean finishWizard() { int ncurStep = getCurrentStep(); - if ( ( ncurStep == SOSUMMARY_PAGE ) - || ( switchToStep( ncurStep, SOSUMMARY_PAGE ) ) - ) + if ((ncurStep == SOSUMMARY_PAGE) + || (switchToStep(ncurStep, SOSUMMARY_PAGE))) { m_createdQuery = m_finalizer.finish(); - if ( m_createdQuery.length() > 0 ) + if (m_createdQuery.length() > 0) { - loadSubComponent( CommandType.QUERY, m_createdQuery, m_finalizer.displayQueryDesign() ); + loadSubComponent(CommandType.QUERY, m_createdQuery, m_finalizer.displayQueryDesign()); xDialog.endExecute(); return true; } diff --git a/wizards/com/sun/star/wizards/ui/FilterComponent.java b/wizards/com/sun/star/wizards/ui/FilterComponent.java index 8dfc12e21fb3..09937a6af6d4 100644 --- a/wizards/com/sun/star/wizards/ui/FilterComponent.java +++ b/wizards/com/sun/star/wizards/ui/FilterComponent.java @@ -113,6 +113,7 @@ public class FilterComponent final int SO_FOURTHBOOLFIELDNAME = 256 + 4; int SO_BOOLEANLIST[] = + { SO_FIRSTBOOLFIELDNAME, SO_SECONDBOOLFIELDNAME, SO_THIRDBOOLFIELDNAME, SO_FOURTHBOOLFIELDNAME }; @@ -254,11 +255,10 @@ public class FilterComponent if (composer.getQuery().length() == 0) { - final String fromClause = composer.getFromClause(); StringBuilder sql = new StringBuilder(); sql.append(composer.getSelectClause(true)); sql.append(' '); - sql.append(fromClause); + sql.append(composer.getFromClause()); composer.getQueryComposer().setElementaryQuery(sql.toString()); } composer.getQueryComposer().setStructuredFilter(new PropertyValue[][] @@ -267,39 +267,36 @@ public class FilterComponent for (int i = 0; i < RowCount; i++) { ControlRow currentControlRow = oControlRows[i]; - if (currentControlRow.isEnabled()) + if (currentControlRow.isEnabled() && currentControlRow.isConditionComplete()) { - if (currentControlRow.isConditionComplete()) + String sFieldName = currentControlRow.getSelectedFieldName(); + int nOperator = (int) currentControlRow.getSelectedOperator(); + FieldColumn aFieldColumn = oQueryMetaData.getFieldColumnByDisplayName(sFieldName); + columnSet.setPropertyValue(PropertyNames.PROPERTY_NAME, aFieldColumn.getFieldName()); + columnSet.setPropertyValue("Type", aFieldColumn.getXColumnPropertySet().getPropertyValue("Type")); + Object value = currentControlRow.getValue(); + switch (aFieldColumn.getFieldType()) { - String sFieldName = currentControlRow.getSelectedFieldName(); - int nOperator = (int) currentControlRow.getSelectedOperator(); - FieldColumn aFieldColumn = oQueryMetaData.getFieldColumnByDisplayName(sFieldName); - columnSet.setPropertyValue(PropertyNames.PROPERTY_NAME, aFieldColumn.getFieldName()); - columnSet.setPropertyValue("Type", aFieldColumn.getXColumnPropertySet().getPropertyValue("Type")); - Object value = currentControlRow.getValue(); - switch (aFieldColumn.getFieldType()) - { - case DataType.TIMESTAMP: - case DataType.DATE: - value = ((Double) value) - oQueryMetaData.getNullDateCorrection(); - break; - } - column.removeProperty("Value"); - final short operator = currentControlRow.getSelectedOperator(); - if ((operator == SQLFilterOperator.SQLNULL) - || (operator == SQLFilterOperator.NOT_SQLNULL) - || AnyConverter.isVoid(value)) - { - column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), new String()); - value = new Any(new Type(TypeClass.VOID), null); - } - else - { - column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), value); - } - columnSet.setPropertyValue("Value", value); - composer.getQueryComposer().appendFilterByColumn(columnSet, getfilterstate() == this.SOI_MATCHALL, nOperator); + case DataType.TIMESTAMP: + case DataType.DATE: + value = ((Double) value) - oQueryMetaData.getNullDateCorrection(); + break; } + column.removeProperty("Value"); + final short operator = currentControlRow.getSelectedOperator(); + if ((operator == SQLFilterOperator.SQLNULL) + || (operator == SQLFilterOperator.NOT_SQLNULL) + || AnyConverter.isVoid(value)) + { + column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), new String()); + value = new Any(new Type(TypeClass.VOID), null); + } + else + { + column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), value); + } + columnSet.setPropertyValue("Value", value); + composer.getQueryComposer().appendFilterByColumn(columnSet, getfilterstate() == this.SOI_MATCHALL, nOperator); } } filterconditions = composer.getNormalizedStructuredFilter(); @@ -342,7 +339,7 @@ public class FilterComponent FieldName = _filtercondition.Name; } String sreturn = JavaTools.replaceSubString(_BaseString, FieldName, ""); - String soperator = sLogicOperators[_filtercondition.Handle-1]; + String soperator = sLogicOperators[_filtercondition.Handle - 1]; sreturn = JavaTools.replaceSubString(sreturn, soperator, ""); String sDisplayValue = ""; if ((_filtercondition.Handle != SQLFilterOperator.SQLNULL)