salto.tool.sql
Class DatabaseInfo

java.lang.Object
  extended by salto.tool.sql.DatabaseInfo

public class DatabaseInfo
extends java.lang.Object

Cette classe permet de r�cup�rer toutes les informations conernant une base de donn�e. Un finalizer permet de supprimer la connection. Toutefois, il est pr�f�rable de la fermer explicitement avec la m�thode closeConnection Les informations sont renvoy�es par l'interm�diaires des objets TableColInfo TaleFK TablePK TableInfo Ces objets respectent les normes JDBC 2.0. Si les informations sont incompl�tes, il faut v�rifier la compatibilit� de votre driver JDBC. Date de cr�ation : (28/01/01 7:56:42)

Author:
: E. Loiez

Field Summary
static int EXPORTED_KEY
           
static int IMPORTED_KEY
          Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table).
 
Constructor Summary
DatabaseInfo(java.sql.Connection conn)
          Commentaire relatif au constructeur DatabaseInfo.
DatabaseInfo(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String pwd)
          Commentaire relatif au constructeur DatabaseInfo.
 
Method Summary
static CatalogInfo[] getCatalogs(ConnectionInfo info)
           
static TableColInfo[] getColumns(TableInfo tbInfo)
          Ins�rez la description de la m�thode � cet endroit.
static TableFK[][] getExportedFK(TableInfo table)
           
static TableFK[] getFK(java.sql.Connection conn, java.lang.String tableName)
           
 TableFK[] getFK(java.sql.Connection conn, java.lang.String[] tableName)
          Gets a description of the foreign key columns in the foreign key table that reference the primary key columns of the primary key table (describe how one table imports another's key.)
static TableFK[] getFK(java.lang.String tableName)
          Gets a description of the foreign key columns in the foreign key table that reference the primary key columns of the primary key table (describe how one table imports another's key.)
static TableFK[][] getFK(TableInfo table, int type)
           
static TableFK[][] getImportedFK(TableInfo table)
           
static TablePK[] getPK(java.sql.Connection conn, java.lang.String catalogue, java.lang.String shema, java.lang.String tableName)
           
static TablePK[] getPK(TableInfo tbInfo)
          Gets a description of a table's primary key columns.
static ShemaInfo[] getShemas(ConnectionInfo info)
           
static TableInfo[] getTables()
          Ins�rez la description de la m�thode � cet endroit.
static TableInfo[] getTables(CatalogInfo info)
           
static TableInfo[] getTables(java.sql.Connection conn)
           
static TableInfo[] getTables(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema)
           
static TableInfo[] getTables(java.sql.Connection conn, java.lang.String catalog, java.lang.String shema, java.lang.String pattern)
           
static TableInfo[] getTables(ShemaInfo shemaInfo)
           
static TypeInfo[] getTypeInfo(java.sql.Connection conn)
          Retrieves a description of all the standard SQL types supported by this database.
 java.lang.String getWhereClause(java.sql.Connection conn, java.lang.String[] tableNames)
           
 java.lang.String getWhereClause(java.lang.String[] tableNames)
          Ins�rez la description de la m�thode � cet endroit.
static boolean isAutoIncrement(int sqlTyp, java.sql.Connection conn)
           
static boolean isAutoIncrement(java.lang.String typeName, java.sql.Connection conn)
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPORTED_KEY

public static final int IMPORTED_KEY
Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table). They are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ.

Each foreign key column description has the following columns:

  1. PKTABLE_CAT String => primary key table catalog (may be null)
  2. PKTABLE_SCHEM String => primary key table schema (may be null)
  3. PKTABLE_NAME String => primary key table name
  4. PKCOLUMN_NAME String => primary key column name
  5. FKTABLE_CAT String => foreign key table catalog (may be null) being exported (may be null)
  6. FKTABLE_SCHEM String => foreign key table schema (may be null) being exported (may be null)
  7. FKTABLE_NAME String => foreign key table name being exported
  8. FKCOLUMN_NAME String => foreign key column name being exported
  9. KEY_SEQ short => sequence number within foreign key
  10. UPDATE_RULE short => What happens to foreign key when primary is updated:
    • importedNoAction - do not allow update of primary key if it has been imported
    • importedKeyCascade - change imported key to agree with primary key update
    • importedKeySetNull - change imported key to NULL if its primary key has been updated
    • importedKeySetDefault - change imported key to default values if its primary key has been updated
    • importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
  11. DELETE_RULE short => What happens to the foreign key when primary is deleted.
    • importedKeyNoAction - do not allow delete of primary key if it has been imported
    • importedKeyCascade - delete rows that import a deleted key
    • importedKeySetNull - change imported key to NULL if its primary key has been deleted
    • importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
    • importedKeySetDefault - change imported key to default if its primary key has been deleted
  12. FK_NAME String => foreign key name (may be null)
  13. PK_NAME String => primary key name (may be null)
  14. DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit
    • importedKeyInitiallyDeferred - see SQL92 for definition
    • importedKeyInitiallyImmediate - see SQL92 for definition
    • importedKeyNotDeferrable - see SQL92 for definition

See Also:
java.sql.DatabaseMetaData.getExportedKeys, Constant Field Values

EXPORTED_KEY

public static final int EXPORTED_KEY
See Also:
Constant Field Values
Constructor Detail

DatabaseInfo

public DatabaseInfo(java.lang.String driver,
                    java.lang.String url,
                    java.lang.String user,
                    java.lang.String pwd)
             throws java.sql.SQLException,
                    DatabaseException
Commentaire relatif au constructeur DatabaseInfo.

Throws:
java.sql.SQLException
DatabaseException

DatabaseInfo

public DatabaseInfo(java.sql.Connection conn)
Commentaire relatif au constructeur DatabaseInfo.

Method Detail

main

public static void main(java.lang.String[] args)

isAutoIncrement

public static boolean isAutoIncrement(int sqlTyp,
                                      java.sql.Connection conn)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

isAutoIncrement

public static boolean isAutoIncrement(java.lang.String typeName,
                                      java.sql.Connection conn)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

getTypeInfo

public static TypeInfo[] getTypeInfo(java.sql.Connection conn)
                              throws java.sql.SQLException
Retrieves a description of all the standard SQL types supported by this database. They are ordered by DATA_TYPE and then by how closely the data type maps to the corresponding JDBC SQL type.

Each type description has the following columns:

  1. TYPE_NAME String => Type name
  2. DATA_TYPE short => SQL data type from java.sql.Types
  3. PRECISION int => maximum precision
  4. LITERAL_PREFIX String => prefix used to quote a literal (may be null)
  5. LITERAL_SUFFIX String => suffix used to quote a literal (may be null)
  6. CREATE_PARAMS String => parameters used in creating the type (may be null)
  7. NULLABLE short => can you use NULL for this type.
    • typeNoNulls - does not allow NULL values
    • typeNullable - allows NULL values
    • typeNullableUnknown - nullability unknown
  8. CASE_SENSITIVE boolean=> is it case sensitive.
  9. SEARCHABLE short => can you use "WHERE" based on this type:
    • typePredNone - No support
    • typePredChar - Only supported with WHERE .. LIKE
    • typePredBasic - Supported except for WHERE .. LIKE
    • typeSearchable - Supported for all WHERE ..
  10. UNSIGNED_ATTRIBUTE boolean => is it unsigned.
  11. FIXED_PREC_SCALE boolean => can it be a money value.
  12. AUTO_INCREMENT boolean => can it be used for an auto-increment value.
  13. LOCAL_TYPE_NAME String => localized version of type name (may be null)
  14. MINIMUM_SCALE short => minimum scale supported
  15. MAXIMUM_SCALE short => maximum scale supported
  16. SQL_DATA_TYPE int => unused
  17. SQL_DATETIME_SUB int => unused
  18. NUM_PREC_RADIX int => usually 2 or 10

Returns:
a ResultSet object in which each row is an SQL type description
Throws:
java.sql.SQLException - if a database access error occurs

getColumns

public static TableColInfo[] getColumns(TableInfo tbInfo)
Ins�rez la description de la m�thode � cet endroit. Date de cr�ation : (28/01/01 9:03:32) Retour de getColumns TABLE_CAT String => table catalog (may be null) TABLE_SCHEM String => table schema (may be null) TABLE_NAME String => table name COLUMN_NAME String => column name DATA_TYPE short => SQL type from java.sql.Types TYPE_NAME String => Data source dependent type name, for a UDT the type name is fully qualified COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision. BUFFER_LENGTH is not used. DECIMAL_DIGITS int => the number of fractional digits NUM_PREC_RADIX int => Radix (typically either 10 or 2) NULLABLE int => is NULL allowed? columnNoNulls - might not allow NULL values columnNullable - definitely allows NULL values columnNullableUnknown - nullability unknown REMARKS String => comment describing column (may be null) COLUMN_DEF String => default value (may be null) SQL_DATA_TYPE int => unused SQL_DATETIME_SUB int => unused CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column ORDINAL_POSITION int => index of column in table (starting at 1) IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.


getFK

public TableFK[] getFK(java.sql.Connection conn,
                       java.lang.String[] tableName)
Gets a description of the foreign key columns in the foreign key table that reference the primary key columns of the primary key table (describe how one table imports another's key.) This should normally return a single foreign key/primary key pair (most tables only import a foreign key from a table once.) They are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ.

Each foreign key column description has the following columns:

  1. PKTABLE_CAT String => primary key table catalog (may be null)
  2. PKTABLE_SCHEM String => primary key table schema (may be null)
  3. PKTABLE_NAME String => primary key table name
  4. PKCOLUMN_NAME String => primary key column name
  5. FKTABLE_CAT String => foreign key table catalog (may be null) being exported (may be null)
  6. FKTABLE_SCHEM String => foreign key table schema (may be null) being exported (may be null)
  7. FKTABLE_NAME String => foreign key table name being exported
  8. FKCOLUMN_NAME String => foreign key column name being exported
  9. KEY_SEQ short => sequence number within foreign key
  10. UPDATE_RULE short => What happens to foreign key when primary is updated:
    • importedNoAction - do not allow update of primary key if it has been imported
    • importedKeyCascade - change imported key to agree with primary key update
    • importedKeySetNull - change imported key to NULL if its primary key has been updated
    • importedKeySetDefault - change imported key to default values if its primary key has been updated
    • importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
  11. DELETE_RULE short => What happens to the foreign key when primary is deleted.
    • importedKeyNoAction - do not allow delete of primary key if it has been imported
    • importedKeyCascade - delete rows that import a deleted key
    • importedKeySetNull - change imported key to NULL if its primary key has been deleted
    • importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
    • importedKeySetDefault - change imported key to default if its primary key has been deleted
  12. FK_NAME String => foreign key name (may be null)
  13. PK_NAME String => primary key name (may be null)
  14. DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit
    • importedKeyInitiallyDeferred - see SQL92 for definition
    • importedKeyInitiallyImmediate - see SQL92 for definition
    • importedKeyNotDeferrable - see SQL92 for definition

Parameters:
primaryCatalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
primarySchema - a schema name; "" retrieves those without a schema
primaryTable - the table name that exports the key
foreignCatalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
foreignSchema - a schema name; "" retrieves those without a schema
foreignTable - the table name that imports the key
Returns:
ResultSet - each row is a foreign key column description
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
#getImportedKeys

getImportedFK

public static TableFK[][] getImportedFK(TableInfo table)

getExportedFK

public static TableFK[][] getExportedFK(TableInfo table)

getFK

public static TableFK[][] getFK(TableInfo table,
                                int type)

getPK

public static TablePK[] getPK(TableInfo tbInfo)
Gets a description of a table's primary key columns. They are ordered by COLUMN_NAME. Each primary key column description has the following columns: TABLE_CAT String => table catalog (may be null) TABLE_SCHEM String => table schema (may be null) TABLE_NAME String => table name COLUMN_NAME String => column name KEY_SEQ short => sequence number within primary key PK_NAME String => primary key name (may be null)


getPK

public static TablePK[] getPK(java.sql.Connection conn,
                              java.lang.String catalogue,
                              java.lang.String shema,
                              java.lang.String tableName)

getTables

public static TableInfo[] getTables()
                             throws DatabaseException
Ins�rez la description de la m�thode � cet endroit. Date de cr�ation : (28/01/01 8:13:15) Retour de getTables TABLE_CAT String => table catalog (may be null) TABLE_SCHEM String => table schema (may be null) TABLE_NAME String => table name TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". REMARKS String => explanatory comment on the table

Throws:
DatabaseException

getTables

public static TableInfo[] getTables(java.sql.Connection conn)
                             throws DatabaseException
Throws:
DatabaseException

getWhereClause

public java.lang.String getWhereClause(java.lang.String[] tableNames)
Ins�rez la description de la m�thode � cet endroit. Date de cr�ation : (3/02/01 11:52:21)

Returns:
java.lang.String

getWhereClause

public java.lang.String getWhereClause(java.sql.Connection conn,
                                       java.lang.String[] tableNames)

getFK

public static TableFK[] getFK(java.lang.String tableName)
Gets a description of the foreign key columns in the foreign key table that reference the primary key columns of the primary key table (describe how one table imports another's key.) This should normally return a single foreign key/primary key pair (most tables only import a foreign key from a table once.) They are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ.

Each foreign key column description has the following columns:

  1. PKTABLE_CAT String => primary key table catalog (may be null)
  2. PKTABLE_SCHEM String => primary key table schema (may be null)
  3. PKTABLE_NAME String => primary key table name
  4. PKCOLUMN_NAME String => primary key column name
  5. FKTABLE_CAT String => foreign key table catalog (may be null) being exported (may be null)
  6. FKTABLE_SCHEM String => foreign key table schema (may be null) being exported (may be null)
  7. FKTABLE_NAME String => foreign key table name being exported
  8. FKCOLUMN_NAME String => foreign key column name being exported
  9. KEY_SEQ short => sequence number within foreign key
  10. UPDATE_RULE short => What happens to foreign key when primary is updated:
    • importedNoAction - do not allow update of primary key if it has been imported
    • importedKeyCascade - change imported key to agree with primary key update
    • importedKeySetNull - change imported key to NULL if its primary key has been updated
    • importedKeySetDefault - change imported key to default values if its primary key has been updated
    • importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
  11. DELETE_RULE short => What happens to the foreign key when primary is deleted.
    • importedKeyNoAction - do not allow delete of primary key if it has been imported
    • importedKeyCascade - delete rows that import a deleted key
    • importedKeySetNull - change imported key to NULL if its primary key has been deleted
    • importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
    • importedKeySetDefault - change imported key to default if its primary key has been deleted
  12. FK_NAME String => foreign key name (may be null)
  13. PK_NAME String => primary key name (may be null)
  14. DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit
    • importedKeyInitiallyDeferred - see SQL92 for definition
    • importedKeyInitiallyImmediate - see SQL92 for definition
    • importedKeyNotDeferrable - see SQL92 for definition

Parameters:
primaryCatalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
primarySchema - a schema name; "" retrieves those without a schema
primaryTable - the table name that exports the key
foreignCatalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteria
foreignSchema - a schema name; "" retrieves those without a schema
foreignTable - the table name that imports the key
Returns:
ResultSet - each row is a foreign key column description
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
#getImportedKeys

getFK

public static TableFK[] getFK(java.sql.Connection conn,
                              java.lang.String tableName)

getCatalogs

public static CatalogInfo[] getCatalogs(ConnectionInfo info)
Parameters:
conn -

getShemas

public static ShemaInfo[] getShemas(ConnectionInfo info)
Parameters:
conn -
catalog -
Returns:

getTables

public static TableInfo[] getTables(ShemaInfo shemaInfo)
Parameters:
conn -
catalog -
name -
Returns:

getTables

public static TableInfo[] getTables(java.sql.Connection conn,
                                    java.lang.String catalog,
                                    java.lang.String schema)

getTables

public static TableInfo[] getTables(java.sql.Connection conn,
                                    java.lang.String catalog,
                                    java.lang.String shema,
                                    java.lang.String pattern)

getTables

public static TableInfo[] getTables(CatalogInfo info)
Parameters:
info -
Returns:


Copyright © 2002-2008 Salto Consulting. All Rights Reserved.