Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / odk / examples / DevelopersGuide / Database / DriverSkeleton / SConnection.hxx
blobdee2dc390181668457cf734c56e2bef04200058f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 #ifndef INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_SCONNECTION_HXX
37 #define INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_SCONNECTION_HXX
39 #include <com/sun/star/sdbc/SQLWarning.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include "OSubComponent.hxx"
42 #include "OTypeInfo.hxx"
43 #include <com/sun/star/lang/DisposedException.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/lang/XUnoTunnel.hpp>
46 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
47 #include <com/sun/star/sdbc/XConnection.hpp>
48 #include <cppuhelper/compbase3.hxx>
49 #include <cppuhelper/weakref.hxx>
51 #include <map>
53 namespace connectivity
55 namespace skeleton
58 typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XConnection,
59 ::com::sun::star::sdbc::XWarningsSupplier,
60 ::com::sun::star::lang::XServiceInfo
61 > OMetaConnection_BASE;
63 class OStatement_Base;
64 class SkeletonDriver;
65 class ODatabaseMetaData;
67 typedef OMetaConnection_BASE OConnection_BASE; // implements basics and text encoding
68 typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector;
69 typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
71 class OConnection : public OBase_Mutex,
72 public OConnection_BASE,
73 public connectivity::skeleton::OSubComponent<OConnection, OConnection_BASE>
75 friend class connectivity::skeleton::OSubComponent<OConnection, OConnection_BASE>;
77 protected:
79 rtl_TextEncoding m_nTextEncoding; // the encoding which is used for all text conversions
81 // Data attributes
83 TTypeInfoVector m_aTypeInfo; // vector containing an entry
84 // for each row returned by
85 // DatabaseMetaData.getTypeInfo.
86 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
88 OWeakRefArray m_aStatements; // vector containing a list
89 // of all the Statement objects
90 // for this Connection
92 ::com::sun::star::sdbc::SQLWarning m_aLastWarning; // Last SQLWarning generated by
93 // an operation
94 ::rtl::OUString m_aURL; // URL of connection
95 ::rtl::OUString m_sUser; // the user name
96 SkeletonDriver* m_pDriver; // Pointer to the owning
97 // driver object
99 sal_Bool m_bClosed;
100 sal_Bool m_bUseCatalog; // should we use the catalog on filebased databases
101 sal_Bool m_bUseOldDateFormat;
104 void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException);
106 public:
107 virtual void construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException);
109 OConnection(SkeletonDriver* _pDriver);
110 virtual ~OConnection();
112 void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);
114 // OComponentHelper
115 virtual void SAL_CALL disposing();
116 // XInterface
117 virtual void SAL_CALL release() throw();
119 // XServiceInfo
120 DECLARE_SERVICE_INFO();
121 // XConnection
122 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
123 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
124 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
125 virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
126 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
127 virtual sal_Bool SAL_CALL getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128 virtual void SAL_CALL commit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
129 virtual void SAL_CALL rollback( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
130 virtual sal_Bool SAL_CALL isClosed( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
131 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
132 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133 virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134 virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135 virtual ::rtl::OUString SAL_CALL getCatalog( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
136 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
138 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
139 virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
140 // XCloseable
141 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
142 // XWarningsSupplier
143 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
144 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
147 // should we use the catalog on filebased databases
148 inline sal_Bool isCatalogUsed() const { return m_bUseCatalog; }
149 inline ::rtl::OUString getUserName() const { return m_sUser; }
150 inline SkeletonDriver* getDriver() const { return m_pDriver;}
151 inline rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; }
156 #endif // INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_SCONNECTION_HXX
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */