1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
27 #include "TableConnectionData.hxx"
28 #endif
29 #ifndef _TOOLS_DEBUG_HXX
30 #include <tools/debug.hxx>
31 #endif
32 #ifndef _COMPHELPER_STLTYPES_HXX_
33 #include <comphelper/stl_types.hxx>
34 #endif
35 
36 using namespace dbaui;
37 using namespace comphelper;
38 //==================================================================
39 // class OTableConnectionData
40 //==================================================================
DBG_NAME(OTableConnectionData)41 DBG_NAME(OTableConnectionData)
42 //------------------------------------------------------------------------
43 OTableConnectionData::OTableConnectionData()
44 {
45 	DBG_CTOR(OTableConnectionData,NULL);
46 	Init();
47 }
48 // -----------------------------------------------------------------------------
OTableConnectionData(const TTableWindowData::value_type & _pReferencingTable,const TTableWindowData::value_type & _pReferencedTable,const String & rConnName)49 OTableConnectionData::OTableConnectionData(const TTableWindowData::value_type& _pReferencingTable
50                                           ,const TTableWindowData::value_type& _pReferencedTable
51                                           ,const String& rConnName )
52  :m_pReferencingTable(_pReferencingTable)
53  ,m_pReferencedTable(_pReferencedTable)
54  ,m_aConnName( rConnName )
55 {
56     DBG_CTOR(OTableConnectionData,NULL);
57 	Init();
58 }
59 //------------------------------------------------------------------------
Init()60 void OTableConnectionData::Init()
61 {
62 	//////////////////////////////////////////////////////////////////////
63 	// LineDataList mit Defaults initialisieren
64 	DBG_ASSERT(m_vConnLineData.size() == 0, "OTableConnectionData::Init() : nur mit leere Linienliste aufzurufen !");
65 	ResetConnLines(sal_True);
66 		// das legt Defaults an
67 }
68 //------------------------------------------------------------------------
OTableConnectionData(const OTableConnectionData & rConnData)69 OTableConnectionData::OTableConnectionData( const OTableConnectionData& rConnData )
70 {
71 	DBG_CTOR(OTableConnectionData,NULL);
72 	*this = rConnData;
73 }
74 //------------------------------------------------------------------------
CopyFrom(const OTableConnectionData & rSource)75 void OTableConnectionData::CopyFrom(const OTableConnectionData& rSource)
76 {
77 	*this = rSource;
78 	// hier ziehe ich mich auf das (nicht-virtuelle) operator= zurueck, das nur meine Members kopiert
79 }
80 
81 //------------------------------------------------------------------------
~OTableConnectionData()82 OTableConnectionData::~OTableConnectionData()
83 {
84 	DBG_DTOR(OTableConnectionData,NULL);
85 	// LineDataList loeschen
86 	OConnectionLineDataVec().swap(m_vConnLineData);
87 	//ResetConnLines(sal_False);
88 }
89 
90 //------------------------------------------------------------------------
operator =(const OTableConnectionData & rConnData)91 OTableConnectionData& OTableConnectionData::operator=( const OTableConnectionData& rConnData )
92 {
93 	if (&rConnData == this)
94 		return *this;
95 
96 	m_pReferencingTable = rConnData.m_pReferencingTable;
97 	m_pReferencedTable = rConnData.m_pReferencedTable;
98 	m_aConnName = rConnData.GetConnName();
99 
100 	// clear line list
101 	ResetConnLines(sal_False);
102 
103 	// und kopieren
104 	OConnectionLineDataVec* pLineData = const_cast<OTableConnectionData*>(&rConnData)->GetConnLineDataList();
105 
106 	OConnectionLineDataVec::const_iterator aIter = pLineData->begin();
107     OConnectionLineDataVec::const_iterator aEnd = pLineData->end();
108 	for(;aIter != aEnd;++aIter)
109 		m_vConnLineData.push_back(new OConnectionLineData(**aIter));
110 
111 	return *this;
112 }
113 
114 //------------------------------------------------------------------------
SetConnLine(sal_uInt16 nIndex,const String & rSourceFieldName,const String & rDestFieldName)115 sal_Bool OTableConnectionData::SetConnLine( sal_uInt16 nIndex, const String& rSourceFieldName, const String& rDestFieldName )
116 {
117 	if (sal_uInt16(m_vConnLineData.size()) < nIndex)
118 		return sal_False;
119 		// == ist noch erlaubt, das entspricht einem Append
120 
121 	if (m_vConnLineData.size() == nIndex)
122 		return AppendConnLine(rSourceFieldName, rDestFieldName);
123 
124 	OConnectionLineDataRef pConnLineData = m_vConnLineData[nIndex];
125 	DBG_ASSERT(pConnLineData != NULL, "OTableConnectionData::SetConnLine : habe ungueltiges LineData-Objekt");
126 
127 	pConnLineData->SetSourceFieldName( rSourceFieldName );
128 	pConnLineData->SetDestFieldName( rDestFieldName );
129 
130 	return sal_True;
131 }
132 
133 //------------------------------------------------------------------------
AppendConnLine(const::rtl::OUString & rSourceFieldName,const::rtl::OUString & rDestFieldName)134 sal_Bool OTableConnectionData::AppendConnLine( const ::rtl::OUString& rSourceFieldName, const ::rtl::OUString& rDestFieldName )
135 {
136 	OConnectionLineDataVec::iterator aIter = m_vConnLineData.begin();
137     OConnectionLineDataVec::iterator aEnd = m_vConnLineData.end();
138 	for(;aIter != aEnd;++aIter)
139 	{
140 		if((*aIter)->GetDestFieldName() == rDestFieldName && (*aIter)->GetSourceFieldName() == rSourceFieldName)
141 			break;
142 	}
143 	if(aIter == aEnd)
144 	{
145 		OConnectionLineDataRef pNew = new OConnectionLineData(rSourceFieldName, rDestFieldName);
146 		if (!pNew.isValid())
147 			return sal_False;
148 
149 		m_vConnLineData.push_back(pNew);
150 	}
151 	return sal_True;
152 }
153 
154 //------------------------------------------------------------------------
ResetConnLines(sal_Bool)155 void OTableConnectionData::ResetConnLines( sal_Bool /*bUseDefaults*/ )
156 {
157 	OConnectionLineDataVec().swap(m_vConnLineData);
158 }
159 
160 //------------------------------------------------------------------------
CreateLineDataObj()161 OConnectionLineDataRef OTableConnectionData::CreateLineDataObj()
162 {
163 	return new OConnectionLineData();
164 }
165 
166 //------------------------------------------------------------------------
CreateLineDataObj(const OConnectionLineData & rConnLineData)167 OConnectionLineDataRef OTableConnectionData::CreateLineDataObj( const OConnectionLineData& rConnLineData )
168 {
169 	return new OConnectionLineData( rConnLineData );
170 }
171 // -----------------------------------------------------------------------------
NewInstance() const172 OTableConnectionData* OTableConnectionData::NewInstance() const
173 {
174 	return new OTableConnectionData();
175 }
176 // -----------------------------------------------------------------------------
normalizeLines()177 void OTableConnectionData::normalizeLines()
178 {
179 	// noch ein wenig Normalisierung auf den LineDatas : leere Lines vom Anfang an das Ende verschieben
180 	sal_Int32 nCount = m_vConnLineData.size();
181 	for(sal_Int32 i=0;i<nCount;)
182 	{
183 		if(!m_vConnLineData[i]->GetSourceFieldName().getLength() || !m_vConnLineData[i]->GetDestFieldName().getLength())
184 		{
185 			OConnectionLineDataRef pData = m_vConnLineData[i];
186 			m_vConnLineData.erase(m_vConnLineData.begin()+i);
187 			m_vConnLineData.push_back(pData);
188 			--nCount;
189 		}
190 		else
191 			++i;
192 	}
193 }
194 // -----------------------------------------------------------------------------
195 
196 
197 
198 
199