1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include "file/FTable.hxx"
29cdf0e10cSrcweir #include "file/FColumns.hxx"
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
32cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
33cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
35cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
36cdf0e10cSrcweir #include <tools/debug.hxx>
37cdf0e10cSrcweir #include <rtl/logfile.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace connectivity;
40cdf0e10cSrcweir using namespace connectivity::file;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::beans;
43cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
44cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
45cdf0e10cSrcweir using namespace ::com::sun::star::container;
46cdf0e10cSrcweir
DBG_NAME(file_OFileTable)47cdf0e10cSrcweir DBG_NAME( file_OFileTable )
48cdf0e10cSrcweir OFileTable::OFileTable(sdbcx::OCollection* _pTables,OConnection* _pConnection)
49cdf0e10cSrcweir : OTable_TYPEDEF(_pTables,_pConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
50cdf0e10cSrcweir ,m_pConnection(_pConnection)
51cdf0e10cSrcweir ,m_pFileStream(NULL)
52cdf0e10cSrcweir ,m_nFilePos(0)
53cdf0e10cSrcweir ,m_pBuffer(NULL)
54cdf0e10cSrcweir ,m_nBufferSize(0)
55cdf0e10cSrcweir ,m_bWriteable(sal_False)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::OFileTable" );
58cdf0e10cSrcweir DBG_CTOR( file_OFileTable, NULL );
59cdf0e10cSrcweir construct();
60cdf0e10cSrcweir TStringVector aVector;
61cdf0e10cSrcweir // m_pColumns = new OColumns(this,m_aMutex,aVector);
62cdf0e10cSrcweir m_aColumns = new OSQLColumns();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir // -------------------------------------------------------------------------
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)65cdf0e10cSrcweir OFileTable::OFileTable( sdbcx::OCollection* _pTables,OConnection* _pConnection,
66cdf0e10cSrcweir const ::rtl::OUString& _Name,
67cdf0e10cSrcweir const ::rtl::OUString& _Type,
68cdf0e10cSrcweir const ::rtl::OUString& _Description ,
69cdf0e10cSrcweir const ::rtl::OUString& _SchemaName,
70cdf0e10cSrcweir const ::rtl::OUString& _CatalogName
71cdf0e10cSrcweir ) : OTable_TYPEDEF(_pTables,_pConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers(),
72cdf0e10cSrcweir _Name,
73cdf0e10cSrcweir _Type,
74cdf0e10cSrcweir _Description,
75cdf0e10cSrcweir _SchemaName,
76cdf0e10cSrcweir _CatalogName)
77cdf0e10cSrcweir ,m_pConnection(_pConnection)
78cdf0e10cSrcweir ,m_pFileStream(NULL)
79cdf0e10cSrcweir ,m_nFilePos(0)
80cdf0e10cSrcweir ,m_pBuffer(NULL)
81cdf0e10cSrcweir ,m_nBufferSize(0)
82cdf0e10cSrcweir ,m_bWriteable(sal_False)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::OFileTable" );
85cdf0e10cSrcweir DBG_CTOR( file_OFileTable, NULL );
86cdf0e10cSrcweir m_aColumns = new OSQLColumns();
87cdf0e10cSrcweir construct();
88cdf0e10cSrcweir // refreshColumns();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir // -------------------------------------------------------------------------
~OFileTable()91cdf0e10cSrcweir OFileTable::~OFileTable( )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir DBG_DTOR( file_OFileTable, NULL );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshColumns()96cdf0e10cSrcweir void OFileTable::refreshColumns()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshColumns" );
99cdf0e10cSrcweir TStringVector aVector;
100cdf0e10cSrcweir Reference< XResultSet > xResult = m_pConnection->getMetaData()->getColumns(Any(),
101cdf0e10cSrcweir m_SchemaName,m_Name,::rtl::OUString::createFromAscii("%"));
102cdf0e10cSrcweir
103cdf0e10cSrcweir if(xResult.is())
104cdf0e10cSrcweir {
105cdf0e10cSrcweir Reference< XRow > xRow(xResult,UNO_QUERY);
106cdf0e10cSrcweir while(xResult->next())
107cdf0e10cSrcweir aVector.push_back(xRow->getString(4));
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir if(m_pColumns)
111cdf0e10cSrcweir m_pColumns->reFill(aVector);
112cdf0e10cSrcweir else
113cdf0e10cSrcweir m_pColumns = new OColumns(this,m_aMutex,aVector);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshKeys()116cdf0e10cSrcweir void OFileTable::refreshKeys()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshKeys" );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshIndexes()121cdf0e10cSrcweir void OFileTable::refreshIndexes()
122cdf0e10cSrcweir {
123cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshIndexes" );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir // -------------------------------------------------------------------------
queryInterface(const Type & rType)126cdf0e10cSrcweir Any SAL_CALL OFileTable::queryInterface( const Type & rType ) throw(RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::queryInterface" );
129cdf0e10cSrcweir if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) ||
130cdf0e10cSrcweir rType == ::getCppuType((const Reference<XRename>*)0) ||
131cdf0e10cSrcweir rType == ::getCppuType((const Reference<XAlterTable>*)0) ||
132cdf0e10cSrcweir rType == ::getCppuType((const Reference<XIndexesSupplier>*)0) ||
133cdf0e10cSrcweir rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))
134cdf0e10cSrcweir return Any();
135cdf0e10cSrcweir
136cdf0e10cSrcweir return OTable_TYPEDEF::queryInterface(rType);
137cdf0e10cSrcweir }
138cdf0e10cSrcweir // -------------------------------------------------------------------------
disposing(void)139cdf0e10cSrcweir void SAL_CALL OFileTable::disposing(void)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::disposing" );
142cdf0e10cSrcweir OTable::disposing();
143cdf0e10cSrcweir
144cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
145cdf0e10cSrcweir
146cdf0e10cSrcweir FileClose();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir //--------------------------------------------------------------------------
getUnoTunnelImplementationId()149cdf0e10cSrcweir Sequence< sal_Int8 > OFileTable::getUnoTunnelImplementationId()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::getUnoTunnelImplementationId" );
152cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0;
153cdf0e10cSrcweir if (! pId)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
156cdf0e10cSrcweir if (! pId)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir static ::cppu::OImplementationId aId;
159cdf0e10cSrcweir pId = &aId;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir return pId->getImplementationId();
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
165cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel
166cdf0e10cSrcweir //------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)167cdf0e10cSrcweir sal_Int64 OFileTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::getSomething" );
170cdf0e10cSrcweir return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
171cdf0e10cSrcweir ? reinterpret_cast< sal_Int64 >( this )
172cdf0e10cSrcweir : OTable_TYPEDEF::getSomething(rId);
173cdf0e10cSrcweir }
174cdf0e10cSrcweir // -----------------------------------------------------------------------------
FileClose()175cdf0e10cSrcweir void OFileTable::FileClose()
176cdf0e10cSrcweir {
177cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::FileClose" );
178cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
179cdf0e10cSrcweir
180cdf0e10cSrcweir if (m_pFileStream && m_pFileStream->IsWritable())
181cdf0e10cSrcweir m_pFileStream->Flush();
182cdf0e10cSrcweir
183cdf0e10cSrcweir delete m_pFileStream;
184cdf0e10cSrcweir m_pFileStream = NULL;
185cdf0e10cSrcweir
186cdf0e10cSrcweir if (m_pBuffer)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir delete[] m_pBuffer;
189cdf0e10cSrcweir m_pBuffer = NULL;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir // -----------------------------------------------------------------------------
acquire()193cdf0e10cSrcweir void SAL_CALL OFileTable::acquire() throw()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir OTable_TYPEDEF::acquire();
196cdf0e10cSrcweir }
197cdf0e10cSrcweir // -----------------------------------------------------------------------------
release()198cdf0e10cSrcweir void SAL_CALL OFileTable::release() throw()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir OTable_TYPEDEF::release();
201cdf0e10cSrcweir }
202cdf0e10cSrcweir // -----------------------------------------------------------------------------
InsertRow(OValueRefVector &,sal_Bool,const::com::sun::star::uno::Reference<::com::sun::star::container::XIndexAccess> &)203cdf0e10cSrcweir sal_Bool OFileTable::InsertRow(OValueRefVector& /*rRow*/, sal_Bool /*bFlush*/,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& /*_xCols*/)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::InsertRow" );
206cdf0e10cSrcweir return sal_False;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir // -----------------------------------------------------------------------------
DeleteRow(const OSQLColumns &)209cdf0e10cSrcweir sal_Bool OFileTable::DeleteRow(const OSQLColumns& /*_rCols*/)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::DeleteRow" );
212cdf0e10cSrcweir return sal_False;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateRow(OValueRefVector &,OValueRefRow &,const::com::sun::star::uno::Reference<::com::sun::star::container::XIndexAccess> &)215cdf0e10cSrcweir sal_Bool OFileTable::UpdateRow(OValueRefVector& /*rRow*/, OValueRefRow& /*pOrgRow*/,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& /*_xCols*/)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::UpdateRow" );
218cdf0e10cSrcweir return sal_False;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir // -----------------------------------------------------------------------------
addColumn(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> &)221cdf0e10cSrcweir void OFileTable::addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& /*descriptor*/)
222cdf0e10cSrcweir {
223cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::addColumn" );
224cdf0e10cSrcweir OSL_ENSURE( false, "OFileTable::addColumn: not implemented!" );
225cdf0e10cSrcweir }
226cdf0e10cSrcweir // -----------------------------------------------------------------------------
dropColumn(sal_Int32)227cdf0e10cSrcweir void OFileTable::dropColumn(sal_Int32 /*_nPos*/)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::dropColumn" );
230cdf0e10cSrcweir OSL_ENSURE( false, "OFileTable::addColumn: not implemented!" );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
233cdf0e10cSrcweir // -----------------------------------------------------------------------------
createStream_simpleError(const String & _rFileName,StreamMode _eOpenMode)234cdf0e10cSrcweir SvStream* OFileTable::createStream_simpleError( const String& _rFileName, StreamMode _eOpenMode)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::createStream_simpleError" );
237cdf0e10cSrcweir utl::UcbLockBytesHandler* p_null_dummy=NULL;
238cdf0e10cSrcweir SvStream* pReturn = ::utl::UcbStreamHelper::CreateStream( _rFileName, _eOpenMode, (_eOpenMode & STREAM_NOCREATE) == STREAM_NOCREATE ,p_null_dummy);
239cdf0e10cSrcweir if (pReturn && (ERRCODE_NONE != pReturn->GetErrorCode()))
240cdf0e10cSrcweir {
241cdf0e10cSrcweir delete pReturn;
242cdf0e10cSrcweir pReturn = NULL;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir return pReturn;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir // -----------------------------------------------------------------------------
refreshHeader()248cdf0e10cSrcweir void OFileTable::refreshHeader()
249cdf0e10cSrcweir {
250cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshHeader" );
251cdf0e10cSrcweir }
252cdf0e10cSrcweir // -----------------------------------------------------------------------------
253cdf0e10cSrcweir
254