1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*96de5490SAndrew Rist * distributed with this work for additional information
6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at
10*96de5490SAndrew Rist *
11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist *
13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist * software distributed under the License is distributed on an
15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the
17*96de5490SAndrew Rist * specific language governing permissions and limitations
18*96de5490SAndrew Rist * under the License.
19*96de5490SAndrew Rist *
20*96de5490SAndrew Rist *************************************************************/
21*96de5490SAndrew Rist
22*96de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef DBAUI_TABLEFIELDDESC_HXX
28cdf0e10cSrcweir #include "TableFieldDescription.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
34cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <functional>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::beans;
43cdf0e10cSrcweir using namespace comphelper;
44cdf0e10cSrcweir using namespace dbaui;
45cdf0e10cSrcweir
DBG_NAME(OTableFieldDesc)46cdf0e10cSrcweir DBG_NAME(OTableFieldDesc)
47cdf0e10cSrcweir //==============================================================================
48cdf0e10cSrcweir OTableFieldDesc::OTableFieldDesc()
49cdf0e10cSrcweir :m_pTabWindow(0)
50cdf0e10cSrcweir ,m_eDataType(1000)
51cdf0e10cSrcweir ,m_eFunctionType( FKT_NONE )
52cdf0e10cSrcweir ,m_eFieldType(TAB_NORMAL_FIELD)
53cdf0e10cSrcweir ,m_eOrderDir( ORDER_NONE )
54cdf0e10cSrcweir ,m_nIndex(0)
55cdf0e10cSrcweir ,m_nColWidth(0)
56cdf0e10cSrcweir ,m_nColumnId((sal_uInt16)-1)
57cdf0e10cSrcweir ,m_bGroupBy(sal_False)
58cdf0e10cSrcweir ,m_bVisible(sal_False)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir DBG_CTOR(OTableFieldDesc,NULL);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir //------------------------------------------------------------------------------
OTableFieldDesc(const OTableFieldDesc & rRS)63cdf0e10cSrcweir OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc& rRS)
64cdf0e10cSrcweir : ::vos::OReference()
65cdf0e10cSrcweir
66cdf0e10cSrcweir {
67cdf0e10cSrcweir DBG_CTOR(OTableFieldDesc,NULL);
68cdf0e10cSrcweir *this = rRS;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir //------------------------------------------------------------------------------
OTableFieldDesc(const::rtl::OUString & rT,const::rtl::OUString & rF)72cdf0e10cSrcweir OTableFieldDesc::OTableFieldDesc(const ::rtl::OUString& rT, const ::rtl::OUString& rF )
73cdf0e10cSrcweir :m_pTabWindow(0)
74cdf0e10cSrcweir ,m_eFunctionType( FKT_NONE )
75cdf0e10cSrcweir ,m_eOrderDir( ORDER_NONE )
76cdf0e10cSrcweir ,m_nColumnId((sal_uInt16)-1)
77cdf0e10cSrcweir ,m_bGroupBy(sal_False)
78cdf0e10cSrcweir ,m_bVisible(sal_False)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir DBG_CTOR(OTableFieldDesc,NULL);
81cdf0e10cSrcweir SetField( rF ); SetTable( rT );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir //------------------------------------------------------------------------------
~OTableFieldDesc()85cdf0e10cSrcweir OTableFieldDesc::~OTableFieldDesc()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir DBG_DTOR(OTableFieldDesc,NULL);
88cdf0e10cSrcweir }
89cdf0e10cSrcweir //------------------------------------------------------------------------------
operator =(const OTableFieldDesc & rRS)90cdf0e10cSrcweir OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir if (&rRS == this)
93cdf0e10cSrcweir return *this;
94cdf0e10cSrcweir
95cdf0e10cSrcweir m_aCriteria = rRS.GetCriteria();
96cdf0e10cSrcweir m_aTableName = rRS.GetTable();
97cdf0e10cSrcweir m_aAliasName = rRS.GetAlias(); // table range
98cdf0e10cSrcweir m_aFieldName = rRS.GetField(); // column
99cdf0e10cSrcweir m_aFieldAlias = rRS.GetFieldAlias(); // column alias
100cdf0e10cSrcweir m_aFunctionName = rRS.GetFunction(); // Funktionsname
101cdf0e10cSrcweir m_pTabWindow = rRS.GetTabWindow();
102cdf0e10cSrcweir m_eDataType = rRS.GetDataType();
103cdf0e10cSrcweir m_eFunctionType = rRS.GetFunctionType();
104cdf0e10cSrcweir m_eFieldType = rRS.GetFieldType();
105cdf0e10cSrcweir m_eOrderDir = rRS.GetOrderDir();
106cdf0e10cSrcweir m_nIndex = rRS.GetFieldIndex();
107cdf0e10cSrcweir m_nColWidth = rRS.GetColWidth();
108cdf0e10cSrcweir m_nColumnId = rRS.m_nColumnId;
109cdf0e10cSrcweir m_bGroupBy = rRS.IsGroupBy();
110cdf0e10cSrcweir m_bVisible = rRS.IsVisible();
111cdf0e10cSrcweir
112cdf0e10cSrcweir return *this;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir //------------------------------------------------------------------------------
operator ==(const OTableFieldDesc & rDesc)115cdf0e10cSrcweir sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir DBG_CHKTHIS(OTableFieldDesc,NULL);
118cdf0e10cSrcweir
119cdf0e10cSrcweir return ( m_eOrderDir != rDesc.GetOrderDir() ||
120cdf0e10cSrcweir m_eDataType != rDesc.GetDataType() ||
121cdf0e10cSrcweir m_aAliasName != rDesc.GetAlias() ||
122cdf0e10cSrcweir m_aFunctionName != rDesc.GetFunction() ||
123cdf0e10cSrcweir m_aFieldName != rDesc.GetField() ||
124cdf0e10cSrcweir m_aTableName != rDesc.GetTable() ||
125cdf0e10cSrcweir m_bGroupBy != rDesc.IsGroupBy() ||
126cdf0e10cSrcweir m_aCriteria != rDesc.GetCriteria() ||
127cdf0e10cSrcweir m_bVisible != rDesc.IsVisible() );
128cdf0e10cSrcweir
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //------------------------------------------------------------------------------
SetCriteria(sal_uInt16 nIdx,const::rtl::OUString & rCrit)132cdf0e10cSrcweir void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const ::rtl::OUString& rCrit)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir DBG_CHKTHIS(OTableFieldDesc,NULL);
135cdf0e10cSrcweir if (nIdx < m_aCriteria.size())
136cdf0e10cSrcweir m_aCriteria[nIdx] = rCrit;
137cdf0e10cSrcweir else
138cdf0e10cSrcweir {
139cdf0e10cSrcweir for(sal_Int32 i=m_aCriteria.size();i<nIdx;++i)
140cdf0e10cSrcweir m_aCriteria.push_back( ::rtl::OUString());
141cdf0e10cSrcweir m_aCriteria.push_back(rCrit);
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir //------------------------------------------------------------------------------
GetCriteria(sal_uInt16 nIdx) const146cdf0e10cSrcweir ::rtl::OUString OTableFieldDesc::GetCriteria( sal_uInt16 nIdx ) const
147cdf0e10cSrcweir {
148cdf0e10cSrcweir DBG_CHKTHIS(OTableFieldDesc,NULL);
149cdf0e10cSrcweir ::rtl::OUString aRetStr;
150cdf0e10cSrcweir if( nIdx < m_aCriteria.size())
151cdf0e10cSrcweir aRetStr = m_aCriteria[nIdx];
152cdf0e10cSrcweir
153cdf0e10cSrcweir return aRetStr;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir // -----------------------------------------------------------------------------
157cdf0e10cSrcweir namespace
158cdf0e10cSrcweir {
159cdf0e10cSrcweir struct SelectPropertyValueAsString : public ::std::unary_function< PropertyValue, ::rtl::OUString >
160cdf0e10cSrcweir {
operator ()__anon886c7a5a0111::SelectPropertyValueAsString161cdf0e10cSrcweir ::rtl::OUString operator()( const PropertyValue& i_rPropValue ) const
162cdf0e10cSrcweir {
163cdf0e10cSrcweir ::rtl::OUString sValue;
164cdf0e10cSrcweir OSL_VERIFY( i_rPropValue.Value >>= sValue );
165cdf0e10cSrcweir return sValue;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir };
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir // -----------------------------------------------------------------------------
Load(const::com::sun::star::beans::PropertyValue & i_rSettings,const bool i_bIncludingCriteria)171cdf0e10cSrcweir void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir DBG_CHKTHIS(OTableFieldDesc,NULL);
174cdf0e10cSrcweir
175cdf0e10cSrcweir ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value );
176cdf0e10cSrcweir m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName );
177cdf0e10cSrcweir m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName );
178cdf0e10cSrcweir m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName );
179cdf0e10cSrcweir m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias );
180cdf0e10cSrcweir m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName );
181cdf0e10cSrcweir m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType );
182cdf0e10cSrcweir m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType );
183cdf0e10cSrcweir m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth );
184cdf0e10cSrcweir m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy );
185cdf0e10cSrcweir m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible );
186cdf0e10cSrcweir
187cdf0e10cSrcweir m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) );
188cdf0e10cSrcweir m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) );
189cdf0e10cSrcweir
190cdf0e10cSrcweir if ( i_bIncludingCriteria )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) );
193cdf0e10cSrcweir m_aCriteria.resize( aCriteria.getLength() );
194cdf0e10cSrcweir ::std::transform(
195cdf0e10cSrcweir aCriteria.getConstArray(),
196cdf0e10cSrcweir aCriteria.getConstArray() + aCriteria.getLength(),
197cdf0e10cSrcweir m_aCriteria.begin(),
198cdf0e10cSrcweir SelectPropertyValueAsString()
199cdf0e10cSrcweir );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir }
202cdf0e10cSrcweir //------------------------------------------------------------------------------
Save(::comphelper::NamedValueCollection & o_rSettings,const bool i_bIncludingCriteria)203cdf0e10cSrcweir void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir DBG_CHKTHIS(OTableFieldDesc,NULL);
206cdf0e10cSrcweir
207cdf0e10cSrcweir o_rSettings.put( "AliasName", m_aAliasName );
208cdf0e10cSrcweir o_rSettings.put( "TableName", m_aTableName );
209cdf0e10cSrcweir o_rSettings.put( "FieldName", m_aFieldName );
210cdf0e10cSrcweir o_rSettings.put( "FieldAlias", m_aFieldAlias );
211cdf0e10cSrcweir o_rSettings.put( "FunctionName", m_aFunctionName );
212cdf0e10cSrcweir o_rSettings.put( "DataType", m_eDataType );
213cdf0e10cSrcweir o_rSettings.put( "FunctionType", (sal_Int32)m_eFunctionType );
214cdf0e10cSrcweir o_rSettings.put( "FieldType", (sal_Int32)m_eFieldType );
215cdf0e10cSrcweir o_rSettings.put( "OrderDir", (sal_Int32)m_eOrderDir );
216cdf0e10cSrcweir o_rSettings.put( "ColWidth", m_nColWidth );
217cdf0e10cSrcweir o_rSettings.put( "GroupBy", m_bGroupBy );
218cdf0e10cSrcweir o_rSettings.put( "Visible", m_bVisible );
219cdf0e10cSrcweir
220cdf0e10cSrcweir if ( i_bIncludingCriteria )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir if ( !m_aCriteria.empty() )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir sal_Int32 c = 0;
225cdf0e10cSrcweir Sequence< PropertyValue > aCriteria( m_aCriteria.size() );
226cdf0e10cSrcweir for ( ::std::vector< ::rtl::OUString >::const_iterator crit = m_aCriteria.begin();
227cdf0e10cSrcweir crit != m_aCriteria.end();
228cdf0e10cSrcweir ++crit, ++c
229cdf0e10cSrcweir )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir aCriteria[c].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c );
232cdf0e10cSrcweir aCriteria[c].Value <<= *crit;
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235cdf0e10cSrcweir o_rSettings.put( "Criteria", aCriteria );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir // -----------------------------------------------------------------------------
240cdf0e10cSrcweir
241cdf0e10cSrcweir
242cdf0e10cSrcweir
243