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_TABLEHELPER_HXX 25 #define CONNECTIVITY_TABLEHELPER_HXX 26 27 #include "connectivity/dbtoolsdllapi.hxx" 28 #include "connectivity/sdbcx/VTable.hxx" 29 #include "connectivity/sdbcx/VKey.hxx" 30 #include "connectivity/StdTypeDefs.hxx" 31 #include <comphelper/stl_types.hxx> 32 #include <com/sun/star/sdb/tools/XTableRename.hpp> 33 #include <com/sun/star/sdb/tools/XTableAlteration.hpp> 34 #include <com/sun/star/sdb/tools/XKeyAlteration.hpp> 35 #include <com/sun/star/sdb/tools/XIndexAlteration.hpp> 36 37 namespace connectivity 38 { 39 typedef sal_Int32 OrdinalPosition; 40 struct ColumnDesc 41 { 42 ::rtl::OUString sName; 43 ::rtl::OUString aField6; 44 ::rtl::OUString sField12; // REMARKS 45 ::rtl::OUString sField13; 46 sal_Int32 nField5 47 , nField7 48 , nField9 49 , nField11; 50 51 OrdinalPosition nOrdinalPosition; 52 ColumnDescconnectivity::ColumnDesc53 ColumnDesc() {} ColumnDescconnectivity::ColumnDesc54 ColumnDesc( const ::rtl::OUString& _rName 55 , sal_Int32 _nField5 56 , const ::rtl::OUString& _aField6 57 , sal_Int32 _nField7 58 , sal_Int32 _nField9 59 , sal_Int32 _nField11 60 , const ::rtl::OUString& _sField12 61 , const ::rtl::OUString& _sField13 62 ,OrdinalPosition _nPosition ) 63 :sName( _rName ) 64 ,aField6(_aField6) 65 ,sField12(_sField12) 66 ,sField13(_sField13) 67 ,nField5(_nField5) 68 ,nField7(_nField7) 69 ,nField9(_nField9) 70 ,nField11(_nField11) 71 ,nOrdinalPosition( _nPosition ) 72 { 73 } 74 }; 75 typedef connectivity::sdbcx::OTable OTable_TYPEDEF; 76 77 OOO_DLLPUBLIC_DBTOOLS ::rtl::OUString getTypeString(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xColProp); 78 79 DECLARE_STL_USTRINGACCESS_MAP( sdbcx::TKeyProperties , TKeyMap); 80 81 struct OTableHelperImpl; 82 83 class OOO_DLLPUBLIC_DBTOOLS OTableHelper : public OTable_TYPEDEF 84 { 85 ::std::auto_ptr<OTableHelperImpl> m_pImpl; 86 87 void refreshPrimaryKeys(TStringVector& _rKeys); 88 void refreshForgeinKeys(TStringVector& _rKeys); 89 90 protected: 91 /** creates the column collection for the table 92 @param _rNames 93 The column names. 94 */ 95 virtual sdbcx::OCollection* createColumns(const TStringVector& _rNames) = 0; 96 97 /** creates the key collection for the table 98 @param _rNames 99 The key names. 100 */ 101 virtual sdbcx::OCollection* createKeys(const TStringVector& _rNames) = 0; 102 103 /** creates the index collection for the table 104 @param _rNames 105 The index names. 106 */ 107 virtual sdbcx::OCollection* createIndexes(const TStringVector& _rNames) = 0; 108 109 /** this function is called upon disposing the component 110 */ 111 virtual void SAL_CALL disposing(); 112 113 /** The default returns "RENAME TABLE " or "RENAME VIEW " depending on the type. 114 * 115 * \return The start of the rename statement. 116 */ 117 virtual ::rtl::OUString getRenameStart() const; 118 119 virtual ~OTableHelper(); 120 121 public: 122 virtual void refreshColumns(); 123 virtual void refreshKeys(); 124 virtual void refreshIndexes(); 125 126 const ColumnDesc* getColumnDescription(const ::rtl::OUString& _sName) const; 127 128 public: 129 OTableHelper( sdbcx::OCollection* _pTables, 130 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, 131 sal_Bool _bCase); 132 OTableHelper( sdbcx::OCollection* _pTables, 133 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, 134 sal_Bool _bCase, 135 const ::rtl::OUString& _Name, 136 const ::rtl::OUString& _Type, 137 const ::rtl::OUString& _Description = ::rtl::OUString(), 138 const ::rtl::OUString& _SchemaName = ::rtl::OUString(), 139 const ::rtl::OUString& _CatalogName = ::rtl::OUString() 140 ); 141 142 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> getMetaData() const; 143 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection() const; 144 145 virtual void SAL_CALL acquire() throw(); 146 virtual void SAL_CALL release() throw(); 147 148 // XRename 149 virtual void SAL_CALL rename( const ::rtl::OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 150 151 // XAlterTable 152 virtual void SAL_CALL alterColumnByIndex( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 153 // XNamed 154 virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); 155 156 // helper method to get key properties 157 sdbcx::TKeyProperties getKeyProperties(const ::rtl::OUString& _sName) const; 158 void addKey(const ::rtl::OUString& _sName,const sdbcx::TKeyProperties& _aKeyProperties); 159 160 virtual ::rtl::OUString getTypeCreatePattern() const; 161 162 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XTableRename> getRenameService() const; 163 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XTableAlteration> getAlterService() const; 164 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XKeyAlteration> getKeyService() const; 165 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XIndexAlteration> getIndexService() const; 166 }; 167 } 168 #endif // CONNECTIVITY_TABLEHELPER_HXX 169 170