Sei sulla pagina 1di 6

DomainModel.

cpp 1
#include "DomainModel.h"
using namespace DBConan;

KeyElementData::~KeyElementData()
{
}

ForeignKeyData::~ForeignKeyData()
{
}

PrimaryKeyData::~PrimaryKeyData()
{
}

ColumnData::~ColumnData()
{
}

TableData::~TableData()
{
}

SchemaData::~SchemaData()
{
}

KeyElementData::KeyElementData() : position(-1)
{
}

KeyElementData::KeyElementData(const KeyElementData & other) : QSharedData(other),


position(other.position),
column(other.column)
{
}

PrimaryKeyData::PrimaryKeyData()
{
name.clear();
elements.clear();
foreignKeys.clear();
}

PrimaryKeyData::PrimaryKeyData(const PrimaryKeyData & other) : QSharedData(other),


name(other.name),
elements(other.elements), foreignKeys(other.foreignKeys), table(other.table)
{
}

ForeignKeyData::ForeignKeyData()
{
name.clear();
elements.empty();
}

ForeignKeyData::ForeignKeyData(const ForeignKeyData & other) : QSharedData(other),


name(other.name),
elements(other.elements), primaryKey(other.primaryKey), table(other.table)
{
}

ColumnData::ColumnData() : position(-1)
{
name.clear();
type.clear();
keyName.clear();
description.clear();
DomainModel.cpp 2
}

ColumnData::ColumnData(const ColumnData & other) : QSharedData(other), name(other.name),


type(other.type), keyName(other.keyName), position(other.position),
description(other.description)
{
}

TableData::TableData() : allPossibleForeignKeysLocked(false)
{
name.clear();
columns.empty();
foreignKeys.empty();
allPossibleForeignKeys.empty();
}

TableData::TableData(const TableData & other) : QSharedData(other),


name(other.name), allPossibleForeignKeysLocked(other.allPossibleForeignKeysLocked),
columns(other.columns),
foreignKeys(other.foreignKeys),
allPossibleForeignKeys(other.allPossibleForeignKeys)
{
}

// -- http://www.cprogramming.com/tutorial/initialization-lists-c++.html
SchemaData::SchemaData() : port(-1)
{
host.clear();
dbName.clear();
name.clear();
userName.clear();
description.clear();
tables.empty();
}

SchemaData::SchemaData(const SchemaData & other) : QSharedData(other), host(other.host),


port(other.port), dbName(other.dbName), name(other.name), userName(other.userName),
dateOfCreation(other.dateOfCreation), description(other.description),
tables(other.tables)
{
}

Schema::Schema()
{
d = new SchemaData;
}

Schema::Schema(const Schema & other) : d(other.d)


{
}

Schema::Schema(QString host, int port, QString dbName, QString name,


QString userName, QDateTime dateOfCreation, QString description)
{
d = new SchemaData;
d->host = host;
d->port = port;
d->dbName = dbName;
d->name = name;
d->userName = userName;
d->dateOfCreation = dateOfCreation;
d->description = description;
}

Table::Table()
{
d = new TableData;
}
DomainModel.cpp 3

Table::Table(const Table & other) : d(other.d)


{
}

Table::Table(QString name, QList<QString> columnNames, QList<QString> columnTypes,


QList<QString> columnKeyNames, QString primaryKeyName,
QList<QString> primaryKeyColumnNames)
{
d = new TableData;
d->name = name;

int numberOfColumns = columnNames.size();


for (int i = 0; i < numberOfColumns; i++)
{
Column col(columnNames.at(i),columnTypes.at(i), columnKeyNames.at(i), i+1, "");
d->columns.append(col);
}

QList<KeyElement> pkElements;
int pkElementPosition = 1;
int numberOfPkColumns = primaryKeyColumnNames.size();
for (int i = 0; i < numberOfPkColumns; i++)
{
for (int j = 0; j < numberOfColumns; j++)
{
Column col = d->columns.at(j);
if (col.name() == primaryKeyColumnNames.at(i))
{
KeyElement pkElement(col, pkElementPosition);
pkElementPosition++;
pkElements.append(pkElement);
}
}
}

PrimaryKey pk(*this, primaryKeyName, pkElements);


d->primaryKey.append(pk);
}

KeyElement::KeyElement()
{
d = new KeyElementData;
}

KeyElement::KeyElement(const KeyElement & other) : d(other.d)


{
}

KeyElement::KeyElement(Column column, int position)


{
d = new KeyElementData;
d->column = column;
d->position = position;
}
PrimaryKey::PrimaryKey()
{
d = new PrimaryKeyData;
}

PrimaryKey::PrimaryKey(const PrimaryKey & other) : d(other.d)


{
}

PrimaryKey::PrimaryKey(Table table, QString name, QList<KeyElement> elements)


{
d = new PrimaryKeyData;
d->table = table;
DomainModel.cpp 4
d->name = name;
d->elements = elements;
}

Column::Column()
{
d = new ColumnData;
}

Column::Column(const Column & other) : d(other.d)


{
}

Column::Column(QString name, QString type, QString keyName,


int position, QString description)
{
d = new ColumnData;
d->name = name;
d->type = type;
d->keyName = keyName;
d->position = position;
d->description = description;
}

ForeignKey::ForeignKey()
{
d = new ForeignKeyData;
}

ForeignKey::ForeignKey(const ForeignKey & other) : d(other.d)


{
}

ForeignKey::ForeignKey(Table table, QString name, QList<KeyElement> elements,


PrimaryKey primaryKey)
{
d = new ForeignKeyData;
d->table = table;
d->name = name;
d->elements = elements;
d->primaryKey = primaryKey;
}

// ---------------
void Schema::addTable(Table table)
{
d->tables.append(table);
}
QString Schema::host() const
{
return d->host;
}
int Schema::port() const
{
return d->port;
}
QString Schema::dbName() const
{
return d->dbName;
}
QString Schema::name() const
{
return d->name;
}
QString Schema::userName() const
{
return d->userName;
}
DomainModel.cpp 5
QDateTime Schema::dateOfCreation() const
{
return d->dateOfCreation;
}
QString Schema::description() const
{
return d->description;
}
QList<Table> Schema::tables() const
{
return d->tables;
}
// ---------------
QString Table::name() const
{
return d->name;
}
QList<Column> Table::columns() const
{
return d->columns;
}
PrimaryKey Table::primaryKey() const
{
return d->primaryKey.at(0);
}
QList<ForeignKey> Table::foreignKeys() const
{
return d->foreignKeys;
}
QList<ForeignKey> Table::allPossibleForeignKeys() const
{
return d->allPossibleForeignKeys;
}
// ---------------
QString Column::name() const {
return d->name;
}
QString Column::type() const {
return d->type;
}
QString Column::keyName() const {
return d->keyName;
}
int Column::position() const {
return d->position;
}
QString Column::description() const {
return d->description;
}
// ---------------
int KeyElement::position() const
{
return d->position;
}
Column KeyElement::column() const
{
return d->column;
}
// ---------------
QString PrimaryKey::name() const
{
return d->name;
}
QList<KeyElement> PrimaryKey::elements() const
{
return d->elements;
}
QList<ForeignKey> PrimaryKey::foreignKeys() const {
DomainModel.cpp 6
return d->foreignKeys;
}
Table PrimaryKey::table() const
{
return d->table;
}
// ---------------
QString ForeignKey::name() const
{
return d->name;
}
QList<KeyElement> ForeignKey::elements() const
{
return d->elements;
}
PrimaryKey ForeignKey::primaryKey() const
{
return d->primaryKey;
}
Table ForeignKey::table() const
{
return d->table;
}
// ---------------

Potrebbero piacerti anche