22#include <com/sun/star/sdbc/SQLException.hpp>
23#include <com/sun/star/sdbcx/XAppend.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
28#include <com/sun/star/sdbcx/XDrop.hpp>
72 [&_rName](
const OIndex& rIndex) { return rIndex.sName == _rName; });
79 [&_rName](
const OIndex& rIndex) { return rIndex.sName == _rName; });
86 [&_rName](
const OIndex& rIndex) { return rIndex.getOriginalName() == _rName; });
93 [&_rName](
const OIndex& rIndex) { return rIndex.getOriginalName() == _rName; });
98 OSL_ENSURE(_rPos->isNew(),
"OIndexCollection::commitNewIndex: index must be new!");
104 if (!xAppendIndex.is())
106 OSL_FAIL(
"OIndexCollection::commitNewIndex: missing an interface of the index container!");
114 xCols = xColsSupp->getColumns();
118 if (!xAppendCols.is())
120 OSL_FAIL(
"OIndexCollection::commitNewIndex: invalid index descriptor returned!");
125 static constexpr OUStringLiteral s_sNamePropertyName =
u"Name";
127 xIndexDescriptor->setPropertyValue(
"IsUnique", css::uno::Any(_rPos->bUnique));
128 xIndexDescriptor->setPropertyValue(s_sNamePropertyName,
Any(_rPos->sName));
131 for (
auto const& field : _rPos->aFields)
133 OSL_ENSURE(!xCols->hasByName(field.sFieldName),
"OIndexCollection::commitNewIndex: double column name (need to prevent this outside)!");
136 OSL_ENSURE(xColDescriptor.is(),
"OIndexCollection::commitNewIndex: invalid column descriptor!");
137 if (xColDescriptor.is())
139 xColDescriptor->setPropertyValue(
"IsAscending", css::uno::Any(field.bSortAscending));
140 xColDescriptor->setPropertyValue(s_sNamePropertyName,
Any(field.sFieldName));
141 xAppendCols->appendByDescriptor(xColDescriptor);
145 xAppendIndex->appendByDescriptor(xIndexDescriptor);
148 _rPos->clearModified();
164 OSL_ENSURE(
m_xIndexes->hasByName(_rPos->getOriginalName()),
"OIndexCollection::drop: invalid name!");
167 if (!xDropIndex.is())
169 OSL_FAIL(
"OIndexCollection::drop: no XDrop interface!");
173 xDropIndex->dropByName(_rPos->getOriginalName());
186 Indexes::iterator aDropped =
findOriginal(_rPos->getOriginalName());
187 OSL_ENSURE(aDropped !=
m_aIndexes.end(),
"OIndexCollection::drop: invalid original name, but successful commit?!");
196 "OIndexCollection::drop: invalid position (fasten your seatbelt... this will crash)!");
214 OSL_FAIL(
"OIndexCollection::implFillIndexInfo: got an invalid index object!");
222 _rIndex.
bPrimaryKey = ::cppu::any2bool(_rxDescriptor->getPropertyValue(
"IsPrimaryKeyIndex"));
223 _rIndex.
bUnique = ::cppu::any2bool(_rxDescriptor->getPropertyValue(
"IsUnique"));
224 _rxDescriptor->getPropertyValue(
"Catalog") >>= _rIndex.
sDescription;
230 xCols = xSuppCols->getColumns();
231 OSL_ENSURE(xCols.is(),
"OIndexCollection::implFillIndexInfo: the index does not have columns!");
238 const OUString* pFieldNames =
aFieldNames.getConstArray();
239 const OUString* pFieldNamesEnd = pFieldNames +
aFieldNames.getLength();
240 IndexFields::iterator aCopyTo = _rIndex.
aFields.begin();
243 for (;pFieldNames < pFieldNamesEnd; ++pFieldNames, ++aCopyTo)
246 xIndexColumn.clear();
247 xCols->getByName(*pFieldNames) >>= xIndexColumn;
248 if (!xIndexColumn.is())
250 OSL_FAIL(
"OIndexCollection::implFillIndexInfo: invalid index column!");
256 aCopyTo->sFieldName = *pFieldNames;
257 aCopyTo->bSortAscending = ::cppu::any2bool(xIndexColumn->getPropertyValue(
"IsAscending"));
267 "OIndexCollection::resetIndex: invalid position!");
271 _rPos->sName = _rPos->getOriginalName();
274 _rPos->clearModified();
289 OSL_ENSURE(
end() ==
find(_rName),
"OIndexCollection::insert: invalid new name!");
290 OIndex aNewIndex((OUString()));
291 aNewIndex.
sName = _rName;
306 const OUString* pNames = aNames.getConstArray();
307 const OUString* pEnd = pNames + aNames.getLength();
308 for (; pNames < pEnd; ++pNames)
315 OSL_FAIL(
"OIndexCollection::implConstructFrom: got an invalid index object ... ignoring!");
320 OIndex aCurrentIndex(*pNames);
const char *const aFieldNames[]
void attach(const css::uno::Reference< css::container::XNameAccess > &_rxIndexes)
void resetIndex(const Indexes::iterator &_rPos)
Indexes::iterator insert(const OUString &_rName)
OIndexCollection & operator=(const OIndexCollection &_rSource)
css::uno::Reference< css::container::XNameAccess > m_xIndexes
bool drop(const Indexes::iterator &_rPos)
drop an index, and remove it from the collection
void commitNewIndex(const Indexes::iterator &_rPos)
static void implFillIndexInfo(OIndex &_rIndex, const css::uno::Reference< css::beans::XPropertySet > &_rxDescriptor)
void implConstructFrom(const css::uno::Reference< css::container::XNameAccess > &_rxIndexes)
bool dropNoRemove(const Indexes::iterator &_rPos)
simply drop the index described by the name, but don't remove the descriptor from the collection
Indexes::const_iterator findOriginal(const OUString &_rName) const
Indexes::const_iterator find(const OUString &_rName) const
Indexes::const_iterator end() const
get access to the (last + 1st) element of the index collection
#define DBG_UNHANDLED_EXCEPTION(...)
const OUString & getOriginalName() const