1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_dbaccess.hxx" 30 31 #ifndef DBAUI_TABLEFIELDDESC_HXX 32 #include "TableFieldDescription.hxx" 33 #endif 34 #ifndef _TOOLS_DEBUG_HXX 35 #include <tools/debug.hxx> 36 #endif 37 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ 38 #include <com/sun/star/sdbc/DataType.hpp> 39 #endif 40 #include <comphelper/namedvaluecollection.hxx> 41 42 #include <functional> 43 44 using namespace ::com::sun::star::sdbc; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::beans; 47 using namespace comphelper; 48 using namespace dbaui; 49 50 DBG_NAME(OTableFieldDesc) 51 //============================================================================== 52 OTableFieldDesc::OTableFieldDesc() 53 :m_pTabWindow(0) 54 ,m_eDataType(1000) 55 ,m_eFunctionType( FKT_NONE ) 56 ,m_eFieldType(TAB_NORMAL_FIELD) 57 ,m_eOrderDir( ORDER_NONE ) 58 ,m_nIndex(0) 59 ,m_nColWidth(0) 60 ,m_nColumnId((sal_uInt16)-1) 61 ,m_bGroupBy(sal_False) 62 ,m_bVisible(sal_False) 63 { 64 DBG_CTOR(OTableFieldDesc,NULL); 65 } 66 //------------------------------------------------------------------------------ 67 OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc& rRS) 68 : ::vos::OReference() 69 70 { 71 DBG_CTOR(OTableFieldDesc,NULL); 72 *this = rRS; 73 } 74 75 //------------------------------------------------------------------------------ 76 OTableFieldDesc::OTableFieldDesc(const ::rtl::OUString& rT, const ::rtl::OUString& rF ) 77 :m_pTabWindow(0) 78 ,m_eFunctionType( FKT_NONE ) 79 ,m_eOrderDir( ORDER_NONE ) 80 ,m_nColumnId((sal_uInt16)-1) 81 ,m_bGroupBy(sal_False) 82 ,m_bVisible(sal_False) 83 { 84 DBG_CTOR(OTableFieldDesc,NULL); 85 SetField( rF ); SetTable( rT ); 86 } 87 88 //------------------------------------------------------------------------------ 89 OTableFieldDesc::~OTableFieldDesc() 90 { 91 DBG_DTOR(OTableFieldDesc,NULL); 92 } 93 //------------------------------------------------------------------------------ 94 OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS ) 95 { 96 if (&rRS == this) 97 return *this; 98 99 m_aCriteria = rRS.GetCriteria(); 100 m_aTableName = rRS.GetTable(); 101 m_aAliasName = rRS.GetAlias(); // table range 102 m_aFieldName = rRS.GetField(); // column 103 m_aFieldAlias = rRS.GetFieldAlias(); // column alias 104 m_aFunctionName = rRS.GetFunction(); // Funktionsname 105 m_pTabWindow = rRS.GetTabWindow(); 106 m_eDataType = rRS.GetDataType(); 107 m_eFunctionType = rRS.GetFunctionType(); 108 m_eFieldType = rRS.GetFieldType(); 109 m_eOrderDir = rRS.GetOrderDir(); 110 m_nIndex = rRS.GetFieldIndex(); 111 m_nColWidth = rRS.GetColWidth(); 112 m_nColumnId = rRS.m_nColumnId; 113 m_bGroupBy = rRS.IsGroupBy(); 114 m_bVisible = rRS.IsVisible(); 115 116 return *this; 117 } 118 //------------------------------------------------------------------------------ 119 sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc ) 120 { 121 DBG_CHKTHIS(OTableFieldDesc,NULL); 122 123 return ( m_eOrderDir != rDesc.GetOrderDir() || 124 m_eDataType != rDesc.GetDataType() || 125 m_aAliasName != rDesc.GetAlias() || 126 m_aFunctionName != rDesc.GetFunction() || 127 m_aFieldName != rDesc.GetField() || 128 m_aTableName != rDesc.GetTable() || 129 m_bGroupBy != rDesc.IsGroupBy() || 130 m_aCriteria != rDesc.GetCriteria() || 131 m_bVisible != rDesc.IsVisible() ); 132 133 } 134 135 //------------------------------------------------------------------------------ 136 void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const ::rtl::OUString& rCrit) 137 { 138 DBG_CHKTHIS(OTableFieldDesc,NULL); 139 if (nIdx < m_aCriteria.size()) 140 m_aCriteria[nIdx] = rCrit; 141 else 142 { 143 for(sal_Int32 i=m_aCriteria.size();i<nIdx;++i) 144 m_aCriteria.push_back( ::rtl::OUString()); 145 m_aCriteria.push_back(rCrit); 146 } 147 } 148 149 //------------------------------------------------------------------------------ 150 ::rtl::OUString OTableFieldDesc::GetCriteria( sal_uInt16 nIdx ) const 151 { 152 DBG_CHKTHIS(OTableFieldDesc,NULL); 153 ::rtl::OUString aRetStr; 154 if( nIdx < m_aCriteria.size()) 155 aRetStr = m_aCriteria[nIdx]; 156 157 return aRetStr; 158 } 159 160 // ----------------------------------------------------------------------------- 161 namespace 162 { 163 struct SelectPropertyValueAsString : public ::std::unary_function< PropertyValue, ::rtl::OUString > 164 { 165 ::rtl::OUString operator()( const PropertyValue& i_rPropValue ) const 166 { 167 ::rtl::OUString sValue; 168 OSL_VERIFY( i_rPropValue.Value >>= sValue ); 169 return sValue; 170 } 171 }; 172 } 173 174 // ----------------------------------------------------------------------------- 175 void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria ) 176 { 177 DBG_CHKTHIS(OTableFieldDesc,NULL); 178 179 ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value ); 180 m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName ); 181 m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName ); 182 m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName ); 183 m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias ); 184 m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName ); 185 m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType ); 186 m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType ); 187 m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth ); 188 m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy ); 189 m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible ); 190 191 m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) ); 192 m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) ); 193 194 if ( i_bIncludingCriteria ) 195 { 196 const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) ); 197 m_aCriteria.resize( aCriteria.getLength() ); 198 ::std::transform( 199 aCriteria.getConstArray(), 200 aCriteria.getConstArray() + aCriteria.getLength(), 201 m_aCriteria.begin(), 202 SelectPropertyValueAsString() 203 ); 204 } 205 } 206 //------------------------------------------------------------------------------ 207 void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria ) 208 { 209 DBG_CHKTHIS(OTableFieldDesc,NULL); 210 211 o_rSettings.put( "AliasName", m_aAliasName ); 212 o_rSettings.put( "TableName", m_aTableName ); 213 o_rSettings.put( "FieldName", m_aFieldName ); 214 o_rSettings.put( "FieldAlias", m_aFieldAlias ); 215 o_rSettings.put( "FunctionName", m_aFunctionName ); 216 o_rSettings.put( "DataType", m_eDataType ); 217 o_rSettings.put( "FunctionType", (sal_Int32)m_eFunctionType ); 218 o_rSettings.put( "FieldType", (sal_Int32)m_eFieldType ); 219 o_rSettings.put( "OrderDir", (sal_Int32)m_eOrderDir ); 220 o_rSettings.put( "ColWidth", m_nColWidth ); 221 o_rSettings.put( "GroupBy", m_bGroupBy ); 222 o_rSettings.put( "Visible", m_bVisible ); 223 224 if ( i_bIncludingCriteria ) 225 { 226 if ( !m_aCriteria.empty() ) 227 { 228 sal_Int32 c = 0; 229 Sequence< PropertyValue > aCriteria( m_aCriteria.size() ); 230 for ( ::std::vector< ::rtl::OUString >::const_iterator crit = m_aCriteria.begin(); 231 crit != m_aCriteria.end(); 232 ++crit, ++c 233 ) 234 { 235 aCriteria[c].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c ); 236 aCriteria[c].Value <<= *crit; 237 } 238 239 o_rSettings.put( "Criteria", aCriteria ); 240 } 241 } 242 } 243 // ----------------------------------------------------------------------------- 244 245 246 247