Class DemoUtil
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);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumxstatic enumUsed to specify how to create a new RowSet. -
Method Summary
Modifier and TypeMethodDescriptionUse this method to parse a file for statements, ';' is the delimiter; column names can not include comment characters.static ConnectiongetConnection(String url, Properties props) Create connection using properties; the properties are passed to the DriverManager.static RowSetgetNewRowSet(Connection connection) Build a RowSet with a connection, or how to get one, for use in the Demo.static RowSetgetNewRowSet(Connection connection, DemoUtil.RowSetSource whichRowSet) Like getNewRowSet(Connection), but specify RowSetSource.static DemoUtil.RowSetSourceThe propertyWhichRowSetDefaultcontrols how a RowSet is created by getNewRowSet(java.sql.Connection).static booleanxstatic voidinitExampleFrame(JFrame frame, Runnable runOnClose) xstatic booleanloadBinaries(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.static voidInvoke this method to output collected statistics to log.static booleanrunSqlStatements(Connection _conn, BufferedReader _br, boolean _verbose) Run SQL statements from the sql file against the database.static booleanrunSqlStatements(Connection _conn, String _resource, boolean _verbose) Run SQL statements from the sql file against the database.static voidsetChildScreenLocation(Window window) Provide a point with the child screen location based on the class name.static voidsetWhichRowSetDefault(DemoUtil.RowSetSource _whichRowSetDefault) Establish the default for how a RowSet is created.
-
Method Details
-
initExampleFrame
x- Parameters:
frame-runOnClose-
-
logConnectionUsage
Invoke this method to output collected statistics to log. -
getWhichRowSetDefault
The propertyWhichRowSetDefaultcontrols how a RowSet is created by getNewRowSet(java.sql.Connection).- Returns:
- default type of RowSet
-
setWhichRowSetDefault
Establish the default for how a RowSet is created.- Parameters:
_whichRowSetDefault- default
-
getNewRowSet
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
-
getConnection
Create connection using properties; the properties are passed to the DriverManager. The properties usually have at least "user" and "password".- Parameters:
url- database urlprops- properties for connection- Returns:
- database connection
-
setChildScreenLocation
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
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
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 connectionresourceName- list of files/keyssql- use to put the binary data into the fileverbose- output progress information- Returns:
- true if successful
-