Revision 949b3ea3
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
| src/cache.cpp | ||
|---|---|---|
|
void Cache::insert(QSharedPointer<Entity> &entity) {
|
||
|
if (entity && entity->getId() > -1) {
|
||
|
QString key = this->generateKey(entity->getId(),
|
||
|
EntityHelper::getClassName(entity.data()));
|
||
|
EntityHelper::getBaseClassName(entity.data(),true));
|
||
|
if (this->cache.contains(key)) {
|
||
|
QSharedPointer<Entity> ptr = this->cache.value(key).toStrongRef();
|
||
|
if (ptr) {
|
||
| ... | ... | |
|
|
||
|
void Cache::remove(const QSharedPointer<Entity> &entity) {
|
||
|
if (entity.data() && entity->getId() > -1) {
|
||
|
this->remove(entity->getId(), EntityHelper::getClassName(entity.data()));
|
||
|
this->remove(entity->getId(), EntityHelper::getBaseClassName(entity.data(),true));
|
||
|
}
|
||
|
}
|
||
|
|
||
| src/entityhelper.cpp | ||
|---|---|---|
|
return objectBefore;
|
||
|
}
|
||
|
|
||
|
const QMetaObject *EntityHelper::getBaseClass(const Entity *entity,
|
||
|
bool stopAtSingleTableInheritance) {
|
||
|
auto list = EntityHelper::superClasses(entity, stopAtSingleTableInheritance);
|
||
|
if(list.isEmpty()) {
|
||
|
return entity->metaObject();
|
||
|
}
|
||
|
return list.last();
|
||
|
}
|
||
|
|
||
|
const QString EntityHelper::getBaseClassName(const Entity *entity,
|
||
|
bool stopAtSingleTableInheritance) {
|
||
|
return EntityHelper::getBaseClass(entity, stopAtSingleTableInheritance)->className();
|
||
|
}
|
||
|
|
||
|
const char *EntityHelper::getClassname(const Entity *entity) {
|
||
|
return entity->metaObject()->className();
|
||
|
}
|
||
| src/entityhelper.h | ||
|---|---|---|
|
static Entity* copyObject(const Entity *entity);
|
||
|
static Entity* getBaseClassObject(const QSharedPointer<Entity> &entity,
|
||
|
QString attributeName);
|
||
|
static const QMetaObject * getBaseClass(const Entity *entity,
|
||
|
bool stopAtSingleTableInheritance
|
||
|
= false);
|
||
|
static const QString getBaseClassName(const Entity *entity,
|
||
|
bool stopAtSingleTableInheritance
|
||
|
= false);
|
||
|
|
||
|
static const char *getClassname(const Entity *entity);
|
||
|
static const QString getClassName(const Entity *entity);
|
||
|
static void addEntityToListProperty(const QSharedPointer<Entity> &entity,
|
||
| src/entitymanager.cpp | ||
|---|---|---|
|
QSharedPointer<Entity> &e,
|
||
|
const bool refresh) {
|
||
|
QSharedPointer<Entity> r;
|
||
|
if (e && (refresh || !(r = this->cache.get(id, EntityHelper::getClassname(e.data()))))) {
|
||
|
if (e && (refresh ||
|
||
|
!(r = this->cache.get(id, EntityHelper::getBaseClassName(e.data(), true))))) {
|
||
|
auto map = this->findByPk(id, e);
|
||
|
r = this->convert(map, EntityHelper::getClassname(e.data()), refresh);
|
||
|
}
|
||
| ... | ... | |
|
QString className = attr->getRelatedClass()->className();
|
||
|
QSharedPointer<Entity> ptr = QSharedPointer<Entity>();
|
||
|
if (!(this->cache.contains(convertedId, className)
|
||
|
/** @todo use Baseclass */
|
||
|
&& (ptr = this->cache.get(convertedId, className)))) {
|
||
|
ptr = this->findById(convertedId, className);
|
||
|
}
|
||
| ... | ... | |
|
QSqlQuery q = this->queryInterpreter->build(query);
|
||
|
auto listMap = this->convertQueryResult(q);
|
||
|
auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()));
|
||
|
EntityHelper::setListProperty(entity,entities,attr->getMetaProperty());
|
||
|
EntityHelper::setListProperty(entity, entities, attr->getMetaProperty());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
for (int var = 0; var < listMap.size(); ++var) {
|
||
|
auto id = listMap.at(var).value(attr->getRelatedColumnName());
|
||
|
if (!(this->cache.contains(id.toLongLong(), secClassName) &&
|
||
|
/** @todo use Baseclass */
|
||
|
(e = this->cache.get(id.toLongLong(), secClassName)))) {
|
||
|
e = this->findById(id.toLongLong(), secClassName);
|
||
|
}
|
||
| tests/em/tst_em.cpp | ||
|---|---|---|
|
p3->setGroups(groups);
|
||
|
QVERIFY(this->e->save(pEnt, true, true));
|
||
|
this->e->refresh(g);
|
||
|
qDebug() << g->getPersons().size();
|
||
|
QVERIFY(g->getPersons().size() == 2);
|
||
|
QVERIFY(g->getPersons().size() == 3);
|
||
|
auto firstPerson = g->getPersons().first();
|
||
|
g->removePerson(firstPerson);
|
||
|
QVERIFY(this->e->save(g, true, true));
|
||
|
this->e->refresh(firstPerson);
|
||
|
QVERIFY(firstPerson->getGroups().size() == 0 && g->getPersons().size() == 1);
|
||
|
QVERIFY(firstPerson->getGroups().size() == 0);
|
||
|
QVERIFY(g->getPersons().size() == 1);
|
||
|
}
|
||
Auch abrufbar als: Unified diff
fixxes