Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d933d48e

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID d933d48e4a3fd67a02a81cb68ef500180b5c5d20
  • Vorgänger 9e62667d
  • Nachfolger da565582

Revert "Dead End? LNK2001 bei vielen obj."

This reverts commit 72b5abad85fe7ef2ded3c217349bd9779de584b6.

Unterschiede anzeigen:

src/cache.h
class Entity;
class Cache {
public:
Q_DECL_EXPORT Cache();
Q_DECL_EXPORT QHash<QString, QWeakPointer<Entity> > getCache() const;
Q_DECL_EXPORT bool contains(qint64 id, const QString &classname);
Q_DECL_EXPORT bool contains(const QString &key);
template<class T> Q_DECL_EXPORT bool contains(qint64 id) {
Cache();
QHash<QString, QWeakPointer<Entity> > getCache() const;
bool contains(qint64 id, const QString &classname);
bool contains(const QString &key);
template<class T> bool contains(qint64 id) {
bool ok = false;
Entity *e = EntityInstanceFactory::createInstance<T>();
if (e) {
......
}
return ok;
}
Q_DECL_EXPORT void insert(QSharedPointer<Entity> &entity);
Q_DECL_EXPORT void remove(const QSharedPointer<Entity> &entity);
Q_DECL_EXPORT void remove(const qint64 &id, const QString &classname);
template<class T> Q_DECL_EXPORT void remove(qint64 id) {
void insert(QSharedPointer<Entity> &entity);
void remove(const QSharedPointer<Entity> &entity);
void remove(const qint64 &id, const QString &classname);
template<class T> void remove(qint64 id) {
Entity *e = EntityInstanceFactory::createInstance<T>();
if (e) {
this->remove(id, QString(e->getClassname()));
......
}
}
Q_DECL_EXPORT QSharedPointer<Entity> get(qint64 id, const QString &classname);
template<class T> Q_DECL_EXPORT QSharedPointer<Entity> get(qint64 id) {
QSharedPointer<Entity> get(qint64 id, const QString &classname);
template<class T> QSharedPointer<Entity> get(qint64 id) {
Entity *e = EntityInstanceFactory::createInstance<T>();
if (e) {
return this->get(id, QString(e->getClassname()));
src/entity.h
Q_PROPERTY(qint64 id READ getId WRITE setId NOTIFY idChanged)
signals:
Q_DECL_EXPORT void idChanged();
void idChanged();
public:
Q_DECL_EXPORT explicit Entity (QObject *parent = 0);
Q_DECL_EXPORT virtual QString toString() const;
Q_DECL_EXPORT virtual ~Entity();
Q_DECL_EXPORT virtual QString getTablename() const;
Q_DECL_EXPORT virtual const QHash<QString, Relation> getRelations() const;
Q_DECL_EXPORT virtual const QStringList getTransientAttributes() const;
Q_DECL_EXPORT virtual const QStringList getBLOBColumns() const;
Q_DECL_EXPORT virtual InheritanceStrategy getInheritanceStrategy() const;
Q_DECL_EXPORT virtual bool isInheritanceCascaded() const;
explicit Entity (QObject *parent = 0);
virtual QString toString() const;
virtual ~Entity();
virtual QString getTablename() const;
virtual const QHash<QString, Relation> getRelations() const;
virtual const QStringList getTransientAttributes() const;
virtual const QStringList getBLOBColumns() const;
virtual InheritanceStrategy getInheritanceStrategy() const;
virtual bool isInheritanceCascaded() const;
//return value must be the exact name defined in Q_PROPERTY
Q_DECL_EXPORT virtual QString getPrimaryKey() const;
Q_DECL_EXPORT const QHash<QString, Relation> getNonInheritedRelations() const;
Q_DECL_EXPORT const QList<const QMetaObject *> superClasses(bool stopAtSingleTableInheritance
virtual QString getPrimaryKey() const;
const QHash<QString, Relation> getNonInheritedRelations() const;
const QList<const QMetaObject *> superClasses(bool stopAtSingleTableInheritance
= false) const;
Q_DECL_EXPORT const QHash<QString, QMetaProperty> getMetaProperties() const;
Q_DECL_EXPORT const QHash<QString, QMetaProperty> getSuperMetaProperties() const;
Q_DECL_EXPORT static const QHash<QString, QMetaProperty> getMetaProperties(
const QHash<QString, QMetaProperty> getMetaProperties() const;
const QHash<QString, QMetaProperty> getSuperMetaProperties() const;
static const QHash<QString, QMetaProperty> getMetaProperties(
const QMetaObject *object);
Q_DECL_EXPORT const QHash<QString, QMetaProperty> getInheritedMetaProperties() const;
Q_DECL_EXPORT const QHash<Relation, QMetaProperty> getRelationProperties() const;
Q_DECL_EXPORT const char *getClassname() const;
const QHash<QString, QMetaProperty> getInheritedMetaProperties() const;
const QHash<Relation, QMetaProperty> getRelationProperties() const;
const char *getClassname() const;
Q_DECL_EXPORT QVariant getProperty(const QString &name) const;
Q_DECL_EXPORT bool setProperty(const QString &name, const QVariant &value);
QVariant getProperty(const QString &name) const;
bool setProperty(const QString &name, const QVariant &value);
Q_DECL_EXPORT qint64 getId() const;
Q_DECL_EXPORT void setId(const qint64 &value);
qint64 getId() const;
void setId(const qint64 &value);
protected:
Q_DECL_EXPORT virtual QString slimToString() const;
virtual QString slimToString() const;
qint64 id;
};
}
src/entityinstancefactory.h
class Entity;
class EntityInstanceFactory {
public:
Q_DECL_EXPORT static Entity *createInstance(const char *className);
Q_DECL_EXPORT static Entity *createInstance(const QString &className);
Q_DECL_EXPORT static Entity *createInstance(int metaTypeId);
Q_DECL_EXPORT static Entity *createInstance(const char *className,
static Entity *createInstance(const char *className);
static Entity *createInstance(const QString &className);
static Entity *createInstance(int metaTypeId);
static Entity *createInstance(const char *className,
const QHash<QString, QVariant> &attributes);
Q_DECL_EXPORT static Entity *setAttributes(Entity *&e,
static Entity *setAttributes(Entity *&e,
const QHash<QString, QVariant> &attributes,
QHash<QString, QMetaProperty> metaprops);
Q_DECL_EXPORT static Entity *setAttributes(Entity *&e,
static Entity *setAttributes(Entity *&e,
const QHash<QString, QVariant> &attributes);
Q_DECL_EXPORT static const QString extractEntityType(const QString &s);
Q_DECL_EXPORT static Entity *newSuperClassInstance(const Entity *e);
Q_DECL_EXPORT static Entity *createInstance(const QMetaObject *object);
Q_DECL_EXPORT static QList<QSharedPointer<Entity>> castQVariantList(QVariant &list);
Q_DECL_EXPORT static QSharedPointer<Entity> castQVariant(QVariant &entity);
static const QString extractEntityType(const QString &s);
static Entity *newSuperClassInstance(const Entity *e);
static Entity *createInstance(const QMetaObject *object);
static QList<QSharedPointer<Entity>> castQVariantList(QVariant &list);
static QSharedPointer<Entity> castQVariant(QVariant &entity);
template<typename T>
Q_DECL_EXPORT static Entity *createInstance() {
static Entity *createInstance() {
return EntityInstanceFactory::createInstance(qMetaTypeId<T>());
}
//http://www.mimec.org/node/350
template<typename T>
Q_DECL_EXPORT static void registerClass() {
static void registerClass() {
constructors().insert( T::staticMetaObject.className(), &constructorHelper<T> );
QString lName = "QList<QSharedPointer<";
lName.append(T::staticMetaObject.className());
......
qRegisterMetaType<QList<QSharedPointer<T>>>(lName.toLatin1().constData());
}
Q_DECL_EXPORT static Entity *createObject( const QByteArray &className) {
static Entity *createObject( const QByteArray &className) {
Constructor constructor = constructors().value( className );
if ( constructor == NULL ) {
return NULL;
src/entitymanager.h
namespace CuteEntityManager {
class EntityManager : public QObject {
class EntityManager : public QObject {
Q_OBJECT
signals:
void actionFinished(qint64 id);
public:
Q_DECL_EXPORT EntityManager(QSqlDatabase database);
Q_DECL_EXPORT EntityManager(const QString &databaseType, QString databasename = "" ,
EntityManager(QSqlDatabase database);
EntityManager(const QString &databaseType, QString databasename = "" ,
QString hostname = "",
QString username = "",
QString password = "", QString port = "");
Q_DECL_EXPORT ~EntityManager();
static QStringList Q_DECL_EXPORT getConnectionNames();
~EntityManager();
static QStringList getConnectionNames();
/**
* @brief startup
* @param version must be unique
......
* @return
*/
public slots:
Q_DECL_EXPORT bool startup(QString version, QStringList toInitialize);
Q_DECL_EXPORT bool executeQuery(const QString &query);
bool startup(QString version, QStringList toInitialize);
bool executeQuery(const QString &query);
static void removeConnectionName(const QString &name);
Q_DECL_EXPORT QSharedPointer<Entity> findById(const qint64 &id, const QString &classname);
Q_DECL_EXPORT QList<QSharedPointer<Entity>> findEntityByAttributes(const
QSharedPointer<Entity> findById(const qint64 &id, const QString &classname);
QList<QSharedPointer<Entity>> findEntityByAttributes(const
QSharedPointer<Entity> &entity,
bool ignoreID = false);
Q_DECL_EXPORT bool create(QList<QSharedPointer<Entity>> entities,
bool create(QList<QSharedPointer<Entity>> entities,
const bool persistRelations = true);
Q_DECL_EXPORT bool create(QSharedPointer<Entity> &entity, const bool persistRelations = true,
bool create(QSharedPointer<Entity> &entity, const bool persistRelations = true,
const bool checkDuplicate = false);
Q_DECL_EXPORT bool save(QSharedPointer<Entity> &entity, const bool persistRelations = true);
Q_DECL_EXPORT qint64 findId(QSharedPointer<Entity> &entity);
bool save(QSharedPointer<Entity> &entity, const bool persistRelations = true);
qint64 findId(QSharedPointer<Entity> &entity);
bool merge(QSharedPointer<Entity> &entity, bool withRelations = true);
bool remove(QSharedPointer<Entity> &entity);
bool removeAll(QString tblname);
Q_DECL_EXPORT bool createTable(const QSharedPointer<Entity> &entity,
bool createTable(const QSharedPointer<Entity> &entity,
bool createRelationTables = true);
qint8 count(const QSharedPointer<Entity> &entity, bool ignoreID = true);
qint8 count(const QString &tableName);
Q_DECL_EXPORT QSharedPointer<Database> getDb() const;
Q_DECL_EXPORT void setDb(const QSharedPointer<Database> &value);
Q_DECL_EXPORT QSharedPointer<Schema> getSchema() const;
Q_DECL_EXPORT void refresh(QSharedPointer<Entity> &entity);
Q_DECL_EXPORT void setSchema(const QSharedPointer<Schema> &value);
QSharedPointer<Database> getDb() const;
void setDb(const QSharedPointer<Database> &value);
QSharedPointer<Schema> getSchema() const;
void refresh(QSharedPointer<Entity> &entity);
void setSchema(const QSharedPointer<Schema> &value);
/**
*@TODO use conditions
*/
public:
template<class T> Q_DECL_EXPORT qint8 count(QHash<QString, QString> condition =
template<class T> qint8 count(QHash<QString, QString> condition =
QHash<QString, QString>()) {
Entity *e = EntityInstanceFactory::createInstance<T>();
qint8 rc = 0;
......
return rc;
}
template<class T> Q_DECL_EXPORT QList<QSharedPointer<Entity>> findAll() {
template<class T> QList<QSharedPointer<Entity>> findAll() {
QSharedPointer<Entity> ptr = QSharedPointer<Entity>
(EntityInstanceFactory::createInstance<T>());
if (ptr) {
......
return QList<QSharedPointer<Entity>>();
}
template<class T> Q_DECL_EXPORT QSharedPointer<Entity> findById(const qint64 &id) {
template<class T> QSharedPointer<Entity> findById(const qint64 &id) {
auto e = EntityInstanceFactory::createInstance<T>();
QSharedPointer<Entity> ptr = QSharedPointer<Entity>(e);
return this->findById(id, ptr);
}
template<class T> Q_DECL_EXPORT QSharedPointer<Entity> findEntityByAttributes(
template<class T> QSharedPointer<Entity> findEntityByAttributes(
const QHash<QString, QString>
&attributes) {
auto list = this->findAllEntitiesByAttributes<T>(attributes, 1, 0);
......
return list.at(0);
}
template<class T> Q_DECL_EXPORT QList<QSharedPointer<Entity>> findAllEntitiesByAttributes(
template<class T> QList<QSharedPointer<Entity>> findAllEntitiesByAttributes(
const QHash<QString, QString> &attributes =
QHash<QString, QString>(), quint32 limit = 0, quint32 offset = 0) {
auto list = this->findAllEntitiesByAttributes<T>(attributes);
return list;
}
template<class T> Q_DECL_EXPORT QList<QSharedPointer<Entity>> findEntitiesBySql(
template<class T> QList<QSharedPointer<Entity>> findEntitiesBySql(
const QString &sql) {
Entity *e = EntityInstanceFactory::createInstance<T>();
if (e) {
......
return QList<QSharedPointer<Entity>>();
}
template<class T> Q_DECL_EXPORT bool remove(const QList<qint64> &ids) {
template<class T> bool remove(const QList<qint64> &ids) {
bool ok = true;
foreach (qint64 var, ids) {
if (!this->remove<T>(var)) {
......
return ok;
}
template<class T> Q_DECL_EXPORT bool remove(qint64 id) {
template<class T> bool remove(qint64 id) {
Entity *e = EntityInstanceFactory::createInstance<T>();
if (e) {
QSharedPointer<Entity> ptr = QSharedPointer<Entity>(e);
......
}
protected:
Q_DECL_EXPORT void init();
Q_DECL_EXPORT QList<QHash<QString, QVariant> > findAll(const QSharedPointer<Entity> &e);
Q_DECL_EXPORT void resolveRelations(const QSharedPointer<Entity> &entity,
void init();
QList<QHash<QString, QVariant> > findAll(const QSharedPointer<Entity> &e);
void resolveRelations(const QSharedPointer<Entity> &entity,
const QHash<QString, QVariant> &map, const bool refresh = false);
Q_DECL_EXPORT QHash<QString, QVariant> findByPk(qint64 id, const QSharedPointer<Entity> &e);
Q_DECL_EXPORT QSharedPointer<Entity> convert(const QHash<QString, QVariant> &map,
QHash<QString, QVariant> findByPk(qint64 id, const QSharedPointer<Entity> &e);
QSharedPointer<Entity> convert(const QHash<QString, QVariant> &map,
const char *classname, const bool refresh = false);
Q_DECL_EXPORT QList<QSharedPointer<Entity>> convert(QList<QHash<QString, QVariant> > maps,
QList<QSharedPointer<Entity>> convert(QList<QHash<QString, QVariant> > maps,
const char *classname, const bool refresh = false);
Q_DECL_EXPORT void manyToOne(const QSharedPointer<Entity> &entity, const QVariant &id,
void manyToOne(const QSharedPointer<Entity> &entity, const QVariant &id,
const QMetaProperty &property, const bool refresh = false);
Q_DECL_EXPORT void oneToMany(const QSharedPointer<Entity> &entity, const Relation &r,
void oneToMany(const QSharedPointer<Entity> &entity, const Relation &r,
const QMetaProperty &property, const bool refresh = false);
Q_DECL_EXPORT void manyToMany(const QSharedPointer<Entity> &entity,
void manyToMany(const QSharedPointer<Entity> &entity,
const QMetaProperty &property, const bool refresh = false);
Q_DECL_EXPORT void oneToOne(const QSharedPointer<Entity> &entity, const Relation &r,
void oneToOne(const QSharedPointer<Entity> &entity, const Relation &r,
const QMetaProperty &property, const bool refresh = false,
const QVariant &id = "");
Q_DECL_EXPORT bool canPersistRelation(const Relation &relation, const RelationType &r,
bool canPersistRelation(const Relation &relation, const RelationType &r,
const QVariant &var) const;
Q_DECL_EXPORT void persistManyToMany(const QSharedPointer<Entity> &entity, const Relation &r,
void persistManyToMany(const QSharedPointer<Entity> &entity, const Relation &r,
QVariant &property);
Q_DECL_EXPORT QList<QHash<QString, QVariant> > findAllByAttributes(const
QList<QHash<QString, QVariant> > findAllByAttributes(const
QSharedPointer<Entity> &entity,
bool ignoreID = false);
Q_DECL_EXPORT QList<QHash<QString, QVariant> > findAllByAttributes(const
QList<QHash<QString, QVariant> > findAllByAttributes(const
QHash<QString, QVariant> &m,
const QString &tblname,
bool ignoreID = false);
Q_DECL_EXPORT QSharedPointer<Entity> findById(const qint64 &id, QSharedPointer<Entity> &e,
QSharedPointer<Entity> findById(const qint64 &id, QSharedPointer<Entity> &e,
const bool refresh = false);
Q_DECL_EXPORT void addEntityToListProperty(const QSharedPointer<Entity> &entity,
void addEntityToListProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> add, const QMetaProperty &property);
Q_DECL_EXPORT void setListProperty(const QSharedPointer<Entity> &entity,
void setListProperty(const QSharedPointer<Entity> &entity,
QList<QSharedPointer<Entity>> &list,
const QMetaProperty &property) const;
Q_DECL_EXPORT void setProperty(const QSharedPointer<Entity> &entity,
void setProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> value,
const QMetaProperty &property) const;
Q_DECL_EXPORT void savePrePersistedRelations(const QSharedPointer<Entity> &entity);
Q_DECL_EXPORT void savePostPersistedRelations(const QSharedPointer<Entity> &entity);
void savePrePersistedRelations(const QSharedPointer<Entity> &entity);
void savePostPersistedRelations(const QSharedPointer<Entity> &entity);
Q_DECL_EXPORT QList<QSharedPointer<Entity>> saveRelationEntities(const
QList<QSharedPointer<Entity>> saveRelationEntities(const
QList<QSharedPointer<Entity>> &list, const Relation &r);
Q_DECL_EXPORT void persistMappedByRelation(const QList<QSharedPointer<Entity>> &list,
void persistMappedByRelation(const QList<QSharedPointer<Entity>> &list,
QSqlQuery &q, const QSharedPointer<Entity> &entity,
const QSharedPointer<Entity> &ptr, const Relation &r,
const QString &tblName);
Q_DECL_EXPORT bool shouldBeSaved(QSharedPointer<Entity> &entity , const Relation &r);
Q_DECL_EXPORT void removeRelations(const QSharedPointer<Entity> &entity);
Q_DECL_EXPORT void removeEntityList(QVariant &var);
Q_DECL_EXPORT void removeManyToManyEntityList(const QSharedPointer<Entity> &e,
bool shouldBeSaved(QSharedPointer<Entity> &entity , const Relation &r);
void removeRelations(const QSharedPointer<Entity> &entity);
void removeEntityList(QVariant &var);
void removeManyToManyEntityList(const QSharedPointer<Entity> &e,
const Relation &r, QVariant &var);
Q_DECL_EXPORT void removeEntity(QVariant &var);
Q_DECL_EXPORT void setNullOneToManyRelation(QVariant &var, const Relation &r);
Q_DECL_EXPORT void setNullEntityPropertyRelation(QVariant &var, const Relation &r);
Q_DECL_EXPORT QMetaProperty mappedProperty(const Relation &r,
void removeEntity(QVariant &var);
void setNullOneToManyRelation(QVariant &var, const Relation &r);
void setNullEntityPropertyRelation(QVariant &var, const Relation &r);
QMetaProperty mappedProperty(const Relation &r,
const QSharedPointer<Entity> &foreignEntity) const;
private:
src/relation.h
class Relation {
public:
Q_DECL_EXPORT explicit Relation();
Q_DECL_EXPORT explicit Relation(QString propertyName, bool optional, RelationType type);
explicit Relation();
explicit Relation(QString propertyName, bool optional, RelationType type);
/**
* @brief Relation
* @param propertyName
* @param type
* @param mappedBy Q_PROPERTY in foreign Entity
*/
Q_DECL_EXPORT explicit Relation(QString propertyName, RelationType type,
explicit Relation(QString propertyName, RelationType type,
QString mappedBy = QString(),
QList<CascadeType> cascadeType = {MERGE, PERSIST, REFRESH});
Q_DECL_EXPORT ~Relation();
Q_DECL_EXPORT RelationType getType() const;
Q_DECL_EXPORT void setType(const RelationType &value);
~Relation();
RelationType getType() const;
void setType(const RelationType &value);
Q_DECL_EXPORT QString getPropertyName() const;
Q_DECL_EXPORT void setPropertyName(const QString &value);
QString getPropertyName() const;
void setPropertyName(const QString &value);
Q_DECL_EXPORT bool getOptional() const;
Q_DECL_EXPORT void setOptional(bool value);
bool getOptional() const;
void setOptional(bool value);
Q_DECL_EXPORT QString getMappedBy() const;
Q_DECL_EXPORT void setMappedBy(const QString &value);
QString getMappedBy() const;
void setMappedBy(const QString &value);
Q_DECL_EXPORT QList<CascadeType> getCascadeType() const;
Q_DECL_EXPORT void setCascadeType(const QList<CascadeType> &value);
QList<CascadeType> getCascadeType() const;
void setCascadeType(const QList<CascadeType> &value);
protected:
QString propertyName;

Auch abrufbar als: Unified diff