/*******************************************************************************
 * Copyright (c) 2016 University of York
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 *     Horacio Hoyos - Initial API and implementation
 *******************************************************************************/
 
 rule packageToSchema
    transform p2s : Patterns!packageToSchema
    to s : rdbms!Schema
{
    s.name = p2s.p.name;
    p2s.p.name.println();
}

function uml!PrimitiveDataType primitiveToName() : String {
    switch(self.name) {
        case 'Integer': return 'NUMBER';
        case 'Boolean':return 'BOOLEAN';
        case 'String':return 'VARCHAR';
    }
    return '';
}

rule classToTable
    transform c2t : Patterns!classToTable
    to t : rdbms!Table, pk: rdbms!Key, pc : rdbms!Column
{
	t.kind = 'base';
    t.schema ::= c2t.c.namespace;
    t.name = c2t.c.name;
    pk.owner = t;
    pk.kind = 'primary';
    pc.owner = t;
    pc.keys = Set{pk};
    pc.type = 'NUMBER';
    pc.name = t.name + '_tid';
    pk.name = t.name + '_pk';
}