1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CONNECTIVITY_FILE_TABLE_HXX_
25 #define _CONNECTIVITY_FILE_TABLE_HXX_
26 
27 #include "connectivity/sdbcx/VTable.hxx"
28 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
29 #include <com/sun/star/lang/XUnoTunnel.hpp>
30 #ifndef _CONNECTIVITY_FILE_BCONNECTION_HXX_
31 #include "file/FConnection.hxx"
32 #endif
33 #include "file/filedllapi.hxx"
34 #include <tools/stream.hxx>
35 #include "connectivity/FValue.hxx"
36 #include "TResultSetHelper.hxx"
37 
38 namespace connectivity
39 {
40 	namespace file
41 	{
42 		typedef connectivity::sdbcx::OTable OTable_TYPEDEF;
43 
44 		class OOO_DLLPUBLIC_FILE OFileTable :	public OTable_TYPEDEF
45 		{
46 		protected:
47 			OConnection*										m_pConnection;
48 			SvStream*											m_pFileStream;
49 			::vos::ORef<OSQLColumns>							m_aColumns;
50 			sal_Int32											m_nFilePos;					// aktuelle IResultSetHelper::Movement
51 			sal_uInt8*											m_pBuffer;
52 			sal_uInt16											m_nBufferSize;	// Groesse des ReadBuffer, wenn pBuffer != NULL
53 			sal_Bool											m_bWriteable;	// svstream cann't say if we are writeable
54 																				// so we have to
55 
56 			virtual void FileClose();
57 			virtual ~OFileTable( );
58 		public:
59 			virtual void refreshColumns();
60 			virtual void refreshKeys();
61 			virtual void refreshIndexes();
62 		public:
63 			OFileTable( sdbcx::OCollection* _pTables,OConnection* _pConnection);
64 			OFileTable(	sdbcx::OCollection* _pTables,OConnection* _pConnection,
65 					const ::rtl::OUString& _Name,
66 					const ::rtl::OUString& _Type,
67 					const ::rtl::OUString& _Description = ::rtl::OUString(),
68 					const ::rtl::OUString& _SchemaName = ::rtl::OUString(),
69 					const ::rtl::OUString& _CatalogName = ::rtl::OUString()
70 				);
71 
72 			//XInterface
73 			virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
74 			virtual void SAL_CALL acquire() throw();
75             virtual void SAL_CALL release() throw();
76 			// ::cppu::OComponentHelper
77 			virtual void SAL_CALL disposing(void);
78 
getConnection() const79 			OConnection* getConnection() const { return m_pConnection;}
getCurrentLastPos() const80 			virtual sal_Int32 getCurrentLastPos() const {return -1;}
81 
82 			virtual sal_Bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) = 0;
83 			virtual sal_Bool fetchRow(OValueRefRow& _rRow,const OSQLColumns& _rCols, sal_Bool _bUseTableDefs,sal_Bool bRetrieveData) = 0;
84 
getTableColumns() const85 			::vos::ORef<OSQLColumns> getTableColumns() const {return m_aColumns;}
86 			virtual sal_Bool InsertRow(OValueRefVector& rRow, sal_Bool bFlush,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols);
87 			virtual sal_Bool DeleteRow(const OSQLColumns& _rCols);
88 			virtual sal_Bool UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols);
89 			virtual void addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& descriptor);
90 			virtual void dropColumn(sal_Int32 _nPos);
91 			// refresh the header of file based tables to see changes done by someone
92 			virtual void refreshHeader();
93 
getName()94 			::rtl::OUString SAL_CALL getName() throw() { return m_Name; }
95 
getSchema()96 			::rtl::OUString getSchema() { return m_SchemaName; }
isReadOnly() const97 			sal_Bool isReadOnly() const { return !m_bWriteable; }
98 				// m_pFileStream && !m_pFileStream->IsWritable(); }
99 			// com::sun::star::lang::XUnoTunnel
100 			virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
101 			static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
102 
103 
getFilePos() const104 			sal_Int32 getFilePos() const { return m_nFilePos; }
105 
106 		public:
107 			// helper
108 
109 			// creates a stream using ::utl::UcbStreamHelper::CreateStream, but the error is simplified
110 			// (NULL or non-NULL is returned)
111 			static SvStream* createStream_simpleError( const String& _rFileName, StreamMode _eOpenMode);
112 		};
113 	}
114 }
115 #endif // _CONNECTIVITY_FILE_TABLE_HXX_
116 
117