package mit.sql ;

public class Table
	implements	sql.Table
{
	private static final sql.TableException GETTABLEFAILED
		= new sql.TableException
			( sql.TableException.GETROWSFAILED
			) ;

	private sql.Connection connection = null ;
	public sql.Connection getConnection()
	{
		return this.connection ;
	}

	private sql.Rows rows = null ;
	public sql.Rows getRows()
	{
		return this.rows ;
	}

	public static sql.Table getTables
		( sql.Connection connection
		)
		throws Exception
	{
		String[] tableTypes = new String[ 2 ] ;
		tableTypes[ 0 ] = "TABLE" ;
		tableTypes[ 1 ] = "VIEW" ;
		return getTables
			( connection
			, null
			, null
			, null
			, tableTypes
			) ;
	}

	public static sql.Table getTables
		( sql.Connection connection
		, String catalog
		, String schemaPattern
		, String tableNamePattern
		, String[] tableTypes
		)
		throws Exception
	{
		return new mit.sql.Table
			( connection
			, catalog
			, schemaPattern
			, tableNamePattern
			, tableTypes
			) ;
	}

	public static sql.Table executeQuery
		( sql.Connection connection
		, String sql
		)
		throws Exception
	{
		sql.Table table
			= new mit.sql.Table
				( connection
				, sql
				, ( Object[] ) null
				, ( int[] ) null
				, ( int[] ) null
				) ;
		return table ;
	}

	public static sql.Table executeQuery
		( sql.Connection connection
		, String sql
		, Object[] objs
		)
		throws Exception
	{
		sql.Table table
			= new mit.sql.Table
				( connection
				, sql
				, objs
				, ( int[] ) null
				, ( int[] ) null
				) ;
		return table ;
	}

	public static sql.Table executeQuery
		( sql.Connection connection
		, String sql
		, Object[] objs
		, int[] targetSqlTypes
		)
		throws Exception
	{
		sql.Table table
			= new mit.sql.Table
				( connection
				, sql
				, objs
				, targetSqlTypes
				, ( int[] ) null
				) ;
		return table ;
	}

	public static sql.Table executeQuery
		( sql.Connection connection
		, String sql
		, Object[] objs
		, int[] targetSqlTypes
		, int[] scales
		)
		throws Exception
	{
		sql.Table table
			= new mit.sql.Table
				( connection
				, sql
				, objs
				, targetSqlTypes
				, scales
				) ;
		return table ;
	}

	public static sql.Table getProcedureColumns
		( sql.Connection connection
		, String catalog
		, String schemaPattern
		, String procedureName
		, String columnNamePattern
		)
		throws Exception
	{
		sql.Table table
			= new mit.sql.Table
				( connection
				, catalog
				, schemaPattern
				, procedureName
				, columnNamePattern
				) ;
		return table ;
	}

	public static sql.Table getProcedures
		( sql.Connection connection
		, String catalog
		, String schemaPattern
		, String procedureNamePattern
		)
		throws Exception
	{
		sql.Table table
			= new mit.sql.Table
				( connection
				, catalog
				, schemaPattern
				, procedureNamePattern
				) ;
		return table ;
	}

	protected Table
		( sql.Connection connection
		, sql.Rows rows
		)
		throws Exception
	{
		this.connection = connection ;
		this.rows = rows ;
	}

	private Table
		( sql.Connection connection
		, String catalog
		, String schemaNamePattern
		, String tableNamePattern
		, String[] tableTypes
		)
		throws Exception
	{
		this.connection = connection ;
		this.rows
			= new mit.sql.Rows
				( this
				, catalog
				, schemaNamePattern
				, tableNamePattern
				, tableTypes
				) ;
	}

	private Table
		( sql.Connection connection
		, String sql
		, Object[] objs
		, int[] targetSqlTypes
		, int[] scales
		)
		throws Exception
	{
		this.connection = connection ;
		this.rows
			= new mit.sql.Rows
				( this
				, sql
				, objs
				, targetSqlTypes
				, scales
				) ;
	}

	private Table
		( sql.Connection connection
		, String catalog
		, String schemaPattern
		, String procedureNamePattern
		)
		throws Exception
	{
		this.connection = connection ;
		this.rows
			= new mit.sql.Rows
				( this
				, catalog
				, schemaPattern
				, procedureNamePattern
				) ;
	}

	private Table
		( sql.Connection connection
		, String catalog
		, String schemaPattern
		, String procedureName
		, String columnNamePattern
		)
		throws Exception
	{
		this.connection = connection ;
		this.rows
			= new mit.sql.Rows
				( this
				, catalog
				, schemaPattern
				, procedureName
				, columnNamePattern
				) ;
	}

}