Revision a42de475
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
| src/entitymanager.h | ||
|---|---|---|
|
return QList<QSharedPointer<T>>();
|
||
|
}
|
||
|
|
||
|
template<class T> quint32 countEntities(Query &q, const bool joinBaseClasses = true) {
|
||
|
auto instance = QSharedPointer<Entity>(EntityInstanceFactory::createInstance<T *>());
|
||
|
quint32 count = 0;
|
||
|
if (instance) {
|
||
|
if (q.getFrom().isEmpty()) {
|
||
|
q.setFrom(QStringList(instance->getTablename()));
|
||
|
}
|
||
|
if (joinBaseClasses) {
|
||
|
q.appendJoins(this->schema->getQueryBuilder()->joinBaseClasses(instance));
|
||
|
}
|
||
|
q.appendSelect("COUNT(*)");
|
||
|
QSqlQuery query = this->queryInterpreter->build(q);
|
||
|
this->db->select(query);
|
||
|
if (query.next()) {
|
||
|
count = query.value(0).toInt();
|
||
|
}
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
template<class T>
|
||
|
bool remove(QSharedPointer<T> &entity) {
|
||
|
static_assert(std::is_base_of<Entity, T>::value, "T must inherit from Entity");
|
||
| tests/em/tst_em.cpp | ||
|---|---|---|
|
}
|
||
|
}
|
||
|
|
||
|
void EmTest::testCountEntities() {
|
||
|
Query q = Query();
|
||
|
auto count = this->e->countEntities<DatabaseMigration>(q, true);
|
||
|
QCOMPARE(count, (unsigned int)1);
|
||
|
}
|
||
|
|
||
|
void EmTest::testTableCreation() {
|
||
|
auto tables = this->e->getSchema()->getTables();
|
||
|
bool containsArticle = tables.contains("article");
|
||
| tests/em/tst_em.h | ||
|---|---|---|
|
void testInheritedRelations();
|
||
|
void testNonCachedInheritedRelations();
|
||
|
void testDatabaseMigrationTable();
|
||
|
void testCountEntities();
|
||
|
void testTableCreation();
|
||
|
|
||
|
private:
|
||
Auch abrufbar als: Unified diff
refs #621