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 #ifndef _CONNECTIVITY_PCOLUMN_HXX_
28 #define _CONNECTIVITY_PCOLUMN_HXX_
29 
30 #include "connectivity/dbtoolsdllapi.hxx"
31 #include "connectivity/sdbcx/VColumn.hxx"
32 #include "connectivity/CommonTools.hxx"
33 #include <vos/ref.hxx>
34 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
35 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <comphelper/proparrhlp.hxx>
38 
39 namespace connectivity
40 {
41 	namespace parse
42 	{
43 		class OParseColumn;
44 
45 		typedef sdbcx::OColumn OParseColumn_BASE;
46         typedef ::comphelper::OPropertyArrayUsageHelper<OParseColumn> OParseColumn_PROP;
47 
48 		class OOO_DLLPUBLIC_DBTOOLS OParseColumn :
49             public OParseColumn_BASE, public OParseColumn_PROP
50 		{
51 			::rtl::OUString	m_aRealName;
52 			::rtl::OUString m_aTableName;
53             ::rtl::OUString m_sLabel;
54 			sal_Bool		m_bFunction;
55 			sal_Bool		m_bDbasePrecisionChanged;
56 			sal_Bool		m_bAggregateFunction;
57             sal_Bool        m_bIsSearchable;
58 
59 		protected:
60 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
61 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
62 
63 			virtual ~OParseColumn();
64 		public:
65             OParseColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn,sal_Bool _bCase);
66 			OParseColumn(const ::rtl::OUString& _Name,
67 					const ::rtl::OUString& _TypeName,
68 					const ::rtl::OUString& _DefaultValue,
69                     const ::rtl::OUString& _Description,
70 					sal_Int32		_IsNullable,
71 					sal_Int32		_Precision,
72 					sal_Int32		_Scale,
73 					sal_Int32		_Type,
74 					sal_Bool		_IsAutoIncrement,
75 					sal_Bool		_IsCurrency,
76 					sal_Bool		_bCase);
77 
78 			virtual void construct();
79 
80 			void setRealName(const ::rtl::OUString& _rName)  { m_aRealName  = _rName; }
81             void setLabel(const ::rtl::OUString& i_sLabel)   { m_sLabel  = i_sLabel; }
82 			void setTableName(const ::rtl::OUString& _rName) { m_aTableName = _rName; }
83 			void setFunction(sal_Bool _bFunction)			 { m_bFunction	= _bFunction; }
84 			void setAggregateFunction(sal_Bool _bFunction)	 { m_bAggregateFunction	= _bFunction; }
85             void setIsSearchable( sal_Bool _bIsSearchable )  { m_bIsSearchable = _bIsSearchable; }
86 			void setDbasePrecisionChanged(sal_Bool _bDbasePrecisionChanged)	{ m_bDbasePrecisionChanged = _bDbasePrecisionChanged; }
87 
88 			::rtl::OUString getRealName()   const { return  m_aRealName; }
89             ::rtl::OUString getLabel()      const { return  m_sLabel; }
90 			::rtl::OUString getTableName()  const { return  m_aTableName; }
91 			sal_Bool		getFunction()   const { return  m_bFunction; }
92 			sal_Bool		getDbasePrecisionChanged()	const { return  m_bDbasePrecisionChanged; }
93 
94         public:
95             /** creates a collection of OParseColumn, as described by a result set meta data instance.
96             */
97             static ::vos::ORef< OSQLColumns >
98                 createColumnsForResultSet(
99                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData >& _rxResMetaData,
100                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxDBMetaData,
101                     const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& i_xQueryColumns
102                 );
103 
104             DECLARE_STL_USTRINGACCESS_MAP(int,StringMap);
105             /** creates a single OParseColumn, as described by a result set meta data instance.
106                 The column names are unique.
107             */
108             static OParseColumn*
109                 createColumnForResultSet(
110                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData >& _rxResMetaData,
111                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxDBMetaData,
112                     sal_Int32 _nColumnPos,
113                     StringMap& _rColumns
114                 );
115 
116 		private:
117 			using OParseColumn_BASE::createArrayHelper;
118 		};
119 
120 		class OOrderColumn;
121 
122 		typedef sdbcx::OColumn OOrderColumn_BASE;
123 		typedef ::comphelper::OPropertyArrayUsageHelper<OOrderColumn> OOrderColumn_PROP;
124 
125 		class OOO_DLLPUBLIC_DBTOOLS OOrderColumn :
126             public OOrderColumn_BASE, public OOrderColumn_PROP
127 		{
128             const   sal_Bool        m_bAscending;
129             const   ::rtl::OUString m_sTableName;
130 
131 		protected:
132 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
133 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
134 
135 			virtual ~OOrderColumn();
136 		public:
137             OOrderColumn(
138                 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn,
139                 const ::rtl::OUString& i_rOriginatingTableName,
140                 sal_Bool _bCase,
141                 sal_Bool _bAscending
142             );
143 
144             OOrderColumn(
145                 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn,
146                 sal_Bool _bCase,
147                 sal_Bool _bAscending
148             );
149 
150 			virtual void construct();
151 
152 			virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
153 		private:
154 			using OOrderColumn_BASE::createArrayHelper;
155 		};
156 	}
157 }
158 
159 #endif //_CONNECTIVITY_PCOLUMN_HXX_
160 
161