Class DemoUtil

java.lang.Object
dev.visdb.seesaw.demo.DemoUtil

public class DemoUtil extends Object
Utilities for setting up a database to use with the demos.

The Demo environment supports 3 ways to get a Rowset using getNewRowSet(java.sql.Connection, dev.visdb.seesaw.demo.DemoUtil.RowSetSource). Two of the ways allow the assignment of a connection to a JdbcRowSet, several JdbcRowSet can share a single connection; any threading and/or concurrency issues are handled by the connection. The third way hooks into an actual connection pool, which is provided by the database, and uses a CachedRowSet; in the case of the demo the pool is never bigger than one.

The demo contains two different DataSource implementations. One is trivial and allows a given connection to be associated with a factory provided RowSet. This scheme is semantically equivalent to the previously mentioned mechanism, but without requiring a custom RowSet implementation. It is used like

   rs = RowSetProvider.newFactory().createJdbcRowSet();
   rs.setDataSourceName(getDsName(connection));

Here is an example for the third way using connection pool, based on a connection pool provided by the database.

   rs = RowSetProvider.newFactory().createCachedRowSet();
   rs.setDataSourceName(DataSourcePool.DATA_SOURCE_NAME);
  • Method Details

    • initExampleFrame

      public static void initExampleFrame(JFrame frame, Runnable runOnClose)
      x
      Parameters:
      frame -
      runOnClose -
    • logConnectionUsage

      public static void logConnectionUsage()
      Invoke this method to output collected statistics to log.
    • getWhichRowSetDefault

      The property WhichRowSetDefault controls how a RowSet is created by getNewRowSet(java.sql.Connection).
      Returns:
      default type of RowSet
    • setWhichRowSetDefault

      public static void setWhichRowSetDefault(DemoUtil.RowSetSource _whichRowSetDefault)
      Establish the default for how a RowSet is created.
      Parameters:
      _whichRowSetDefault - default
    • getNewRowSet

      public static RowSet getNewRowSet(Connection connection) throws SQLException
      Build a RowSet with a connection, or how to get one, for use in the Demo. There a flag for whether or not to use the jdk standard mechanisms or Pangburn group's JdbcRowSetImpl.
      Parameters:
      connection - only used to build JdbcRowSetImpl.
      Returns:
      The RowSet with either a Connection or DataSource
      Throws:
      SQLException - passed through
    • getNewRowSet

      public static RowSet getNewRowSet(Connection connection, DemoUtil.RowSetSource whichRowSet) throws SQLException
      Like getNewRowSet(Connection), but specify RowSetSource. Note: connection can be null, but only if whichRowSet is POOL_CACHED.
      Parameters:
      connection - only used to build JdbcRowSetImpl.
      whichRowSet - how to construct the RowSet and/or get it's connection
      Returns:
      The RowSet with either a Connection or DataSource
      Throws:
      SQLException - passed through
    • hasDriver

      public static boolean hasDriver(DemoUtil.DemoDriver dd)
      x
      Parameters:
      dd -
      Returns:
    • getConnection

      public static Connection getConnection(String url, Properties props)
      Create connection using properties; the properties are passed to the DriverManager. The properties usually have at least "user" and "password".
      Parameters:
      url - database url
      props - properties for connection
      Returns:
      database connection
    • setChildScreenLocation

      public static void setChildScreenLocation(Window window)
      Provide a point with the child screen location based on the class name. This must only be called once per window.
      Parameters:
      window - name of Window to position
    • runSqlStatements

      public static boolean runSqlStatements(Connection _conn, String _resource, boolean _verbose)
      Run SQL statements from the sql file against the database. If an error is encountered a message is printed to stderr.
      Parameters:
      _conn - database connection
      _resource - sql resource name to run against the database
      _verbose - indicates verbose mode
      Returns:
      false if an error was encountered
    • runSqlStatements

      public static boolean runSqlStatements(Connection _conn, BufferedReader _br, boolean _verbose)
      Run SQL statements from the sql file against the database.
      Parameters:
      _conn - database connection
      _br - sql file to run against the database
      _verbose - indicates verbose mode
      Returns:
      connection to the database
    • extractStatements

      Use this method to parse a file for statements, ';' is the delimiter; column names can not include comment characters. Comments starting with '#' or '--' terminate at end of line. SlashStar-StarSlash comments may span multiple lines, or there may be multiple of these on a single line, or both.

      NOTE: for SQL file, column names must not have '#', '--' or SlashStar since those are treated as comments.

      Parameters:
      _br - the file resource.
      Returns:
      List of query strings
    • loadBinaries

      public static boolean loadBinaries(Connection conn, String resourceName, String sql, boolean verbose)
      Load binary data into a database table. resourceName is read for a list of binary resource name and key. The sql is compiled into a prepared statement. Parameter 1 is set with a binary stream; parameter 2 is expected to be a key.
      Parameters:
      conn - database connection
      resourceName - list of files/keys
      sql - use to put the binary data into the file
      verbose - output progress information
      Returns:
      true if successful