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_connectivity.hxx"
26 #include "connectivity/sdbcx/VColumn.hxx"
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <comphelper/sequence.hxx>
29 #include "TConnection.hxx"
30 #include <com/sun/star/sdbc/ColumnValue.hpp>
31 // -------------------------------------------------------------------------
32 using namespace connectivity;
33 using namespace connectivity::sdbcx;
34 using namespace cppu;
35 using namespace connectivity;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::sdbc;
40 
41 // -----------------------------------------------------------------------------
42 ::rtl::OUString SAL_CALL OColumn::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
43 {
44 	if(isNew())
45 		return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VColumnDescriptor");
46 	return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VColumn");
47 }
48 // -----------------------------------------------------------------------------
49 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OColumn::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
50 {
51 	::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
52 	if(isNew())
53 		aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ColumnDescriptor");
54 	else
55 		aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Column");
56 
57 	return aSupported;
58 }
59 // -----------------------------------------------------------------------------
60 sal_Bool SAL_CALL OColumn::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
61 {
62 	Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
63 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
64 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
65 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
66 		;
67 
68 	return pSupported != pEnd;
69 }
70 // -------------------------------------------------------------------------
71 OColumn::OColumn(sal_Bool _bCase)
72     :OColumnDescriptor_BASE(m_aMutex)
73     ,ODescriptor(OColumnDescriptor_BASE::rBHelper,_bCase,sal_True)
74     ,m_IsNullable(ColumnValue::NULLABLE)
75     ,m_Precision(0)
76     ,m_Scale(0)
77     ,m_Type(0)
78     ,m_IsAutoIncrement(sal_False)
79     ,m_IsRowVersion(sal_False)
80     ,m_IsCurrency(sal_False)
81 {
82 	construct();
83 }
84 // -------------------------------------------------------------------------
85 OColumn::OColumn(	const ::rtl::OUString& _Name,
86 					const ::rtl::OUString& _TypeName,
87 					const ::rtl::OUString& _DefaultValue,
88                     const ::rtl::OUString& _Description,
89 					sal_Int32		_IsNullable,
90 					sal_Int32		_Precision,
91 					sal_Int32		_Scale,
92 					sal_Int32		_Type,
93 					sal_Bool		_IsAutoIncrement,
94 					sal_Bool		_IsRowVersion,
95 					sal_Bool		_IsCurrency,
96 					sal_Bool		_bCase)
97     :OColumnDescriptor_BASE(m_aMutex)
98     ,ODescriptor(OColumnDescriptor_BASE::rBHelper,_bCase)
99     ,m_TypeName(_TypeName)
100     ,m_Description(_Description)
101     ,m_DefaultValue(_DefaultValue)
102     ,m_IsNullable(_IsNullable)
103     ,m_Precision(_Precision)
104     ,m_Scale(_Scale)
105     ,m_Type(_Type)
106     ,m_IsAutoIncrement(_IsAutoIncrement)
107     ,m_IsRowVersion(_IsRowVersion)
108     ,m_IsCurrency(_IsCurrency)
109 {
110 	m_Name = _Name;
111 
112 	construct();
113 }
114 // -------------------------------------------------------------------------
115 OColumn::~OColumn()
116 {
117 }
118 // -----------------------------------------------------------------------------
119 ::cppu::IPropertyArrayHelper* OColumn::createArrayHelper( sal_Int32 /*_nId*/ ) const
120 {
121     return doCreateArrayHelper();
122 }
123 // -----------------------------------------------------------------------------
124 ::cppu::IPropertyArrayHelper& SAL_CALL OColumn::getInfoHelper()
125 {
126 	return *OColumn_PROP::getArrayHelper(isNew() ? 1 : 0);
127 }
128 // -----------------------------------------------------------------------------
129 void SAL_CALL OColumn::acquire() throw()
130 {
131 	OColumnDescriptor_BASE::acquire();
132 }
133 // -----------------------------------------------------------------------------
134 void SAL_CALL OColumn::release() throw()
135 {
136 	OColumnDescriptor_BASE::release();
137 }
138 // -----------------------------------------------------------------------------
139 Any SAL_CALL OColumn::queryInterface( const Type & rType ) throw(RuntimeException)
140 {
141 	Any aRet = ODescriptor::queryInterface( rType);
142 	if(!aRet.hasValue())
143 	{
144 		if(!isNew())
145 			aRet = OColumn_BASE::queryInterface(rType);
146 		if(!aRet.hasValue())
147 			aRet = OColumnDescriptor_BASE::queryInterface( rType);
148 	}
149 	return aRet;
150 }
151 // -------------------------------------------------------------------------
152 Sequence< Type > SAL_CALL OColumn::getTypes(  ) throw(RuntimeException)
153 {
154 	if(isNew())
155 		return ::comphelper::concatSequences(ODescriptor::getTypes(),OColumnDescriptor_BASE::getTypes());
156 
157 	return ::comphelper::concatSequences(ODescriptor::getTypes(),OColumn_BASE::getTypes(),OColumnDescriptor_BASE::getTypes());
158 }
159 // -------------------------------------------------------------------------
160 void OColumn::construct()
161 {
162 	ODescriptor::construct();
163 
164 	sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
165 
166 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME),			PROPERTY_ID_TYPENAME,			nAttrib,&m_TypeName,		::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
167 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION),		PROPERTY_ID_DESCRIPTION,		nAttrib,&m_Description,		::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
168 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE),		PROPERTY_ID_DEFAULTVALUE,		nAttrib,&m_DefaultValue,	::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
169 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION),		PROPERTY_ID_PRECISION,			nAttrib,&m_Precision,		::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
170 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),				PROPERTY_ID_TYPE,				nAttrib,&m_Type,			::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
171 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE),			PROPERTY_ID_SCALE,				nAttrib,&m_Scale,			::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
172 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE),		PROPERTY_ID_ISNULLABLE,			nAttrib,&m_IsNullable,		::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
173 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT),	PROPERTY_ID_ISAUTOINCREMENT,	nAttrib,&m_IsAutoIncrement,	::getBooleanCppuType());
174 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISROWVERSION),		PROPERTY_ID_ISROWVERSION,		nAttrib,&m_IsRowVersion,	::getBooleanCppuType());
175 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY),		PROPERTY_ID_ISCURRENCY,			nAttrib,&m_IsCurrency,		::getBooleanCppuType());
176 }
177 // -------------------------------------------------------------------------
178 void OColumn::disposing(void)
179 {
180 	OPropertySetHelper::disposing();
181 
182 	::osl::MutexGuard aGuard(m_aMutex);
183 	checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed);
184 
185 }
186 // -------------------------------------------------------------------------
187 Reference< XPropertySet > SAL_CALL OColumn::createDataDescriptor(  ) throw(RuntimeException)
188 {
189 	::osl::MutexGuard aGuard(m_aMutex);
190 	checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed);
191 
192 
193 	OColumn* pNewColumn = new OColumn(	m_Name,
194 										m_TypeName,
195 										m_DefaultValue,
196                                         m_Description,
197 										m_IsNullable,
198 										m_Precision,
199 										m_Scale,
200 										m_Type,
201 										m_IsAutoIncrement,
202 										m_IsRowVersion,
203 										m_IsCurrency,
204 										isCaseSensitive());
205 	pNewColumn->setNew(sal_True);
206 	return pNewColumn;
207 }
208 // -----------------------------------------------------------------------------
209 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OColumn::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
210 {
211 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
212 }
213 // -----------------------------------------------------------------------------
214 // XNamed
215 ::rtl::OUString SAL_CALL OColumn::getName(  ) throw(::com::sun::star::uno::RuntimeException)
216 {
217 	return m_Name;
218 }
219 // -----------------------------------------------------------------------------
220 void SAL_CALL OColumn::setName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException)
221 {
222 	m_Name = aName;
223 }
224 // -----------------------------------------------------------------------------
225 
226