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 DBA_HELPERCOLLECTIONS_HXX
27 #include "HelperCollections.hxx"
28 #endif
29 
30 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
31 #include "dbastrings.hrc"
32 #endif
33 
34 namespace dbaccess
35 {
36 	using namespace dbtools;
37 	using namespace comphelper;
38 	using namespace connectivity;
39 	using namespace ::com::sun::star::uno;
40 	using namespace ::com::sun::star::beans;
41 	using namespace ::com::sun::star::sdbc;
42 	using namespace ::com::sun::star::sdb;
43 	using namespace ::com::sun::star::sdbcx;
44 	using namespace ::com::sun::star::container;
45 	using namespace ::com::sun::star::lang;
46 	using namespace ::com::sun::star::script;
47 	using namespace ::cppu;
48 	using namespace ::osl;
49 	// -----------------------------------------------------------------------------
OPrivateColumns(const::vos::ORef<::connectivity::OSQLColumns> & _rColumns,sal_Bool _bCase,::cppu::OWeakObject & _rParent,::osl::Mutex & _rMutex,const::std::vector<::rtl::OUString> & _rVector,sal_Bool _bUseAsIndex)50 	OPrivateColumns::OPrivateColumns(const ::vos::ORef< ::connectivity::OSQLColumns>& _rColumns,
51 						sal_Bool _bCase,
52 						::cppu::OWeakObject& _rParent,
53 						::osl::Mutex& _rMutex,
54 						const ::std::vector< ::rtl::OUString> &_rVector,
55 						sal_Bool _bUseAsIndex
56 					) : sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector,_bUseAsIndex)
57 						,m_aColumns(_rColumns)
58 	{
59 	}
60 
61 	// -------------------------------------------------------------------------
createWithIntrinsicNames(const::vos::ORef<::connectivity::OSQLColumns> & _rColumns,sal_Bool _bCase,::cppu::OWeakObject & _rParent,::osl::Mutex & _rMutex)62     OPrivateColumns* OPrivateColumns::createWithIntrinsicNames( const ::vos::ORef< ::connectivity::OSQLColumns >& _rColumns,
63         sal_Bool _bCase, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex )
64     {
65         ::std::vector< ::rtl::OUString > aNames; aNames.reserve( _rColumns->get().size() );
66 
67         ::rtl::OUString sColumName;
68         for (   ::connectivity::OSQLColumns::Vector::const_iterator column = _rColumns->get().begin();
69                 column != _rColumns->get().end();
70                 ++column
71             )
72         {
73             Reference< XPropertySet > xColumn( *column, UNO_QUERY_THROW );
74             xColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumName;
75             aNames.push_back( sColumName );
76         }
77         return new OPrivateColumns( _rColumns, _bCase, _rParent, _rMutex, aNames, sal_False );
78     }
79 
80 	// -------------------------------------------------------------------------
disposing(void)81 	void SAL_CALL OPrivateColumns::disposing(void)
82 	{
83 		m_aColumns = NULL;
84 		clear_NoDispose();
85 			// we're not owner of the objects we're holding, instead the object we got in our ctor is
86 			// So we're not allowed to dispose our elements.
87 		OPrivateColumns_Base::disposing();
88 	}
89 	// -------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)90 	connectivity::sdbcx::ObjectType OPrivateColumns::createObject(const ::rtl::OUString& _rName)
91 	{
92 		if ( m_aColumns.isValid() )
93 		{
94 			::connectivity::OSQLColumns::Vector::const_iterator aIter = find(m_aColumns->get().begin(),m_aColumns->get().end(),_rName,isCaseSensitive());
95 			if(aIter == m_aColumns->get().end())
96 				aIter = findRealName(m_aColumns->get().begin(),m_aColumns->get().end(),_rName,isCaseSensitive());
97 
98 			if(aIter != m_aColumns->get().end())
99 				return connectivity::sdbcx::ObjectType(*aIter,UNO_QUERY);
100 
101 			OSL_ENSURE(0,"Column not found in collection!");
102 		}
103 		return NULL;
104 	}
105 	// -------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)106 	connectivity::sdbcx::ObjectType OPrivateTables::createObject(const ::rtl::OUString& _rName)
107 	{
108 		if ( !m_aTables.empty() )
109 		{
110 			OSQLTables::iterator aIter = m_aTables.find(_rName);
111 			OSL_ENSURE(aIter != m_aTables.end(),"Table not found!");
112 			OSL_ENSURE(aIter->second.is(),"Table is null!");
113 			return connectivity::sdbcx::ObjectType(m_aTables.find(_rName)->second,UNO_QUERY);
114 		}
115 		return NULL;
116 	}
117 	// -----------------------------------------------------------------------------
118 }
119