1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BUsers.cxx,v $
10 * $Revision: 1.19.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "adabas/BUsers.hxx"
34 #include "adabas/BUser.hxx"
35 #include "adabas/BTable.hxx"
36 #include <com/sun/star/sdbc/XRow.hpp>
37 #include <com/sun/star/sdbc/XResultSet.hpp>
38 #include "connectivity/sdbcx/IRefreshable.hxx"
39 #include <comphelper/types.hxx>
40 #include "connectivity/dbexception.hxx"
41 #include "connectivity/dbtools.hxx"
42 #include "resource/adabas_res.hrc"
44 using namespace ::comphelper
;
45 using namespace connectivity
;
46 using namespace connectivity::adabas
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::beans
;
49 // using namespace ::com::sun::star::sdbcx;
50 using namespace ::com::sun::star::sdbc
;
51 using namespace ::com::sun::star::container
;
52 using namespace ::com::sun::star::lang
;
53 typedef connectivity::sdbcx::OCollection OCollection_TYPE
;
55 sdbcx::ObjectType
OUsers::createObject(const ::rtl::OUString
& _rName
)
57 return new OAdabasUser(m_pConnection
,_rName
);
59 // -------------------------------------------------------------------------
60 void OUsers::impl_refresh() throw(RuntimeException
)
62 m_pParent
->refreshUsers();
64 // -------------------------------------------------------------------------
65 Reference
< XPropertySet
> OUsers::createDescriptor()
67 OUserExtend
* pNew
= new OUserExtend(m_pConnection
);
70 // -------------------------------------------------------------------------
72 sdbcx::ObjectType
OUsers::appendObject( const ::rtl::OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
74 ::rtl::OUString aSql
= ::rtl::OUString::createFromAscii("CREATE USER ");
75 ::rtl::OUString aQuote
= m_pConnection
->getMetaData()->getIdentifierQuoteString( );
77 ::rtl::OUString
sUserName( _rForName
);
78 sUserName
= sUserName
.toAsciiUpperCase();
79 descriptor
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
),makeAny(sUserName
));
80 aSql
+= ::dbtools::quoteName(aQuote
,sUserName
)
81 + ::rtl::OUString::createFromAscii(" PASSWORD ")
82 + getString(descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD
)));
83 aSql
+= ::rtl::OUString::createFromAscii(" RESOURCE NOT EXCLUSIVE");
85 Reference
< XStatement
> xStmt
= m_pConnection
->createStatement( );
88 ::comphelper::disposeComponent(xStmt
);
90 return createObject( _rForName
);
92 // -------------------------------------------------------------------------
94 void OUsers::dropObject(sal_Int32
/*_nPos*/,const ::rtl::OUString _sElementName
)
97 // first we have to check if this user is live relevaant for the database
98 // which means with out these users the database will miss more than one important system table
99 ::rtl::OUString sUsers
= ::rtl::OUString::createFromAscii("SELECT USERMODE,USERNAME FROM DOMAIN.USERS WHERE USERNAME = '");
100 sUsers
+= _sElementName
+ ::rtl::OUString::createFromAscii("'");
101 Reference
< XStatement
> xStmt
= m_pConnection
->createStatement();
104 Reference
<XResultSet
> xRes
= xStmt
->executeQuery(sUsers
);
105 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
106 if(xRes
.is() && xRow
.is() && xRes
->next()) // there can only be one user with this name
108 static const ::rtl::OUString sDbaUser
= ::rtl::OUString::createFromAscii("DBA");
109 if(xRow
->getString(1) == sDbaUser
)
111 ::comphelper::disposeComponent(xStmt
);
112 m_pConnection
->throwGenericSQLException(STR_USER_NO_DELETE
,static_cast< XDrop
* >( this ));
115 ::comphelper::disposeComponent(xStmt
);
120 ::rtl::OUString aSql
= ::rtl::OUString::createFromAscii("DROP USER ");
121 ::rtl::OUString aQuote
= m_pConnection
->getMetaData()->getIdentifierQuoteString( );
122 aSql
+= ::dbtools::quoteName(aQuote
,_sElementName
);
124 Reference
< XStatement
> xStmt
= m_pConnection
->createStatement( );
126 xStmt
->execute(aSql
);
127 ::comphelper::disposeComponent(xStmt
);
131 // -------------------------------------------------------------------------