Revision 95b60eb2
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/database.cpp | ||
---|---|---|
|
||
|
||
bool Database::commitTransaction() {
|
||
if (this->supportTransactions && !this->database.commit()) {
|
||
this->database.rollback();
|
||
return false;
|
||
}
|
||
return true;
|
||
this->supportTransactions &&this->database.commit();
|
||
}
|
||
|
||
bool Database::rollbackTransaction() {
|
||
return supportTransactions && this->database.rollback();
|
||
}
|
||
|
||
DatabaseType Database::getDatabaseType(QString s) {
|
src/database.h | ||
---|---|---|
QSqlQuery select(const QString &query);
|
||
void startTransaction();
|
||
bool commitTransaction();
|
||
bool rollbackTransaction();
|
||
|
||
static DatabaseType getDatabaseType(QString s);
|
||
static QSharedPointer<Schema> getSchema(int db,
|
||
QSharedPointer<Database> database);
|
src/entitymanager.cpp | ||
---|---|---|
bool rc = false;
|
||
this->db->startTransaction();
|
||
this->removeRelations(entity);
|
||
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->remove(entity);
|
||
if (q.exec() && this->db->commitTransaction()) {
|
||
auto queries = this->schema.data()->getQueryBuilder().data()->remove(entity);
|
||
bool ok = true;
|
||
for (int var = 0; var < queries.size(); ++var) {
|
||
auto q = queries.at(var);
|
||
if (!q.exec()) {
|
||
this->db->rollbackTransaction();
|
||
qDebug() << "Remove transaction rolled back";
|
||
ok = false;
|
||
break;
|
||
}
|
||
}
|
||
if (ok && this->db->commitTransaction()) {
|
||
this->cache.remove(entity);
|
||
entity.clear();
|
||
rc = true;
|
src/entitymanager.h | ||
---|---|---|
*@TODO use conditions
|
||
*/
|
||
/**
|
||
* @TODO Inheritance at create,save,merge,remove
|
||
* @TODO Inheritance at create,save,merge
|
||
*/
|
||
template<class T> qint8 count(QHash<QString, QString> condition =
|
||
QHash<QString, QString>()) {
|
src/querybuilder.cpp | ||
---|---|---|
return r;
|
||
}
|
||
|
||
QSqlQuery QueryBuilder::find(const qint64 &id, const QSharedPointer<Entity> &entity, qint64 offset) const
|
||
{
|
||
QSqlQuery QueryBuilder::find(const qint64 &id,
|
||
const QSharedPointer<Entity> &entity, qint64 offset) const {
|
||
QSqlQuery q = this->database.data()->getQuery(this->selectBase(QStringList(
|
||
entity.data()->getTablename())) + this->joinSuperClasses(
|
||
entity) + " WHERE id= :id" + this->limit(1, offset));
|
||
... | ... | |
return this->database->getQuery(this->selectBase(QStringList(tableName)) + ";");
|
||
}
|
||
|
||
QSqlQuery QueryBuilder::remove(const QSharedPointer<Entity> &entity) const {
|
||
QList<QSqlQuery> QueryBuilder::remove(const QSharedPointer<Entity> &entity)
|
||
const {
|
||
QList<QSqlQuery> queries = QList<QSqlQuery>();
|
||
if (entity.data()->getInheritanceStrategy() != PER_CLASS_TABLE) {
|
||
auto stack = entity.data()->superClasses(true);
|
||
while (!stack.isEmpty()) {
|
||
auto item = stack.pop();
|
||
auto instance = EntityInstanceFactory::createInstance(item->className());
|
||
if (instance) {
|
||
queries.append(this->remove(instance->getTablename(), entity.data()->getId()));
|
||
delete instance;
|
||
instance = 0;
|
||
}
|
||
}
|
||
}
|
||
queries.append(this->remove(entity.data()->getTablename(),
|
||
entity.data()->getId()));
|
||
return queries;
|
||
}
|
||
|
||
|
||
QSqlQuery QueryBuilder::remove(const QString &tableName,
|
||
const qint64 &id) const {
|
||
QSqlQuery q = this->database->getQuery("DELETE FROM " +
|
||
this->schema.data()->quoteTableName(
|
||
entity.data()->getTablename()) + " WHERE " +
|
||
tableName) + " WHERE " +
|
||
this->schema.data()->quoteColumnName("id") + "=:id;");
|
||
q.bindValue(":id", entity.data()->getId());
|
||
q.bindValue(":id", id);
|
||
return q;
|
||
}
|
||
|
||
|
||
QSqlQuery QueryBuilder::findId(const QSharedPointer<Entity> &entity) const {
|
||
QHash<QString, QVariant> values = this->getEntityAttributes(
|
||
entity.data()->getMetaProperties(),
|
src/querybuilder.h | ||
---|---|---|
QSqlQuery findAll(const QString &tableName) const;
|
||
QSqlQuery findAll(const QSharedPointer<Entity> &entity, const qint64 limit = 0,
|
||
qint64 offset = 0);
|
||
QSqlQuery remove(const QSharedPointer<Entity> &entity) const;
|
||
QList<QSqlQuery> remove(const QSharedPointer<Entity> &entity) const;
|
||
QSqlQuery findId(const QSharedPointer<Entity> &entity) const;
|
||
QSqlQuery count(const QSharedPointer<Entity> &entity, bool ignoreID) const;
|
||
QSqlQuery count(const QString &tableName) const;
|
||
... | ... | |
QSqlQuery getQuery() const;
|
||
|
||
protected:
|
||
QSqlQuery remove(const QString &tableName, const qint64 &id) const;
|
||
virtual void createRelationFK(QStringList &queries,
|
||
const QSharedPointer<Entity> &entity, const Relation &relation,
|
||
const QMetaProperty &metaProperty, const QString &update,
|
Auch abrufbar als: Unified diff
remove inheritance