Revision da565582
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
samples/example/main.cpp | ||
---|---|---|
EntityInstanceFactory::registerClass<Address>();
|
||
QThread *entityManager = new QThread();
|
||
e->moveToThread(entityManager);
|
||
QStringList inits = QStringList() << "Contact" << "Address" << "Person" <<
|
||
QStringList inits = QStringList() << "Contact" << "Address" <<
|
||
"Pupil" << "Group";
|
||
e->startup("0.1", inits);
|
||
|
||
... | ... | |
* PERSIST
|
||
* ---------------------------------
|
||
*/
|
||
Group *g = new Group();
|
||
g->setName("9b");
|
||
CreateFakeModelData::fillGroup(g);
|
||
QSharedPointer<Group> gPtr = QSharedPointer<Group>(g);
|
||
|
||
QSharedPointer<Group> gPtr = QSharedPointer<Group>(new Group());
|
||
CreateFakeModelData::fillGroup(gPtr.data());
|
||
gPtr->setName("9b");
|
||
e->createTable(gPtr);
|
||
QSharedPointer<Entity> groupPtr = gPtr.objectCast<Entity>();
|
||
QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Max",
|
||
... | ... | |
* FIND
|
||
* ---------------------------------
|
||
*/
|
||
QSharedPointer<Person> foundMainTeacher = e->findById<Person*>(1).objectCast<Person>();
|
||
qDebug() << "Founded:" << foundMainTeacher->toString();
|
||
qDebug() << "FoundedGroupSize:" << foundMainTeacher->getMaintainedGroups().size();
|
||
|
||
QSharedPointer<Entity> groupFindPtr = e->findById<Group *>(1);
|
||
QSharedPointer<Group> grp = groupFindPtr.objectCast<Group>();
|
||
qDebug()<< "Group:" << groupFindPtr->toString();
|
samples/example/models/group.cpp | ||
---|---|---|
|
||
const QHash<QString, CuteEntityManager::Relation> Group::getRelations() const {
|
||
auto hash = QHash<QString, CuteEntityManager::Relation>();
|
||
//hash.insert("pupils", CuteEntityManager::Relation("pupils", MANY_TO_MANY));
|
||
hash.insert("persons", CuteEntityManager::Relation("persons", MANY_TO_MANY));
|
||
hash.insert("pupils", CuteEntityManager::Relation("pupils", RelationType::MANY_TO_MANY));
|
||
hash.insert("persons", CuteEntityManager::Relation("persons", RelationType::MANY_TO_MANY));
|
||
hash.insert("mainTeacher", CuteEntityManager::Relation("mainTeacher",
|
||
MANY_TO_ONE));
|
||
RelationType::MANY_TO_ONE));
|
||
return hash;
|
||
}
|
||
|
samples/example/models/group.h | ||
---|---|---|
|
||
class Group: public CuteEntityManager::Entity {
|
||
Q_OBJECT
|
||
//Q_PROPERTY(QList<QSharedPointer<Pupil>> pupils READ getPupils WRITE setPupils)
|
||
Q_PROPERTY(QList<QSharedPointer<Pupil>> pupils READ getPupils WRITE setPupils)
|
||
Q_PROPERTY(QList<QSharedPointer<Person>> persons READ getPersons WRITE setPersons)
|
||
Q_PROPERTY(QString name READ getName WRITE setName)
|
||
Q_PROPERTY(QSharedPointer<Person> mainTeacher READ getMainTeacher WRITE
|
samples/example/models/person.cpp | ||
---|---|---|
|
||
const QHash<QString, CuteEntityManager::Relation> Person::getRelations() const {
|
||
auto hash = QHash<QString, CuteEntityManager::Relation>();
|
||
hash.insert("groups", CuteEntityManager::Relation("groups", MANY_TO_MANY,
|
||
hash.insert("groups", CuteEntityManager::Relation("groups",
|
||
RelationType::MANY_TO_MANY,
|
||
QString("persons")));
|
||
hash.insert("maintainedGroups", CuteEntityManager::Relation("maintainedGroups",
|
||
RelationType::ONE_TO_MANY,
|
||
QString("mainTeacher")));
|
||
return hash;
|
||
}
|
||
|
||
... | ... | |
void Person::addAddress(Address *address) {
|
||
this->addresses.append(QSharedPointer<Address>(address));
|
||
}
|
||
QList<QSharedPointer<Group> > Person::getMaintainedGroups() const
|
||
{
|
||
return maintainedGroups;
|
||
}
|
||
|
||
void Person::setMaintainedGroups(const QList<QSharedPointer<Group> > &value)
|
||
{
|
||
maintainedGroups = value;
|
||
}
|
||
|
samples/example/models/person.h | ||
---|---|---|
Q_PROPERTY(QDate birthday READ getBirthday WRITE setBirthday)
|
||
Q_PROPERTY(Gender gender READ getGender WRITE setGender)
|
||
Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
|
||
Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
|
||
getMaintainedGroups WRITE setMaintainedGroups)
|
||
|
||
public:
|
||
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
|
||
... | ... | |
void addContact(Contact *contact);
|
||
void addAddress(Address *address);
|
||
|
||
QList<QSharedPointer<Group> > getMaintainedGroups() const;
|
||
void setMaintainedGroups(const QList<QSharedPointer<Group> > &value);
|
||
|
||
protected:
|
||
QString firstName;
|
||
QString familyName;
|
||
... | ... | |
QList <QSharedPointer<Contact>> contacts;
|
||
QList <QSharedPointer<Address>> addresses;
|
||
QList <QSharedPointer<Group>> groups;
|
||
QList <QSharedPointer<Group>> maintainedGroups;
|
||
};
|
||
|
||
|
samples/example/models/pupil.cpp | ||
---|---|---|
|
||
Pupil::Pupil(QString firstName, QString familyName, Gender gender,
|
||
QString customPictureFileName, QString namePrefix, QString nickName,
|
||
QDate birthday, QString form, QObject *parent)
|
||
QDate birthday, QString legalGuardianNote, QObject *parent)
|
||
: Person(firstName, familyName, gender, customPictureFileName, namePrefix,
|
||
nickName, birthday, parent) {
|
||
setFirstName(firstName);
|
||
... | ... | |
setBirthday(birthday);
|
||
setGender(gender);
|
||
setCustomPictureFileName(customPictureFileName);
|
||
setForm(form);
|
||
this->setLegalGuardianNote(legalGuardianNote);
|
||
}
|
||
|
||
QString Pupil::getLegalGuardianNote() const {
|
||
... | ... | |
legalGuardianNote = value;
|
||
}
|
||
|
||
QString Pupil::getForm() const {
|
||
return form;
|
||
}
|
||
|
||
void Pupil::setForm(const QString &value) {
|
||
form = value;
|
||
}
|
||
|
||
|
||
|
samples/example/models/pupil.h | ||
---|---|---|
Pupil(QString firstName, QString familyName,
|
||
Gender gender = Gender::UNKNOWNGENDER,
|
||
QString customPictureFileName = QString(), QString namePrefix = QString(),
|
||
QString nickName = QString(), QDate birthday = QDate(),
|
||
QString form = QString(), QObject *parent = 0);
|
||
QString nickName = QString(), QDate birthday = QDate(), QString legalGuardianNote = "", QObject *parent = 0);
|
||
|
||
QString getLegalGuardianNote() const;
|
||
void setLegalGuardianNote(const QString &value);
|
||
... | ... | |
|
||
protected:
|
||
QString legalGuardianNote;
|
||
QString form;
|
||
|
||
};
|
||
|
src/entity.cpp | ||
---|---|---|
}
|
||
|
||
InheritanceStrategy Entity::getInheritanceStrategy() const {
|
||
return JOINED_TABLE;
|
||
return InheritanceStrategy::JOINED_TABLE;
|
||
}
|
||
|
||
bool Entity::isInheritanceCascaded() const {
|
||
... | ... | |
stopAtSingleTableInheritance) const {
|
||
QList<const QMetaObject *> classes = QList<const QMetaObject *>();
|
||
auto superMetaObject = this->metaObject()->superClass();
|
||
if (this->getInheritanceStrategy() == JOINED_TABLE) {
|
||
if (this->getInheritanceStrategy() == InheritanceStrategy::JOINED_TABLE) {
|
||
Entity *e = nullptr;
|
||
while (superMetaObject && QString(superMetaObject->className()) !=
|
||
QString("CuteEntityManager::Entity")) {
|
||
... | ... | |
if (e) {
|
||
classes.append(superMetaObject);
|
||
superMetaObject = superMetaObject->superClass();
|
||
quint8 s = e->getInheritanceStrategy();
|
||
InheritanceStrategy s = e->getInheritanceStrategy();
|
||
delete e;
|
||
e = nullptr;
|
||
if (stopAtSingleTableInheritance && s == PER_CLASS_TABLE) {
|
||
if (stopAtSingleTableInheritance && s == InheritanceStrategy::PER_CLASS_TABLE) {
|
||
break;
|
||
}
|
||
} else {
|
||
... | ... | |
auto superMetaObjectPropertyMap = QHash<QString, QMetaProperty>();
|
||
auto superMeta = this->metaObject()->superClass();
|
||
if (QString(superMeta->className()) != QString("CuteEntityManager::Entity")
|
||
&& this->getInheritanceStrategy() == JOINED_TABLE) {
|
||
&& this->getInheritanceStrategy() == InheritanceStrategy::JOINED_TABLE) {
|
||
for (int var = 0; var < superMeta->propertyCount(); ++var) {
|
||
QMetaProperty prop = superMeta->property(var);
|
||
if (prop.isReadable() && prop.isWritable()) {
|
src/entitymanager.cpp | ||
---|---|---|
const Relation r = iterator.key();
|
||
auto var = iterator.value().read(entity.data());
|
||
if (!var.isNull()) {
|
||
if (r.getType() == MANY_TO_ONE) {
|
||
if (r.getType() == RelationType::MANY_TO_ONE) {
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
if (this->shouldBeSaved(e, r)) {
|
||
this->save(e);
|
||
}
|
||
} else if (r.getType() == ONE_TO_ONE && r.getMappedBy().isEmpty()) {
|
||
} else if (r.getType() == RelationType::ONE_TO_ONE
|
||
&& r.getMappedBy().isEmpty()) {
|
||
auto entity = EntityInstanceFactory::castQVariant(var);
|
||
this->save(entity);
|
||
}
|
||
... | ... | |
const Relation r = iterator.key();
|
||
auto var = iterator.value().read(entity.data());
|
||
if (!var.isNull()) {
|
||
if (this->canPersistRelation(r, MANY_TO_MANY, var)) {
|
||
if (this->canPersistRelation(r, RelationType::MANY_TO_MANY, var)) {
|
||
this->persistManyToMany(entity, r, var);
|
||
} else if (this->canPersistRelation(r, ONE_TO_MANY, var)) {
|
||
} else if (this->canPersistRelation(r, RelationType::ONE_TO_MANY, var)) {
|
||
QList<QSharedPointer<Entity>> list = EntityInstanceFactory::castQVariantList(
|
||
var);
|
||
for (int var = 0; var < list.size(); ++var) {
|
||
... | ... | |
this->save(entity);
|
||
}
|
||
}
|
||
} else if (r.getType() == ONE_TO_ONE && !r.getMappedBy().isEmpty()) {
|
||
} else if (r.getType() == RelationType::ONE_TO_ONE
|
||
&& !r.getMappedBy().isEmpty()) {
|
||
auto entity = EntityInstanceFactory::castQVariant(var);
|
||
this->save(entity);
|
||
}
|
||
... | ... | |
const QSharedPointer<Entity> &ptr, const Relation &r,
|
||
const QString &tblName) {
|
||
q.clear();
|
||
QList<QSharedPointer<Entity>> saved = r.getCascadeType().contains(ALL)
|
||
|| r.getCascadeType().contains(MERGE)
|
||
|| r.getCascadeType().contains(PERSIST) ? this->saveRelationEntities(list,
|
||
QList<QSharedPointer<Entity>> saved = r.getCascadeType().contains(
|
||
CascadeType::ALL)
|
||
|| r.getCascadeType().contains(CascadeType::MERGE)
|
||
|| r.getCascadeType().contains(CascadeType::PERSIST) ?
|
||
this->saveRelationEntities(list,
|
||
r) : list;
|
||
this->db->startTransaction();
|
||
auto builder = this->schema->getQueryBuilder();
|
||
... | ... | |
q.lastError().text();
|
||
qDebug() << "Involved entities: " << entity->getClassname() <<
|
||
"(MainEntitiy) and " << entity->getClassname();
|
||
qDebug() << "Relation:" << r.getType() << r.getPropertyName();
|
||
qDebug() << "Relation:" << r.getPropertyName();
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
|
||
bool EntityManager::shouldBeSaved(QSharedPointer<Entity> &entity,
|
||
const Relation &r) {
|
||
return entity && (r.getCascadeType().contains(ALL)
|
||
return entity && (r.getCascadeType().contains(CascadeType::ALL)
|
||
|| (entity->getProperty(entity->getPrimaryKey()) > -1
|
||
&& r.getCascadeType().contains(MERGE))
|
||
&& r.getCascadeType().contains(CascadeType::MERGE))
|
||
|| (entity->getProperty(entity->getPrimaryKey()) <= -1
|
||
&& r.getCascadeType().contains(PERSIST)));
|
||
&& r.getCascadeType().contains(CascadeType::PERSIST)));
|
||
}
|
||
|
||
void EntityManager::removeRelations(const QSharedPointer<Entity> &entity) {
|
||
... | ... | |
const Relation r = iterator.key();
|
||
auto property = iterator.value();
|
||
auto var = property.read(entity.data());
|
||
if (r.getType() == MANY_TO_MANY) {
|
||
if (r.getType() == RelationType::MANY_TO_MANY) {
|
||
this->removeManyToManyEntityList(entity, r, var);
|
||
} else if (r.getType() == ONE_TO_MANY) {
|
||
if (r.getCascadeType().contains(REMOVE) || r.getCascadeType().contains(ALL)) {
|
||
} else if (r.getType() == RelationType::ONE_TO_MANY) {
|
||
if (r.getCascadeType().contains(CascadeType::REMOVE)
|
||
|| r.getCascadeType().contains(CascadeType::ALL)) {
|
||
this->removeEntityList(var);
|
||
} else {
|
||
this->setNullOneToManyRelation(var, r);
|
||
}
|
||
} else if (r.getType() == MANY_TO_ONE || r.getType() == MANY_TO_ONE) {
|
||
} else if (r.getType() == RelationType::MANY_TO_ONE
|
||
|| r.getType() == RelationType::MANY_TO_ONE) {
|
||
this->setNullEntityPropertyRelation(var, r);
|
||
}
|
||
++iterator;
|
||
... | ... | |
|
||
void EntityManager::setNullEntityPropertyRelation(QVariant &var,
|
||
const Relation &r) {
|
||
if (r.getCascadeType().contains(REMOVE) || r.getCascadeType().contains(ALL)) {
|
||
if (r.getCascadeType().contains(CascadeType::REMOVE)
|
||
|| r.getCascadeType().contains(CascadeType::ALL)) {
|
||
this->removeEntity(var);
|
||
} else if (!r.getMappedBy().isEmpty() && !var.isNull()) {
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
... | ... | |
QSqlQuery q = builder->manyToManyDelete(
|
||
tblName, builder->generateManyToManyColumnName(e),
|
||
e->getProperty(e->getPrimaryKey()).toLongLong());
|
||
bool refresh = r.getCascadeType().contains(REFRESH)
|
||
|| r.getCascadeType().contains(ALL);
|
||
bool remove = r.getCascadeType().contains(REMOVE)
|
||
|| r.getCascadeType().contains(ALL);
|
||
bool refresh = r.getCascadeType().contains(CascadeType::REFRESH)
|
||
|| r.getCascadeType().contains(CascadeType::ALL);
|
||
bool remove = r.getCascadeType().contains(CascadeType::REMOVE)
|
||
|| r.getCascadeType().contains(CascadeType::ALL);
|
||
if (q.exec()) {
|
||
for (int var = 0; var < list.size(); ++var) {
|
||
auto entity = list.at(var);
|
||
... | ... | |
QString colName = this->schema->getQueryBuilder()->generateColumnNameID(
|
||
r.getPropertyName());
|
||
switch (r.getType()) {
|
||
case MANY_TO_ONE:
|
||
case RelationType::MANY_TO_ONE:
|
||
if (map.contains(colName)) {
|
||
this->manyToOne(entity, map.value(colName), property, refresh);
|
||
}
|
||
break;
|
||
case MANY_TO_MANY:
|
||
case RelationType::MANY_TO_MANY:
|
||
this->manyToMany(entity, property, refresh);
|
||
break;
|
||
case ONE_TO_MANY:
|
||
case RelationType::ONE_TO_MANY:
|
||
this->oneToMany(entity, r, property, refresh);
|
||
break;
|
||
case ONE_TO_ONE:
|
||
case RelationType::ONE_TO_ONE:
|
||
this->oneToOne(entity, r, property, refresh, map.value(colName));
|
||
break;
|
||
}
|
src/querybuilder.cpp | ||
---|---|---|
bool QueryBuilder::createTable(const QSharedPointer<Entity> &entity,
|
||
bool createRelationTables) const {
|
||
bool rc = false;
|
||
if (entity.data()) {
|
||
if (entity) {
|
||
auto tableDefinition = this->generateTableDefinition(entity);
|
||
QString tableName = entity->getTablename();
|
||
this->schema->containsTable(tableName) ? rc = true : rc = false;
|
||
... | ... | |
while (iterator != relations.constEnd()) {
|
||
auto relation = iterator.value();
|
||
if (relation.getMappedBy().isEmpty() && !relation.getCascadeType().isEmpty()) {
|
||
QString update = relation.getCascadeType().contains(MERGE)
|
||
|| relation.getCascadeType().contains(ALL) ? this->getForeignKeyCascade(
|
||
QString update = relation.getCascadeType().contains(CascadeType::MERGE)
|
||
|| relation.getCascadeType().contains(CascadeType::ALL) ?
|
||
this->getForeignKeyCascade(
|
||
CASCADE) : this->getForeignKeyCascade(NO_ACTION);
|
||
QString remove = relation.getCascadeType().contains(REMOVE)
|
||
|| relation.getCascadeType().contains(ALL) ? this->getForeignKeyCascade(
|
||
CASCADE) : this->getForeignKeyCascade(SET_NULL);
|
||
QString remove = relation.getCascadeType().contains(CascadeType::REMOVE)
|
||
|| relation.getCascadeType().contains(CascadeType::ALL) ?
|
||
this->getForeignKeyCascade(
|
||
CASCADE) : this->getForeignKeyCascade(DbForeignKeyCascade::SET_NULL);
|
||
this->createRelationFK(queries, entity, relation,
|
||
props.value(relation.getPropertyName()), update, remove);
|
||
}
|
||
... | ... | |
auto ptr = QSharedPointer<Entity>
|
||
(EntityInstanceFactory::createInstance(metaProperty.type()));
|
||
if (ptr) {
|
||
if (relation.getType() == ONE_TO_ONE || relation.getType() == MANY_TO_ONE) {
|
||
if (relation.getType() == RelationType::ONE_TO_ONE
|
||
|| relation.getType() == RelationType::MANY_TO_ONE) {
|
||
QString indexName = this->generateIndexName(relation.getPropertyName(),
|
||
entity->getTablename(),
|
||
this->generateColumnNameID(relation.getPropertyName()),
|
||
... | ... | |
ptr->getTablename(),
|
||
QStringList(ptr->getPrimaryKey()), remove, update));
|
||
|
||
} else if (relation.getType() == MANY_TO_MANY) {
|
||
} else if (relation.getType() == RelationType::MANY_TO_MANY) {
|
||
QString tableName = this->generateManyToManyTableName(entity, ptr);
|
||
queries.append(this->createForeignKeyManyToMany(tableName, entity, update,
|
||
remove));
|
||
... | ... | |
QString QueryBuilder::createFkSuperClass(const Entity *e) const {
|
||
QString r = "";
|
||
auto superMetaObject = e->metaObject()->superClass();
|
||
if (e->getInheritanceStrategy() == JOINED_TABLE
|
||
if (e->getInheritanceStrategy() == InheritanceStrategy::JOINED_TABLE
|
||
&& QString(superMetaObject->className()) !=
|
||
this->entityClassname()) {
|
||
Entity *superClass = EntityInstanceFactory::createInstance(
|
||
... | ... | |
QHash<QString, Relation> relations = entity->getRelations();
|
||
for (int var = 0; var < o->propertyCount(); ++var) {
|
||
auto m = o->property(var);
|
||
if (!superMetaObjectPropertyMap.contains(QString(m.name()))
|
||
if ((!superMetaObjectPropertyMap.contains(QString(m.name()))
|
||
|| entity->getInheritanceStrategy() == InheritanceStrategy::PER_CLASS_TABLE)
|
||
&& m.name() != QString("objectName") && m.isReadable()
|
||
&& !entity->getTransientAttributes().contains(m.name())) {
|
||
if (m.isEnumType()) {
|
||
... | ... | |
}
|
||
}
|
||
}
|
||
if (!(QString(superMetaObject->className()) !=
|
||
if (QString(superMetaObject->className()) ==
|
||
this->entityClassname()
|
||
&& entity->getInheritanceStrategy() == JOINED_TABLE)) {
|
||
|| entity->getInheritanceStrategy() == InheritanceStrategy::PER_CLASS_TABLE) {
|
||
map.insert(entity->getPrimaryKey(), this->schema->TYPE_BIGPK);
|
||
} else {
|
||
map.insert(entity->getPrimaryKey(), this->schema->TYPE_BIGINT);
|
||
}
|
||
return map;
|
||
}
|
||
... | ... | |
auto props = entity->getMetaProperties();
|
||
for (auto i = m.begin(); i != m.end(); ++i) {
|
||
Relation r = i.value();
|
||
if (r.getType() == MANY_TO_MANY && r.getMappedBy().isEmpty()) {
|
||
if (r.getType() == RelationType::MANY_TO_MANY && r.getMappedBy().isEmpty()) {
|
||
QHash<QString, QString> h = QHash<QString, QString>();
|
||
h.insert(entity->getPrimaryKey(), this->schema->TYPE_BIGPK);
|
||
h.insert(this->generateManyToManyColumnName(entity),
|
||
... | ... | |
QList<QSqlQuery> queries = QList<QSqlQuery>();
|
||
queries.append(this->remove(entity->getTablename(),
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong()));
|
||
if (entity->getInheritanceStrategy() != PER_CLASS_TABLE
|
||
if (entity->getInheritanceStrategy() != InheritanceStrategy::PER_CLASS_TABLE
|
||
&& entity->isInheritanceCascaded()) {
|
||
auto classes = entity->superClasses(true);
|
||
for (int var = 0; var < classes.size(); ++var) {
|
||
... | ... | |
QList<QueryBuilder::ClassAttributes> QueryBuilder::inheritedAttributes(
|
||
const QSharedPointer<Entity> &entity) const {
|
||
auto list = QList<QueryBuilder::ClassAttributes>();
|
||
if (entity->getInheritanceStrategy() == JOINED_TABLE) {
|
||
if (entity->getInheritanceStrategy() == InheritanceStrategy::JOINED_TABLE) {
|
||
auto classes = QList<const QMetaObject *>();
|
||
classes.append(entity->metaObject());
|
||
classes.append(entity->superClasses(true));
|
||
... | ... | |
auto i = relations.constBegin();
|
||
while (i != relations.constEnd()) {
|
||
Relation r = i.value();
|
||
if ((r.getType() == MANY_TO_ONE && props.contains(i.key()))
|
||
|| (r.getType() == ONE_TO_ONE && r.getMappedBy().isEmpty())) {
|
||
if ((r.getType() == RelationType::MANY_TO_ONE && props.contains(i.key()))
|
||
|| (r.getType() == RelationType::ONE_TO_ONE && r.getMappedBy().isEmpty())) {
|
||
auto v = props.value(i.key()).read(entity.data());
|
||
QSharedPointer<Entity> e = EntityInstanceFactory::castQVariant(v);
|
||
if (e) {
|
src/relation.cpp | ||
---|---|---|
this->propertyName = propertyName;
|
||
this->type = type;
|
||
this->optional = optional;
|
||
this->cascadeType = {MERGE,
|
||
PERSIST,
|
||
REFRESH
|
||
this->cascadeType = {CascadeType::MERGE,
|
||
CascadeType::PERSIST,
|
||
CascadeType::REFRESH
|
||
};
|
||
}
|
||
|
||
... | ... | |
this->type = type;
|
||
this->mappedBy = mappedBy;
|
||
this->optional = true;
|
||
if (this->type == ONE_TO_ONE) {
|
||
this->cascadeType = {ALL};
|
||
if (this->type == RelationType::ONE_TO_ONE) {
|
||
this->cascadeType = {CascadeType::ALL};
|
||
} else {
|
||
this->cascadeType = cascadeType;
|
||
}
|
src/relation.h | ||
---|---|---|
#include <QString>
|
||
#include <QHash>
|
||
namespace CuteEntityManager {
|
||
enum RelationType {
|
||
enum class RelationType {
|
||
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>
|
||
... | ... | |
MANY_TO_MANY = 3, //e.g. QList<QSharedPointer<Person>> - realized with seperated database table
|
||
};
|
||
|
||
enum InheritanceStrategy {
|
||
enum class InheritanceStrategy {
|
||
PER_CLASS_TABLE,
|
||
JOINED_TABLE,
|
||
};
|
||
|
||
enum CascadeType {
|
||
enum class CascadeType {
|
||
ALL,
|
||
MERGE,
|
||
PERSIST,
|
||
... | ... | |
*/
|
||
explicit Relation(QString propertyName, RelationType type,
|
||
QString mappedBy = QString(),
|
||
QList<CascadeType> cascadeType = {MERGE, PERSIST, REFRESH});
|
||
QList<CascadeType> cascadeType = {CascadeType::MERGE, CascadeType::PERSIST, CascadeType::REFRESH});
|
||
~Relation();
|
||
RelationType getType() const;
|
||
void setType(const RelationType &value);
|
Auch abrufbar als: Unified diff
small update