Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 43457c84

Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt

  • ID 43457c847392bca6be2d6378961c0c81be9b09d9
  • Vorgänger 5f3c7a9c
  • Nachfolger 886bdb22

entity inspector improvements

Unterschiede anzeigen:

src/entityinspector.cpp
qWarning() << msg;
ok = false;
} else {
msg = "Entity class " + classes.at(i) + " seems ok!\n";
msg = "Entity class " + classes.at(i) + " seems ok.\n";
qInfo() << msg;
}
this->logger->logMsg(msg);
......
bool EntityInspector::checkEntity(QString name) {
QString msg = "--------------------\n";
msg += "Checking " + name + " now!\n";
msg += "Checking " + name + " now.\n";
qDebug() << msg;
auto entity = this->instantiateEntity(name, msg);
bool ok = true;
......
auto entity = EntityInstanceFactory::createInstance(name);
QString internMsg = "";
if (entity) {
internMsg = name + " is instanceable!";
internMsg = name + " is instantiable.";
qInfo() << internMsg;
} else {
internMsg = name + " is NOT instanceable!";
internMsg = name + " is NOT instantiable!";
qCritical() << internMsg;
}
msg += internMsg + "\n";
......
for (auto i = relations.constBegin(); i != relations.constEnd(); ++i) {
this->checkRelationTypos(i.key(), i.value(), iMsg, ok);
if (!metaProperties.contains(i.key())) {
iMsg += "For relation " + i.key() + " no property exists.";
iMsg += "For relation " + i.key() + " no property exists!";
ok = false;
} else {
auto metaProperty = metaProperties.value(i.key());
if (!QString(metaProperty.typeName()).contains("QSharedPointer")) {
iMsg += "Property " + QString(metaProperty.name()) +
" must be a type like QList<QSharedPointer<T>> or simply QSharedPointer<T>";
" must be a type like QList<QSharedPointer<T>> or simply QSharedPointer<T>.";
} else {
auto var = metaProperty.read(entity);
bool rel = this->checkRelation(var, i.value(), msg, metaProperty);
if (!rel) {
ok = false;
} else {
this->checkRelationMappings(metaProperty, i.value(), msg, ok);
}
}
}
......
}
}
void EntityInspector::checkRelationMappings(QMetaProperty &property,
const Relation &r, QString &msg, bool &ok) {
QString foreignEntityName = EntityInstanceFactory::extractEntityType(
property.typeName());
auto foreignInstance = EntityInstanceFactory::createInstance(foreignEntityName);
if (foreignInstance) {
auto foreignRelations = EntityHelper::getRelationProperties(foreignInstance);
int foundMappedBy = 0;
bool foundForeignMappedRelation = false;
for (auto i = foreignRelations.constBegin(); i != foreignRelations.constEnd();
++i) {
if (r.getMappedBy().isEmpty()
&& i.key().getPropertyName() == r.getPropertyName()) {
++foundMappedBy;
} else if (!r.getMappedBy().isEmpty()
&& r.getMappedBy() == i.key().getPropertyName()) {
foundForeignMappedRelation = true;
break;
}
}
if (r.getMappedBy().isEmpty()) {
if (foundMappedBy == 0) {
msg += "Optional: The relation " + r.getPropertyName() +
" is not mapped in foreign class " + foreignEntityName +
". You could map it.\n";
} else if (foundMappedBy > 1) {
msg += "The relation " + r.getPropertyName() + " is mapped several times (" +
QString::number(foundMappedBy) + ") by foreign class " + foreignEntityName +
". You should map it only once!\n";
ok = false;
}
} else if (!foundForeignMappedRelation) {
msg += "Relation " + r.getPropertyName() + " with mappedBy attribute " +
r.getMappedBy() + " has no mapped relation in " + foreignEntityName +
" class!\n";
ok = false;
}
} else {
msg += "Can't create object for property/relation " + r.getPropertyName() +
"!\n";
msg += "Classname: " + foreignEntityName + "\n";
msg += "Is the class registered?\n";
ok = false;
}
}
bool EntityInspector::checkPrimaryKey(Entity *&entity, QString &msg) {
QString pk = entity->getPrimaryKey();
auto metaprops = EntityHelper::getMetaProperties(entity);

Auch abrufbar als: Unified diff