1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "file/FTable.hxx"
22 #include "file/FColumns.hxx"
23 #include <com/sun/star/sdbc/XRow.hpp>
24 #include <com/sun/star/sdbc/XResultSet.hpp>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/sdbc/ColumnValue.hpp>
28 #include <unotools/ucbstreamhelper.hxx>
30 using namespace connectivity
;
31 using namespace connectivity::file
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::sdbcx
;
35 using namespace ::com::sun::star::sdbc
;
36 using namespace ::com::sun::star::container
;
38 OFileTable::OFileTable(sdbcx::OCollection
* _pTables
,OConnection
* _pConnection
)
39 : OTable_TYPEDEF(_pTables
,_pConnection
->getMetaData()->supportsMixedCaseQuotedIdentifiers())
40 ,m_pConnection(_pConnection
)
48 m_aColumns
= new OSQLColumns();
51 OFileTable::OFileTable( sdbcx::OCollection
* _pTables
,OConnection
* _pConnection
,
52 const OUString
& _Name
,
53 const OUString
& _Type
,
54 const OUString
& _Description
,
55 const OUString
& _SchemaName
,
56 const OUString
& _CatalogName
)
57 : OTable_TYPEDEF(_pTables
,_pConnection
->getMetaData()->supportsMixedCaseQuotedIdentifiers(),
63 , m_pConnection(_pConnection
)
70 m_aColumns
= new OSQLColumns();
75 OFileTable::~OFileTable( )
79 void OFileTable::refreshColumns()
81 TStringVector aVector
;
82 Reference
< XResultSet
> xResult
= m_pConnection
->getMetaData()->getColumns(Any(),
83 m_SchemaName
,m_Name
, OUString("%"));
87 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
88 while(xResult
->next())
89 aVector
.push_back(xRow
->getString(4));
93 m_pColumns
->reFill(aVector
);
95 m_pColumns
= new OColumns(this,m_aMutex
,aVector
);
98 void OFileTable::refreshKeys()
102 void OFileTable::refreshIndexes()
106 Any SAL_CALL
OFileTable::queryInterface( const Type
& rType
) throw(RuntimeException
, std::exception
)
108 if( rType
== cppu::UnoType
<XKeysSupplier
>::get()||
109 rType
== cppu::UnoType
<XRename
>::get()||
110 rType
== cppu::UnoType
<XAlterTable
>::get()||
111 rType
== cppu::UnoType
<XIndexesSupplier
>::get()||
112 rType
== cppu::UnoType
<XDataDescriptorFactory
>::get())
115 return OTable_TYPEDEF::queryInterface(rType
);
118 void SAL_CALL
OFileTable::disposing()
122 ::osl::MutexGuard
aGuard(m_aMutex
);
127 Sequence
< sal_Int8
> OFileTable::getUnoTunnelImplementationId()
129 static ::cppu::OImplementationId
* pId
= 0;
132 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
135 static ::cppu::OImplementationId aId
;
139 return pId
->getImplementationId();
142 // com::sun::star::lang::XUnoTunnel
144 sal_Int64
OFileTable::getSomething( const Sequence
< sal_Int8
> & rId
) throw (RuntimeException
, std::exception
)
146 return (rId
.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId
.getConstArray(), 16 ) )
147 ? reinterpret_cast< sal_Int64
>( this )
148 : OTable_TYPEDEF::getSomething(rId
);
151 void OFileTable::FileClose()
153 ::osl::MutexGuard
aGuard(m_aMutex
);
155 if (m_pFileStream
&& m_pFileStream
->IsWritable())
156 m_pFileStream
->Flush();
158 delete m_pFileStream
;
159 m_pFileStream
= NULL
;
168 void SAL_CALL
OFileTable::acquire() throw()
170 OTable_TYPEDEF::acquire();
173 void SAL_CALL
OFileTable::release() throw()
175 OTable_TYPEDEF::release();
178 bool OFileTable::InsertRow(OValueRefVector
& /*rRow*/, bool /*bFlush*/, const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& /*_xCols*/)
183 bool OFileTable::DeleteRow(const OSQLColumns
& /*_rCols*/)
188 bool OFileTable::UpdateRow(OValueRefVector
& /*rRow*/, OValueRefRow
& /*pOrgRow*/,const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& /*_xCols*/)
193 void OFileTable::addColumn(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*descriptor*/)
195 OSL_FAIL( "OFileTable::addColumn: not implemented!" );
198 void OFileTable::dropColumn(sal_Int32
/*_nPos*/)
200 OSL_FAIL( "OFileTable::addColumn: not implemented!" );
204 SvStream
* OFileTable::createStream_simpleError( const OUString
& _rFileName
, StreamMode _eOpenMode
)
206 SvStream
* pReturn
= ::utl::UcbStreamHelper::CreateStream( _rFileName
, _eOpenMode
, bool(_eOpenMode
& StreamMode::NOCREATE
));
207 if (pReturn
&& (ERRCODE_NONE
!= pReturn
->GetErrorCode()))
216 void OFileTable::refreshHeader()
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */