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