001package bradleyross.library.database; 002import bradleyross.library.database.DatabaseProperties; 003import bradleyross.library.helpers.GenericPrinter; 004import java.sql.SQLException; 005import java.sql.Connection; 006import java.sql.DatabaseMetaData; 007import java.io.PrintStream; 008import java.io.PrintWriter; 009/** 010 * Displays information about database. 011 * @see DatabaseMetaData 012 * @author Bradley Ross 013 * 014 */ 015public class ShowProperties 016{ 017 /** 018 * Object containing information on the database. 019 */ 020 protected DatabaseMetaData meta = null; 021 /** 022 * True indicates that the class was able to 023 * successfully obtain a DatabaseMetaData object. 024 */ 025 protected boolean valid = false; 026 /** 027 * Constructor using java.sql.Connection object. 028 * @param conn Connection object 029 * @throws SQLException 030 */ 031 public ShowProperties(Connection conn) throws SQLException 032 { 033 try 034 { 035 meta = conn.getMetaData(); 036 } 037 catch (SQLException e) 038 { 039 throw e; 040 } 041 valid = true; 042 } 043 /** 044 * Constructor using my database class. 045 * @param data Object containing database connectivity information. 046 * @throws SQLException 047 */ 048 public ShowProperties(DatabaseProperties data) throws SQLException 049 { 050 Connection conn; 051 try 052 { 053 conn = data.getConnection(); 054 meta = conn.getMetaData(); 055 } 056 catch (SQLException e) 057 { 058 throw e; 059 } 060 valid = true; 061 } 062 /** 063 * Class returning database meta data object. 064 * @return Database meta data object 065 */ 066 public DatabaseMetaData getMetaData() 067 { 068 return meta; 069 } 070 /** 071 * Sends information on the database to the object. 072 * @param value Object for printing information, 073 * @throws SQLException 074 */ 075 public void printInfo(PrintStream value) throws SQLException 076 { 077 GenericPrinter printer = new GenericPrinter(value); 078 printInfo(printer); 079 } 080 /** 081 * Sends information on the database to the object. 082 * @param value Object for printing information. 083 * @throws SQLException 084 */ 085 public void printInfo(PrintWriter value) throws SQLException 086 { 087 GenericPrinter printer = new GenericPrinter(value); 088 printInfo(printer); 089 } 090 /** 091 * Sends information on the database to the object. 092 * @param printer GenericPrinter object to be used for output 093 * @throws SQLException 094 */ 095 public void printInfo(GenericPrinter printer) throws SQLException 096 { 097 printer.println("Database is " + meta.getDatabaseProductName() + " " 098 + Integer.toString(meta.getDatabaseMajorVersion()) + "." 099 + Integer.toString(meta.getDatabaseMinorVersion())); 100 printer.println("Handler is " + meta.getDriverName()); 101 printer.println("The term catalog corresponds to " + meta.getCatalogTerm()); 102 printer.println("The term schema corresponds to " + meta.getSchemaTerm()); 103 printer.println("Time/Date functions are " + meta.getTimeDateFunctions()); 104 printer.println("Supports catalogs in data manipulation: " 105 + Boolean.toString(meta.supportsCatalogsInDataManipulation())); 106 printer.println("Supports schemas in data manipulation: " 107 + Boolean.toString(meta.supportsSchemasInDataManipulation())); 108 printer.println("The following characters can be used in unquoted identifier names: " 109 + meta.getExtraNameCharacters()); 110 } 111 /** 112 * Sends information on the database to System.out. 113 * @see System#out 114 * @throws SQLException 115 */ 116 public void printInfo() throws SQLException 117 { 118 printInfo(System.out); 119 } 120 121}