Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision dfaffebe

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID dfaffebe56e92031a1224b5b9342ac8ff7eca3b9
  • Vorgänger 38a2aaf2
  • Nachfolger 7d60c5a2

fix in cache...drecksau^^

Unterschiede anzeigen:

samples/example/main.cpp
"Mustermann", Person::Gender::MALE));
gPtr->setMainTeacher(mainTeacher);
//Persons will also persisted
//e->create(groupPtr, true, true);
e->create(groupPtr, true, true);
/** ---------------------------------
* FIND Group
* ---------------------------------
*/
QSharedPointer<Person> foundMainTeacher = e->findById<Person*>(1).objectCast<Person>();
qDebug() << "Founded:" << foundMainTeacher->toString();
qDebug() << "FoundedGroupSize:" << foundMainTeacher->getMaintainedGroups().size();
// QSharedPointer<Person> foundMainTeacher = e->findById<Person*>(1).objectCast<Person>();
// qDebug() << "Founded:" << foundMainTeacher->toString();
// qDebug() << "FoundedGroupSize:" << foundMainTeacher->getMaintainedGroups().size();
QSharedPointer<Entity> groupFindPtr = e->findById<Group *>(1);
QSharedPointer<Group> grp = groupFindPtr.objectCast<Group>();
......
e->refresh(personFindPtr);
QSharedPointer<Person> pers = personFindPtr.objectCast<Person>();
qDebug()<< "MainTeacher:" << personFindPtr->toString();
qDebug() << "GroupSize:" << pers->getGroupsMainTeacher().size();
qDebug() << "GroupSize:" << pers->getMaintainedGroups().size();
src/cache.cpp
}
void Cache::insert(QSharedPointer<Entity> &entity) {
if (entity.data() && entity->getId() > -1) {
if (entity && entity->getId() > -1) {
QString key = this->generateKey(entity->getId(),
QString(entity->getClassname()));
if (this->cache.contains(key)) {
QSharedPointer<Entity> ptr = this->cache.value(key).toStrongRef();
if (!ptr.isNull()) {
ptr.reset(entity.data());
entity = ptr;
if (ptr) {
ptr.swap(entity);
return;
}
}
this->cache.insert(key, entity.toWeakRef());
......
QString key = this->generateKey(id, classname);
if (this->contains(key)) {
QSharedPointer<Entity> ptr = this->cache.value(key).toStrongRef();
if (!ptr.data()) {
if (!ptr) {
this->remove(id, classname);
}
return ptr;
src/entity.h
void idChanged();
public:
explicit Entity (QObject *parent = 0);
virtual QString toString() const;
virtual ~Entity();
virtual QString getTablename() const;
......
void setId(const qint64 &value);
protected:
explicit Entity (QObject *parent = 0);
virtual QString slimToString() const;
qint64 id;
};
src/entityinstancefactory.cpp
Entity *EntityInstanceFactory::createInstance(const char *className,
const QHash<QString, QVariant> &attributes) {
Entity *e = EntityInstanceFactory::createInstance(className);
Entity *e = EntityInstanceFactory::createInstance(className);
e = EntityInstanceFactory::setAttributes(e, attributes);
return e;
}
......
Entity *EntityInstanceFactory::setAttributes(Entity *&e,
const QHash<QString, QVariant> &attributes) {
if(!attributes.isEmpty()) {
auto metaprops = e->getMetaProperties();
return EntityInstanceFactory::setAttributes(e, attributes, metaprops);
} else {
return e;
}
}
const QString EntityInstanceFactory::extractEntityType(const QString &s) {
src/entitymanager.cpp
QSharedPointer<Entity> EntityManager::convert(const QHash<QString, QVariant>
&map,
const char *classname, const bool refresh) {
auto ptr = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(
classname, map));
auto e = EntityInstanceFactory::createInstance(
classname, map);
auto ptr = QSharedPointer<Entity>(e);
this->cache.insert(ptr);
this->resolveRelations(ptr, map, refresh);
return ptr;

Auch abrufbar als: Unified diff