1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef DBUI_TABLECONTROLLER_HXX 28*cdf0e10cSrcweir #define DBUI_TABLECONTROLLER_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "singledoccontroller.hxx" 31*cdf0e10cSrcweir #include "moduledbu.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp> 36*cdf0e10cSrcweir #include "TypeInfo.hxx" 37*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XKeysSupplier.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir class FixedText; 42*cdf0e10cSrcweir namespace dbaui 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir class OTableRow; 45*cdf0e10cSrcweir class OFieldDescription; 46*cdf0e10cSrcweir typedef OSingleDocumentController OTableController_BASE; 47*cdf0e10cSrcweir class OTableController : public OTableController_BASE 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir private: 50*cdf0e10cSrcweir OModuleClient m_aModuleClient; 51*cdf0e10cSrcweir ::std::vector< ::boost::shared_ptr<OTableRow> > m_vRowList; 52*cdf0e10cSrcweir OTypeInfoMap m_aTypeInfo; 53*cdf0e10cSrcweir ::std::vector<OTypeInfoMap::iterator> m_aTypeInfoIndex; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir ::rtl::OUString m_sCatalogName; // catalog for update data 58*cdf0e10cSrcweir ::rtl::OUString m_sSchemaName; // schema for update data 59*cdf0e10cSrcweir ::rtl::OUString m_sName; // table for update data 60*cdf0e10cSrcweir ::rtl::OUString m_sAutoIncrementValue; // the autoincrement value set in the datasource 61*cdf0e10cSrcweir String m_sTypeNames; // these type names are the ones out of the resource file 62*cdf0e10cSrcweir TOTypeInfoSP m_pTypeInfo; // fall back when type is unkown because database driver has a failure 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir sal_Bool m_bAllowAutoIncrementValue; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property 65*cdf0e10cSrcweir sal_Bool m_bNew : 1; // is true when we create a new table 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir void reSyncRows(); 69*cdf0e10cSrcweir void assignTable(); // set the table if a name is given 70*cdf0e10cSrcweir void loadData(); 71*cdf0e10cSrcweir sal_Bool checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException); // check if we have double column names 72*cdf0e10cSrcweir String createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxTables,const String& _rDefault); 73*cdf0e10cSrcweir void appendColumns(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns = sal_False); 74*cdf0e10cSrcweir void appendPrimaryKey(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XKeysSupplier>& _rxSup,sal_Bool _bNew); 75*cdf0e10cSrcweir void alterColumns(); 76*cdf0e10cSrcweir void dropPrimaryKey(); 77*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getKeyColumns() const; 78*cdf0e10cSrcweir ::rtl::OUString createUniqueName(const ::rtl::OUString& _rName); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir void reload(); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // all the features which should be handled by this class 83*cdf0e10cSrcweir virtual void describeSupportedFeatures(); 84*cdf0e10cSrcweir // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot. 85*cdf0e10cSrcweir virtual FeatureState GetState(sal_uInt16 nId) const; 86*cdf0e10cSrcweir // execute a feature 87*cdf0e10cSrcweir virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir virtual void losingConnection( ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir virtual ::rtl::OUString getPrivateTitle( ) const; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir void doEditIndexes(); 94*cdf0e10cSrcweir sal_Bool doSaveDoc(sal_Bool _bSaveAs); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir virtual ~OTableController(); 97*cdf0e10cSrcweir public: 98*cdf0e10cSrcweir OTableController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getTable() { return m_xTable;} 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir sal_Bool isAddAllowed() const; 103*cdf0e10cSrcweir sal_Bool isDropAllowed() const; 104*cdf0e10cSrcweir sal_Bool isAlterAllowed() const; 105*cdf0e10cSrcweir bool isAutoIncrementPrimaryKey() const; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir inline sal_Bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; } 108*cdf0e10cSrcweir inline const ::rtl::OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir virtual void impl_onModifyChanged(); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir inline ::std::vector< ::boost::shared_ptr<OTableRow> >* getRows() { return &m_vRowList; } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir /// returns the postion of the the first empty row 115*cdf0e10cSrcweir sal_Int32 getFirstEmptyRowPosition(); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir inline const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo; } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir inline TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) const { return m_aTypeInfoIndex[_nPos]->second; } 120*cdf0e10cSrcweir TOTypeInfoSP getTypeInfoByType(sal_Int32 _nDataType) const; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir inline TOTypeInfoSP getTypeInfoFallBack() const { return m_pTypeInfo; } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir virtual sal_Bool Construct(Window* pParent); 125*cdf0e10cSrcweir // XEventListener 126*cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // ::com::sun::star::frame::XController 129*cdf0e10cSrcweir virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ::com::sun::star::lang::XComponent 132*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // XServiceInfo 135*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); 136*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); 137*cdf0e10cSrcweir // need by registration 138*cdf0e10cSrcweir static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException ); 139*cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException ); 140*cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 141*cdf0e10cSrcweir SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // 144*cdf0e10cSrcweir virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn); 145*cdf0e10cSrcweir virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir protected: 148*cdf0e10cSrcweir void startTableListening(); 149*cdf0e10cSrcweir void stopTableListening(); 150*cdf0e10cSrcweir virtual void impl_initialize(); 151*cdf0e10cSrcweir }; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir #endif // DBUI_TABLECONTROLLER_HXX 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir 156