Herunterladen als
root/src/relation.h @ 77dbed04
c22391b2 | Christian Ehringfeld | /*
|
|
* 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/>.
|
|||
*/
|
|||
24c5480c | Christian Ehringfeld | #ifndef RELATION_H
|
|
#define RELATION_H
|
|||
#include <QString>
|
|||
2d9fab10 | Christian Ehringfeld | #include <QHash>
|
|
24c5480c | Christian Ehringfeld | namespace CuteEntityManager {
|
|
da565582 | Christian Ehringfeld | enum class RelationType {
|
|
abb9e8c5 | Christian Ehringfeld | ONE_TO_ONE = 0, //e.g. specialization, heritage
|
|
ONE_TO_MANY = 1, //@OneToMany(cascade=ALL, mappedBy="customer") e.g. QList<QSharedPointer<Person>>
|
|||
MANY_TO_ONE = 2, //e.g. QSharedPointer<Person>
|
|||
5b49a450 | Christian Ehringfeld | //1-n Entity foreign key in same table
|
|
3eae124b | Christian Ehringfeld | MANY_TO_MANY = 3 //e.g. QList<QSharedPointer<Person>> - realized with seperated database table
|
|
ba800d6d | Christian Ehringfeld | };
|
|
da565582 | Christian Ehringfeld | enum class InheritanceStrategy {
|
|
1a3b37ba | Christian Ehringfeld | PER_CLASS_TABLE,
|
|
3eae124b | Christian Ehringfeld | JOINED_TABLE
|
|
1a3b37ba | Christian Ehringfeld | };
|
|
da565582 | Christian Ehringfeld | enum class CascadeType {
|
|
ba800d6d | Christian Ehringfeld | ALL,
|
|
MERGE,
|
|||
PERSIST,
|
|||
REFRESH,
|
|||
3eae124b | Christian Ehringfeld | REMOVE
|
|
24c5480c | Christian Ehringfeld | };
|
|
class Relation {
|
|||
public:
|
|||
d933d48e | Christian Ehringfeld | explicit Relation();
|
|
explicit Relation(QString propertyName, bool optional, RelationType type);
|
|||
ba800d6d | Christian Ehringfeld | /**
|
|
* @brief Relation
|
|||
* @param propertyName
|
|||
* @param type
|
|||
* @param mappedBy Q_PROPERTY in foreign Entity
|
|||
*/
|
|||
d933d48e | Christian Ehringfeld | explicit Relation(QString propertyName, RelationType type,
|
|
abb9e8c5 | Christian Ehringfeld | QString mappedBy = QString(),
|
|
ea09b5be | Christian Ehringfeld | QList<CascadeType> cascadeType = QList<CascadeType> {CascadeType::MERGE, CascadeType::PERSIST, CascadeType::REFRESH});
|
|
d933d48e | Christian Ehringfeld | ~Relation();
|
|
RelationType getType() const;
|
|||
ea09b5be | Christian Ehringfeld | QString getTypeAsString() const;
|
|
d933d48e | Christian Ehringfeld | void setType(const RelationType &value);
|
|
24c5480c | Christian Ehringfeld | ||
d933d48e | Christian Ehringfeld | QString getPropertyName() const;
|
|
void setPropertyName(const QString &value);
|
|||
24c5480c | Christian Ehringfeld | ||
d933d48e | Christian Ehringfeld | bool getOptional() const;
|
|
void setOptional(bool value);
|
|||
24c5480c | Christian Ehringfeld | ||
d933d48e | Christian Ehringfeld | QString getMappedBy() const;
|
|
void setMappedBy(const QString &value);
|
|||
ba800d6d | Christian Ehringfeld | ||
d933d48e | Christian Ehringfeld | QList<CascadeType> getCascadeType() const;
|
|
void setCascadeType(const QList<CascadeType> &value);
|
|||
ba800d6d | Christian Ehringfeld | ||
24c5480c | Christian Ehringfeld | protected:
|
|
QString propertyName;
|
|||
ba800d6d | Christian Ehringfeld | QString mappedBy;
|
|
24c5480c | Christian Ehringfeld | RelationType type;
|
|
91ed1164 | Christian Ehringfeld | QList<CascadeType> cascadeType;
|
|
24c5480c | Christian Ehringfeld | bool optional;
|
|
};
|
|||
2d9fab10 | Christian Ehringfeld | ||
inline bool operator==(const Relation &e1, const Relation &e2) {
|
|||
return e1.getPropertyName() == e2.getPropertyName();
|
|||
}
|
|||
inline uint qHash(const Relation &key, uint seed) {
|
|||
return qHash(key.getPropertyName(), seed);
|
|||
}
|
|||
24c5480c | Christian Ehringfeld | }
|
|
#endif // RELATION_H
|