Revision 01fe6db3
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
samples/example/main.cpp | ||
---|---|---|
// SqliteBackupProcessor *sqliteproc = new SqliteBackupProcessor(e->getDb(),
|
||
// QDir::currentPath());
|
||
// qWarning() << "DB Loaded:" << sqliteproc->sqliteDBMemFile(false, "db.sqlite");
|
||
qDebug() << "EntityManagerObjectName:" << e->objectName();
|
||
qDebug() << "EntityManagerObjectName:" << e->objectName();
|
||
QThread *entityManager = new QThread();
|
||
e->moveToThread(entityManager);
|
||
qWarning() << "-----------------------------";
|
||
... | ... | |
QSharedPointer<Group> groupFindPtr = groups.at(0);
|
||
qWarning() << "Group:" << groupFindPtr->toString();
|
||
qWarning() << "MainTeacher:" << groupFindPtr->getMainTeacher()->toString();
|
||
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Person By Id Version 1";
|
||
qWarning() << "-----------------------------";
|
||
|
||
QSharedPointer<Entity> personFindPtr = e->findById(1, QString("Person"));
|
||
qDebug() << "HASCHANGED:" << e->hasChanged(personFindPtr);
|
||
e->refresh(personFindPtr);
|
||
... | ... | |
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Person By Id Version 2";
|
||
qWarning() << "-----------------------------";
|
||
|
||
QSharedPointer<Person> foundMainTeacher = e->findById<Person>(1);
|
||
qWarning() << "FoundMainTeacher:" << foundMainTeacher->toString();
|
||
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Pupil with Query Class";
|
||
qWarning() << "-----------------------------";
|
||
|
||
Query q = Query();
|
||
q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim"),
|
||
JokerPosition::BEHIND));
|
||
q.appendWhere(e->getQueryBuilder()->andOperator());
|
||
q.appendWhere(e->getQueryBuilder()->arbitraryOperator("<", "birthday",
|
||
QDate(2000, 10, 10)));
|
||
//q.appendJoin(Join("person", "pupil.id = person.id"));
|
||
q.setDistinct(true);
|
||
q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
q.setLimit(10);
|
||
... | ... | |
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Pupil by Attributes";
|
||
qWarning() << "-----------------------------";
|
||
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["familyName"] = QString("Dunst");
|
||
QSharedPointer<Pupil> pupil = e->findEntityByAttributes<Pupil>
|
||
... | ... | |
qWarning() << "Remove Group";
|
||
qWarning() << "-----------------------------";
|
||
e->remove(entityGroupFindPtr);
|
||
|
||
//sqliteproc->sqliteDBMemFile(true, "db.sqlite");
|
||
qWarning() << "Duration:" << t.elapsed();
|
||
// delete sqliteproc;
|
src/database.h | ||
---|---|---|
#define DEFAULTMSGTYPE MsgType::CRITICAL
|
||
#endif
|
||
class Database {
|
||
private:
|
||
QSqlDatabase database;
|
||
QString connectionName;
|
||
bool supportTransactions;
|
||
Logger *logger = nullptr;
|
||
void init();
|
||
void initLogger(bool logQueries, bool logErrors, MsgType type);
|
||
bool logQueries;
|
||
bool logErrors;
|
||
|
||
public:
|
||
Database(QSqlDatabase database, bool logQueries = false, bool logErrors = true, MsgType type = DEFAULTMSGTYPE);
|
||
Database(QSqlDatabase database, bool logQueries = false, bool logErrors = true,
|
||
MsgType type = DEFAULTMSGTYPE);
|
||
~Database();
|
||
Database(QString databaseType, QString connectionName = QString(""),
|
||
QString hostname = QString(""),
|
||
... | ... | |
bool rollbackTransaction();
|
||
static DatabaseType getDatabaseType(QString s);
|
||
static Schema *getSchema(DatabaseType db,
|
||
QSharedPointer<Database> database);
|
||
QSharedPointer<Database> database);
|
||
Logger *getLogger() const;
|
||
private:
|
||
QSqlDatabase database;
|
||
QString connectionName;
|
||
bool supportTransactions;
|
||
Logger *logger = nullptr;
|
||
void init();
|
||
void initLogger(bool logQueries, bool logErrors, MsgType type);
|
||
bool logQueries;
|
||
bool logErrors;
|
||
};
|
||
}
|
||
#endif // DATABASE_H
|
src/query.cpp | ||
---|---|---|
return qb->where(condition, values);
|
||
}
|
||
|
||
Expression Query::equal(const QSharedPointer<QueryBuilder> &qb, QString &key,
|
||
QVariant &value) const {
|
||
Expression Query::equal(const QSharedPointer<QueryBuilder> &qb, QString key,
|
||
QVariant value) const {
|
||
return qb->equal(key, value);
|
||
}
|
||
|
||
Expression Query::notEqual(const QSharedPointer<QueryBuilder> &qb, QString &key,
|
||
QVariant &value) const {
|
||
Expression Query::notEqual(const QSharedPointer<QueryBuilder> &qb, QString key,
|
||
QVariant value) const {
|
||
return qb->notEqual(key, value);
|
||
}
|
||
|
src/query.h | ||
---|---|---|
QString conjunction = QStringLiteral("AND")) const;
|
||
Expression whereCondition(const QSharedPointer<QueryBuilder> &qb, QString condition,
|
||
QHash<QString, QVariant> values = QHash<QString, QVariant>()) const;
|
||
Expression equal(const QSharedPointer<QueryBuilder> &qb, QString &key, QVariant &value) const;
|
||
Expression notEqual(const QSharedPointer<QueryBuilder> &qb, QString &key,
|
||
QVariant &value) const;
|
||
Expression equal(const QSharedPointer<QueryBuilder> &qb, QString key, QVariant value) const;
|
||
Expression notEqual(const QSharedPointer<QueryBuilder> &qb, QString key,
|
||
QVariant value) const;
|
||
Expression between(const QSharedPointer<QueryBuilder> &qb, QString column,
|
||
QVariant firstValue,
|
||
QVariant secondValue) const;
|
src/querybuilder.cpp | ||
---|---|---|
return joined;
|
||
}
|
||
|
||
//QHash<QString, QVariant> values
|
||
|
||
Expression QueryBuilder::where(QHash<QString, QVariant> conditions,
|
||
QString conjunction) const {
|
||
Expression exp = Expression(this->where(conditions, conjunction, false, "id",
|
src/schema.cpp | ||
---|---|---|
|
||
QString Schema::decimal(int precision, int scale, bool notNull,
|
||
QString defaultValue, bool unique, QString checkConstraint) const {
|
||
|
||
return this->buildColumnSchema(TYPE_DECIMAL,
|
||
this->combineScaleAndPrecision(precision, scale), notNull, defaultValue,
|
||
unique, checkConstraint);
|
||
... | ... | |
return name.indexOf("`") != -1 || name == "*" ? name : ("`" + name + "`");
|
||
}
|
||
|
||
QHash<QString, QSharedPointer<TableSchema> > Schema::getTableSchemas(
|
||
QString schema, bool refresh) {
|
||
QHash<QString, QSharedPointer<TableSchema>> Schema::getTableSchemas(
|
||
QString schema, bool refresh) {
|
||
QStringList names = this->getTableNames();
|
||
for (int i = 0; i < names.size(); ++i) {
|
||
QString name = names.at(i);
|
||
... | ... | |
return this->database->getDatabase().tables().contains(tblname);
|
||
}
|
||
|
||
bool Schema::containsColumn(QString tblName, QString colName) {
|
||
bool r = false;
|
||
if(this->containsTable(tblName)) {
|
||
r = this->tables.value(tblName)->containsColumn(colName);
|
||
}
|
||
return r;
|
||
}
|
||
|
||
QSharedPointer<TableSchema> Schema::getTableSchema(QString name, bool refresh) {
|
||
if (this->tables.contains(name) && !refresh) {
|
||
return this->tables.value(name);
|
||
... | ... | |
return queryBuilder;
|
||
}
|
||
|
||
QSharedPointer<QHash<QString, QString> > Schema::getAbstractTypeMap() const {
|
||
QSharedPointer<QHash<QString, QString>> Schema::getAbstractTypeMap() const {
|
||
return abstractTypeMap;
|
||
}
|
||
|
||
void Schema::setAbstractTypeMap(const QSharedPointer<QHash<QString, QString> >
|
||
void Schema::setAbstractTypeMap(const QSharedPointer<QHash<QString, QString>>
|
||
&value) {
|
||
abstractTypeMap = value;
|
||
}
|
||
... | ... | |
}
|
||
|
||
|
||
QHash<QString, QSharedPointer<TableSchema> > Schema::getTables() {
|
||
QHash<QString, QSharedPointer<TableSchema>> Schema::getTables() {
|
||
if (this->tables.size() != this->getTableNames().size()) {
|
||
this->setTables(this->getTableSchemas());
|
||
}
|
||
return this->tables;
|
||
}
|
||
|
||
void Schema::setTables(const QHash<QString, QSharedPointer<TableSchema> >
|
||
void Schema::setTables(const QHash<QString, QSharedPointer<TableSchema>>
|
||
&value) {
|
||
tables = value;
|
||
}
|
src/schema.h | ||
---|---|---|
virtual void refresh();
|
||
virtual QString getRawTable(QString name);
|
||
virtual bool containsTable(QString tblname);
|
||
virtual bool containsColumn(QString tblName, QString colName);
|
||
|
||
QHash<QString, QSharedPointer<TableSchema> > getTables();
|
||
void setTables(const QHash<QString, QSharedPointer<TableSchema> > &value);
|
src/tableschema.cpp | ||
---|---|---|
return QSharedPointer<QSqlField>();
|
||
}
|
||
|
||
bool TableSchema::containsColumn(QString name) const {
|
||
return this->columns.contains(name);
|
||
}
|
||
|
||
const QStringList TableSchema::getColumnNames() {
|
||
QStringList l;
|
||
auto columns = this->getColumns();
|
||
... | ... | |
sequenceName = value;
|
||
}
|
||
|
||
QHash<QString, QSharedPointer<QSqlField> > TableSchema::getColumns() const {
|
||
QHash<QString, QSharedPointer<QSqlField>> TableSchema::getColumns() const {
|
||
return columns;
|
||
}
|
||
|
||
void TableSchema::setColumns(const QHash<QString, QSharedPointer<QSqlField> >
|
||
void TableSchema::setColumns(const QHash<QString, QSharedPointer<QSqlField>>
|
||
&value) {
|
||
columns = value;
|
||
}
|
||
QHash<QString, QSharedPointer<QSqlRelation> > TableSchema::getRelations()
|
||
QHash<QString, QSharedPointer<QSqlRelation>> TableSchema::getRelations()
|
||
const {
|
||
return relations;
|
||
}
|
||
|
||
void TableSchema::setRelations(
|
||
const QHash<QString, QSharedPointer<QSqlRelation> > &value) {
|
||
const QHash<QString, QSharedPointer<QSqlRelation>> &value) {
|
||
relations = value;
|
||
}
|
||
|
src/tableschema.h | ||
---|---|---|
TableSchema();
|
||
virtual ~TableSchema();
|
||
virtual QSharedPointer<QSqlField> const getColumn(QString name) const;
|
||
virtual bool containsColumn(QString name) const;
|
||
virtual const QStringList getColumnNames();
|
||
|
||
QString getSchemaName() const;
|
src/validators/comparevalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef COMPAREVALIDATOR_H
|
||
#define COMPAREVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/datevalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef DATEVALIDATOR_H
|
||
#define DATEVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/defaultvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef DEFAULTVALIDATOR_H
|
||
#define DEFAULTVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/emailvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef EMAILVALIDATOR_H
|
||
#define EMAILVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/errormsg.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef ERRORMSG_H
|
||
#define ERRORMSG_H
|
||
#include <QString>
|
src/validators/existvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef EXISTVALIDATOR_H
|
||
#define EXISTVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/filevalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef FILEVALIDATOR_H
|
||
#define FILEVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/imagevalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef IMAGEVALIDATOR_H
|
||
#define IMAGEVALIDATOR_H
|
||
#include "filevalidator.h"
|
src/validators/lengthvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef LENGTHVALIDATOR_H
|
||
#define LENGTHVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/numbervalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef NUMBERVALIDATOR_H
|
||
#define NUMBERVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/param.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef PARAM_H
|
||
#define PARAM_H
|
||
|
src/validators/patternvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef PATTERNVALIDATOR_H
|
||
#define PATTERNVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/requiredvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef REQUIREDVALIDATOR_H
|
||
#define REQUIREDVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/uniquevalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef UNIQUEVALIDATOR_H
|
||
#define UNIQUEVALIDATOR_H
|
||
#include "validator.h"
|
src/validators/urlvalidator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef URLVALIDATOR_H
|
||
#define URLVALIDATOR_H
|
||
|
src/validators/validator.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef VALIDATOR_H
|
||
#define VALIDATOR_H
|
||
|
src/validators/validatorfactory.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef VALIDATORFACTORY_H
|
||
#define VALIDATORFACTORY_H
|
||
#include <QString>
|
src/validators/validatorrule.h | ||
---|---|---|
/*
|
||
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify it
|
||
* under the terms of the GNU Lesser General Public License as published by
|
||
* the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
* for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#ifndef VALIDATORATTRIBUTE_H
|
||
#define VALIDATORATTRIBUTE_H
|
||
#include <QString>
|
tests/em/tst_em.cpp | ||
---|---|---|
CuteEntityManager::EntityInstanceFactory::registerClass<Employee>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<WorkerGroup>();
|
||
this->e = new CuteEntityManager::EntityManager("QSQLITE",
|
||
":memory:", "", "", "", "", true, "foreign_keys = ON",false);
|
||
":memory:", "", "", "", "", true, "foreign_keys = ON", false);
|
||
}
|
||
|
||
void EmTest::cleanupTestCase() {
|
tests/em/tst_querybuilder.cpp | ||
---|---|---|
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 11, 11), "A"));
|
||
QSharedPointer<Person> p4 = QSharedPointer<Person>(new Person("Fenja", "Neu",
|
||
Person::Gender::FEMALE, "fenja2.jpeg", "", "Fenni", QDate(1980, 5, 30)));
|
||
QSharedPointer<Employee> p5 = QSharedPointer<Employee>(new Employee(90, "Milan", "Mes.",
|
||
Person::Gender::MALE, "milan.jpeg", "", "", QDate(1994, 3, 27), "D"));
|
||
QSharedPointer<Person> p6 = QSharedPointer<Person>(new Person("Kristina", "Zero",
|
||
Person::Gender::FEMALE, "kristina.jpeg", "", "", QDate(1996, 5, 17)));
|
||
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("Group Psy"));
|
||
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("Group Health"));
|
||
g->setLeader(p1);
|
||
... | ... | |
auto gEnt = g.objectCast<Entity>();
|
||
auto g2Ent = g2.objectCast<Entity>();
|
||
auto wgEnt = wg.objectCast<Entity>();
|
||
auto p5Ent = p5.objectCast<Entity>();
|
||
auto p6Ent = p6.objectCast<Entity>();
|
||
try {
|
||
QVERIFY(this->e->save(p5Ent));
|
||
QVERIFY(this->e->save(gEnt));
|
||
QVERIFY(this->e->save(wgEnt));
|
||
QVERIFY(this->e->save(g2Ent));
|
||
QVERIFY(this->e->save(p6Ent));
|
||
} catch(QString s) {
|
||
qWarning() << s;
|
||
}
|
||
... | ... | |
}
|
||
|
||
void QuerybuilderTest::testQueryBuilder() {
|
||
// Query q = Query();
|
||
// q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim"),
|
||
// JokerPosition::BEHIND));
|
||
// q.appendWhere(e->getQueryBuilder()->andOperator());
|
||
// q.appendWhere(e->getQueryBuilder()->arbitraryOperator("<", "birthday",
|
||
// QDate(2000, 10, 10)));
|
||
// //q.appendJoin(Join("person", "pupil.id = person.id"));
|
||
// q.setDistinct(true);
|
||
// q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
// q.setLimit(10);
|
||
// QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q, true);
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.like(qb, QString("firstName"), QString("Fenj"),
|
||
JokerPosition::BEHIND));
|
||
q.setLimit(10);
|
||
QList<QSharedPointer<Person>> list = e->find<Person>(q);
|
||
QCOMPARE(list.size(), 2);
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderEntityInheritance() {
|
||
auto qb = e->getQueryBuilder();
|
||
QSharedPointer<Employee> emp = QSharedPointer<Employee>(new Employee());
|
||
Query q = Query();
|
||
q.appendJoins(q.joinBaseClasses(qb, emp));
|
||
try {
|
||
QList<QSharedPointer<Employee>> list = e->find<Employee>(q);
|
||
QCOMPARE(list.size(), 3);
|
||
} catch(QString e) {
|
||
qWarning() << e;
|
||
QFAIL("Exception");
|
||
}
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderEntityInheritanceWithoutJoin() {
|
||
Query q = Query();
|
||
try {
|
||
QList<QSharedPointer<Employee>> list = e->find<Employee>(q, true);
|
||
QCOMPARE(list.size(), 3);
|
||
} catch(QString e) {
|
||
qWarning() << e;
|
||
QFAIL("Exception");
|
||
}
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderArbitraryOperator() {
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.arbitraryOperator(qb, "<", "birthday",
|
||
QDate(1991, 10, 10)));
|
||
q.setDistinct(true);
|
||
q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
q.setLimit(10);
|
||
QList<QSharedPointer<Person>> list = e->find<Person>(q, true);
|
||
QCOMPARE(list.size(), 2);
|
||
QCOMPARE(list.at(0)->getFirstName(), QString("Janine"));
|
||
QCOMPARE(list.at(1)->getFirstName(), QString("Lucien"));
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderJoins() {
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.equal(qb, "firstName", "Kristina"));
|
||
q.appendJoin(Join("person", "person.id = employee.id"));
|
||
QList<QSharedPointer<Employee>> list = e->find<Employee>(q, false);
|
||
QCOMPARE(list.size(), 1);
|
||
QCOMPARE(list.at(0)->getFirstName(), QString("Kristina"));
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderManyToOneRelation() {
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.equal(qb, "persNumber", 42));
|
||
QList<QSharedPointer<Employee>> list = e->find<Employee>(q, true);
|
||
QCOMPARE(list.size(), 1);
|
||
QCOMPARE(list.at(0)->getNickName(), QString("Lotta"));
|
||
q = Query();
|
||
q.appendWhere(q.equal(qb, "leader", QVariant(list.at(0))));
|
||
QList<QSharedPointer<Group>> groupList = e->find<Group>(q, false);
|
||
QCOMPARE(groupList.size(), 1);
|
||
QCOMPARE(groupList.at(0)->getName(), QString("Group Health"));
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderManyToOneRelationAttribute() {
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.equal(qb, "leader.firstName", QString("Fenja")));
|
||
QList<QSharedPointer<Group>> groupList = e->find<Group>(q, false, false);
|
||
QCOMPARE(groupList.size(), 1);
|
||
QCOMPARE(groupList.at(0)->getName(), QString("Group Health"));
|
||
QCOMPARE(groupList.at(0)->getPersons().size(), 0);
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderManyToManyRelation() {
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.equal(qb, "persNumber", 42));
|
||
QList<QSharedPointer<Employee>> list = e->find<Employee>(q, true);
|
||
QCOMPARE(list.size(), 1);
|
||
QCOMPARE(list.at(0)->getNickName(), QString("Lotta"));
|
||
q = Query();
|
||
q.appendWhere(q.equal(qb, "persons", QVariant(list.at(0))));
|
||
QList<QSharedPointer<Group>> groupList = e->find<Group>(q, false);
|
||
QCOMPARE(groupList.size(), 1);
|
||
QCOMPARE(groupList.at(0)->getName(), QString("Group Health"));
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderManyToManyRelationAttribute() {
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
q.appendWhere(q.equal(qb, "persons.firstName", QString("Janine")));
|
||
QList<QSharedPointer<Group>> groupList = e->find<Group>(q, false);
|
||
QCOMPARE(groupList.size(), 1);
|
||
QCOMPARE(groupList.at(0)->getName(), QString("Group Psy"));
|
||
QCOMPARE(groupList.at(0)->getPersons().size(), 3);
|
||
}
|
tests/em/tst_querybuilder.h | ||
---|---|---|
void testFindByAttributesManyToManyRelationWithList();
|
||
void testFindByAttributesManyToManyRelationAttribute();
|
||
void testQueryBuilder();
|
||
void testQueryBuilderEntityInheritance();
|
||
void testQueryBuilderEntityInheritanceWithoutJoin();
|
||
void testQueryBuilderArbitraryOperator();
|
||
void testQueryBuilderJoins();
|
||
void testQueryBuilderManyToOneRelation();
|
||
void testQueryBuilderManyToOneRelationAttribute();
|
||
void testQueryBuilderManyToManyRelation();
|
||
void testQueryBuilderManyToManyRelationAttribute();
|
||
|
||
private:
|
||
CuteEntityManager::EntityManager *e;
|
||
};
|
Auch abrufbar als: Unified diff
included license texts, completed for new query builder test