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_file.hxx"
26 #include "file/FDriver.hxx"
27 #include "file/FConnection.hxx"
28 #include "file/fcode.hxx"
29 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <comphelper/types.hxx>
31 #include "connectivity/dbexception.hxx"
32 #include "resource/common_res.hrc"
33 #include "resource/sharedresources.hxx"
34 #include <rtl/logfile.hxx>
35
36
37 using namespace connectivity::file;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::beans;
41 using namespace com::sun::star::sdbc;
42 using namespace com::sun::star::sdbcx;
43 using namespace com::sun::star::container;
44 // --------------------------------------------------------------------------------
OFileDriver(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)45 OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
46 : ODriver_BASE(m_aMutex)
47 ,m_xFactory(_rxFactory)
48 {
49 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::OFileDriver" );
50 }
51 // --------------------------------------------------------------------------------
disposing()52 void OFileDriver::disposing()
53 {
54 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::disposing" );
55 ::osl::MutexGuard aGuard(m_aMutex);
56
57
58 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
59 {
60 Reference< XComponent > xComp(i->get(), UNO_QUERY);
61 if (xComp.is())
62 xComp->dispose();
63 }
64 m_xConnections.clear();
65
66 ODriver_BASE::disposing();
67 }
68
69 // static ServiceInfo
70 //------------------------------------------------------------------------------
getImplementationName_Static()71 rtl::OUString OFileDriver::getImplementationName_Static( )
72 {
73 return rtl::OUString::createFromAscii("com.sun.star.sdbc.driver.file.Driver");
74 }
75 //------------------------------------------------------------------------------
getSupportedServiceNames_Static()76 Sequence< ::rtl::OUString > OFileDriver::getSupportedServiceNames_Static( )
77 {
78 Sequence< ::rtl::OUString > aSNS( 2 );
79 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
80 aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver");
81 return aSNS;
82 }
83
84 //------------------------------------------------------------------
getImplementationName()85 ::rtl::OUString SAL_CALL OFileDriver::getImplementationName( )
86 {
87 return getImplementationName_Static();
88 }
89
90 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)91 sal_Bool SAL_CALL OFileDriver::supportsService( const ::rtl::OUString& _rServiceName )
92 {
93 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
94 const ::rtl::OUString* pSupported = aSupported.getConstArray();
95 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
96 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
97 ;
98
99 return pSupported != pEnd;
100 }
101
102 //------------------------------------------------------------------
getSupportedServiceNames()103 Sequence< ::rtl::OUString > SAL_CALL OFileDriver::getSupportedServiceNames( )
104 {
105 return getSupportedServiceNames_Static();
106 }
107
108 // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)109 Reference< XConnection > SAL_CALL OFileDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info )
110 {
111 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::connect" );
112 ::osl::MutexGuard aGuard( m_aMutex );
113 checkDisposed(ODriver_BASE::rBHelper.bDisposed);
114
115 OConnection* pCon = new OConnection(this);
116 Reference< XConnection > xCon = pCon;
117 pCon->construct(url,info);
118 m_xConnections.push_back(WeakReferenceHelper(*pCon));
119
120 return xCon;
121 }
122 // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)123 sal_Bool SAL_CALL OFileDriver::acceptsURL( const ::rtl::OUString& url )
124 {
125 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::acceptsURL" );
126 return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:file:"),10));
127 }
128 // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)129 Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ )
130 {
131 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getPropertyInfo" );
132 if ( acceptsURL(url) )
133 {
134 ::std::vector< DriverPropertyInfo > aDriverInfo;
135
136 Sequence< ::rtl::OUString > aBoolean(2);
137 aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
138 aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
139
140 aDriverInfo.push_back(DriverPropertyInfo(
141 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
142 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
143 ,sal_False
144 ,::rtl::OUString()
145 ,Sequence< ::rtl::OUString >())
146 );
147 aDriverInfo.push_back(DriverPropertyInfo(
148 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension"))
149 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension of the file format."))
150 ,sal_False
151 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*"))
152 ,Sequence< ::rtl::OUString >())
153 );
154 aDriverInfo.push_back(DriverPropertyInfo(
155 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted"))
156 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display inactive records."))
157 ,sal_False
158 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
159 ,aBoolean)
160 );
161 aDriverInfo.push_back(DriverPropertyInfo(
162 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EnableSQL92Check"))
163 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use SQL92 naming constraints."))
164 ,sal_False
165 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
166 ,aBoolean)
167 );
168 aDriverInfo.push_back(DriverPropertyInfo(
169 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseRelativePath"))
170 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Handle the connection url as relative path."))
171 ,sal_False
172 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
173 ,aBoolean)
174 );
175 aDriverInfo.push_back(DriverPropertyInfo(
176 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL"))
177 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The URL of the database document which is used to create an absolute path."))
178 ,sal_False
179 ,::rtl::OUString()
180 ,Sequence< ::rtl::OUString >())
181 );
182 return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
183 } // if ( acceptsURL(url) )
184 {
185 ::connectivity::SharedResources aResources;
186 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
187 ::dbtools::throwGenericSQLException(sMessage ,*this);
188 } // if ( ! acceptsURL(url) )
189 return Sequence< DriverPropertyInfo >();
190 }
191 // --------------------------------------------------------------------------------
getMajorVersion()192 sal_Int32 SAL_CALL OFileDriver::getMajorVersion( )
193 {
194 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMajorVersion" );
195 return 1;
196 }
197 // --------------------------------------------------------------------------------
getMinorVersion()198 sal_Int32 SAL_CALL OFileDriver::getMinorVersion( )
199 {
200 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMinorVersion" );
201 return 0;
202 }
203 // --------------------------------------------------------------------------------
204 // --------------------------------------------------------------------------------
205 // XDataDefinitionSupplier
getDataDefinitionByConnection(const Reference<::com::sun::star::sdbc::XConnection> & connection)206 Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection )
207 {
208 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByConnection" );
209 ::osl::MutexGuard aGuard( m_aMutex );
210 checkDisposed(ODriver_BASE::rBHelper.bDisposed);
211
212 Reference< XTablesSupplier > xTab = NULL;
213 Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
214 if(xTunnel.is())
215 {
216 OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) );
217 OConnection* pConnection = NULL;
218 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
219 {
220 if ((OConnection*) Reference< XConnection >::query(i->get().get()).get() == pSearchConnection)
221 {
222 pConnection = pSearchConnection;
223 break;
224 }
225 }
226
227 if(pConnection)
228 xTab = pConnection->createCatalog();
229 }
230 return xTab;
231 }
232
233 // --------------------------------------------------------------------------------
getDataDefinitionByURL(const::rtl::OUString & url,const Sequence<PropertyValue> & info)234 Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info )
235 {
236 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByURL" );
237 if ( ! acceptsURL(url) )
238 {
239 ::connectivity::SharedResources aResources;
240 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
241 ::dbtools::throwGenericSQLException(sMessage ,*this);
242 }
243 return getDataDefinitionByConnection(connect(url,info));
244 }
245 // -----------------------------------------------------------------------------
describe(const Reference<XPropertySet> & rColumn,::vos::ORef<connectivity::OSQLColumns> rParameterColumns)246 void OOperandParam::describe(const Reference< XPropertySet>& rColumn, ::vos::ORef<connectivity::OSQLColumns> rParameterColumns)
247 {
248 // den alten namen beibehalten
249
250 OSL_ENSURE(getRowPos() < rParameterColumns->get().size(),"Invalid index for orderkey values!");
251
252 Reference< XPropertySet> xColumn = (rParameterColumns->get())[getRowPos()];
253
254 try
255 {
256 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)));
257 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)));
258 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)));
259 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)));
260 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)));
261 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)));
262 xColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT),rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)));
263 }
264 catch(const Exception&)
265 {
266 }
267
268 m_eDBType = ::comphelper::getINT32(rColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)));
269 }
270 // -----------------------------------------------------------------------------
OOperandAttr(sal_uInt16 _nPos,const Reference<XPropertySet> & _xColumn)271 OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn)
272 : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
273 , m_xColumn(_xColumn)
274 {
275 }
276 // -----------------------------------------------------------------------------
277