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