1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FTable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
35 #include "file/FTable.hxx"
36 #include "file/FColumns.hxx"
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/sdbc/XResultSet.hpp>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/sdbc/ColumnValue.hpp>
42 #include <unotools/ucbstreamhelper.hxx>
43 #include <tools/debug.hxx>
44 #include <rtl/logfile.hxx>
46 using namespace connectivity
;
47 using namespace connectivity::file
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::sdbcx
;
51 using namespace ::com::sun::star::sdbc
;
52 using namespace ::com::sun::star::container
;
54 DBG_NAME( file_OFileTable
)
55 OFileTable::OFileTable(sdbcx::OCollection
* _pTables
,OConnection
* _pConnection
)
56 : OTable_TYPEDEF(_pTables
,_pConnection
->getMetaData()->storesMixedCaseQuotedIdentifiers())
57 ,m_pConnection(_pConnection
)
62 ,m_bWriteable(sal_False
)
64 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::OFileTable" );
65 DBG_CTOR( file_OFileTable
, NULL
);
67 TStringVector aVector
;
68 // m_pColumns = new OColumns(this,m_aMutex,aVector);
69 m_aColumns
= new OSQLColumns();
71 // -------------------------------------------------------------------------
72 OFileTable::OFileTable( sdbcx::OCollection
* _pTables
,OConnection
* _pConnection
,
73 const ::rtl::OUString
& _Name
,
74 const ::rtl::OUString
& _Type
,
75 const ::rtl::OUString
& _Description
,
76 const ::rtl::OUString
& _SchemaName
,
77 const ::rtl::OUString
& _CatalogName
78 ) : OTable_TYPEDEF(_pTables
,_pConnection
->getMetaData()->storesMixedCaseQuotedIdentifiers(),
84 ,m_pConnection(_pConnection
)
89 ,m_bWriteable(sal_False
)
91 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::OFileTable" );
92 DBG_CTOR( file_OFileTable
, NULL
);
93 m_aColumns
= new OSQLColumns();
97 // -------------------------------------------------------------------------
98 OFileTable::~OFileTable( )
100 DBG_DTOR( file_OFileTable
, NULL
);
102 // -------------------------------------------------------------------------
103 void OFileTable::refreshColumns()
105 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshColumns" );
106 TStringVector aVector
;
107 Reference
< XResultSet
> xResult
= m_pConnection
->getMetaData()->getColumns(Any(),
108 m_SchemaName
,m_Name
,::rtl::OUString::createFromAscii("%"));
112 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
113 while(xResult
->next())
114 aVector
.push_back(xRow
->getString(4));
118 m_pColumns
->reFill(aVector
);
120 m_pColumns
= new OColumns(this,m_aMutex
,aVector
);
122 // -------------------------------------------------------------------------
123 void OFileTable::refreshKeys()
125 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshKeys" );
127 // -------------------------------------------------------------------------
128 void OFileTable::refreshIndexes()
130 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshIndexes" );
132 // -------------------------------------------------------------------------
133 Any SAL_CALL
OFileTable::queryInterface( const Type
& rType
) throw(RuntimeException
)
135 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::queryInterface" );
136 if( rType
== ::getCppuType((const Reference
<XKeysSupplier
>*)0) ||
137 rType
== ::getCppuType((const Reference
<XRename
>*)0) ||
138 rType
== ::getCppuType((const Reference
<XAlterTable
>*)0) ||
139 rType
== ::getCppuType((const Reference
<XIndexesSupplier
>*)0) ||
140 rType
== ::getCppuType((const Reference
<XDataDescriptorFactory
>*)0))
143 return OTable_TYPEDEF::queryInterface(rType
);
145 // -------------------------------------------------------------------------
146 void SAL_CALL
OFileTable::disposing(void)
148 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::disposing" );
151 ::osl::MutexGuard
aGuard(m_aMutex
);
155 //--------------------------------------------------------------------------
156 Sequence
< sal_Int8
> OFileTable::getUnoTunnelImplementationId()
158 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::getUnoTunnelImplementationId" );
159 static ::cppu::OImplementationId
* pId
= 0;
162 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
165 static ::cppu::OImplementationId aId
;
169 return pId
->getImplementationId();
172 // com::sun::star::lang::XUnoTunnel
173 //------------------------------------------------------------------
174 sal_Int64
OFileTable::getSomething( const Sequence
< sal_Int8
> & rId
) throw (RuntimeException
)
176 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::getSomething" );
177 return (rId
.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId
.getConstArray(), 16 ) )
178 ? reinterpret_cast< sal_Int64
>( this )
179 : OTable_TYPEDEF::getSomething(rId
);
181 // -----------------------------------------------------------------------------
182 void OFileTable::FileClose()
184 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::FileClose" );
185 ::osl::MutexGuard
aGuard(m_aMutex
);
187 if (m_pFileStream
&& m_pFileStream
->IsWritable())
188 m_pFileStream
->Flush();
190 delete m_pFileStream
;
191 m_pFileStream
= NULL
;
199 // -----------------------------------------------------------------------------
200 void SAL_CALL
OFileTable::acquire() throw()
202 OTable_TYPEDEF::acquire();
204 // -----------------------------------------------------------------------------
205 void SAL_CALL
OFileTable::release() throw()
207 OTable_TYPEDEF::release();
209 // -----------------------------------------------------------------------------
210 BOOL
OFileTable::InsertRow(OValueRefVector
& /*rRow*/, BOOL
/*bFlush*/,const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& /*_xCols*/)
212 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::InsertRow" );
215 // -----------------------------------------------------------------------------
216 BOOL
OFileTable::DeleteRow(const OSQLColumns
& /*_rCols*/)
218 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::DeleteRow" );
221 // -----------------------------------------------------------------------------
222 BOOL
OFileTable::UpdateRow(OValueRefVector
& /*rRow*/, OValueRefRow
& /*pOrgRow*/,const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& /*_xCols*/)
224 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::UpdateRow" );
227 // -----------------------------------------------------------------------------
228 void OFileTable::addColumn(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*descriptor*/)
230 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::addColumn" );
231 OSL_ENSURE( false, "OFileTable::addColumn: not implemented!" );
233 // -----------------------------------------------------------------------------
234 void OFileTable::dropColumn(sal_Int32
/*_nPos*/)
236 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::dropColumn" );
237 OSL_ENSURE( false, "OFileTable::addColumn: not implemented!" );
240 // -----------------------------------------------------------------------------
241 SvStream
* OFileTable::createStream_simpleError( const String
& _rFileName
, StreamMode _eOpenMode
)
243 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::createStream_simpleError" );
244 utl::UcbLockBytesHandler
* p_null_dummy
=NULL
;
245 SvStream
* pReturn
= ::utl::UcbStreamHelper::CreateStream( _rFileName
, _eOpenMode
, (_eOpenMode
& STREAM_NOCREATE
) == STREAM_NOCREATE
,p_null_dummy
);
246 if (pReturn
&& (ERRCODE_NONE
!= pReturn
->GetErrorCode()))
254 // -----------------------------------------------------------------------------
255 void OFileTable::refreshHeader()
257 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileTable::refreshHeader" );
259 // -----------------------------------------------------------------------------