commit 01fe6db345d30c37fdc7e7634320b8af5397fde3
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Sun Dec 6 00:42:28 2015 +0100

    included license texts, completed for new query builder test

diff --git a/samples/example/main.cpp b/samples/example/main.cpp
index d435163..ab8ecf6 100644
--- a/samples/example/main.cpp
+++ b/samples/example/main.cpp
@@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
 //    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() << "-----------------------------";
@@ -76,11 +76,9 @@ qDebug() << "EntityManagerObjectName:" << e->objectName();
     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);
@@ -89,21 +87,17 @@ qDebug() << "EntityManagerObjectName:" << e->objectName();
     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);
@@ -120,7 +114,6 @@ qDebug() << "EntityManagerObjectName:" << e->objectName();
     qWarning() << "-----------------------------";
     qWarning() << "Find Pupil by Attributes";
     qWarning() << "-----------------------------";
-
     QHash<QString, QVariant> attributes;
     attributes["familyName"] = QString("Dunst");
     QSharedPointer<Pupil> pupil = e->findEntityByAttributes<Pupil>
@@ -137,7 +130,6 @@ qDebug() << "EntityManagerObjectName:" << e->objectName();
     qWarning() << "Remove Group";
     qWarning() << "-----------------------------";
     e->remove(entityGroupFindPtr);
-
     //sqliteproc->sqliteDBMemFile(true, "db.sqlite");
     qWarning() << "Duration:" << t.elapsed();
 //    delete sqliteproc;
diff --git a/src/database.h b/src/database.h
index 70dbbdb..fefc931 100644
--- a/src/database.h
+++ b/src/database.h
@@ -34,18 +34,10 @@ namespace CuteEntityManager {
 #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(""),
@@ -73,8 +65,17 @@ class Database {
     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
diff --git a/src/query.cpp b/src/query.cpp
index 3870392..b2aa54d 100644
--- a/src/query.cpp
+++ b/src/query.cpp
@@ -111,13 +111,13 @@ Expression Query::whereCondition(const QSharedPointer<QueryBuilder> &qb,
     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);
 }
 
diff --git a/src/query.h b/src/query.h
index b1335b6..5c92388 100644
--- a/src/query.h
+++ b/src/query.h
@@ -124,9 +124,9 @@ class Query {
                      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;
diff --git a/src/querybuilder.cpp b/src/querybuilder.cpp
index 4d8e701..96458bb 100644
--- a/src/querybuilder.cpp
+++ b/src/querybuilder.cpp
@@ -1288,8 +1288,6 @@ const {
     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",
diff --git a/src/schema.cpp b/src/schema.cpp
index 8f6db2c..cc0aca8 100644
--- a/src/schema.cpp
+++ b/src/schema.cpp
@@ -86,7 +86,6 @@ QString Schema::doubleColumn(int precision, bool notNull, QString defaultValue,
 
 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);
@@ -194,8 +193,8 @@ QString Schema::quoteSimpleColumnName(QString name) {
     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);
@@ -237,6 +236,14 @@ bool Schema::containsTable(QString tblname) {
     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);
@@ -260,11 +267,11 @@ QSharedPointer<QueryBuilder> Schema::getQueryBuilder() const {
     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;
 }
@@ -353,14 +360,14 @@ bool Schema::findColumns(const QSharedPointer<TableSchema> &ts) {
 }
 
 
-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;
 }
diff --git a/src/schema.h b/src/schema.h
index f391a41..aa55739 100644
--- a/src/schema.h
+++ b/src/schema.h
@@ -106,6 +106,7 @@ class Schema {
     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);
diff --git a/src/tableschema.cpp b/src/tableschema.cpp
index 3fd1563..4eb35fc 100644
--- a/src/tableschema.cpp
+++ b/src/tableschema.cpp
@@ -32,6 +32,10 @@ const QSharedPointer<QSqlField> TableSchema::getColumn(QString name) const {
     return QSharedPointer<QSqlField>();
 }
 
+bool TableSchema::containsColumn(QString name) const {
+    return this->columns.contains(name);
+}
+
 const QStringList TableSchema::getColumnNames() {
     QStringList l;
     auto columns = this->getColumns();
@@ -77,21 +81,21 @@ void TableSchema::setSequenceName(const QString &value) {
     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;
 }
 
diff --git a/src/tableschema.h b/src/tableschema.h
index c14611a..36ae405 100644
--- a/src/tableschema.h
+++ b/src/tableschema.h
@@ -30,6 +30,7 @@ class TableSchema {
     TableSchema();
     virtual ~TableSchema();
     virtual QSharedPointer<QSqlField> const getColumn(QString name) const;
+    virtual bool containsColumn(QString name) const;
     virtual const QStringList getColumnNames();
 
     QString getSchemaName() const;
diff --git a/src/validators/comparevalidator.h b/src/validators/comparevalidator.h
index a24df9c..7399a36 100644
--- a/src/validators/comparevalidator.h
+++ b/src/validators/comparevalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/datevalidator.h b/src/validators/datevalidator.h
index 81d0f00..39b16b4 100644
--- a/src/validators/datevalidator.h
+++ b/src/validators/datevalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/defaultvalidator.h b/src/validators/defaultvalidator.h
index ecb18fb..ab58818 100644
--- a/src/validators/defaultvalidator.h
+++ b/src/validators/defaultvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/emailvalidator.h b/src/validators/emailvalidator.h
index b4972f0..ec69c7b 100644
--- a/src/validators/emailvalidator.h
+++ b/src/validators/emailvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/errormsg.h b/src/validators/errormsg.h
index 69f56f0..50e9ecd 100644
--- a/src/validators/errormsg.h
+++ b/src/validators/errormsg.h
@@ -1,3 +1,18 @@
+/*
+ * 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>
diff --git a/src/validators/existvalidator.h b/src/validators/existvalidator.h
index cb2ac39..a6e7386 100644
--- a/src/validators/existvalidator.h
+++ b/src/validators/existvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/filevalidator.h b/src/validators/filevalidator.h
index d9b0b8f..46308a9 100644
--- a/src/validators/filevalidator.h
+++ b/src/validators/filevalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/imagevalidator.h b/src/validators/imagevalidator.h
index 413e9f1..546dd31 100644
--- a/src/validators/imagevalidator.h
+++ b/src/validators/imagevalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/lengthvalidator.h b/src/validators/lengthvalidator.h
index dc1b80e..1c84494 100644
--- a/src/validators/lengthvalidator.h
+++ b/src/validators/lengthvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/numbervalidator.h b/src/validators/numbervalidator.h
index dde1606..f3df580 100644
--- a/src/validators/numbervalidator.h
+++ b/src/validators/numbervalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/param.h b/src/validators/param.h
index 716112d..93add64 100644
--- a/src/validators/param.h
+++ b/src/validators/param.h
@@ -1,3 +1,18 @@
+/*
+ * 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
 
diff --git a/src/validators/patternvalidator.h b/src/validators/patternvalidator.h
index bd1aedf..7f160b3 100644
--- a/src/validators/patternvalidator.h
+++ b/src/validators/patternvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/requiredvalidator.h b/src/validators/requiredvalidator.h
index bdea3b4..57dab4f 100644
--- a/src/validators/requiredvalidator.h
+++ b/src/validators/requiredvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/uniquevalidator.h b/src/validators/uniquevalidator.h
index 2e377fb..87ca0db 100644
--- a/src/validators/uniquevalidator.h
+++ b/src/validators/uniquevalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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"
diff --git a/src/validators/urlvalidator.h b/src/validators/urlvalidator.h
index a2fdf3a..4bb2634 100644
--- a/src/validators/urlvalidator.h
+++ b/src/validators/urlvalidator.h
@@ -1,3 +1,18 @@
+/*
+ * 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
 
diff --git a/src/validators/validator.h b/src/validators/validator.h
index 18e5c6e..a302cb3 100644
--- a/src/validators/validator.h
+++ b/src/validators/validator.h
@@ -1,3 +1,18 @@
+/*
+ * 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
 
diff --git a/src/validators/validatorfactory.h b/src/validators/validatorfactory.h
index d7c3552..df9b653 100644
--- a/src/validators/validatorfactory.h
+++ b/src/validators/validatorfactory.h
@@ -1,3 +1,18 @@
+/*
+ * 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>
diff --git a/src/validators/validatorrule.h b/src/validators/validatorrule.h
index c2b70b4..b5373e7 100644
--- a/src/validators/validatorrule.h
+++ b/src/validators/validatorrule.h
@@ -1,3 +1,18 @@
+/*
+ * 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>
diff --git a/tests/em/tst_em.cpp b/tests/em/tst_em.cpp
index 224ffdc..5318522 100644
--- a/tests/em/tst_em.cpp
+++ b/tests/em/tst_em.cpp
@@ -7,7 +7,7 @@ void EmTest::initTestCase() {
     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() {
diff --git a/tests/em/tst_querybuilder.cpp b/tests/em/tst_querybuilder.cpp
index 060b2fc..fe9ec04 100644
--- a/tests/em/tst_querybuilder.cpp
+++ b/tests/em/tst_querybuilder.cpp
@@ -19,6 +19,10 @@ void QuerybuilderTest::initTestCase() {
                                   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);
@@ -32,10 +36,14 @@ void QuerybuilderTest::initTestCase() {
     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;
     }
@@ -133,15 +141,108 @@ void QuerybuilderTest::testFindByAttributesManyToManyRelationAttribute() {
 }
 
 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);
 }
diff --git a/tests/em/tst_querybuilder.h b/tests/em/tst_querybuilder.h
index 94053c6..23fc7d1 100644
--- a/tests/em/tst_querybuilder.h
+++ b/tests/em/tst_querybuilder.h
@@ -19,6 +19,15 @@ class QuerybuilderTest : public QObject {
     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;
 };
