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