24#include <core_resource.hxx>
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/beans/PropertyState.hpp>
29#include <com/sun/star/beans/XPropertyState.hpp>
30#include <com/sun/star/sdb/TableDefinition.hpp>
31#include <com/sun/star/sdbc/XConnection.hpp>
32#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
33#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
34#include <com/sun/star/sdbc/XRow.hpp>
35#include <com/sun/star/sdbc/SQLException.hpp>
57using namespace ::
cppu;
62 bool lcl_isPropertySetDefaulted(
const Sequence< OUString>& _aNames,
const Reference<XPropertySet>& _xProp)
64 Reference<XPropertyState> xState(_xProp,UNO_QUERY);
67 const OUString* pIter = _aNames.getConstArray();
68 const OUString* pEnd = pIter + _aNames.getLength();
69 for(;pIter != pEnd;++pIter)
73 PropertyState aState = xState->getPropertyState(*pIter);
74 if ( aState != PropertyState_DEFAULT_VALUE )
77 catch(
const Exception&)
82 return ( pIter == pEnd );
89 ::osl::Mutex& _rMutex,
90 const Reference< XConnection >& _xCon,
92 const Reference< XNameContainer >& _xTableDefinitions,
94 std::atomic<std::size_t>& _nInAppend)
96 ,m_xTableDefinitions(_xTableDefinitions)
109 xCont->removeContainerListener(
this );
124OUString SAL_CALL OTableContainer::getImplementationName()
126 return "com.sun.star.sdb.dbaccess.OTableContainer";
128sal_Bool SAL_CALL OTableContainer::supportsService(
const OUString& _rServiceName)
131 for (
const OUString& s : aSupported)
132 if (s == _rServiceName)
137css::uno::Sequence< OUString > SAL_CALL OTableContainer::getSupportedServiceNames()
145void lcl_createDefinitionObject(
const OUString& _rName
146 ,
const Reference< XNameContainer >& _xTableDefinitions
147 ,Reference<XPropertySet>& _xTableDefinition
148 ,Reference<XNameAccess>& _xColumnDefinitions)
150 if ( !_xTableDefinitions.is() )
153 if ( _xTableDefinitions->hasByName(_rName) )
154 _xTableDefinition.set(_xTableDefinitions->getByName(_rName),UNO_QUERY);
158 _xTableDefinition = TableDefinition::createWithName( ::comphelper::getProcessComponentContext(), _rName );
159 _xTableDefinitions->insertByName(_rName,
Any(_xTableDefinition));
161 Reference<XColumnsSupplier> xColumnsSupplier(_xTableDefinition,UNO_QUERY);
162 if ( xColumnsSupplier.is() )
163 _xColumnDefinitions = xColumnsSupplier->getColumns();
170 Reference<XColumnsSupplier > xSup;
177 Reference<XPropertySet> xTableDefinition;
178 Reference<XNameAccess> xColumnDefinitions;
179 lcl_createDefinitionObject(_rName,
m_xTableDefinitions,xTableDefinition,xColumnDefinitions);
195 ::dbtools::EComposeRule::InDataManipulation);
199 OUString
sType,sDescription;
200 Sequence< OUString> aTypeFilter;
203 Reference< XResultSet > xRes;
206 if(xRes.is() && xRes->next())
208 Reference< XRow > xRow(xRes,UNO_QUERY);
211 sType = xRow->getString(4);
212 sDescription = xRow->getString(5);
215 ::comphelper::disposeComponent(xRes);
223 ,xColumnDefinitions);
227 Reference<XPropertySet> xDest(xRet,UNO_QUERY);
228 if ( xTableDefinition.is() )
229 ::comphelper::copyProperties(xTableDefinition,xDest);
243 Reference< XPropertySet > xRet;
247 Reference<XColumnsSupplier > xMasterColumnsSup;
251 xMasterColumnsSup.set( xDataFactory->createDataDescriptor(), UNO_QUERY );
276 Reference< XConnection > xConnection(
m_xConnection.get(), UNO_QUERY );
278 pApprove->approveElement(
aName );
285 xAppend->appendByDescriptor(descriptor);
289 OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor,
m_xConnection);
292 OSL_ENSURE(xCon.is(),
"Connection is null!");
295 Reference< XStatement > xStmt = xCon->createStatement( );
297 xStmt->execute(aSql);
298 ::comphelper::disposeComponent(xStmt);
303 Reference<XPropertySet> xTableDefinition;
304 Reference<XNameAccess> xColumnDefinitions;
306 Reference<XColumnsSupplier> xSup(descriptor,UNO_QUERY);
307 Reference<XDataDescriptorFactory> xFac(xColumnDefinitions,UNO_QUERY);
308 Reference<XAppend> xAppend(xColumnDefinitions,UNO_QUERY);
309 bool bModified =
false;
310 if ( xSup.is() && xColumnDefinitions.is() && xFac.is() && xAppend.is() )
312 Reference<XNameAccess> xNames = xSup->getColumns();
315 Reference<XPropertySet> xProp = xFac->createDataDescriptor();
316 Sequence< OUString>
aSeq = xNames->getElementNames();
317 const OUString* pIter =
aSeq.getConstArray();
318 const OUString* pEnd = pIter +
aSeq.getLength();
319 for(;pIter != pEnd;++pIter)
321 if ( !xColumnDefinitions->hasByName(*pIter) )
323 Reference<XPropertySet>
xColumn(xNames->getByName(*pIter),UNO_QUERY);
326 ::comphelper::copyProperties(
xColumn, xProp );
327 xAppend->appendByDescriptor( xProp );
334 Sequence< OUString> aNames{
338 if ( bModified || !lcl_isPropertySetDefaulted(aNames,xTableDefinition) )
349 xDrop->dropByName(_sElementName);
354 bool bIsView =
false;
359 if (
m_xMetaData->supportsCatalogsInTableDefinitions())
361 if (
m_xMetaData->supportsSchemasInTableDefinitions())
369 bIsView =
sType.equalsIgnoreAsciiCase(
"VIEW");
373 ::dbtools::throwFunctionSequenceException(
static_cast<XTypeProvider*
>(
static_cast<OFilteredContainer*
>(
this)));
375 OUString aSql(
"DROP ");
383 OSL_ENSURE(xCon.is(),
"Connection is null!");
386 Reference< XStatement > xStmt = xCon->createStatement( );
388 xStmt->execute(aSql);
389 ::comphelper::disposeComponent(xStmt);
403 Event.Accessor >>=
sName;
424 OUString sOldComposedName,sNewComposedName;
425 Event.ReplacedElement >>= sOldComposedName;
426 Event.Accessor >>= sNewComposedName;
448 xCont->addContainerListener(
this );
OptionalString sComposedName
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
void insertElement(const OUString &_sElementName, const ObjectType &_xElement)
ObjectType getObject(sal_Int32 _nIndex)
void renameObject(const OUString &_sOldName, const OUString &_sNewName)
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
::comphelper::OInterfaceContainerHelper3< css::container::XContainerListener > m_aContainerListeners
static bool hasDefaultSettings(const css::uno::Reference< css::beans::XPropertySet > &_rxColumn)
check if the persistent settings have their default value
css::uno::Reference< css::container::XNameAccess > m_xMasterContainer
void getAllTableTypeFilter(css::uno::Sequence< OUString > &_rFilter) const
retrieve a table type filter to pass to <member scope="css::sdbc">XDatabaseMetaData::getTables</membe...
virtual OUString getNameForObject(const ::connectivity::sdbcx::ObjectType &_xObject) override
std::atomic< std::size_t > & m_nInAppend
virtual void disposing() override
tell the container to free all elements and all additional resources.
css::uno::WeakReference< css::sdbc::XConnection > m_xConnection
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
virtual void addMasterContainerListener() override
virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
css::uno::Reference< css::container::XNameContainer > m_xTableDefinitions
virtual void disposing() override
tell the container to free all elements and all additional resources.
virtual connectivity::sdbcx::ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
virtual connectivity::sdbcx::ObjectType createObject(const OUString &_rName) override
virtual void removeMasterContainerListener() override
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
::rtl::Reference< OContainerMediator > m_pTableMediator
virtual ~OTableContainer() override
virtual void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
virtual OUString getTableTypeRestriction() const override
returns a string denoting the only type of tables allowed in this container, or an empty string if th...
virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< sal_Int8 > aSeq
OUString getString(const Any &_rAny)
css::uno::Sequence< OUString > getSupportedServiceNames()
css::uno::Reference< css::beans::XPropertySet > ObjectType
void notifyDataSourceModified(const css::uno::Reference< css::uno::XInterface > &_rxObject)
std::shared_ptr< IContainerApprove > PContainerApprove
constexpr OUStringLiteral PROPERTY_TEXTCOLOR(u"TextColor")
constexpr OUStringLiteral SERVICE_SDBCX_CONTAINER
constexpr OUStringLiteral PROPERTY_SCHEMANAME(u"SchemaName")
constexpr OUStringLiteral PROPERTY_APPLYFILTER(u"ApplyFilter")
constexpr OUStringLiteral PROPERTY_TEXTEMPHASIS(u"FontEmphasisMark")
constexpr OUStringLiteral PROPERTY_FILTER(u"Filter")
constexpr OUStringLiteral PROPERTY_FONT(u"FontDescriptor")
constexpr OUStringLiteral SQLSTATE_GENERAL
constexpr OUStringLiteral PROPERTY_CATALOGNAME(u"CatalogName")
constexpr OUStringLiteral PROPERTY_TEXTLINECOLOR(u"TextLineColor")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_TEXTRELIEF(u"FontRelief")
constexpr OUStringLiteral SERVICE_SDBCX_TABLES
constexpr OUStringLiteral PROPERTY_ROW_HEIGHT(u"RowHeight")
constexpr OUStringLiteral PROPERTY_ORDER(u"Order")