LibreOffice Module connectivity (master) 1
AKeys.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <ado/AKeys.hxx>
21#include <ado/AKey.hxx>
22#include <com/sun/star/sdbc/XRow.hpp>
23#include <com/sun/star/sdbc/XResultSet.hpp>
24#include <com/sun/star/sdbcx/KeyType.hpp>
25#include <com/sun/star/sdbc/KeyRule.hpp>
26#include <ado/AConnection.hxx>
28#include <comphelper/types.hxx>
29#include <ado/Awrapado.hxx>
31#include <strings.hrc>
32
33using namespace ::comphelper;
34using namespace connectivity;
35using namespace connectivity::ado;
36using namespace com::sun::star::uno;
37using namespace com::sun::star::lang;
38using namespace com::sun::star::beans;
39using namespace com::sun::star::sdbc;
40using namespace com::sun::star::sdbcx;
41using namespace com::sun::star::container;
42
43sdbcx::ObjectType OKeys::createObject(const OUString& _rName)
44{
46}
47
49{
51}
52
54{
56}
57
58// XAppend
60{
61 OAdoKey* pKey = dynamic_cast<OAdoKey*>( descriptor.get() );
62 if ( pKey == nullptr)
63 m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
64
65 // To pass as column parameter to Key's Append method
66 OLEVariant vOptional;
67 vOptional.setNoArg();
68
70
71 WpADOKey aKey = pKey->getImpl();
72 OUString sName = aKey.get_Name();
73 if(!sName.getLength())
74 aKey.put_Name(u"PrimaryKey");
75
76 ADOKeys* pKeys = m_aCollection;
77 if ( FAILED(pKeys->Append(OLEVariant(static_cast<ADOKey*>(aKey)),
78 adKeyPrimary, // must be every time adKeyPrimary
79 vOptional)) )
80 {
81 ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
82 // just make sure that an SQLExceptionis thrown here
83 m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
84 }
85
86 return new OAdoKey(isCaseSensitive(),m_pConnection,pKey->getImpl());
87}
88
89// XDrop
90void OKeys::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
91{
92 if(!m_aCollection.Delete(OLEVariant(_sElementName).getString()))
93 ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
94}
95
96
97/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
void throwGenericSQLException(TranslateId pErrorResourceId, const css::uno::Reference< css::uno::XInterface > &_xContext)
Definition: TConnection.cxx:74
static void ThrowException(ADOConnection *_pAdoCon, const css::uno::Reference< css::uno::XInterface > &_xInterface)
Definition: ADriver.cxx:207
WpADOKey getImpl() const
Definition: AKey.hxx:44
static KeyTypeEnum Map2KeyRule(sal_Int32 _eNum)
WpADOConnection & getConnection()
WpADOKeys m_aCollection
Definition: AKeys.hxx:30
OConnection * m_pConnection
Definition: AKeys.hxx:31
virtual void impl_refresh() override
Definition: AKeys.cxx:48
virtual sdbcx::ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
appends an object described by a descriptor, under a given name
Definition: AKeys.cxx:59
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: AKeys.cxx:90
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: AKeys.cxx:53
void put_Name(std::u16string_view _rName)
Definition: Awrapado.cxx:1100
OUString get_Name() const
Definition: Awrapado.cxx:1092
bool Delete(const OUString &sName)
Definition: Aolewrap.hxx:165
WrapT GetItem(sal_Int32 index) const
Definition: Aolewrap.hxx:102
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
float u
OUString sName
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
#define PROPERTY_ID_TYPE
Definition: propertyids.hxx:51