Example #1
0
void Index::addElement(Column *column, OperatorClass *op_class, bool asc_order, bool nulls_first)
{
	//Case the column is not allocated raises an error
	if(!column)
	{
		throw Exception(Exception::getErrorMessage(ERR_ASG_NOT_ALOC_COLUMN)
										.arg(Utf8String::create(this->getName()))
										.arg(BaseObject::getTypeName(OBJ_INDEX)),
										ERR_ASG_NOT_ALOC_COLUMN,__PRETTY_FUNCTION__,__FILE__,__LINE__);
	}
	else
	{
		IndexElement elem;

		//Case the column exists on index
		if(isElementExists(column) >= 0)
			throw Exception(ERR_INS_DUPLIC_COLUMN,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		//Configures the element
		elem.setColumn(column);
		elem.setOperatorClass(op_class);
		elem.setSortAttribute(IndexElement::NULLS_FIRST, nulls_first);
		elem.setSortAttribute(IndexElement::ASC_ORDER, asc_order);

		elements.push_back(elem);
	}
}
Example #2
0
void Index::addIndexElement(IndexElement elem)
{
	if(getElementIndex(elem) >= 0)
		throw Exception(ERR_INS_DUPLIC_ELEMENT,__PRETTY_FUNCTION__,__FILE__,__LINE__);
	else if(elem.getExpression().isEmpty() && !elem.getColumn())
		throw Exception(ERR_ASG_INV_EXPR_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

	idx_elements.push_back(elem);
}
Example #3
0
void IndexWidget::editElement(int elem_idx)
{
	IndexElement elem;

	elem=elements_tab->getRowData(elem_idx).value<IndexElement>();

	if(elem.getColumn())
	{
		column_rb->setChecked(true);
		column_cmb->setCurrentIndex(column_cmb->findText(Utf8String::create(elem.getColumn()->getName())));
	}
	else
	{
		expression_rb->setChecked(true);
		elem_expr_txt->setPlainText(Utf8String::create(elem.getExpression()));
	}

	if(elem.getSortingAttribute(IndexElement::ASC_ORDER))
		ascending_rb->setChecked(true);
	else
		descending_rb->setChecked(true);

	nulls_first_chk->setChecked(elem.getSortingAttribute(IndexElement::NULLS_FIRST));
	sorting_chk->setChecked(elem.isSortingEnabled());
	op_class_sel->setSelectedObject(elem.getOperatorClass());
}
Example #4
0
void Index::addIndexElement(const QString &expr, Collation *coll, OperatorClass *op_class, bool use_sorting, bool asc_order, bool nulls_first)
{
	try
	{
		IndexElement elem;

		//Raises an error if the expression is empty
		if(expr.isEmpty())
			throw Exception(ERR_ASG_INV_EXPR_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		//Configures the element
		elem.setExpression(expr);
		elem.setOperatorClass(op_class);
		elem.setCollation(coll);
		elem.setSortingEnabled(use_sorting);
		elem.setSortingAttribute(IndexElement::NULLS_FIRST, nulls_first);
		elem.setSortingAttribute(IndexElement::ASC_ORDER, asc_order);

		if(getElementIndex(elem) >= 0)
			throw Exception(ERR_INS_DUPLIC_ELEMENT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		idx_elements.push_back(elem);
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
Example #5
0
void Index::addIndexElement(Column *column, Collation *coll, OperatorClass *op_class, bool use_sorting, bool asc_order, bool nulls_first)
{
	try
	{
		IndexElement elem;

		//Case the column is not allocated raises an error
		if(!column)
			throw Exception(Exception::getErrorMessage(ERR_ASG_NOT_ALOC_COLUMN)
											.arg(Utf8String::create(this->getName())).arg(Utf8String::create(this->getTypeName())),
											ERR_ASG_NOT_ALOC_COLUMN, __PRETTY_FUNCTION__,__FILE__,__LINE__);

		//Configures the element
		elem.setColumn(column);
		elem.setOperatorClass(op_class);
		elem.setCollation(coll);
		elem.setSortingEnabled(use_sorting);
		elem.setSortingAttribute(IndexElement::NULLS_FIRST, nulls_first);
		elem.setSortingAttribute(IndexElement::ASC_ORDER, asc_order);

		if(getElementIndex(elem) >= 0)
			throw Exception(ERR_INS_DUPLIC_ELEMENT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		idx_elements.push_back(elem);
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
Example #6
0
void IndexWidget::handleElement(int elem_idx)
{
	if(column_rb->isChecked() ||
		 (expression_rb->isChecked() && !elem_expr_txt->toPlainText().isEmpty()))
	{
		IndexElement elem;

		elem.setSortingEnabled(sorting_chk->isChecked());
		elem.setSortingAttribute(IndexElement::NULLS_FIRST, nulls_first_chk->isChecked());
		elem.setSortingAttribute(IndexElement::ASC_ORDER, ascending_rb->isChecked());
		elem.setOperatorClass(dynamic_cast<OperatorClass *>(op_class_sel->getSelectedObject()));

		if(expression_rb->isChecked())
			elem.setExpression(elem_expr_txt->toPlainText().toUtf8());
		else
			elem.setColumn(reinterpret_cast<Column *>(column_cmb->itemData(column_cmb->currentIndex()).value<void *>()));

		showElementData(elem, elem_idx);

		elem_expr_txt->clear();
		ascending_rb->setChecked(true);
		sorting_chk->setChecked(true);
		op_class_sel->clearSelector();
		nulls_first_chk->setChecked(false);
	}
	else if(elements_tab->getCellText(elem_idx,0).isEmpty())
		elements_tab->removeRow(elem_idx);
}
Example #7
0
void Index::addElement(const QString &expr, OperatorClass *op_class, bool asc_order, bool nulls_first)
{
	//Raises an error if the expression is empty
	if(expr.isEmpty())
	{
		throw Exception(ERR_ASG_INV_EXPR_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);
	}
	else
	{
		IndexElement elem;

		//Case the expression exists on index
		if(isElementExists(expr) >= 0)
			throw Exception(ERR_INS_DUPLIC_ELEMENT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

		//Configures the element
		elem.setExpression(expr);
		elem.setOperatorClass(op_class);
		elem.setSortAttribute(IndexElement::NULLS_FIRST, nulls_first);
		elem.setSortAttribute(IndexElement::ASC_ORDER, asc_order);

		elements.push_back(elem);
	}
}
Example #8
0
void IndexWidget::showElementData(IndexElement elem, int elem_idx)
{
	if(elem.getColumn())
	{
		elements_tab->setCellText(Utf8String::create(elem.getColumn()->getName()), elem_idx, 0);
		elements_tab->setCellText(Utf8String::create(elem.getColumn()->getTypeName()), elem_idx, 1);
	}
	else
	{
		elements_tab->setCellText(Utf8String::create(elem.getExpression()), elem_idx, 0);
		elements_tab->setCellText(tr("Expression"), elem_idx, 1);
	}

	if(elem.getOperatorClass())
		elements_tab->setCellText(Utf8String::create(elem.getOperatorClass()->getName(true)), elem_idx, 2);
	else
		elements_tab->setCellText("-", elem_idx, 2);

	if(elem.isSortingEnabled())
	{
		if(elem.getSortingAttribute(IndexElement::ASC_ORDER))
			elements_tab->setCellText(ascending_rb->text(), elem_idx, 3);
		else
			elements_tab->setCellText(descending_rb->text(), elem_idx, 3);

		if(elem.getSortingAttribute(IndexElement::NULLS_FIRST))
			elements_tab->setCellText(trUtf8("Yes"), elem_idx, 4);
		else
			elements_tab->setCellText(trUtf8("No"), elem_idx, 4);
	}
	else
	{
		elements_tab->setCellText("-", elem_idx, 3);
		elements_tab->setCellText("-", elem_idx, 4);
	}

	elements_tab->setRowData(QVariant::fromValue<IndexElement>(elem), elem_idx);
}
Example #9
0
void Table::getColumnReferences(Column *column, vector<TableObject *> &refs, bool exclusion_mode)
{
	if(column && !column->isAddedByRelationship())
	{
		unsigned count, i;
		IndexElement elem;
		Column *col=nullptr, *col1=nullptr;
		vector<TableObject *>::iterator itr, itr_end;
		bool found=false;
		Index *ind=nullptr;
		Constraint *constr=nullptr;
		Trigger *trig=nullptr;

		itr=indexes.begin();
		itr_end=indexes.end();

		while(itr!=itr_end && (!exclusion_mode || (exclusion_mode && !found)))
		{
			ind=dynamic_cast<Index *>(*itr);
			itr++;

			count=ind->getIndexElementCount();
			for(i=0; i < count  && (!exclusion_mode || (exclusion_mode && !found)); i++)
			{
				elem=ind->getIndexElement(i);
				col=elem.getColumn();
				if(col && col==column)
				{
					found=true;
					refs.push_back(ind);
				}
			}
		}

		itr=constraints.begin();
		itr_end=constraints.end();

		while(itr!=itr_end && (!exclusion_mode || (exclusion_mode && !found)))
		{
			constr=dynamic_cast<Constraint *>(*itr);
			itr++;

			col=constr->getColumn(column->getName(),true);
			col1=constr->getColumn(column->getName(),false);

			if((col && col==column) || (col1 && col1==column))
			{
				found=true;
				refs.push_back(constr);
			}
		}

		itr=triggers.begin();
		itr_end=triggers.end();

		while(itr!=itr_end && (!exclusion_mode || (exclusion_mode && !found)))
		{
			trig=dynamic_cast<Trigger *>(*itr);
			itr++;

			count=trig->getColumnCount();
			for(i=0; i < count && (!exclusion_mode || (exclusion_mode && !found)); i++)
			{
				if(trig->getColumn(i)==column)
				{
					found=true;
					refs.push_back(trig);
				}
			}
		}
	}
}
Example #10
0
void BagOfWordsTest2::test_indexElementDefaultConstructor()
{
  qDebug() << "BagOfWordsTest2::test_indexElementDefaultConstructor";
//     IndexElement();
  IndexElement el;
  QVERIFY(el.getId() == 0);
  QVERIFY(el.getType() == BOW_NOTYPE);
  QVERIFY(el.getSimpleTerm() == "");
  QVERIFY(el.getCategory() == 0);
  QVERIFY(el.getPosition() == 0);
  QVERIFY(el.getLength() == 0);
  QVERIFY(el.getNamedEntityType() == EntityType());
  QVERIFY(!el.isSimpleTerm());
  QVERIFY(!el.isComposedTerm());
  QVERIFY(!el.isNamedEntity());
  QVERIFY(!el.isPredicate());
  QVERIFY(el.getStructure().empty());
  QVERIFY(el.getRelations().empty());
}
Example #11
0
void BagOfWordsTest2::test_indexElementOperatorAffect()
{
  qDebug() << "BagOfWordsTest2::test_indexElementCopyConstructor";
//   IndexElement(const IndexElement& ie);
  uint64_t id = 1;
  BoWType type = BOW_TOKEN;
  QString word = QString::fromUtf8("word");
  uint64_t cat = 0;
  uint64_t position = 0;
  uint64_t length = (uint64_t)word.size();
  EntityType neType = EntityType();
  uint64_t reType = 0;
  IndexElement* el = new IndexElement(id,type,word,cat,position,length,neType,reType);

  uint64_t id2 = 2;
  BoWType type2 = BOW_TERM;
  QString word2 = QString::fromUtf8("other");
  uint64_t cat2 = 1;
  uint64_t position2 = 10;
  uint64_t length2 = (uint64_t)word.size();
  EntityType neType2 = EntityType();
  uint64_t reType2 = 0;
  IndexElement el2(id2,type2,word2,cat2,position2,length2,neType2,reType2);

  el2 = *el;

  QVERIFY(el->getId() == el2.getId());
  QVERIFY(el->getType() == el2.getType());
  QVERIFY(el->getSimpleTerm() == el2.getSimpleTerm());
  QVERIFY(el->getCategory() == el2.getCategory());
  QVERIFY(el->getPosition() == el2.getPosition());
  QVERIFY(el->getLength() == el2.getLength());
  QVERIFY(el->getNamedEntityType() == el2.getNamedEntityType());
  QVERIFY(el->isSimpleTerm() && el2.isSimpleTerm());
  QVERIFY(!el->isComposedTerm() && !el2.isComposedTerm());
  QVERIFY(!el->isNamedEntity() && !el2.isNamedEntity());
  QVERIFY(!el->isPredicate() && !el2.isPredicate());
  QVERIFY(el->getStructure().empty() && el2.getStructure().empty());
  QVERIFY(el->getRelations().empty() && el2.getRelations().empty());

  delete el; el = 0;
  // Test members after deleting original objects
  QVERIFY(el2.getId() == 1);
  QVERIFY(el2.getType() == BOW_TOKEN);
  QVERIFY(el2.getSimpleTerm() == "word");
  QVERIFY(el2.getCategory() == 0);
  QVERIFY(el2.getPosition() == 0);
  QVERIFY(el2.getLength() == (uint64_t)word.size());
  QVERIFY(el2.getNamedEntityType() == neType);
  QVERIFY(el2.isSimpleTerm());
  QVERIFY(!el2.isComposedTerm());
  QVERIFY(!el2.isNamedEntity());
  QVERIFY(!el2.isPredicate());
  QVERIFY(el2.getStructure().empty());
  QVERIFY(el2.getRelations().empty());

}