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_ADABAS_BDRIVER_HXX_ 25 #define _CONNECTIVITY_ADABAS_BDRIVER_HXX_ 26 27 #include <com/sun/star/sdbc/XDriver.hpp> 28 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> 29 #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 30 #include <com/sun/star/sdbcx/XCreateCatalog.hpp> 31 #include <com/sun/star/sdbcx/XDropCatalog.hpp> 32 33 #include <com/sun/star/lang/XEventListener.hpp> 34 35 //#include <unotools/tempfile.hxx> 36 #include <cppuhelper/implbase4.hxx> 37 #include "odbc/OFunctiondefs.hxx" 38 #include "odbc/ODriver.hxx" 39 40 namespace connectivity 41 { 42 namespace adabas 43 { 44 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ); 45 46 typedef ::cppu::ImplHelper4< ::com::sun::star::sdbcx::XCreateCatalog, 47 ::com::sun::star::sdbcx::XDataDefinitionSupplier, 48 ::com::sun::star::lang::XEventListener, 49 ::com::sun::star::sdbcx::XDropCatalog> ODriver_BASE2; 50 51 typedef odbc::ODBCDriver ODriver_BASE; 52 53 class ODriver : public ODriver_BASE, 54 public ODriver_BASE2 55 { 56 typedef struct DatabaseStruct 57 { 58 ::rtl::OUString sControlUser; 59 ::rtl::OUString sControlPassword; 60 ::rtl::OUString sSysUser; 61 ::rtl::OUString sSysPassword; 62 ::rtl::OUString sDomainPassword; 63 ::rtl::OUString sCacheSize; 64 ::rtl::OUString sBackupFile; 65 ::rtl::OUString sDataDevName; 66 ::rtl::OUString sSysDevSpace; 67 ::rtl::OUString sTransLogName; 68 ::rtl::OUString sDBName; 69 sal_Int32 nDataIncrement; // which size the database should grow 70 sal_Int32 nDataSize; 71 sal_Int32 nLogSize; 72 sal_Bool bShutDown; 73 sal_Bool bRestoreDatabase; 74 DatabaseStructconnectivity::adabas::ODriver::DatabaseStruct75 DatabaseStruct() : nDataIncrement(0),nDataSize(0),nLogSize(0),bShutDown(sal_False),bRestoreDatabase(sal_False){ } 76 } TDatabaseStruct; 77 78 DECLARE_STL_USTRINGACCESS_MAP(TDatabaseStruct,TDatabaseMap); 79 TDatabaseMap m_aDatabaseMap; // contains all adabas databases with their flag to shut down or not 80 81 // environment vars 82 ::rtl::OUString m_sDbWork; 83 ::rtl::OUString m_sDbConfig; 84 ::rtl::OUString m_sDbRoot; 85 ::rtl::OUString m_sDbWorkURL; 86 ::rtl::OUString m_sDbConfigURL; 87 ::rtl::OUString m_sDbRootURL; 88 ::rtl::OUString m_sDbRunDir; 89 ::rtl::OUString m_sDelimit; 90 91 void checkAndInsertNewDevSpace(const ::rtl::OUString& _rDBName,const TDatabaseStruct& _rDBInfo); 92 void checkAndRestart(const ::rtl::OUString& _rDBName,const TDatabaseStruct& _rDbInfo); 93 void X_CONS(const ::rtl::OUString& _DBNAME,const ::rtl::OString& _ACTION,const ::rtl::OUString& _FILENAME); 94 sal_Bool getDBName(const ::rtl::OUString& _rName,::rtl::OUString& _rDBName) const; 95 ::rtl::OUString getDatabaseInitFile( const TDatabaseStruct& _aInfo); 96 ::rtl::OUString generateInitFile() const; 97 void fillEnvironmentVariables(); 98 void fillInfo(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info, TDatabaseStruct& _rDBInfo /*out*/); 99 void LoadBatch(const ::rtl::OUString& _rDBNAME, 100 const ::rtl::OUString& _rUSR, 101 const ::rtl::OUString& _rPWD, 102 const ::rtl::OUString& _rBatch); 103 void XUTIL(const ::rtl::OUString& _rParam, 104 const ::rtl::OUString& _DBNAME, 105 const ::rtl::OUString& _USRNAME, 106 const ::rtl::OUString& _USRPWD); 107 int X_STOP(const ::rtl::OUString& _DBNAME); 108 int X_START(const ::rtl::OUString& _DBNAME); 109 void createDb(const TDatabaseStruct& _aInfo); 110 void clearDatabase(const ::rtl::OUString& _rDBName); 111 int X_PARAM(const ::rtl::OUString& _DBNAME, 112 const ::rtl::OUString& _USR, 113 const ::rtl::OUString& _PWD, 114 const ::rtl::OUString& _CMD); 115 sal_Int32 CreateFiles(const TDatabaseStruct& _aInfo); 116 sal_Bool CreateFile(const ::rtl::OUString &_FileName, 117 sal_Int32 _nSize); 118 void PutParam(const ::rtl::OUString& rDBNAME, 119 const ::rtl::OUString& rWhat, 120 const ::rtl::OUString& rHow); 121 void createNeededDirs( const ::rtl::OUString& _rDBName); 122 sal_Bool isKernelVersion(const char* _pVersion); 123 sal_Bool isVersion( const ::rtl::OUString& _rDBName, 124 const char* _pVersion); 125 126 void convertOldVersion( const ::rtl::OUString& _rDBName, 127 const TDatabaseStruct& _rDbInfo); 128 129 void installSystemTables( const TDatabaseStruct& _aInfo); 130 131 protected: 132 virtual SQLHANDLE EnvironmentHandle(::rtl::OUString &_rPath); 133 virtual ~ODriver(); 134 public: 135 explicit ODriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 136 137 // XInterface 138 static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); 139 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); 140 private: 141 DECLARE_SERVICE_INFO(); 142 143 virtual oslGenericFunction getOdbcFunction(sal_Int32 _nIndex) const; 144 // OComponentHelper 145 virtual void SAL_CALL disposing(void); 146 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 147 virtual void SAL_CALL acquire() throw(); 148 virtual void SAL_CALL release() throw(); 149 150 // XDriver 151 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connect( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 152 virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 153 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 154 virtual sal_Int32 SAL_CALL getMajorVersion( ) throw(::com::sun::star::uno::RuntimeException); 155 virtual sal_Int32 SAL_CALL getMinorVersion( ) throw(::com::sun::star::uno::RuntimeException); 156 157 // XDataDefinitionSupplier 158 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 159 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 160 161 // XCreateCatalog 162 virtual void SAL_CALL createCatalog( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 163 // XDropCatalog 164 virtual void SAL_CALL dropCatalog( const ::rtl::OUString& catalogName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 165 // XEventListener 166 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 167 }; 168 } 169 170 } 171 #endif //_CONNECTIVITY_ADABAS_BDRIVER_HXX_ 172 173 174