/*
 * Copyright (C) 2004-2005  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.cope.testmodel.PointerItem;
import com.exedio.cope.testmodel.PointerItem2;

public class JoinOuterTest extends DatabaseLibTest
{
	PointerItem leftJoined;
	PointerItem leftLonely;
	PointerItem2 rightJoined;
	PointerItem2 rightLonely;

	protected void setUp() throws Exception
	{
		super.setUp();
		deleteOnTearDown(rightLonely = new PointerItem2("right"));
		deleteOnTearDown(rightJoined = new PointerItem2("joined"));
		deleteOnTearDown(leftJoined = new PointerItem("joined", rightJoined));
		deleteOnTearDown(leftLonely = new PointerItem("left", rightJoined));
	}

	public void testJoin()
	{
		{
			final Query query = new Query(PointerItem.TYPE, null);
			query.join(PointerItem2.TYPE, Cope.equal(PointerItem.code, PointerItem2.code));
			assertContains(leftJoined, query.search());
		}
		{
			final Query query = new Query(PointerItem.TYPE, null);
			query.joinOuterLeft(PointerItem2.TYPE, Cope.equal(PointerItem.code, PointerItem2.code));
			assertContains(leftJoined, leftLonely, query.search());
		}

		if(hsqldb)
		{
			final Query query = new Query(PointerItem.TYPE, null);
			query.joinOuterRight(PointerItem2.TYPE, Cope.equal(PointerItem.code, PointerItem2.code));
			try
			{
				query.search();
				fail("should have throws RuntimeException");
			}
			catch(RuntimeException e)
			{
				assertEquals("hsqldb not support right outer joins", e.getMessage());
			}
		}
		else
		{
			final Query query = new Query(PointerItem.TYPE, null);
			query.joinOuterRight(PointerItem2.TYPE, Cope.equal(PointerItem.code, PointerItem2.code));
			assertContains(leftJoined, null, query.search());
		}
	}

}

@@ -1851,21 +1851,8 @@
 %09%7D%0A%0A
-%09%09if(hsqldb)%0A
 %09%09%7B%0A
@@ -2002,16 +2002,36 @@
 code));%0A
+%09%09%09if(hsqldb)%0A%09%09%09%7B%0A%09
 %09%09%09try%0A%09
@@ -2028,26 +2028,28 @@
 %0A%09%09%09%09try%0A%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09query.se
@@ -2056,16 +2056,17 @@
 arch();%0A
+%09
 %09%09%09%09fail
@@ -2110,16 +2110,17 @@
 %22);%0A
+%09
 %09%09%09%7D%0A%09%09%09
 catc
@@ -2115,16 +2115,17 @@
 %09%09%09%7D%0A%09%09%09
+%09
 catch(Ru
@@ -2141,26 +2141,28 @@
 ption e)%0A%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09assertEq
@@ -2230,14 +2230,17 @@
 %0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%7D%0A
+%09
 %09%09el
@@ -2248,161 +2248,12 @@
 e%0A%09%09
+%09
 %7B%0A%09
-%09%09final Query query = new Query(PointerItem.TYPE, null);%0A%09%09%09query.joinOuterRight(PointerItem2.TYPE, Cope.equal(PointerItem.code, PointerItem2.code));%0A
 %09%09%09a
@@ -2297,22 +2297,27 @@
 .search());%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A%7D%0A

refactor hsqldb exception