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