Revision 4d57a79b
Von Christian Ehringfeld vor etwa 10 Jahren hinzugefügt
| README.md | ||
|---|---|---|
|
# CuteEntityManager for Qt
|
||
|
|
||
|
[](https://ci.appveyor.com/project/Professi/cuteentitymanager/branch/master)
|
||
|
|
||
|
## English
|
||
|
With CuteEntityManager it is possible to persist, merge, find or delete
|
||
|
entities. Its functionality is based on JPA's EntityManager. For a
|
||
| src/entityhelper.h | ||
|---|---|---|
|
#include <QString>
|
||
|
#include <QHash>
|
||
|
#include <QMetaProperty>
|
||
|
#include <QPair>
|
||
|
namespace CuteEntityManager {
|
||
|
|
||
|
class Relation;
|
||
| src/entityinspector.cpp | ||
|---|---|---|
|
if (!rel) {
|
||
|
ok = false;
|
||
|
} else {
|
||
|
this->checkRelationMappings(metaProperty, i.value(), ok);
|
||
|
this->checkRelationMappings(metaProperty, i.value(), ok,entity);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
void EntityInspector::checkRelationMappings(QMetaProperty &property,
|
||
|
const Relation &r, bool &ok) {
|
||
|
const Relation &r, bool &ok, Entity *&entity) {
|
||
|
QString foreignEntityName = EntityInstanceFactory::extractEntityType(
|
||
|
property.typeName());
|
||
|
auto foreignInstance = EntityInstanceFactory::createInstance(foreignEntityName);
|
||
| ... | ... | |
|
auto foreignRelations = EntityHelper::getRelationProperties(foreignInstance);
|
||
|
int foundMappedBy = 0;
|
||
|
bool foundForeignMappedRelation = false;
|
||
|
auto superClasses = EntityHelper::superClasses(entity,true);
|
||
|
QStringList classNames = QStringList {EntityHelper::getClassName(entity)};
|
||
|
for (int s = 0; s < superClasses.size(); ++s) {
|
||
|
classNames.append(superClasses.at(s)->className());
|
||
|
}
|
||
|
for (auto i = foreignRelations.constBegin(); i != foreignRelations.constEnd();
|
||
|
++i) {
|
||
|
/**
|
||
|
* @todo compare classes of properties
|
||
|
**/
|
||
|
if (r.getMappedBy().isEmpty()
|
||
|
&& i.key().getMappedBy() == r.getPropertyName()) {
|
||
|
++foundMappedBy;
|
||
|
for (int x = 0; x < classNames.size(); ++x) {
|
||
|
if(QString(i.value().typeName()).contains(classNames.at(x))) {
|
||
|
++foundMappedBy;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
} else if (!r.getMappedBy().isEmpty()
|
||
|
&& r.getMappedBy() == i.key().getPropertyName()) {
|
||
|
foundForeignMappedRelation = true;
|
||
| ... | ... | |
|
this->logger->logMsg("The relation " + r.getPropertyName() +
|
||
|
" is mapped several times (" +
|
||
|
QString::number(foundMappedBy) + ") by foreign class " + foreignEntityName +
|
||
|
". You should map it only once!\n", MsgType::WARNING);
|
||
|
ok = false;
|
||
|
". You should map it only once!\n",
|
||
|
MsgType::WARNING);
|
||
|
}
|
||
|
} else if (!foundForeignMappedRelation) {
|
||
|
this->logger->logMsg("Relation " + r.getPropertyName() +
|
||
| src/entityinspector.h | ||
|---|---|---|
|
void checkRelationTypos(const QString &name, const Relation &r,
|
||
|
bool &ok);
|
||
|
void checkRelationMappings(QMetaProperty &property, const Relation &r,
|
||
|
bool &ok);
|
||
|
bool &ok, Entity *&entity);
|
||
|
bool checkPrimaryKey(Entity *&entity);
|
||
|
void verifyBlobAttributes(Entity *&entity);
|
||
|
void checkMetaProperties(QHash<QString, QMetaProperty> &metaProperties,
|
||
Auch abrufbar als: Unified diff
improvement