Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2fedfe76

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 2fedfe763af5db9dd9aa9b8573eacb58dc0f5aae
  • Vorgänger 409ca288
  • Nachfolger 790ec827

ticket #582 and startup method improvement

Unterschiede anzeigen:

src/entitymanager.cpp
QString c = toInitialize.at(var);
auto entity = QSharedPointer<Entity>
(EntityInstanceFactory::createInstance(c));
ok = this->createTable(entity);
ok = this->createTable(entity, false);
entities.append(entity);
} else {
qWarning() << "startup of version " << version << " failed";
qWarning() << "erroneous entity:" << (var == 0 ? "null, this should not happen!" : toInitialize.at(
var - 1));
break;
}
}
if (createIndices) {
if (ok) {
for (int i = 0; i < entities.size(); ++i) {
ok = this->schema->getQueryBuilder()->createRelationTables(entities.at(i));
if (!ok) {
break;
}
}
}
if (ok && createIndices) {
for (int i = 0; i < entities.size(); ++i) {
ok = this->schema->getQueryBuilder()->createIndices(entities.at(i));
if (!ok) {
break;
}
}
}
if (ok) {
src/querybuilder.cpp
if (!rc) {
QSqlQuery q = this->database->getQuery(this->createTable(tableName,
tableDefinition));
if (this->database->exec(q)) {
if (createRelationTables) {
auto relTables = this->generateRelationTables(entity);
auto i = relTables.constBegin();
while (i != relTables.constEnd()) {
auto query = this->database->getQuery(this->createTable(i.key(),
i.value()));
this->database->exec(query);
++i;
}
}
this->schema->getTableSchema(tableName);
if (this->database->exec(q) && (!createRelationTables || (createRelationTables
&& this->createRelationTables(entity)))) {
rc = true;
} else {
qWarning() << "Table " << entity->getTablename() << " could not be created.";
}
this->schema->getTableSchema(tableName);
}
}
return rc;
}
bool QueryBuilder::createRelationTables(const QSharedPointer<Entity> &entity)
const {
bool ok = true;
auto relTables = this->generateRelationTables(entity);
auto i = relTables.constBegin();
while (i != relTables.constEnd()) {
auto query = this->database->getQuery(this->createTable(i.key(), i.value()));
if (!this->database->exec(query)) {
ok = false;
qWarning() << "Relational table for table " << entity->getTablename() <<
" could not be created." << " Tablename:" << i.key();
break;
}
++i;
}
return ok;
}
bool QueryBuilder::createIndices(const QSharedPointer<Entity> &entity) const {
bool ok = true;
QStringList queries = QStringList();
src/querybuilder.h
virtual bool createIndices(const QSharedPointer<Entity> &entity) const;
virtual QString createTable(const QString &tableName,
const QHash<QString, QString> &tableDefinition) const;
virtual bool createRelationTables(const QSharedPointer<Entity> &entity) const;
virtual QString createTableQuery(const QString &tableName,
const QHash<QString, QString> &tableDefinition) const;
virtual QString renameTable(QString tableName, QString newName) const;

Auch abrufbar als: Unified diff