/*
 * Copyright (c) 2009-2013 Topi Nieminen
 */
package fi.tnie.db.meta.impl.hsqldb;


import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import fi.tnie.db.AbstractUnitTest;
import fi.tnie.db.TestContext;
import fi.tnie.db.env.Implementation;
import fi.tnie.db.env.hsqldb.HSQLDBImplementation;
import fi.tnie.db.env.util.ResultSetWriter;
import fi.tnie.db.query.QueryException;

public class HSQLDBTest
	extends AbstractUnitTest
{	
	public HSQLDBTest() {
		super();	
	}
		
	@Override
	protected Implementation createImplementation() {
		return new HSQLDBImplementation();
	}
		
	public void testA() throws SQLException {		
		logger().debug("enter: " + getName());
		TestContext imp = getContext();
		
		assertNotNull(imp);
		logger().debug("exit: " + getName());
	}
	
	
	public void testConnection() throws SQLException, QueryException {
		
		TestContext imp = getContext();
		Driver d = imp.getImplementation().getDriver();
		
		Connection c = d.connect("jdbc:hsqldb:mem:test", null);
		
		assertNotNull(c);
		
		
		Statement st = c.createStatement();
		
		{		
			String cr = "create table a(id integer generated by default as identity, primary key(id), name varchar(200) default '')";
			
			{
				int u = st.executeUpdate(cr);
				logger().debug("testConnection: u=" + u);
			}
			
		 
			{
				String is = "insert into a(name) values ( default ) ";
				int u = st.executeUpdate(is, Statement.RETURN_GENERATED_KEYS);
				logger().debug("testConnection: u=" + u);
							
				ResultSet rs = st.getGeneratedKeys();
				
				ResultSetWriter rw = new ResultSetWriter(System.out, false);
				rw.apply(rs, true);
				
			}
		}
		
		
		{		
			String cr = "create table b(id integer generated by default as identity (start with 15), primary key(id), name varchar(200) default '')";
			
			{
				int u = st.executeUpdate(cr);
				logger().debug("testConnection: u=" + u);
			}
			
		 
			{
				String is = "insert into b(name) values ( default ), ( default ) ";
				int u = st.executeUpdate(is, Statement.RETURN_GENERATED_KEYS);
				logger().debug("testConnection: ub=" + u);
							
				ResultSet rs = st.getGeneratedKeys();
				
				ResultSetWriter rw = new ResultSetWriter(System.out, false);
				rw.apply(rs, true);
				
			}
		}		

		
		{		
			String cr = "create table c(id integer generated by default as identity (start with 1 increment by 2), name varchar(200) default '', primary key(id, name))";
			
			{
				int u = st.executeUpdate(cr);
				logger().debug("testConnection: u=" + u);
			}
			
		 
			{
				String is = "insert into c(id, name) values ( default, default ), ( default, default), (1, 'abc') ";
				int u = st.executeUpdate(is, Statement.RETURN_GENERATED_KEYS);
				logger().debug("testConnection: uc=" + u);
							
				ResultSet rs = st.getGeneratedKeys();
				
				ResultSetWriter rw = new ResultSetWriter(System.out, false);
				rw.apply(rs, true);				
			}
		}	
		
		st.close();
		
		c.close();
		
		
	}

	
}

Add HSQLDBTest