cox.jmatt.java.MathTools.demo
Class MathDBCDemo

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by cox.jmatt.java.MathTools.demo.MathDBCDemo
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class MathDBCDemo
extends java.awt.Panel
implements java.awt.event.ActionListener

This class serves as a MathDBC demo and as a JDBC tool. Although not visible MathDBC is used to create a Connection to the specified database. The Driver class name and JDBC URL are configured on the Config panel and the main area holds SQL commands to be executed. The Login Properties panel holds properties that are used when establishing a Driver Connection and an URLLoaderPanel rounds out the mix. The Loader panel is used to set the CapCom Math ClassLoader for the MathDBC instance to use.

If the last SQL statement executed generates a ResultSet it can be printed via a MathTestFormatter. The config panel holds a TextField for the template String and the output can be sent to the clipboard. (BasicMathPrinter processMathObject()). No formatting tokens other than the ResultSet or built-in ones are available but those should suffice.

In its second role MathDBCDemo allows 'raw' SQL to be executed using JDBC. While there are many other tools dedicated solely to that purpose none of them are included in MathTools! This tool allows the quick creation or manipulation of a JDBC-enabled database without needing to wrap the SQL in scripting language statements. This means a database can be created quickly from nothing but SQL. It is also possible to execute queries against it, quickly and from within MathTools, after it has been created.

Besides quick database creation MathDBCDemo allows SQL experimentation. This makes it possible to 'debug' SQL statements before including them in scripts, without resorting to an external tool.

Configuration and Debugging

MathDBCDemo defines a set of macro commands that allow in-line configuration and debugging. These commands are all two characters in length, the first of which is a slash. All necessary information, such as Driver class name and JDBC connection URL, can be specified within the SQL commands. The echo command ('/e') prints a message and the break command ('/x') STOPS execution. This allows SQL debugging with single line progressive granularity. This means a LONG batch of SQL can be debugged without the need for massive amounts of typing or re-loading.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String KEY_CONFIG
          This is the constant key used to select the configuration panel.
static java.lang.String KEY_PROPS
          This is the constant key used to select the connect() panel.
static java.lang.String KEY_SQL
          This is the constant key used to select the SQL entry panel in the main display area.
static java.lang.String KEY_URL
          This is the constant key used to select the URL ClassLoader.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MathDBCDemo()
          Zero-argument constructor.
MathDBCDemo(java.awt.Dialog pParent)
          Build the demo around a Dialog.
MathDBCDemo(java.awt.Frame pParent)
          Build the demo around a Dialog.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aev)
          Handle all button clicks.
 void clearProps(boolean pOkToClear)
          Clear the parameter area.
 void clearSQL(boolean pOkToClear)
          Clear the SQL area.
 java.awt.Panel configPanel()
          This is the configuration Panel.
 void executeSQL()
          This method executes the SQL statements in the main Panel.
 java.lang.String getDriver()
          Get the current driver name.
 java.lang.String getJDBC()
          Get the current database URL.
 java.util.Properties getPizza()
          Parse the config Properties object and return it.
 java.lang.String getSQL()
          Fetch the current SQL commands.
 java.lang.String getTemplate()
          Get the current row format template.
 void loadFile(java.lang.String pKey)
          Load a script or pizza from a FileDialog.
 void loadFile(java.lang.String pFile, java.lang.String pKey)
          Load a script or Properties from a file.
 java.awt.Panel loginPropsPanel()
          This Panel holds the Properties object used to enter database login parameters.
 boolean processMacroCommand(java.lang.String pCmd)
          This method processes any macro commands embedded within SQL comments.
 void setDriver(java.lang.String pDriver)
          Set the name of the JDBC driver.
 void setJDBC(java.lang.String pJDBC)
          Set the database URL.
 void setSQL(java.lang.String pScript)
          Put SQL commands in the SQL Entry Area.
 void setTemplate(java.lang.String pTemplate)
          Set the row format template.
 java.awt.Panel SQLEntryPanel()
          This is the Panel used to enter the SQL commands.
 java.awt.Panel standardGUI()
          This method builds the standard GUI and returns itself as a reference.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_SQL

public static final java.lang.String KEY_SQL
This is the constant key used to select the SQL entry panel in the main display area.

See Also:
Constant Field Values

KEY_PROPS

public static final java.lang.String KEY_PROPS
This is the constant key used to select the connect() panel.

See Also:
Constant Field Values

KEY_CONFIG

public static final java.lang.String KEY_CONFIG
This is the constant key used to select the configuration panel.

See Also:
Constant Field Values

KEY_URL

public static final java.lang.String KEY_URL
This is the constant key used to select the URL ClassLoader.

See Also:
Constant Field Values
Constructor Detail

MathDBCDemo

public MathDBCDemo()
Zero-argument constructor. FileDialog functionality will not be present.


MathDBCDemo

public MathDBCDemo(java.awt.Dialog pParent)
Build the demo around a Dialog. All functions available.


MathDBCDemo

public MathDBCDemo(java.awt.Frame pParent)
Build the demo around a Dialog. All functions available.

Method Detail

standardGUI

public final java.awt.Panel standardGUI()
This method builds the standard GUI and returns itself as a reference. It should be used in constructing the GUI.


SQLEntryPanel

public final java.awt.Panel SQLEntryPanel()
This is the Panel used to enter the SQL commands.


configPanel

public final java.awt.Panel configPanel()
This is the configuration Panel.


loginPropsPanel

public final java.awt.Panel loginPropsPanel()
This Panel holds the Properties object used to enter database login parameters.


actionPerformed

public final void actionPerformed(java.awt.event.ActionEvent aev)
Handle all button clicks.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

getPizza

public java.util.Properties getPizza()
Parse the config Properties object and return it.


loadFile

public void loadFile(java.lang.String pKey)
Load a script or pizza from a FileDialog. This method only works if its ScriptPanel was created around a Frame or a Dialog.

Parameters:
pKey - The KEY_ constant determining where to load.

loadFile

public void loadFile(java.lang.String pFile,
                     java.lang.String pKey)
Load a script or Properties from a file. This method expects a text file as it will attempt to create a FileReader and copy it to the specified Area. Any Exceptions are reported at the Error level. If the filename or key is null or empty this method returns silently. The pKey parameter determines where to send the load: KEY_SQL loads SQL, KEY_PROPS loads into the config panel. If pKey is not valid or not recognized the load goes to CapCom.println();

Parameters:
pFile - The name of the file to load.
pKey - The place to send the loaded file.

getSQL

public java.lang.String getSQL()
Fetch the current SQL commands.


setSQL

public void setSQL(java.lang.String pScript)
Put SQL commands in the SQL Entry Area.


getDriver

public java.lang.String getDriver()
Get the current driver name.


setDriver

public void setDriver(java.lang.String pDriver)
Set the name of the JDBC driver.


getJDBC

public java.lang.String getJDBC()
Get the current database URL.


setJDBC

public void setJDBC(java.lang.String pJDBC)
Set the database URL.


getTemplate

public java.lang.String getTemplate()
Get the current row format template.


setTemplate

public void setTemplate(java.lang.String pTemplate)
Set the row format template.


clearSQL

public void clearSQL(boolean pOkToClear)
Clear the SQL area. The default implementation clears on the state of the '[]Lock all clear functions' Checkbox.

Parameters:
pOkToClear - true to REALLY clear the area, false not to.

clearProps

public void clearProps(boolean pOkToClear)
Clear the parameter area. The default implementation clears on the state of the '[]Lock all clear functions' Checkbox.

Parameters:
pOkToClear - true to REALLY clear the config props.

executeSQL

public void executeSQL()

This method executes the SQL statements in the main Panel. If the last statement executed returns a ResultSet and the 'format result' Checkbox is enabled it is sent to a MathTestFormatter for formatting. The formatting template is entered in the 'template' TextArea. If the 'processMathObject()' Checkbox is enabled the resulting String is sent to CapCom.processMathObject(), which sends it to the clipboard.


processMacroCommand

public boolean processMacroCommand(java.lang.String pCmd)

This method processes any macro commands embedded within SQL comments. The macro commands allow configuration values to be set. The macro commands all start with a slash character ('/') and consist of a single letter followed by the data to be configured. The command line must start with a double hyphen followed by a single space: '-- ' and then the command. The macro commands are as follows.

Uppercase letters will also work.

NOTE: The macro commands are embedded within SQL line comments. In order to be executed the (trimmed) line must start with a double hyphen followed by at least one space. The macro parser ignores any line that does not begin '-- ' and further ignores lines whose fourth character is not a slash.

Parameters:
pCmd - The macro command to execute.
Returns:
false on 'break' ('/x'), true otherwise.