%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CLASS2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

class2(Name,Id):-table(Name,Id).

class2(Name,Id):-row(Name,_,Id).

class2(Name,Id):-col(Name,_,_,Id).

class2(Name,Id):-key(Name,_,_,Id).

class2(Name,Id):-foreign(Name,_,_,Id).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% EXTENSION2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

extension2('table_extension').

extension2('row_extension').

extension2('column_extension').

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEREOTYPE2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

stereotype2('table','table_stereotype').

stereotype2('row','row_stereotype').

stereotype2('column','column_stereotype').

 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PROPERTY2 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

property2(Name,Type,false,false,'1','1',false,IdF,Id_attribute):-
	attribute(Name,Type,IdF,Id_attribute).

property2(Name,Id_role,Is_composite,Is_unique,Lower,Upper,false,IdF,Id_role):-
	associationlink(Name,Is_composite,Is_unique,IdF,Id_role,Lower,Upper).



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ASSOCIATION2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

association2('',Id_association):-associationEnds2(ownedEnd,Id_association,_).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ASSOCIATIONENDS2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

associationEnds2(extension,Id_table,'table_extension'):-
			table(_,Id_table).
	 
	
associationEnds2(extension,Id_row,'row_extension'):-
			row(_,_,Id_row).
	 

associationEnds2(extension,Id_column,'column_extension'):-
			col(_,_,_,Id_column).

associationEnds2(extension,Id_column,'column_extension'):-
			foreign(_,_,_,Id_column).
	
associationEnds2(extension,Id_column,'column_extension'):-
			key(_,_,_,Id_column).
	 

associationEnds2(stereotype,'table_extension','table_stereotype').
	 

associationEnds2(stereotype,'row_extension','row_stereotype').
	 

associationEnds2(stereotype,'column_extension','column_stereotype').
 

associationEnds2(ownedAttribute,Id_column,Id_attribute):-
			attribute(_,_,Id_column,Id_attribute).

associationEnds2(ownedEnd,[Id_link1,Id_link2],Id_link2):-
		associationlink('foreign',_,_,Id_link1,Id_link2,_,_).

associationEnds2(ownedEnd,[Id_link1,Id_link2],Id_link2):-
			associationlink('line',_,_,Id_link1,Id_link2,_,_).

associationEnds2(ownedEnd,[Id_link1,Id_link2],Id_link2):-
			associationlink('key',_,_,Id_link1,Id_link2,_,_).

associationEnds2(ownedEnd,[Id_link1,Id_link2],Id_link2):-
			associationlink('col',_,_,Id_link1,Id_link2,_,_).

associationEnds2(navigableOwnedEnd,Id_association,Id_link):-
			associationEnds2(ownedEnd,Id_association,Id_link).


%%%%%%%%%%%%%%%%%%%%%%%%%%
% ASSOCIATION-LINK
%%%%%%%%%%%%%%%%%%%%%%%%%%%
	 

associationlink('line',false,false,Id_table,Id_row,'0','*'):-
		table(_,Id_table),
		row(_,Id_table,Id_row).

associationlink('',true,false,Id_row,Id_table,'1','1'):-
		table(_,Id_table),
		row(_,Id_table,Id_row).

associationlink('foreign',false,false,Id_row,Id_column,'1','1'):-
		 row-mix(_,_,Id_row),
		 foreign(_,_,Id_row,Id_column).

associationlink('',true,false,Id_column,Id_row,'1','1'):-
		row-mix(_,_,Id_row),
		foreign(_,_,Id_row,Id_column).

associationlink('col',false,false,Id_row,Id_column,'1','1'):-
		row-store(_,_,Id_row),
		col(_,_,Id_row,Id_column).

associationlink('',true,false,Id_column,Id_row,'1','1'):-
		row-store(_,_,Id_row),
		col(_,_,Id_row,Id_column).

associationlink('key',false,false,Id_row,Id_column,'1','1'):-
		row-store(_,_,Id_row),
		key(_,_,Id_row,Id_column).

associationlink('',true,false,Id_column,Id_row,'1','1'):-
		row-store(_,_,Id_row),
		key(_,_,Id_row,Id_column).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ATTRIBUTE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

attribute('type',Type,[Id_table,Id_row,Id_column],[Id_table,Id_row,Id_column,Id_attribute]):-
		attribute(Name,Type,true,Id_row,Id_attribute),
		row-store(_,Id_table,[Id_table,Id_row]),
		key(Name,Type,[Id_table,Id_row],[Id_table,Id_row,Id_column]). 

attribute('type',Type,[Id_table,Id_row,Id_column],[Id_table,Id_row,Id_column,Id_attribute]):-
		attribute(Name,Type,false,Id_row,Id_attribute),
		row-store(_,Id_table,[Id_table,Id_row]),
		col(Name,Type,[Id_table,Id_row],[Id_table,Id_row,Id_column]). 

attribute('type',Type,[Id_table,Id_row,Id_column],[Id_table,Id_row,Id_column,Id_column]):-
		row-mix(_,Id_table,[Id_table,Id_row]),
		foreign(_,Type,[Id_table,Id_row],[Id_table,Id_row,Id_column]).



