Quadcap Embeddable Database

com.quadcap.sql.tools.Loader Class Reference

List of all members.

Detailed Description

A simple SQL loader utility which scans the input file for semicolon-delimited SQL statements which are executed using JDBC against a database connection.

If a statement generates a ResultSet, the ResultSet is displayed to a PrintWriter.

Author:
Stan Bailes

Definition at line 68 of file Loader.java.

Public Member Functions

 Loader ()
 No-argument bean constructor.

 Loader (Connection conn)
 Construct a new Loader object bound to the specified database connection.

void setConnection (Connection conn)
 Set this loader's database connection.

Connection getConnection ()
 Get this loader's database connection.

void setWriter (PrintWriter writer)
 Set the loader's writer object.

PrintWriter getWriter ()
 Return the loader's writer.

void execute (String sql)
 Execute a single SQL statement.

void loadStream (InputStream in) throws IOException, SQLException
void loadFile (String filename)
 The specified file is scanned for semicolon-delimited SQL statements which are executed one at a time.


Static Public Member Functions

String getLine (InputStream is) throws IOException

Package Functions

final void print (String s)
final void println (String s)
final void print (Throwable t)
final void showResultSet (ResultSet rs) throws SQLException
final void showResultSet (ResultSet rs, int lim) throws SQLException

Static Package Functions

final String pad (int wid, String s)

Package Attributes

Connection conn
StringBuffer buffer = new StringBuffer()
PrintWriter writer = null
int rsLimit = Integer.MAX_VALUE

Static Package Attributes

final ConfigNumber trace
final int COLMAX = 12


Constructor & Destructor Documentation

com.quadcap.sql.tools.Loader.Loader  ) 
 

No-argument bean constructor.

We need a connection to do something useful.

Definition at line 82 of file Loader.java.

com.quadcap.sql.tools.Loader.Loader Connection  conn  ) 
 

Construct a new Loader object bound to the specified database connection.

Parameters:
conn the database connection

Definition at line 91 of file Loader.java.


Member Function Documentation

void com.quadcap.sql.tools.Loader.execute String  sql  ) 
 

Execute a single SQL statement.

There are several statements that are not passed directly to the JDBC driver, but instead are executed by the loader:

BEGINTRANSACTION Upon seeing this, the loader performs a Connection.setAutoCommit(false) call on the current database connection.
ENDTRANSACTION The loader performs:

          Connection.commit()
          Connection.setAutocommit(true);
     
LIMITK The loader performs:

          Connection.rollback()
          Connection.setAutocommit(true);
     

Parameters:
sql the SQL statement to execute.

Definition at line 277 of file Loader.java.

References com.quadcap.sql.tools.Loader.conn, com.quadcap.sql.tools.Loader.execute(), com.quadcap.sql.tools.Loader.rsLimit, and com.quadcap.sql.Connection.setAutoCommit().

Referenced by com.quadcap.sql.tools.Loader.execute().

Connection com.quadcap.sql.tools.Loader.getConnection  ) 
 

Get this loader's database connection.

Returns:
the current database connection

Definition at line 109 of file Loader.java.

String com.quadcap.sql.tools.Loader.getLine InputStream  is  )  throws IOException [static]
 

Definition at line 208 of file Loader.java.

References com.quadcap.sql.tools.Loader.getLine().

Referenced by com.quadcap.sql.tools.Loader.getLine().

PrintWriter com.quadcap.sql.tools.Loader.getWriter  ) 
 

Return the loader's writer.

Returns:
the current writer.

Definition at line 129 of file Loader.java.

References com.quadcap.sql.tools.Loader.writer.

void com.quadcap.sql.tools.Loader.loadFile String  filename  ) 
 

The specified file is scanned for semicolon-delimited SQL statements which are executed one at a time.

Parameters:
filename the name of the input file
See also:
execute

Definition at line 354 of file Loader.java.

References com.quadcap.sql.tools.Loader.loadFile().

Referenced by com.quadcap.sql.tools.Loader.loadFile(), and com.quadcap.sql.tools.XmlLoad.main().

void com.quadcap.sql.tools.Loader.loadStream InputStream  in  )  throws IOException, SQLException
 

Definition at line 308 of file Loader.java.

References com.quadcap.sql.tools.Loader.conn, com.quadcap.sql.tools.Loader.loadStream(), com.quadcap.sql.tools.Loader.rsLimit, com.quadcap.sql.Connection.setAutoCommit(), and com.quadcap.sql.tools.Loader.trace.

Referenced by com.quadcap.sql.tools.Loader.loadStream().

final String com.quadcap.sql.tools.Loader.pad int  wid,
String  s
[static, package]
 

Definition at line 162 of file Loader.java.

References com.quadcap.sql.tools.Loader.pad().

Referenced by com.quadcap.sql.tools.Loader.pad().

final void com.quadcap.sql.tools.Loader.print Throwable  t  )  [package]
 

Definition at line 149 of file Loader.java.

References com.quadcap.sql.tools.Loader.trace, and com.quadcap.sql.tools.Loader.writer.

final void com.quadcap.sql.tools.Loader.print String  s  )  [package]
 

Definition at line 133 of file Loader.java.

References com.quadcap.sql.tools.Loader.buffer, com.quadcap.sql.tools.Loader.print(), com.quadcap.sql.tools.Loader.trace, and com.quadcap.sql.tools.Loader.writer.

Referenced by com.quadcap.sql.tools.Loader.print().

final void com.quadcap.sql.tools.Loader.println String  s  )  [package]
 

Definition at line 140 of file Loader.java.

References com.quadcap.sql.tools.Loader.buffer, com.quadcap.sql.tools.Loader.println(), com.quadcap.sql.tools.Loader.trace, and com.quadcap.sql.tools.Loader.writer.

Referenced by com.quadcap.sql.tools.Loader.println().

void com.quadcap.sql.tools.Loader.setConnection Connection  conn  ) 
 

Set this loader's database connection.

Parameters:
conn the new database connection

Definition at line 100 of file Loader.java.

References com.quadcap.sql.tools.Loader.setConnection().

Referenced by com.quadcap.sql.tools.Loader.setConnection().

void com.quadcap.sql.tools.Loader.setWriter PrintWriter  writer  ) 
 

Set the loader's writer object.

Depending on the loader's trace level, the loader will write a trace of SQL statement execution to this writer.

Parameters:
writer the new writer object

Definition at line 120 of file Loader.java.

References com.quadcap.sql.tools.Loader.setWriter().

Referenced by com.quadcap.sql.tools.XmlLoad.main(), and com.quadcap.sql.tools.Loader.setWriter().

final void com.quadcap.sql.tools.Loader.showResultSet ResultSet  rs,
int  lim
throws SQLException [package]
 

Definition at line 177 of file Loader.java.

References com.quadcap.sql.tools.Loader.COLMAX.

final void com.quadcap.sql.tools.Loader.showResultSet ResultSet  rs  )  throws SQLException [package]
 

Definition at line 173 of file Loader.java.

References com.quadcap.sql.tools.Loader.showResultSet().

Referenced by com.quadcap.sql.tools.Loader.showResultSet().


Member Data Documentation

StringBuffer com.quadcap.sql.tools.Loader.buffer = new StringBuffer() [package]
 

Definition at line 73 of file Loader.java.

Referenced by com.quadcap.sql.tools.Loader.print(), and com.quadcap.sql.tools.Loader.println().

final int com.quadcap.sql.tools.Loader.COLMAX = 12 [static, package]
 

Definition at line 76 of file Loader.java.

Referenced by com.quadcap.sql.tools.Loader.showResultSet().

Connection com.quadcap.sql.tools.Loader.conn [package]
 

Definition at line 72 of file Loader.java.

Referenced by com.quadcap.sql.tools.Loader.execute(), and com.quadcap.sql.tools.Loader.loadStream().

int com.quadcap.sql.tools.Loader.rsLimit = Integer.MAX_VALUE [package]
 

Definition at line 75 of file Loader.java.

Referenced by com.quadcap.sql.tools.Loader.execute(), and com.quadcap.sql.tools.Loader.loadStream().

final ConfigNumber com.quadcap.sql.tools.Loader.trace [static, package]
 

Initial value:

ConfigNumber.find("trace.sql.tools.Loader", "0")

Definition at line 69 of file Loader.java.

Referenced by com.quadcap.sql.tools.Loader.loadStream(), com.quadcap.sql.tools.Loader.print(), and com.quadcap.sql.tools.Loader.println().

PrintWriter com.quadcap.sql.tools.Loader.writer = null [package]
 

Definition at line 74 of file Loader.java.

Referenced by com.quadcap.sql.tools.Loader.getWriter(), com.quadcap.sql.tools.Loader.print(), and com.quadcap.sql.tools.Loader.println().