/*
 * Copyright (C) 2004-2006  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cope;

import com.exedio.dsmf.ForeignKeyConstraint;

final class ItemColumn extends IntegerColumn
{
	final Type<?> targetType;
	final String integrityConstraintName;

	ItemColumn(final Table table, final String id,
					  final boolean optional,
					  final Type<?> targetType)
	{
		super(table, id, optional, Type.MIN_PK, Type.MAX_PK, false);
		if(targetType==null)
			throw new RuntimeException();
		this.targetType = targetType;
		this.integrityConstraintName = table.database.makeName( table.id + '_' + this.id/* not equal to "id"! */ + "_Fk" ).intern();
	}

	/**
	 * Creates a primary key column with a foreign key contraint.
	 */
	ItemColumn(final Table table, final Type<? extends Item> targetType)
	{
		super(table);
		if(targetType==null)
			throw new RuntimeException();
		this.targetType = targetType;
		this.integrityConstraintName = table.id+"_Sup";
	}

	@Override
	void makeSchema(final com.exedio.dsmf.Table dsmfTable)
	{
		super.makeSchema(dsmfTable);
		final Table targetTable = targetType.getTable();
		new ForeignKeyConstraint(dsmfTable, integrityConstraintName, id, targetTable.id, targetTable.primaryKey.id);
	}
		
}

@@ -1030,23 +1030,16 @@
 ring id,
-%0A%09%09%09%09%09 
  final b
@@ -1058,15 +1058,8 @@
 nal,
-%0A%09%09%09%09%09 
  fin
@@ -1145,27 +1145,31 @@
 , false);%0A%09%09
-if(
+assert 
 targetType==
@@ -1170,47 +1170,14 @@
 Type
-=
+!
 =null
-)%0A%09%09%09throw new RuntimeException()
 ;%0A%09%09
@@ -1505,11 +1505,15 @@
 ;%0A%09%09
-if(
+assert 
 targ
@@ -1522,47 +1522,14 @@
 Type
-=
+!
 =null
-)%0A%09%09%09throw new RuntimeException()
 ;%0A%09%09

use assert statement