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