Package anvil.core.sql

Source Code of anvil.core.sql.AnyMetaData

/*
* $Id: AnyMetaData.java,v 1.5 2002/09/16 08:05:03 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.core.sql;

import anvil.core.Any;
import anvil.core.AnyAbstractClass;
import anvil.core.AnyString;
import anvil.core.AnyList;
import anvil.core.Array;
import anvil.script.Context;
import anvil.util.SQLUtil;
import anvil.java.util.BindingEnumeration;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

/// @class MetaData
/// Abstract base class for types having SQL meta data description
/// available.

/**
* class AnyMetaData
*
* @author: Jani Lehtim�ki
*/
public class AnyMetaData extends AnyAbstractClass
{


 
  protected ResultSetMetaData _metadata = null;
 
 
  public AnyMetaData(ResultSetMetaData metadata)
  {
    super();
  }
 
   
  public anvil.script.ClassType classOf()
  {
    return __class__;
  }


  public Object toObject()
  {
    try {
      return getMetaData();
    } catch (SQLException e) {
      throw Context.getInstance().exception(e);
    }
  }


  protected ResultSetMetaData getMetaData() throws SQLException
  {
    return _metadata;
  }


  protected int toColumnIndex(Any index) throws SQLException
  {
    if (index.isInt()) {
      return index.toInt() + 1;
    } else {
      return toColumnIndex(index.toString());
    }
  }


  protected int toColumnIndex(String name) throws SQLException
  {
    ResultSetMetaData meta = getMetaData();
    int n = meta.getColumnCount();
    for(int i=1; i<=n; i++) {
      if (meta.getColumnName(i).equals(name)) {
        return i;
      }
    }
    return 0;
  }



  /// @method getColumnCount
  /// Returns the number of columns in this result set
  /// @synopsis int getColumnCount()
  /// @return the number of columns in this ResultSet
  public Any m_getColumnCount(Context context)
  {
    try {
      return create(getMetaData().getColumnCount());
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }
 

  /// @method getCatalogName
  /// Returns the catalog name of given column.
  /// @synopsis string getCatalogName(string columnName)
  /// @synopsis string getCatalogName(int column)
  /// @param columnName
  /// @param column
  /// @return a column's table's catalog name
  /// @throws SQLError if an error occured
  public static final Object[] p_getCatalogName = { null, "column" };
  public Any m_getCatalogName(Context context, Any column)
  {
    try {
      return create(getMetaData().getCatalogName(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }
 

  /// @method getSchemaName
  /// Returns the schema name of given column.
  /// @synopsis string getSchemaName(string columnName)
  /// @synopsis string getSchemaName(int column)
  /// @param columnName
  /// @param column
  /// @return a column's table's schema
  /// @throws SQLError if an error occured
  public static final Object[] p_getSchemaName = { null, "column" };
  public Any m_getSchemaName(Context context, Any column)
  {
    try {
      return create(getMetaData().getSchemaName(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }


  /// @method getTableName
  /// Returns the table name of given column.
  /// @synopsis string getTableName(string columnName)
  /// @synopsis string getTableName(int column)
  /// @param columnName
  /// @param column
  /// @return a column's table name
  /// @throws SQLError if an error occured
  public static final Object[] p_getTableName = { null, "column" };
  public Any m_getTableName(Context context, Any column)
  {
    try {
      return create(getMetaData().getTableName(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }
 

  /// @method getColumnName
  /// Returns the name of column.
  /// @synopsis string getColumnName(string columnName)
  /// @synopsis  string getColumnName(int column)
  /// @param columnName
  /// @param column
  /// @return a column's name
  /// @throws SQLError if an error occured
  public static final Object[] p_getColumnName = { null, "column" };
  public Any m_getColumnName(Context context, Any column)
  {
    try {
      return create(getMetaData().getColumnName(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  } 


  /// @method getColumnLabel
  /// Returns the suggested column title.
  /// @synopsis string getColumnLabel(string columnName)
  /// @synopsis string getColumnLabel(int column)
  /// @param columnName
  /// @param column
  /// @return the suggested column title for use in printouts and displays
  /// @throws SQLError if an error occured
  public static final Object[] p_getColumnLabel = { null, "column" };
  public Any m_getColumnLabel(Context context, Any column)
  {
    try {
      return create(getMetaData().getColumnLabel(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }   


  /// @method getColumnType
  /// Returns the type of column.
  /// @synopsis string getColumnType(string columnName)
  /// @synopsis string getColumnType(int column)
  /// @param columnName
  /// @param column
  /// @return Retrieves a column's SQL type
  /// @throws SQLError if an error occured
  public static final Object[] p_getColumnType = { null, "column" };
  public Any m_getColumnType(Context context, Any column)
  {
    try {
      return create(getMetaData().getColumnTypeName(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }  


  /// @method getColumnLength
  /// Returns the column's normal maximum length.
  /// @synopsis int getColumnLength(string columnName)
  /// @synopsis int getColumnLength(int column)
  /// @param columnName
  /// @param column
  /// @return indicates the column's normal max width in chars
  /// @throws SQLError if an error occured
  public static final Object[] p_getColumnLength = { null, "column" };
  public Any m_getColumnLength(Context context, Any column)
  {
    try {
      return create(getMetaData().getColumnDisplaySize(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }  


  /// @method getPrecision
  /// Returns the column's precision.
  /// @synopsis int getPrecision(string columnName)
  /// @synopsis int getPrecision(int column)
  /// @param columnName
  /// @param column
  /// @return a column's number of decimal digits
  /// @throws SQLError if an error occured
  public static final Object[] p_getPrecision = { null, "column" };
  public Any m_getPrecision(Context context, Any column)
  {
    try {
      return create(getMetaData().getPrecision(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }  
 

  /// @method getScale
  /// Returns the column's scale.
  /// @synopsis int getScale(string columnName)
  /// @synopsis int getScale(int column)
  /// @param columnName
  /// @param column
  /// @return a column's number of digits to right of the decimal point
  /// @throws SQLError if an error occured
  public static final Object[] p_getScale = { null, "column" };
  public Any m_getScale(Context context, Any column)
  {
    try {
      return create(getMetaData().getScale(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }  


  /// @method isAutoIncrement
  /// Indicates whether the column is automatically numbered, thus read-only.
  /// @synopsis boolean isAutoIncrement(string columnName)
  /// @synopsis boolean isAutoIncrement(int column)
  /// @param columnName
  /// @param column
  /// @return true if is automatically numbered
  /// @throws SQLError if an error occured
  public static final Object[] p_isAutoIncrement = { null, "column" };
  public Any m_isAutoIncrement(Context context, Any column)
  {
    try {
      return create(getMetaData().isAutoIncrement(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }  
 
 
  /// @method isCaseSensitive
  /// Indicates whether a column's case matters.
  /// @synopsis boolean isCaseSensitive(string columnName)
  /// @synopsis boolean isCaseSensitive(int column)
  /// @param columnName
  /// @param column
  /// @return true if is case sensitive
  /// @throws SQLError if an error occured
  public static final Object[] p_isCaseSensitive = { null, "column" };
  public Any m_isCaseSensitive(Context context, Any column)
  {
    try {
      return create(getMetaData().isCaseSensitive(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }    
 

  /// @method isCurrency
  /// Indicates whether the column is a cash value
  /// @synopsis boolean isCurrency(string columnName)
  /// @synopsis boolean isCurrency(int column)
  /// @param columnName
  /// @param column
  /// @return true if is currency
  /// @throws SQLError if an error occured
  public static final Object[] p_isCurrency = { null, "column" };
  public Any m_isCurrency(Context context, Any column)
  {
    try {
      return create(getMetaData().isCurrency(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }    


  /// @method isDefinitelyWritable
  /// Indicates whether a write on the column will definitely succeed.
  /// @synopsis boolean isDefinitelyWritable(string columnName)
  /// @synopsis boolean isDefinitelyWritable(int column)
  /// @param columnName
  /// @param column
  /// @return true / false
  /// @throws SQLError if an error occured
  public static final Object[] p_isDefinitelyWritable = { null, "column" };
  public Any m_isDefinitelyWritable(Context context, Any column)
  {
    try {
      return create(getMetaData().isDefinitelyWritable(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }  
 

  /// @method isNullable
  /// @synopsis boolean isNullable(string columnName)
  /// @synopsis boolean isNullable(int column)
  /// @param columnName
  /// @param column
  /// @return <code>true</code> is nullable, <code>false</code> if
  ///    not nullable and <code>null</code> is status in not known.
  /// @throws SQLError if an error occured
  public static final Object[] p_isNullable = { null, "column" };
  public Any m_isNullable(Context context, Any column)
  {
    try {
      switch(getMetaData().isNullable(toColumnIndex(column))) {
      case ResultSetMetaData.columnNoNulls:
        return FALSE;
      case ResultSetMetaData.columnNullable:
        return TRUE;
      case ResultSetMetaData.columnNullableUnknown:
        return NULL;
      default:
        return FALSE;
      }
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }   
  

  /// @method isReadOnly
  /// Indicates whether a column is definitely not writable.
  /// @synopsis boolean isReadOnly(string columnName)
  /// @synopsis boolean isReadOnly(int column)
  /// @param columnName
  /// @param column
  /// @return true / false
  /// @throws SQLError if an error occured
  public static final Object[] p_isReadOnly = { null, "column" };
  public Any m_isReadOnly(Context context, Any column)
  {
    try {
      return create(getMetaData().isReadOnly(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  } 
 
  
  /// @method isSearchable
  /// Indicates whether the column can be used in a where clause.
  /// @synopsis boolean isSearchable(string columnName)
  /// @synopsis boolean isSearchable(int column)
  /// @param columnName
  /// @param column
  /// @return true / false
  /// @throws SQLError if an error occured
  public static final Object[] p_isSearchable = { null, "column" };
  public Any m_isSearchable(Context context, Any column)
  {
    try {
      return create(getMetaData().isSearchable(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }     
    
  /// @method isSigned
  /// Indicates whether values in the column are signed numbers.
  /// @synopsis boolean isSigned(string columnName)
  /// @synopsis boolean isSigned(int column)
  /// @param columnName
  /// @param column
  /// @return true if signed
  /// @throws SQLError if an error occured
  public static final Object[] p_isSigned = { null, "column" };
  public Any m_isSigned(Context context, Any column)
  {
    try {
      return create(getMetaData().isSigned(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }          

  /// @method isWritable
  /// Indicates whether it is possible for a write on the column to succeed.
  /// @synopsis boolean isWritable(string columnName)
  /// @synopsis boolean isWritable(int column)
  /// @param columnName
  /// @param column
  /// @return true if is possible
  /// @throws SQLError if an error occured
  public static final Object[] p_isWritable = { null, "column" };
  public Any m_isWritable(Context context, Any column)
  {
    try {
      return create(getMetaData().isWritable(toColumnIndex(column)));
    } catch (SQLException e) {
      throw context.exception(e);
    }
  }    


  public static final anvil.script.compiler.NativeClass __class__ =
    new anvil.script.compiler.NativeClass("MetaData", AnyMetaData.class,
    //DOC{{
    ""+
      " @class MetaData\n" +
      " Abstract base class for types having SQL meta data description\n" +
      " available.\n" +
      " @method getColumnCount \n" +
      " Returns the number of columns in this result set\n" +
      " @synopsis int getColumnCount()\n" +
      " @return the number of columns in this ResultSet\n" +
      " @method getCatalogName \n" +
      " Returns the catalog name of given column.\n" +
      " @synopsis string getCatalogName(string columnName)\n" +
      " @synopsis string getCatalogName(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return a column's table's catalog name\n" +
      " @throws SQLError if an error occured\n" +
      " @method getSchemaName \n" +
      " Returns the schema name of given column.\n" +
      " @synopsis string getSchemaName(string columnName)\n" +
      " @synopsis string getSchemaName(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return a column's table's schema\n" +
      " @throws SQLError if an error occured\n" +
      " @method getTableName \n" +
      " Returns the table name of given column.\n" +
      " @synopsis string getTableName(string columnName)\n" +
      " @synopsis string getTableName(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return a column's table name\n" +
      " @throws SQLError if an error occured\n" +
      " @method getColumnName \n" +
      " Returns the name of column.\n" +
      " @synopsis string getColumnName(string columnName)\n" +
      " @synopsis  string getColumnName(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return a column's name\n" +
      " @throws SQLError if an error occured\n" +
      " @method getColumnLabel \n" +
      " Returns the suggested column title.\n" +
      " @synopsis string getColumnLabel(string columnName)\n" +
      " @synopsis string getColumnLabel(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return the suggested column title for use in printouts and displays\n" +
      " @throws SQLError if an error occured\n" +
      " @method getColumnType \n" +
      " Returns the type of column.\n" +
      " @synopsis string getColumnType(string columnName)\n" +
      " @synopsis string getColumnType(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return Retrieves a column's SQL type\n" +
      " @throws SQLError if an error occured\n" +
      " @method getColumnLength \n" +
      " Returns the column's normal maximum length.\n" +
      " @synopsis int getColumnLength(string columnName)\n" +
      " @synopsis int getColumnLength(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return indicates the column's normal max width in chars\n" +
      " @throws SQLError if an error occured\n" +
      " @method getPrecision \n" +
      " Returns the column's precision.\n" +
      " @synopsis int getPrecision(string columnName)\n" +
      " @synopsis int getPrecision(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return a column's number of decimal digits\n" +
      " @throws SQLError if an error occured\n" +
      " @method getScale \n" +
      " Returns the column's scale.\n" +
      " @synopsis int getScale(string columnName)\n" +
      " @synopsis int getScale(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return a column's number of digits to right of the decimal point\n" +
      " @throws SQLError if an error occured\n" +
      " @method isAutoIncrement \n" +
      " Indicates whether the column is automatically numbered, thus read-only.\n" +
      " @synopsis boolean isAutoIncrement(string columnName)\n" +
      " @synopsis boolean isAutoIncrement(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true if is automatically numbered\n" +
      " @throws SQLError if an error occured\n" +
      " @method isCaseSensitive \n" +
      " Indicates whether a column's case matters.\n" +
      " @synopsis boolean isCaseSensitive(string columnName)\n" +
      " @synopsis boolean isCaseSensitive(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true if is case sensitive\n" +
      " @throws SQLError if an error occured\n" +
      " @method isCurrency \n" +
      " Indicates whether the column is a cash value\n" +
      " @synopsis boolean isCurrency(string columnName)\n" +
      " @synopsis boolean isCurrency(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true if is currency\n" +
      " @throws SQLError if an error occured\n" +
      " @method isDefinitelyWritable \n" +
      " Indicates whether a write on the column will definitely succeed.\n" +
      " @synopsis boolean isDefinitelyWritable(string columnName)\n" +
      " @synopsis boolean isDefinitelyWritable(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true / false\n" +
      " @throws SQLError if an error occured\n" +
      " @method isNullable\n" +
      " @synopsis boolean isNullable(string columnName)\n" +
      " @synopsis boolean isNullable(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return <code>true</code> is nullable, <code>false</code> if\n" +
      "    not nullable and <code>null</code> is status in not known.\n" +
      " @throws SQLError if an error occured\n" +
      " @method isReadOnly \n" +
      " Indicates whether a column is definitely not writable.\n" +
      " @synopsis boolean isReadOnly(string columnName)\n" +
      " @synopsis boolean isReadOnly(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true / false\n" +
      " @throws SQLError if an error occured\n" +
      " @method isSearchable \n" +
      " Indicates whether the column can be used in a where clause.\n" +
      " @synopsis boolean isSearchable(string columnName)\n" +
      " @synopsis boolean isSearchable(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true / false\n" +
      " @throws SQLError if an error occured\n" +
      " @method isSigned \n" +
      " Indicates whether values in the column are signed numbers.\n" +
      " @synopsis boolean isSigned(string columnName)\n" +
      " @synopsis boolean isSigned(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true if signed\n" +
      " @throws SQLError if an error occured\n" +
      " @method isWritable \n" +
      " Indicates whether it is possible for a write on the column to succeed.\n" +
      " @synopsis boolean isWritable(string columnName)\n" +
      " @synopsis boolean isWritable(int column)\n" +
      " @param columnName\n" +
      " @param column\n" +
      " @return true if is possible\n" +
      " @throws SQLError if an error occured\n"
    //}}DOC
    );
  static {
    SQLModule.class.getName();
  }


}
TOP

Related Classes of anvil.core.sql.AnyMetaData

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.