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/AViews.hxx>
21 #include <ado/AView.hxx>
22 #include <ado/ATables.hxx>
23 #include <ado/ACatalog.hxx>
24 #include <ado/AConnection.hxx>
25 #include <ado/Awrapado.hxx>
26 #include <TConnection.hxx>
27 #include <comphelper/servicehelper.hxx>
28 #include <comphelper/types.hxx>
29 #include <connectivity/dbexception.hxx>
30 #include <rtl/ref.hxx>
31 #include <strings.hrc>
32
33 using namespace ::comphelper;
34
35 using namespace connectivity;
36 using namespace connectivity::ado;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::beans;
40 using namespace com::sun::star::sdbc;
41 using namespace com::sun::star::container;
42
createObject(const OUString & _rName)43 sdbcx::ObjectType OViews::createObject(const OUString& _rName)
44 {
45 rtl::Reference<OAdoView> pView = new OAdoView(isCaseSensitive(),m_aCollection.GetItem(_rName));
46 pView->setNew(false);
47 return pView;
48 }
49
impl_refresh()50 void OViews::impl_refresh( )
51 {
52 m_aCollection.Refresh();
53 }
54
createDescriptor()55 Reference< XPropertySet > OViews::createDescriptor()
56 {
57 return new OAdoView(isCaseSensitive());
58 }
59
60
61 // XAppend
appendObject(const OUString & _rForName,const Reference<XPropertySet> & descriptor)62 sdbcx::ObjectType OViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
63 {
64 OAdoView* pView = getUnoTunnelImplementation<OAdoView>( descriptor );
65 if ( pView == nullptr )
66 m_pCatalog->getConnection()->throwGenericSQLException( STR_INVALID_VIEW_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
67
68 WpADOCommand aCommand;
69 aCommand.Create();
70 if ( !aCommand.IsValid() )
71 m_pCatalog->getConnection()->throwGenericSQLException( STR_VIEW_NO_COMMAND_ERROR,static_cast<XTypeProvider*>(this) );
72
73 OUString sName( _rForName );
74 aCommand.put_Name(sName);
75 aCommand.put_CommandText(getString(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND))));
76 ADOViews* pViews = m_aCollection;
77 if(FAILED(pViews->Append(OLEString(sName).asBSTR(),aCommand)))
78 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
79
80 OTables* pTables = static_cast<OTables*>(static_cast<OCatalog&>(m_rParent).getPrivateTables());
81 if ( pTables )
82 pTables->appendNew(sName);
83
84 return createObject( _rForName );
85 }
86
87 // XDrop
dropObject(sal_Int32,const OUString & _sElementName)88 void OViews::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
89 {
90 if(!m_aCollection.Delete(_sElementName))
91 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
92 }
93
94
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
96