FileDocCategorySizeDatePackage
DatabaseReporter.javaAPI DocGlassfish v2 API6198Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

DatabaseReporter

public class DatabaseReporter extends Object
This class will created a dummy database called testconnectivity. and handshake with the database to get the Client Driver info.
author
Jane Young
version
$Revision: 1.2 $

Fields Summary
private static final com.sun.enterprise.util.i18n.StringManager
lsm
private static final com.sun.enterprise.cli.framework.CLILogger
logger
private static final String
DERBY_CLIENT_DRIVER_CLASS_NAME
private static final String
URL
private static final String
DB_NAME
private static final String
USER
private static final String
PASS
private static final String
DB_PORT
private static final String
DB_HOME
private final String
dcn
private final String
url
private final String
user
private final String
password
private final String
dbhome
private final String
dbport
private final Connection
conn
Constructors Summary
public DatabaseReporter(String dbhome, String dbport, String dcn, String url, String user, String password)


        //constructor
              
                                        
	    this.dcn = dcn;
    	this.user = user;
    	this.password = password;
        this.dbhome = dbhome;
        this.dbport = dbport;
        this.url = url+dbport+DB_NAME;
    	Class.forName(dcn);
    	conn = DriverManager.getConnection(this.url, this.user, this.password);
    
Methods Summary
private voiddisplay()
display the database info.

        logger.printMessage(getDatabaseInfoMsg());
        logger.printMessage(getDatabaseDriverNameMsg());
        logger.printMessage(getDatabaseDriverVersionMsg());
        logger.printMessage(getJDBCSpecificationMsg());
    
private java.lang.StringgetDatabaseDriverNameMsg()
get database driver name.

        final String sDriverName = conn.getMetaData().getDriverName();
        return ( lsm.getString("database.driver.name.msg", sDriverName));
    
private java.lang.StringgetDatabaseDriverVersionMsg()
get database driver version.

        final String sDriverVersion = conn.getMetaData().getDriverVersion();
        return ( lsm.getString("database.driver.version.msg", sDriverVersion));
    
private java.lang.StringgetDatabaseInfoMsg()
get database info msg.

        return (lsm.getString("database.info.msg"));
    
private java.lang.StringgetJDBCSpecificationMsg()
get jdbc major and minor version.

        final int iJDBCMajorVersion = conn.getMetaData().getJDBCMajorVersion();
        final int iJDBCMinorVersion = conn.getMetaData().getJDBCMinorVersion();
        final String sJDBCSpec = iJDBCMajorVersion + "." + iJDBCMinorVersion;
        return ( lsm.getString("jdbc.version.msg", sJDBCSpec));
    
public static voidmain(java.lang.String[] args)

	    DatabaseReporter dmt = null;
    	if (args == null || (args.length < 6 && args.length>2) ) {
	        dmt = new DatabaseReporter(DB_HOME, DB_PORT, DERBY_CLIENT_DRIVER_CLASS_NAME, URL, USER, PASS);
    	}
        else if (args.length == 2) {
	        dmt = new DatabaseReporter(args[0], args[1], DERBY_CLIENT_DRIVER_CLASS_NAME, URL, USER, PASS);
        }
    	else {
	        dmt = new DatabaseReporter(args[0], args[1], args[2], args[3], args[4], args[5]);
    	}
        try {
            dmt.display();
            dmt.removeDatabaseFile();
        }
        catch (Exception e) {
            logger.printMessage(lsm.getString("UnableToConnectToDatabase"));
            System.exit(1);
        }
        
    
private voidremoveDatabaseFile()
remove database file

		File f = new File(dbhome, "testconnectivity");
		FileUtils.whack(f);