diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /connectivity/source/inc/dbase | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | connectivity/source/inc/dbase/DCatalog.hxx | 42 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DColumns.hxx | 48 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DConnection.hxx | 50 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DDatabaseMetaData.hxx | 61 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DDriver.hxx | 55 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DIndex.hxx | 145 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DIndexColumns.hxx | 53 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DIndexIter.hxx | 71 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DIndexes.hxx | 54 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DPreparedStatement.hxx | 43 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DResultSet.hxx | 82 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DStatement.hxx | 43 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DTable.hxx | 198 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DTables.hxx | 50 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/dindexnode.hxx | 314 |
15 files changed, 1309 insertions, 0 deletions
diff --git a/connectivity/source/inc/dbase/DCatalog.hxx b/connectivity/source/inc/dbase/DCatalog.hxx new file mode 100644 index 000000000..3ccfed6f6 --- /dev/null +++ b/connectivity/source/inc/dbase/DCatalog.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCATALOG_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCATALOG_HXX + +#include <file/FCatalog.hxx> + +namespace connectivity +{ + namespace dbase + { + class ODbaseConnection; + class ODbaseCatalog : public file::OFileCatalog + { + public: + virtual void refreshTables() override; + + public: + ODbaseCatalog(ODbaseConnection* _pCon); + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCATALOG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DColumns.hxx b/connectivity/source/inc/dbase/DColumns.hxx new file mode 100644 index 000000000..c282b43e8 --- /dev/null +++ b/connectivity/source/inc/dbase/DColumns.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCOLUMNS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCOLUMNS_HXX + +#include <file/FColumns.hxx> + +namespace connectivity +{ + namespace dbase + { + class ODbaseColumns : public file::OColumns + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + ODbaseColumns(file::OFileTable* _pTable, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector + ) : file::OColumns(_pTable,_rMutex,_rVector) + {} + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCOLUMNS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DConnection.hxx b/connectivity/source/inc/dbase/DConnection.hxx new file mode 100644 index 000000000..f81f7b494 --- /dev/null +++ b/connectivity/source/inc/dbase/DConnection.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCONNECTION_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCONNECTION_HXX + +#include <file/FConnection.hxx> + +namespace connectivity +{ + namespace dbase + { + class ODriver; + class ODbaseConnection : public file::OConnection + { + protected: + virtual ~ODbaseConnection() override; + public: + ODbaseConnection(ODriver* _pDriver); + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XConnection + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override; + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCONNECTION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DDatabaseMetaData.hxx b/connectivity/source/inc/dbase/DDatabaseMetaData.hxx new file mode 100644 index 000000000..3424f9c8b --- /dev/null +++ b/connectivity/source/inc/dbase/DDatabaseMetaData.hxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDATABASEMETADATA_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDATABASEMETADATA_HXX + +#include <file/FDatabaseMetaData.hxx> + +namespace connectivity +{ + namespace dbase + { + + //************ Class: java.sql.DatabaseMetaDataDate + + + class ODbaseDatabaseMetaData : public file::ODatabaseMetaData + { + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual OUString SAL_CALL getURL( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; + + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + + virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn( ) override; + virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn( ) override; + + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override; + protected: + virtual ~ODbaseDatabaseMetaData() override; + public: + ODbaseDatabaseMetaData(file::OConnection* _pCon); + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDATABASEMETADATA_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DDriver.hxx b/connectivity/source/inc/dbase/DDriver.hxx new file mode 100644 index 000000000..9378b4c5f --- /dev/null +++ b/connectivity/source/inc/dbase/DDriver.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDRIVER_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDRIVER_HXX + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <connectivity/CommonTools.hxx> +#include <file/FDriver.hxx> + +namespace connectivity +{ + namespace dbase + { + /// @throws css::uno::Exception + css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); + + class ODriver : public file::OFileDriver + { + public: + ODriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext) : file::OFileDriver(_rxContext){} + + // XInterface + /// @throws css::uno::RuntimeException + static OUString getImplementationName_Static( ); + // static css::uno::Sequence< OUString > getSupportedServiceNames_Static( ) throw (css::uno::RuntimeException); + + OUString SAL_CALL getImplementationName( ) override; + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + }; + } + +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDRIVER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndex.hxx b/connectivity/source/inc/dbase/DIndex.hxx new file mode 100644 index 000000000..018c4b915 --- /dev/null +++ b/connectivity/source/inc/dbase/DIndex.hxx @@ -0,0 +1,145 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX + +#include <sdbcx/VIndex.hxx> +#include <dbase/DTable.hxx> +#include <dbase/dindexnode.hxx> + +#define dBASE_III_GROUP "dBase III" + +namespace connectivity +{ + namespace dbase + { + class OIndexIterator; + class ONDXKey; + + typedef sdbcx::OIndex ODbaseIndex_BASE; + + class ODbaseIndex : public ODbaseIndex_BASE + { + friend SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&); + friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&); + + friend class ONDXNode; + friend class ONDXPage; + friend class ONDXPagePtr; + friend class OIndexIterator; + + public: + + // Header struct - stays in memory + + struct NDXHeader + { + sal_uInt32 db_rootpage; /* Rootpage position */ + sal_uInt32 db_pagecount; /* Page count */ + sal_uInt8 db_free[4]; /* Reserved */ + sal_uInt16 db_keylen; /* Key length */ + sal_uInt16 db_maxkeys; /* Maximum number of keys per page */ + sal_uInt16 db_keytype; /* Type of key: + 0 = Text + 1 = Numerical */ + sal_uInt16 db_keyrec; /* Length of an index record + RecordNumber + keylen */ + sal_uInt8 db_free1[3]; /* Reserved */ + sal_uInt8 db_unique; /* Unique */ + char db_name[488]; /* index_name (field name) */ + }; + + private: + std::unique_ptr<SvStream> m_pFileStream; // Stream to read/write the index + NDXHeader m_aHeader = {}; + std::vector<ONDXPage*> + m_aCollector; // Pool of obsolete pages + ONDXPagePtr m_aRoot, // Root of the B+ tree + m_aCurLeaf; // Current leaf + sal_uInt16 m_nCurNode; // Position of the current node + + sal_uInt32 m_nPageCount, + m_nRootPage; + + ODbaseTable* m_pTable; + bool m_bUseCollector : 1; // Use the Garbage Collector + + OUString getCompletePath() const; + void closeImpl(); + // Closes and kills the index file and throws an error + void impl_killFileAndthrowError_throw(const char* pErrorId, const OUString& _sFile); + protected: + virtual ~ODbaseIndex() override; + public: + ODbaseIndex(ODbaseTable* _pTable); + ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& Name); + + void openIndexFile(); + virtual void refreshColumns() override; + + // css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); + + const ODbaseTable* getTable() const { return m_pTable; } + const NDXHeader& getHeader() const { return m_aHeader; } + std::unique_ptr<OIndexIterator> createIterator(); + + void SetRootPos(sal_uInt32 nPos) {m_nRootPage = nPos;} + void SetPageCount(sal_uInt32 nCount) {m_nPageCount = nCount;} + + sal_uInt32 GetPageCount() const {return m_nPageCount;} + + sal_uInt16 GetMaxNodes() const {return m_aHeader.db_maxkeys;} + + bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue); + bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&); + bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue); + bool Find(sal_uInt32 nRec, const ORowSetValue& rValue); + + void createINFEntry(); + void CreateImpl(); + void DropImpl(); + + DECLARE_SERVICE_INFO(); + protected: + + ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = nullptr, bool bLoad = false); + void Collect(ONDXPage*); + ONDXPagePtr const & getRoot(); + + bool isUnique() const { return m_IsUnique; } + bool UseCollector() const {return m_bUseCollector;} + // Tree operations + void Release(bool bSave = true); + bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue); + }; + + SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&); + SvStream& operator >> (SvStream &rStream, ODbaseIndex&); + + void ReadHeader(SvStream & rStream, ODbaseIndex::NDXHeader & rHeader); + } +} + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexColumns.hxx b/connectivity/source/inc/dbase/DIndexColumns.hxx new file mode 100644 index 000000000..07aa3d551 --- /dev/null +++ b/connectivity/source/inc/dbase/DIndexColumns.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXCOLUMNS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXCOLUMNS_HXX + +#include <connectivity/sdbcx/VCollection.hxx> +#include <dbase/DIndex.hxx> +#include <dbase/DTable.hxx> + +namespace connectivity +{ + namespace dbase + { + class ODbaseIndexColumns : public sdbcx::OCollection + { + ODbaseIndex* m_pIndex; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + public: + ODbaseIndexColumns( ODbaseIndex* _pIndex, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) + : sdbcx::OCollection(*_pIndex,_pIndex->getTable()->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(),_rMutex,_rVector) + , m_pIndex(_pIndex) + {} + + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXCOLUMNS_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexIter.hxx b/connectivity/source/inc/dbase/DIndexIter.hxx new file mode 100644 index 000000000..1401a0ecc --- /dev/null +++ b/connectivity/source/inc/dbase/DIndexIter.hxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXITER_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXITER_HXX + +#include <file/fcode.hxx> +#include <dbase/DIndex.hxx> +#include <dbase/dindexnode.hxx> + +namespace connectivity +{ + namespace dbase + { + + // IndexIterator + + class OIndexIterator final + { + file::OBoolOperator* m_pOperator; + const file::OOperand* m_pOperand; + rtl::Reference<ODbaseIndex> m_xIndex; + ONDXPagePtr m_aRoot, + m_aCurLeaf; + sal_uInt16 m_nCurNode; + + sal_uInt32 Find(bool bFirst); + sal_uInt32 GetCompare(bool bFirst); + sal_uInt32 GetLike(bool bFirst); + sal_uInt32 GetNull(bool bFirst); + sal_uInt32 GetNotNull(bool bFirst); + + ONDXKey* GetFirstKey(ONDXPage* pPage, + const file::OOperand& rKey); + ONDXKey* GetNextKey(); + + public: + OIndexIterator(ODbaseIndex* pInd) + :m_pOperator(nullptr) + ,m_pOperand(nullptr) + ,m_xIndex(pInd) + ,m_nCurNode(NODE_NOTFOUND) + { + } + + ~OIndexIterator(); + sal_uInt32 First(); + sal_uInt32 Next(); + + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXITER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexes.hxx b/connectivity/source/inc/dbase/DIndexes.hxx new file mode 100644 index 000000000..cccc9347f --- /dev/null +++ b/connectivity/source/inc/dbase/DIndexes.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXES_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXES_HXX + +#include <connectivity/sdbcx/VCollection.hxx> +#include <dbase/DTable.hxx> + +namespace connectivity +{ + namespace dbase + { + class ODbaseTable; + + typedef sdbcx::OCollection ODbaseIndexes_BASE; + + class ODbaseIndexes : public ODbaseIndexes_BASE + { + ODbaseTable* m_pTable; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + ODbaseIndexes(ODbaseTable* _pTable, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : ODbaseIndexes_BASE(*_pTable,_pTable->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(),_rMutex,_rVector) + , m_pTable(_pTable) + {} + + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DPreparedStatement.hxx b/connectivity/source/inc/dbase/DPreparedStatement.hxx new file mode 100644 index 000000000..22df7be8e --- /dev/null +++ b/connectivity/source/inc/dbase/DPreparedStatement.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DPREPAREDSTATEMENT_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DPREPAREDSTATEMENT_HXX + +#include <file/FPreparedStatement.hxx> + +namespace connectivity +{ + namespace dbase + { + class OConnection; + class ODbasePreparedStatement : public file::OPreparedStatement + { + protected: + virtual file::OResultSet* createResultSet() override; + public: + ODbasePreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + } +} + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DPREPAREDSTATEMENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DResultSet.hxx b/connectivity/source/inc/dbase/DResultSet.hxx new file mode 100644 index 000000000..31a0f6722 --- /dev/null +++ b/connectivity/source/inc/dbase/DResultSet.hxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DRESULTSET_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DRESULTSET_HXX + +#include <file/FResultSet.hxx> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbcx/XDeleteRows.hpp> +#include <cppuhelper/implbase2.hxx> + +namespace connectivity +{ + namespace dbase + { + class ODbaseResultSet; + // these typedef's are only necessary for the compiler + typedef ::cppu::ImplHelper2< css::sdbcx::XRowLocate, + css::sdbcx::XDeleteRows> ODbaseResultSet_BASE; + typedef file::OResultSet ODbaseResultSet_BASE2; + typedef ::comphelper::OPropertyArrayUsageHelper<ODbaseResultSet> ODbaseResultSet_BASE3; + + + class ODbaseResultSet : public ODbaseResultSet_BASE2, + public ODbaseResultSet_BASE, + public ODbaseResultSet_BASE3 + { + bool m_bBookmarkable; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual bool fillIndexValues(const css::uno::Reference< css::sdbcx::XColumnsSupplier> &_xIndex) override; + public: + DECLARE_SERVICE_INFO(); + + ODbaseResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() throw() override; + virtual void SAL_CALL release() throw() override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + + // XRowLocate + virtual css::uno::Any SAL_CALL getBookmark( ) override; + virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; + virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; + virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; + // XDeleteRows + virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; + + // own methods + sal_Int32 getCurrentFilePos() const; + + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DRESULTSET_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DStatement.hxx b/connectivity/source/inc/dbase/DStatement.hxx new file mode 100644 index 000000000..9c02e2abe --- /dev/null +++ b/connectivity/source/inc/dbase/DStatement.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DSTATEMENT_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DSTATEMENT_HXX + +#include <file/FStatement.hxx> + +namespace connectivity +{ + namespace dbase + { + class OConnection; + class ODbaseStatement : public file::OStatement + { + protected: + virtual file::OResultSet* createResultSet() override; + public: + ODbaseStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + } +} + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DSTATEMENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DTable.hxx b/connectivity/source/inc/dbase/DTable.hxx new file mode 100644 index 000000000..5b9843987 --- /dev/null +++ b/connectivity/source/inc/dbase/DTable.hxx @@ -0,0 +1,198 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX + +#include <file/FTable.hxx> +#include <connectivity/CommonTools.hxx> +#include <tools/urlobj.hxx> + + +namespace connectivity +{ + namespace dbase + { + typedef file::OFileTable ODbaseTable_BASE; + class ODbaseConnection; + + class ODbaseTable : public ODbaseTable_BASE + { + // The first byte of a dBase file specifies its type + public: + enum DBFType { dBaseIII = 0x03, + dBaseIV = 0x04, + dBaseV = 0x05, + VisualFoxPro = 0x30, + VisualFoxProAuto = 0x31, // Visual FoxPro with AutoIncrement field + dBaseFS = 0x43, + dBaseFSMemo = 0xB3, + dBaseIIIMemo = 0x83, + dBaseIVMemo = 0x8B, + dBaseIVMemoSQL = 0x8E, + FoxProMemo = 0xF5 + }; + enum DBFMemoType { MemodBaseIII = 0, + MemodBaseIV, + MemoFoxPro + }; + + private: + // sources: https://www.clicketyclick.dk/databases/xbase/format/dbf.html (dBASE III and 5) + // http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm (dBASE 7) which is similar at least for this part + struct DBFHeader { // address/pos in trailer + DBFType type; // dBASE/xBASE type, see DBFType 00h + sal_uInt8 dateElems[3]; // Date of last change (YYMMDD) 01h + sal_uInt32 nbRecords; // Number of records 04h + sal_uInt16 headerLength; // 08h + sal_uInt16 recordLength; // Length of 1 record 10h + sal_uInt8 trailer[20]; + // this last field contains these data: + // - reserved:2 bytes:should be filled with 0 12h/0 + // - incomplete transaction:1 byte:dBASE IV 14h/2 + // 00h Transaction ended (or rolled back) + // 01h Transaction started + // - encryptionFlag:1 byte: dBASE IV 15h/3 + // 00h not encrypted + // 01h for encrypted + // - freeRecordThread:4 bytes:reserved for LAN only 16h/4 + // - multiUserdBASE:8 bytes:reserved for multi-user dBASE (dBASE III+) 20h/8 + // - MDXFlag:1 byte:dBASE IV 28h/16 + // 0x01 if a production .MDX file exists for this table + // 0x00 if no .MDX file exists + // - languageDriver:1 byte:codepage (from Foxpro) 29h/17 + // - reserved:2 bytes: should be filled with 0 30h/18 + }; + struct DBFColumn { /* Column descriptors */ + sal_uInt8 db_fnm[11]; /* Field name */ + sal_uInt8 db_typ; /* Field type */ + sal_uInt32 db_adr; /* Field address */ + sal_uInt8 db_flng; /* Field length */ + sal_uInt8 db_dez; /* Decimal places for N */ + sal_uInt8 db_free2[14]; /* Reserved */ + }; + struct DBFMemoHeader + { + DBFMemoType db_typ; /* File type */ + sal_uInt32 db_next; /* Next free block */ + sal_uInt16 db_size; /* Block size: dBase 3 fixed */ + DBFMemoHeader() + : db_typ(MemodBaseIII) + , db_next(0) + , db_size(0) + { + } + }; + + std::vector<sal_Int32> m_aTypes; // holds all types for columns just to avoid to ask the propertyset + std::vector<sal_Int32> m_aPrecisions; // same as above + std::vector<sal_Int32> m_aScales; + std::vector<sal_Int32> m_aRealFieldLengths; + DBFHeader m_aHeader = {}; + DBFMemoHeader m_aMemoHeader; + std::unique_ptr<SvStream> m_pMemoStream; + rtl_TextEncoding m_eEncoding; + + void alterColumn(sal_Int32 index, + const css::uno::Reference< css::beans::XPropertySet>& descriptor , + const css::uno::Reference< css::sdbcx::XDataDescriptorFactory>& xOldColumn ); + void readHeader(); + void fillColumns(); + OUString createTempFile(); + void copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos); + bool CreateFile(const INetURLObject& aFile, bool& bCreateMemo); + bool CreateMemoFile(const INetURLObject& aFile); + bool HasMemoFields() const { return m_aHeader.type > dBaseIV;} + void ReadMemoHeader(); + bool ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable); + + void WriteMemo(const ORowSetValue& aVariable, std::size_t& rBlockNr); + bool WriteBuffer(); + bool UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRow, const css::uno::Reference< css::container::XIndexAccess>& _xCols, bool bForceAllFields); + css::uno::Reference< css::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos); + bool AllocBuffer(); + + void throwInvalidDbaseFormat(); + /// @throws css::sdbc::SQLException + /// @throws css::container::ElementExistException + /// @throws css::uno::RuntimeException + void renameImpl( const OUString& newName ); + void throwInvalidColumnType(const char* pErrorId, const OUString& _sColumnName); + + protected: + virtual void FileClose() override; +// using ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper; + + public: + virtual void refreshColumns() override; + virtual void refreshIndexes() override; + + public: + ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection); + ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description = OUString(), + const OUString& SchemaName = OUString(), + const OUString& CatalogName = OUString() + ); + + void construct() override; // can throw any exception + + virtual sal_Int32 getCurrentLastPos() const override; + virtual bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) override; + virtual bool fetchRow(OValueRefRow& _rRow,const OSQLColumns& _rCols, bool bRetrieveData) override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual void SAL_CALL disposing() override; + + // css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); + // XAlterTable + virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void SAL_CALL alterColumnByIndex( sal_Int32 index, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + // XRename + virtual void SAL_CALL rename( const OUString& newName ) override; + + bool DropImpl(); + bool CreateImpl(); + + + virtual bool InsertRow(OValueRefVector& rRow, const css::uno::Reference< css::container::XIndexAccess>& _xCols) override; + virtual bool DeleteRow(const OSQLColumns& _rCols) override; + virtual bool UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const css::uno::Reference< css::container::XIndexAccess>& _xCols) override; + + virtual void addColumn(const css::uno::Reference< css::beans::XPropertySet>& descriptor) override; + virtual void dropColumn(sal_Int32 _nPos) override; + + static OUString getEntry(file::OConnection const * _pConnection,const OUString& _sURL ); + static bool Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, sdbcx::OCollection* _pIndexes ); + + virtual void refreshHeader() override; + + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() const override; + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DTables.hxx b/connectivity/source/inc/dbase/DTables.hxx new file mode 100644 index 000000000..fa1957236 --- /dev/null +++ b/connectivity/source/inc/dbase/DTables.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLES_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLES_HXX + +#include <file/FTables.hxx> + +namespace connectivity +{ + namespace dbase + { + typedef file::OTables ODbaseTables_BASE; + + class ODbaseTables : public ODbaseTables_BASE + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + ODbaseTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : ODbaseTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) + {} + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/dindexnode.hxx b/connectivity/source/inc/dbase/dindexnode.hxx new file mode 100644 index 000000000..70c7b832a --- /dev/null +++ b/connectivity/source/inc/dbase/dindexnode.hxx @@ -0,0 +1,314 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXNODE_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXNODE_HXX + +#include <file/fcode.hxx> +#include <connectivity/FValue.hxx> +#include <memory> + +#define NODE_NOTFOUND 0xFFFF +#define DINDEX_PAGE_SIZE 512 + +class SvStream; + +namespace connectivity +{ + namespace dbase + { + + class ONDXNode; + class ODbaseIndex; + + // Index Key + + typedef file::OOperand ONDXKey_BASE; + class ONDXKey : public ONDXKey_BASE + { + friend class ONDXNode; + sal_uInt32 nRecord; /* Record pointer */ + ORowSetValue xValue; /* Key values */ + + public: + ONDXKey(); + ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, sal_uInt32 nRec); + ONDXKey(const OUString& aStr, sal_uInt32 nRec); + ONDXKey(double aVal, sal_uInt32 nRec); + + inline ONDXKey(const ONDXKey& rKey); + + inline ONDXKey& operator= (const ONDXKey& rKey); + virtual void setValue(const ORowSetValue& _rVal) override; + + virtual const ORowSetValue& getValue() const override; + + sal_uInt32 GetRecord() const { return nRecord; } + void setRecord(sal_uInt32 _nRec) { nRecord = _nRec; } + void ResetRecord() { nRecord = 0; } + + bool operator == (const ONDXKey& rKey) const; + bool operator != (const ONDXKey& rKey) const; + bool operator < (const ONDXKey& rKey) const; + bool operator <= (const ONDXKey& rKey) const; + bool operator > (const ONDXKey& rKey) const; + + static bool IsText(sal_Int32 eType); + + private: + int Compare(const ONDXKey& rKey) const; + }; + + + class ONDXPage; + + // Index Page Pointer + // This is ref-count pointer class + class ONDXPagePtr + { + friend SvStream& WriteONDXPagePtr(SvStream &rStream, const ONDXPagePtr&); + friend SvStream& operator >> (SvStream &rStream, ONDXPagePtr&); + + ONDXPage* mpPage; + sal_uInt32 nPagePos; // Position in the index file + + public: + ONDXPagePtr(); + ONDXPagePtr(ONDXPagePtr&& rObj) noexcept; + ONDXPagePtr(ONDXPagePtr const & rRef); + ONDXPagePtr(ONDXPage* pRefPage); + ~ONDXPagePtr(); + void Clear(); + ONDXPagePtr& operator=(ONDXPagePtr const & rRef); + ONDXPagePtr& operator=(ONDXPagePtr && rRef); + bool Is() const { return mpPage != nullptr; } + + ONDXPage * operator ->() const { assert(mpPage != nullptr); return mpPage; } + operator ONDXPage *() const { return mpPage; } + + sal_uInt32 GetPagePos() const {return nPagePos;} + bool HasPage() const {return nPagePos != 0;} + }; + + // Index Page + // This is a ref-counted class, with re-cycling + class ONDXPage + { + friend class ODbaseIndex; + friend class ONDXPagePtr; + + friend SvStream& WriteONDXPage(SvStream &rStream, const ONDXPage&); + friend SvStream& operator >> (SvStream &rStream, ONDXPage&); + + // work around a clang 3.5 optimization bug: if the bNoDelete is *first* + // it mis-compiles "if (--nRefCount == 0)" and never deletes any object + unsigned int nRefCount : 31; + // the only reason this is not bool is because MSVC cannot handle mixed type bitfields + unsigned int bNoDelete : 1; + sal_uInt32 nPagePos; // Position in the index file + bool bModified : 1; + sal_uInt16 nCount; + + ONDXPagePtr aParent, // Parent page + aChild; // Pointer to the right child page + ODbaseIndex& rIndex; + std::unique_ptr<ONDXNode[]> + ppNodes; // Array of nodes + + public: + // Node operations + sal_uInt16 Count() const {return nCount;} + + bool Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft = 0); + bool Insert(sal_uInt16 nIndex, ONDXNode& rNode); + bool Append(ONDXNode& rNode); + void Delete(sal_uInt16); + void Remove(sal_uInt16); + void Release(bool bSave = true); + void ReleaseFull(); + + // Split and merge + ONDXNode Split(ONDXPage& rPage); + void Merge(sal_uInt16 nParentNodePos, const ONDXPagePtr& xPage); + + // Access operators + ONDXNode& operator[] (sal_uInt16 nPos); + const ONDXNode& operator[] (sal_uInt16 nPos) const; + + bool IsRoot() const; + bool IsLeaf() const; + bool IsModified() const; + bool HasParent() const; + + bool IsFull() const; + + sal_uInt32 GetPagePos() const {return nPagePos;} + ONDXPagePtr& GetChild(ODbaseIndex const * pIndex = nullptr); + + // Parent does not need to be reloaded + const ONDXPagePtr& GetParent() const; + ODbaseIndex& GetIndex() {return rIndex;} + const ODbaseIndex& GetIndex() const {return rIndex;} + + // Setting the child, via reference to retain the PagePos + void SetChild(ONDXPagePtr aCh); + void SetParent(ONDXPagePtr aPa); + + sal_uInt16 Search(const ONDXKey& rSearch); + sal_uInt16 Search(const ONDXPage* pPage); + void SearchAndReplace(const ONDXKey& rSearch, ONDXKey const & rReplace); + + protected: + ONDXPage(ODbaseIndex& rIndex, sal_uInt32 nPos, ONDXPage*); + ~ONDXPage(); + + void ReleaseRef(); + void QueryDelete(); + void AddNextRef() + { + assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" ); + ++nRefCount; + } + void AddFirstRef() + { + assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" ); + if( bNoDelete ) + bNoDelete = 0; + ++nRefCount; + } + + void SetModified(bool bMod) {bModified = bMod;} + void SetPagePos(sal_uInt32 nPage) {nPagePos = nPage;} + + bool Find(const ONDXKey&); // Descend recursively + sal_uInt16 FindPos(const ONDXKey& rKey) const; + +#if OSL_DEBUG_LEVEL > 1 + void PrintPage(); +#endif + }; + + SvStream& WriteONDXPagePtr(SvStream &rStream, const ONDXPagePtr&); + SvStream& operator >> (SvStream &rStream, ONDXPagePtr&); + + inline bool ONDXPage::IsRoot() const {return !aParent.Is();} + inline bool ONDXPage::IsLeaf() const {return !aChild.HasPage();} + inline bool ONDXPage::IsModified() const {return bModified;} + inline bool ONDXPage::HasParent() const {return aParent.Is();} + inline const ONDXPagePtr& ONDXPage::GetParent() const {return aParent;} + + inline void ONDXPage::SetParent(ONDXPagePtr aPa = ONDXPagePtr()) + { + aParent = aPa; + } + + inline void ONDXPage::SetChild(ONDXPagePtr aCh = ONDXPagePtr()) + { + aChild = aCh; + if (aChild.Is()) + aChild->SetParent(this); + } + SvStream& operator >> (SvStream &rStream, ONDXPage& rPage); + SvStream& WriteONDXPage(SvStream &rStream, const ONDXPage& rPage); + + + // Index Node + + class ONDXNode + { + friend class ONDXPage; + ONDXPagePtr aChild; /* Next page reference */ + ONDXKey aKey; + + public: + ONDXNode(){} + ONDXNode(const ONDXKey& rKey) + :aKey(rKey) {} + + // Does the node point to a page? + bool HasChild() const {return aChild.HasPage();} + // If an index is provided, we may be able to retrieve the page + ONDXPagePtr& GetChild(ODbaseIndex* pIndex = nullptr, ONDXPage* = nullptr); + + const ONDXKey& GetKey() const { return aKey;} + ONDXKey& GetKey() { return aKey;} + + // Setting the child, via reference to retain the PagePos + void SetChild(ONDXPagePtr aCh = ONDXPagePtr(), ONDXPage* = nullptr); + + void Write(SvStream &rStream, const ONDXPage& rPage) const; + void Read(SvStream &rStream, ODbaseIndex const &); + }; + + inline ONDXKey::ONDXKey(const ONDXKey& rKey) + : ONDXKey_BASE(rKey.getDBType()) + ,nRecord(rKey.nRecord) + ,xValue(rKey.xValue) + { + } + + inline ONDXKey& ONDXKey::operator=(const ONDXKey& rKey) + { + if(&rKey == this) + return *this; + + xValue = rKey.xValue; + nRecord = rKey.nRecord; + m_eDBType = rKey.getDBType(); + return *this; + } + + inline bool ONDXKey::operator == (const ONDXKey& rKey) const + { + if(&rKey == this) + return true; + return Compare(rKey) == 0; + } + inline bool ONDXKey::operator != (const ONDXKey& rKey) const + { + return !operator== (rKey); + } + inline bool ONDXKey::operator < (const ONDXKey& rKey) const + { + return Compare(rKey) < 0; + } + inline bool ONDXKey::operator > (const ONDXKey& rKey) const + { + return Compare(rKey) > 0; + } + inline bool ONDXKey::operator <= (const ONDXKey& rKey) const + { + return !operator > (rKey); + } + + inline void ONDXNode::SetChild(ONDXPagePtr aCh, ONDXPage* pParent) + { + aChild = aCh; + if (aChild.Is()) + aChild->SetParent(pParent); + } + + } + +} + + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXNODE_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |