001 package com.sptci.rwt;
002
003 import java.sql.Connection;
004 import java.sql.SQLException;
005 import java.util.Collection;
006 import java.util.logging.Logger;
007
008 import com.sptci.KeyValue;
009
010 /**
011 * An abstract base class analyser for the various database objects.
012 *
013 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
014 * @author Rakesh Vidyadharan 2007-09-25
015 * @version $Id: Analyser.java 4123 2008-05-25 21:49:01Z rakesh $
016 */
017 public abstract class Analyser
018 {
019 /** The logger to use to log errors/messages to. */
020 protected static final Logger logger = Logger.getAnonymousLogger();
021
022 /**
023 * The connection manager to use to fetch connections.
024 */
025 protected final ConnectionManager manager;
026
027 /**
028 * Create a new instance of the class using the specified connection
029 * manager.
030 *
031 * @param manager The connection manager to use.
032 */
033 protected Analyser( final ConnectionManager manager )
034 {
035 this.manager = manager;
036 }
037
038 /**
039 * Analyse the database connected to and return the appropriate metadata
040 * objects. Returns a collection of metadata objects that represent all
041 * the objects of this type available to the user.
042 *
043 * @param parameters Optional parameters that are required to analyse
044 * objects of this type.
045 * @return The collection of metadata objects representing all objects of
046 * this type.
047 * @throws SQLException If errors are encountered while analysisng the
048 */
049 public abstract Collection<? extends MetaData> analyse(
050 final MetaData... parameters ) throws SQLException;
051
052 /**
053 * Return a value object that represents the names of the catalogue and/or
054 * schema specified.
055 *
056 * @since Version 1.1
057 * @param metaData The meta data object out of which the names are
058 * to be retrieved.
059 * @return The value object that contains the names.
060 */
061 protected CatalogueSchema getNames( final MetaData metaData )
062 {
063 String catalogue = null;
064 String schema = null;
065 if ( metaData != null )
066 {
067 if ( metaData instanceof CatalogueMetaData )
068 {
069 catalogue = metaData.getName();
070 }
071 else
072 {
073 SchemaMetaData smd = (SchemaMetaData) metaData;
074 if ( smd.getCatalogue() != null )
075 {
076 catalogue = smd.getCatalogue().getName();
077 }
078 schema = smd.getName();
079 }
080 }
081
082 return new CatalogueSchema( catalogue, schema );
083 }
084
085 /**
086 * A value object used to represent the names of the catalogue and
087 * schema.
088 */
089 protected class CatalogueSchema extends KeyValue<String,String>
090 {
091 /**
092 * Create a new instance of the value object with the specified
093 * values.
094 *
095 * @param catalogue The name of the catalogue. May be null.
096 * @param schema The name of the schema. May be null.
097 */
098 public CatalogueSchema( final String catalogue, final String schema )
099 {
100 super( catalogue, schema );
101 }
102
103 /** Return the name of the catalogue. */
104 public String getCatalogue() { return getKey(); }
105
106 /** Return the name of the schema. */
107 public String getSchema() { return getValue(); }
108 }
109 }