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
27 #include <stdio.h>
28 #include "file/FTable.hxx"
29 #include "file/FColumns.hxx"
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <com/sun/star/sdbc/XResultSet.hpp>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <com/sun/star/sdbc/ColumnValue.hpp>
35 #include <unotools/ucbstreamhelper.hxx>
36 #include <tools/debug.hxx>
37 #include <rtl/logfile.hxx>
38
39 using namespace connectivity;
40 using namespace connectivity::file;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::sdbcx;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::container;
46
DBG_NAME(file_OFileTable)47 DBG_NAME( file_OFileTable )
48 OFileTable::OFileTable(sdbcx::OCollection* _pTables,OConnection* _pConnection)
49 : OTable_TYPEDEF(_pTables,_pConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
50 ,m_pConnection(_pConnection)
51 ,m_pFileStream(NULL)
52 ,m_nFilePos(0)
53 ,m_pBuffer(NULL)
54 ,m_nBufferSize(0)
55 ,m_bWriteable(sal_False)
56 {
57 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::OFileTable" );
58 DBG_CTOR( file_OFileTable, NULL );
59 construct();
60 TStringVector aVector;
61 // m_pColumns = new OColumns(this,m_aMutex,aVector);
62 m_aColumns = new OSQLColumns();
63 }
64 // -------------------------------------------------------------------------
OFileTable(sdbcx::OCollection * _pTables,OConnection * _pConnection,const::rtl::OUString & _Name,const::rtl::OUString & _Type,const::rtl::OUString & _Description,const::rtl::OUString & _SchemaName,const::rtl::OUString & _CatalogName)65 OFileTable::OFileTable( sdbcx::OCollection* _pTables,OConnection* _pConnection,
66 const ::rtl::OUString& _Name,
67 const ::rtl::OUString& _Type,
68 const ::rtl::OUString& _Description ,
69 const ::rtl::OUString& _SchemaName,
70 const ::rtl::OUString& _CatalogName
71 ) : OTable_TYPEDEF(_pTables,_pConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers(),
72 _Name,
73 _Type,
74 _Description,
75 _SchemaName,
76 _CatalogName)
77 ,m_pConnection(_pConnection)
78 ,m_pFileStream(NULL)
79 ,m_nFilePos(0)
80 ,m_pBuffer(NULL)
81 ,m_nBufferSize(0)
82 ,m_bWriteable(sal_False)
83 {
84 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::OFileTable" );
85 DBG_CTOR( file_OFileTable, NULL );
86 m_aColumns = new OSQLColumns();
87 construct();
88 // refreshColumns();
89 }
90 // -------------------------------------------------------------------------
~OFileTable()91 OFileTable::~OFileTable( )
92 {
93 DBG_DTOR( file_OFileTable, NULL );
94 }
95 // -------------------------------------------------------------------------
refreshColumns()96 void OFileTable::refreshColumns()
97 {
98 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshColumns" );
99 TStringVector aVector;
100 Reference< XResultSet > xResult = m_pConnection->getMetaData()->getColumns(Any(),
101 m_SchemaName,m_Name,::rtl::OUString::createFromAscii("%"));
102
103 if(xResult.is())
104 {
105 Reference< XRow > xRow(xResult,UNO_QUERY);
106 while(xResult->next())
107 aVector.push_back(xRow->getString(4));
108 }
109
110 if(m_pColumns)
111 m_pColumns->reFill(aVector);
112 else
113 m_pColumns = new OColumns(this,m_aMutex,aVector);
114 }
115 // -------------------------------------------------------------------------
refreshKeys()116 void OFileTable::refreshKeys()
117 {
118 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshKeys" );
119 }
120 // -------------------------------------------------------------------------
refreshIndexes()121 void OFileTable::refreshIndexes()
122 {
123 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshIndexes" );
124 }
125 // -------------------------------------------------------------------------
queryInterface(const Type & rType)126 Any SAL_CALL OFileTable::queryInterface( const Type & rType ) throw(RuntimeException)
127 {
128 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::queryInterface" );
129 if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) ||
130 rType == ::getCppuType((const Reference<XRename>*)0) ||
131 rType == ::getCppuType((const Reference<XAlterTable>*)0) ||
132 rType == ::getCppuType((const Reference<XIndexesSupplier>*)0) ||
133 rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))
134 return Any();
135
136 return OTable_TYPEDEF::queryInterface(rType);
137 }
138 // -------------------------------------------------------------------------
disposing(void)139 void SAL_CALL OFileTable::disposing(void)
140 {
141 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::disposing" );
142 OTable::disposing();
143
144 ::osl::MutexGuard aGuard(m_aMutex);
145
146 FileClose();
147 }
148 //--------------------------------------------------------------------------
getUnoTunnelImplementationId()149 Sequence< sal_Int8 > OFileTable::getUnoTunnelImplementationId()
150 {
151 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::getUnoTunnelImplementationId" );
152 static ::cppu::OImplementationId * pId = 0;
153 if (! pId)
154 {
155 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
156 if (! pId)
157 {
158 static ::cppu::OImplementationId aId;
159 pId = &aId;
160 }
161 }
162 return pId->getImplementationId();
163 }
164
165 // com::sun::star::lang::XUnoTunnel
166 //------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)167 sal_Int64 OFileTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
168 {
169 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::getSomething" );
170 return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
171 ? reinterpret_cast< sal_Int64 >( this )
172 : OTable_TYPEDEF::getSomething(rId);
173 }
174 // -----------------------------------------------------------------------------
FileClose()175 void OFileTable::FileClose()
176 {
177 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::FileClose" );
178 ::osl::MutexGuard aGuard(m_aMutex);
179
180 if (m_pFileStream && m_pFileStream->IsWritable())
181 m_pFileStream->Flush();
182
183 delete m_pFileStream;
184 m_pFileStream = NULL;
185
186 if (m_pBuffer)
187 {
188 delete[] m_pBuffer;
189 m_pBuffer = NULL;
190 }
191 }
192 // -----------------------------------------------------------------------------
acquire()193 void SAL_CALL OFileTable::acquire() throw()
194 {
195 OTable_TYPEDEF::acquire();
196 }
197 // -----------------------------------------------------------------------------
release()198 void SAL_CALL OFileTable::release() throw()
199 {
200 OTable_TYPEDEF::release();
201 }
202 // -----------------------------------------------------------------------------
InsertRow(OValueRefVector &,sal_Bool,const::com::sun::star::uno::Reference<::com::sun::star::container::XIndexAccess> &)203 sal_Bool OFileTable::InsertRow(OValueRefVector& /*rRow*/, sal_Bool /*bFlush*/,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& /*_xCols*/)
204 {
205 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::InsertRow" );
206 return sal_False;
207 }
208 // -----------------------------------------------------------------------------
DeleteRow(const OSQLColumns &)209 sal_Bool OFileTable::DeleteRow(const OSQLColumns& /*_rCols*/)
210 {
211 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::DeleteRow" );
212 return sal_False;
213 }
214 // -----------------------------------------------------------------------------
UpdateRow(OValueRefVector &,OValueRefRow &,const::com::sun::star::uno::Reference<::com::sun::star::container::XIndexAccess> &)215 sal_Bool OFileTable::UpdateRow(OValueRefVector& /*rRow*/, OValueRefRow& /*pOrgRow*/,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& /*_xCols*/)
216 {
217 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::UpdateRow" );
218 return sal_False;
219 }
220 // -----------------------------------------------------------------------------
addColumn(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> &)221 void OFileTable::addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& /*descriptor*/)
222 {
223 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::addColumn" );
224 OSL_ENSURE( false, "OFileTable::addColumn: not implemented!" );
225 }
226 // -----------------------------------------------------------------------------
dropColumn(sal_Int32)227 void OFileTable::dropColumn(sal_Int32 /*_nPos*/)
228 {
229 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::dropColumn" );
230 OSL_ENSURE( false, "OFileTable::addColumn: not implemented!" );
231 }
232
233 // -----------------------------------------------------------------------------
createStream_simpleError(const String & _rFileName,StreamMode _eOpenMode)234 SvStream* OFileTable::createStream_simpleError( const String& _rFileName, StreamMode _eOpenMode)
235 {
236 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::createStream_simpleError" );
237 utl::UcbLockBytesHandler* p_null_dummy=NULL;
238 SvStream* pReturn = ::utl::UcbStreamHelper::CreateStream( _rFileName, _eOpenMode, (_eOpenMode & STREAM_NOCREATE) == STREAM_NOCREATE ,p_null_dummy);
239 if (pReturn && (ERRCODE_NONE != pReturn->GetErrorCode()))
240 {
241 delete pReturn;
242 pReturn = NULL;
243 }
244 return pReturn;
245 }
246
247 // -----------------------------------------------------------------------------
refreshHeader()248 void OFileTable::refreshHeader()
249 {
250 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshHeader" );
251 }
252 // -----------------------------------------------------------------------------
253
254