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 #ifndef DBAUI_RTABLECONNECTIONDATA_HXX
24 #define DBAUI_RTABLECONNECTIONDATA_HXX
25 
26 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
27 #include "TableConnectionData.hxx"
28 #endif
29 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #endif
32 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #endif
35 #ifndef DBAUI_ENUMTYPES_HXX
36 #include "QEnumTypes.hxx"
37 #endif
38 
39 namespace dbaui
40 {
41 	const sal_uInt16 CARDINAL_UNDEFINED	= 0x0000;
42 	const sal_uInt16 CARDINAL_ONE_MANY	= 0x0001;
43 	const sal_uInt16 CARDINAL_MANY_ONE	= 0x0002;
44 	const sal_uInt16 CARDINAL_ONE_ONE	= 0x0004;
45 
46 	class OConnectionLineData;
47 	//==================================================================
48 	class ORelationTableConnectionData :	public OTableConnectionData
49 	{
50         friend bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs);
operator !=(const ORelationTableConnectionData & lhs,const ORelationTableConnectionData & rhs)51 		friend bool operator!=(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs) { return !(lhs == rhs); }
52 
53 		::osl::Mutex	m_aMutex;
54 
55 		// @see com.sun.star.sdbc.KeyRule
56 		sal_Int32 m_nUpdateRules;
57 		sal_Int32 m_nDeleteRules;
58 		sal_Int32 m_nCardinality;
59 
60 		sal_Bool checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& i_xTable,EConnectionSide _eEConnectionSide) const;
IsSourcePrimKey() const61 		sal_Bool IsSourcePrimKey()	const { return checkPrimaryKey(getReferencingTable()->getTable(),JTCS_FROM);	}
IsDestPrimKey() const62 		sal_Bool IsDestPrimKey()	const { return checkPrimaryKey(getReferencedTable()->getTable(),JTCS_TO);		}
63 
64 	protected:
65 		virtual OConnectionLineDataRef CreateLineDataObj();
66 		virtual OConnectionLineDataRef CreateLineDataObj( const OConnectionLineData& rConnLineData );
67 
68 		ORelationTableConnectionData& operator=( const ORelationTableConnectionData& rConnData );
69 	public:
70 		ORelationTableConnectionData();
71 		ORelationTableConnectionData( const ORelationTableConnectionData& rConnData );
72 		ORelationTableConnectionData( const TTableWindowData::value_type& _pReferencingTable,
73                                       const TTableWindowData::value_type& _pReferencedTable,
74 									  const ::rtl::OUString& rConnName = ::rtl::OUString() );
75 		virtual ~ORelationTableConnectionData();
76 
77 		virtual void CopyFrom(const OTableConnectionData& rSource);
NewInstance() const78 		virtual OTableConnectionData* NewInstance() const { return new ORelationTableConnectionData(); }
79 
80 		/** Update create a new relation
81 
82 			@return true if successful
83 		*/
84 		virtual sal_Bool Update();
85 
86 
87 		void		SetCardinality();
SetUpdateRules(sal_Int32 nAttr)88 		inline void	SetUpdateRules( sal_Int32 nAttr ){ m_nUpdateRules = nAttr; }
SetDeleteRules(sal_Int32 nAttr)89 		inline void	SetDeleteRules( sal_Int32 nAttr ){ m_nDeleteRules = nAttr; }
90 
GetUpdateRules() const91 		inline sal_Int32	GetUpdateRules() const { return m_nUpdateRules; }
GetDeleteRules() const92 		inline sal_Int32	GetDeleteRules() const { return m_nDeleteRules; }
GetCardinality() const93 		inline sal_Int32	GetCardinality() const { return m_nCardinality; }
94 
95 		sal_Bool		IsConnectionPossible();
96 		void		ChangeOrientation();
97 		sal_Bool		DropRelation();
98 	};
99 }
100 
101 #endif // DBAUI_RTABLECONNECTIONDATA_HXX
102 
103 
104 
105