public class ShowSchema extends HttpServlet
DatabaseMetaData
.
This was an earlier attempt to do an autodocumenter for database schemas. There was a later version that also listed indices and foreign keys and used better formatting, and I'm trying to locate it.
It should be noted that SQL Server does not have a BOOLEAN type but uses an integer value instead for result sets containing boolean data. A value of 0 indicates false while a value of 1 indicates true.
The servlet uses the init parameters class, system, and account.
DatabaseProperties
that serves to connect the databases.DatabaseMetaData.getCrossReference(String, String, String, String, String, String)
,
DatabaseMetaData.getIndexInfo(String, String, String, boolean, boolean)
,
DatabaseMetaData.getTables(String, String, String, String[])
,
DatabaseMetaData.getImportedKeys(String, String, String)
,
DatabaseMetaData.getExportedKeys(String, String, String)
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected String |
databaseAccount
Name of account to be used for database connection.
|
protected Class<?> |
databaseClass
Class for handling database.
|
protected String |
databaseClassName
Name of class for handling database.
|
protected String |
databaseDescription
Description of database.
|
protected String |
databaseSystem
Name of system for database connection.
|
protected Vector<String> |
errorMessages
List of warning or error messages generated by this application.
|
protected Vector<String> |
infoMessages
List of informative messages generated by this application.
|
protected boolean |
isValid
True if servlet was correctly instantiated.
|
(package private) Logger |
log |
(package private) ExceptionHelper |
logger |
Constructor and Description |
---|
ShowSchema()
Default constructor.
|
ShowSchema(String className,
String system,
String account)
Constructor to allow the methods to be used by a stand-alone
application.
|
Modifier and Type | Method and Description |
---|---|
String |
buildErrorMessage(String title,
String message)
Generates an error message for the application.
|
protected DatabaseProperties |
getData()
Obtain a connection to the database based on the initialization
parameters for the servlet.
|
void |
init(ServletConfig configIn)
Initializes object for use with servlets.
|
protected boolean |
isIncluded(DatabaseProperties data,
String catalog,
String schema,
String item)
Determines whether an item in the database is to be included in the
reports.
|
protected void |
ProblemFound(Exception e,
GenericPrinter output,
String message)
Place error message on web page if exception is encountered.
|
protected void |
processDatabaseInformation(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate a page containing information about the database system.
|
protected void |
processDescribeTable(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate a web page describing the layout of a table.
|
protected void |
processListProcedures(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate the list of procedures in the database.
|
protected void |
processListTables(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate the list of tables in the database.
|
protected void |
processListViews(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate the list of views in the database.
|
protected void |
processRootPage(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate the root page for schema information for the database.
|
protected void |
processUDTInformation(DatabaseProperties data,
GenericPrinter output,
HttpServletRequest req,
HttpServletResponse res)
Generate the list of user defined types for the database system.
|
void |
service(HttpServletRequest req,
HttpServletResponse res)
This is the method that is executed each time a request is made for the
web page.
|
protected int |
showResultSet(GenericPrinter output,
ResultSet rs)
Displays a result set as an HTML table.
|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
ExceptionHelper logger
protected boolean isValid
protected String databaseClassName
protected Class<?> databaseClass
protected String databaseSystem
protected String databaseDescription
protected String databaseAccount
protected Vector<String> errorMessages
protected Vector<String> infoMessages
public ShowSchema()
The default constructor is used by the Tomcat application server when setting up the servlet. The default constructor must be explicitly defined since there is an explicit constructor for the class.
public ShowSchema(String className, String system, String account)
className
- Name of class for defining database connections.system
- Database system for which connection is to be made.account
- Account name to be used in connecting to the
database.public String buildErrorMessage(String title, String message)
title
- Text to appear in titlemessage
- Text to appear in body of messageprotected boolean isIncluded(DatabaseProperties data, String catalog, String schema, String item)
When dealing with SQLServer, dbo.dtproperties was showing up on the list of tables even though it was a system table. The other system tables weren't appearing.
data
- Object describing data connectioncatalog
- Name of catalog for item in databaseschema
- Name of schema for item in databaseitem
- Name of item in databaseprotected DatabaseProperties getData()
databaseAccount
,
databaseSystem
,
databaseClassName
public void init(ServletConfig configIn) throws ServletException
The following servlet configuration items are used.
init
in interface Servlet
init
in class GenericServlet
configIn
- Servlet configuration objectServletException
protected void ProblemFound(Exception e, GenericPrinter output, String message)
e
- Exceptionoutput
- Output device for servlet writerpublic void service(HttpServletRequest req, HttpServletResponse res) throws IOException
service
in class HttpServlet
req
- Request informationres
- Response informationIOException
protected void processRootPage(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
data
- Object describing database connectionoutput
- Object for writing web pagereq
- HTTP request informationres
- HTTP response informationIOException
protected void processListTables(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
data
- Object describing database connectionoutput
- Object for writing web pagereq
- HTTP request informationres
- HTTP response informationIOException
protected void processListViews(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
data
- Object describing database connectionoutput
- Object for writing web pagereq
- HTTP request informationres
- HTTP response informationIOException
protected void processListProcedures(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
data
- Object containing database connection informationoutput
- Object for writing web pagereq
- HTTP request informationres
- HTTP response informationIOException
DatabaseMetaData.getProcedures(String, String, String)
protected void processUDTInformation(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
Needs to have code for User Defined Types inserted.
data
- Database connection informationoutput
- GenericPrinter object to which material is sentreq
- HTTP request objectres
- HTTP response objectIOException
DatabaseMetaData.getUDTs(String, String, String, int[])
protected void processDatabaseInformation(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
data
- Object containing database connection informationoutput
- Object for writing web pagereq
- HTTP request informationres
- HTTP response informationIOException
DatabaseMetaData
protected void processDescribeTable(DatabaseProperties data, GenericPrinter output, HttpServletRequest req, HttpServletResponse res) throws IOException
data
- Database connection data objectoutput
- GenericPrinter object to which information is sentreq
- HTTP request objectres
- HTTP response objectIOException
DatabaseMetaData.getTables(String, String, String, String[])
,
DatabaseMetaData.getColumns(String, String, String, String)
,
DatabaseMetaData.getIndexInfo(String, String, String, boolean, boolean)
,
DatabaseMetaData.getExportedKeys(String, String, String)
,
DatabaseMetaData.getImportedKeys(String, String, String)
protected int showResultSet(GenericPrinter output, ResultSet rs)
output
- Object for printing to HTML pagers
- Result set to be processed