com.zentense.step2.view
Class ResultSetView

java.lang.Object
  extended by com.zentense.step2.view.View
      extended by com.zentense.step2.view.ResultSetView
Direct Known Subclasses:
View.Empty

public class ResultSetView
extends View

A view is a collection of rows where a row is a collection of columns. Rows are ordered while columns are not (although in ResultSetViews are also ordered). Views are used mainly to show or process data.

A ResultSetView is a view created by a ResultSetModel after executing a SQL statement on a database through JDBC. The ResultSetView encapsulates the resulting JDBC Resultset.

Author:
kurt

Nested Class Summary
 
Nested classes/interfaces inherited from class com.zentense.step2.view.View
View.Empty
 
Field Summary
 
Fields inherited from class com.zentense.step2.view.View
EMPTY
 
Constructor Summary
ResultSetView()
          Default constructor
ResultSetView(java.sql.Connection db, int type, int concur)
          Creates and initializes a ResultSetView
 
Method Summary
 void close()
          Closes statement.
static java.sql.PreparedStatement createPrepared(java.sql.Connection db, java.lang.String sql, int type, int concur)
          Creates a prepared statement
 View execPrepared(java.sql.PreparedStatement ps)
          Executes a prepared statement.
 void executeQuery(java.lang.String sql)
          Executes SQL query.
 void executeUpdate(java.lang.String sql)
          Executes SQL statement with no results.
 void finalize()
           
 View first()
           
 java.lang.Object get(int idx)
          Gets the n-th column of current row
 java.lang.Object get(java.lang.String colName)
          Gets a column value
 java.lang.String[] getCols()
          Returns view columns
 int getCount()
          Gets results total size
 int getOrdinal()
          Gets the current position of this view.
 java.sql.ResultSet getResultSet()
          Gets JDBC Resultset
 int getSize()
          Gets results size.
 int getStart()
          Returns the first visible row in this view.
 java.sql.Statement getStatement()
          Gets JDBC Statement
 void insertRow()
          Inserts current row into database.
 boolean next()
          Advances the view to the next row.
 void open()
          Position the view before the first visible row
 void set(java.lang.String colName, java.lang.Object obj)
          Sets a (key, value) pair.
 void setPageBounds(int begin, int step)
          Unboxed version of setPageBounds
 void setPosition(int pos)
          Moves to another row in view
 java.lang.String toString()
          Returns an string representation of this object
 void updateRow()
          Updates current row into database.
 
Methods inherited from class com.zentense.step2.view.View
asDelegated, asDelegatedResultSet, asResultSet, fillFromRow, fillRowFromRequest, getBool, getCachedClone, getColsAsView, getDouble, getIndent, getInt, getRow, getRow, getSum, randomPosition, setPageBounds, setPageBounds, setPageBounds
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResultSetView

public ResultSetView()
Default constructor


ResultSetView

public ResultSetView(java.sql.Connection db,
                     int type,
                     int concur)
              throws java.sql.SQLException
Creates and initializes a ResultSetView

Parameters:
db - JDBC connection
type - Resultset type (TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE)
concur - Resultset concurrency (CONCUR_READ_ONLY, CONCUR_UPDATABLE)
Throws:
java.sql.SQLException
Method Detail

createPrepared

public static final java.sql.PreparedStatement createPrepared(java.sql.Connection db,
                                                              java.lang.String sql,
                                                              int type,
                                                              int concur)
                                                       throws java.sql.SQLException
Creates a prepared statement

Parameters:
db - JDBC connection
sql - SQL statement to be prepared
type - Resultset type (TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE)
concur - Resultset concurrency (CONCUR_READ_ONLY, CONCUR_UPDATABLE)
Throws:
java.sql.SQLException

execPrepared

public View execPrepared(java.sql.PreparedStatement ps)
                  throws java.sql.SQLException
Executes a prepared statement. Used by ResultSetModel

Throws:
java.sql.SQLException

getStatement

public final java.sql.Statement getStatement()
Gets JDBC Statement


getResultSet

public final java.sql.ResultSet getResultSet()
Gets JDBC Resultset


close

public final void close()
Closes statement. Statements are automatically closed when disposed so it is not mandatory call this method.


setPageBounds

public final void setPageBounds(int begin,
                                int step)
                         throws java.sql.SQLException
Unboxed version of setPageBounds

Overrides:
setPageBounds in class View
Parameters:
begin - First row in page
step - Number of rows in page
Throws:
java.sql.SQLException

first

public View first()
Overrides:
first in class View

open

public void open()
          throws java.lang.Exception
Description copied from class: View
Position the view before the first visible row

Overrides:
open in class View
Throws:
java.lang.Exception

next

public boolean next()
             throws java.lang.Exception
Description copied from class: View
Advances the view to the next row. Returns true while more rows are available

Overrides:
next in class View
Throws:
java.lang.Exception

executeQuery

public final void executeQuery(java.lang.String sql)
                        throws java.sql.SQLException
Executes SQL query. Used by ResultSetModel

Throws:
java.sql.SQLException

executeUpdate

public final void executeUpdate(java.lang.String sql)
                         throws java.sql.SQLException
Executes SQL statement with no results. Used by ResultSetModel

Throws:
java.sql.SQLException

getStart

public int getStart()
Description copied from class: View
Returns the first visible row in this view.

Overrides:
getStart in class View
See Also:
View#setPageBounds(Integer, Integer)

getCount

public int getCount()
             throws java.lang.Exception
Gets results total size

Overrides:
getCount in class View
Returns:
Number of results in view (even outside page).
Throws:
java.lang.Exception

getSize

public int getSize()
            throws java.lang.Exception
Gets results size. For a paged view it returns the page size.

Specified by:
getSize in class View
Returns:
Visible results size
Throws:
java.lang.Exception

getOrdinal

public int getOrdinal()
               throws java.lang.Exception
Description copied from class: View
Gets the current position of this view. First is 0

Overrides:
getOrdinal in class View
Throws:
java.lang.Exception

setPosition

public void setPosition(int pos)
                 throws java.lang.Exception
Description copied from class: View
Moves to another row in view

Overrides:
setPosition in class View
Throws:
java.lang.Exception

set

public final void set(java.lang.String colName,
                      java.lang.Object obj)
               throws java.lang.Exception
Sets a (key, value) pair. This only will work if ResultSet is updatable. If its concurrency is CONCUR_READ_ONLY will throw an SQLException.

Specified by:
set in class View
Parameters:
colName - Column name (key)
obj - Value
Throws:
java.lang.Exception

get

public java.lang.Object get(java.lang.String colName)
                     throws java.lang.Exception
Description copied from class: View
Gets a column value

Specified by:
get in class View
Parameters:
colName - Column name (key)
Returns:
Column value
Throws:
java.lang.Exception

get

public final java.lang.Object get(int idx)
                           throws java.lang.Exception
Gets the n-th column of current row

Throws:
java.lang.Exception

getCols

public java.lang.String[] getCols()
                           throws java.lang.Exception
Description copied from class: View
Returns view columns

Specified by:
getCols in class View
Throws:
java.lang.Exception

toString

public java.lang.String toString()
Returns an string representation of this object

Overrides:
toString in class java.lang.Object
Returns:
String representation of the rowview

insertRow

public final void insertRow()
                     throws java.sql.SQLException
Inserts current row into database. This only will work if this ResultSetView was obtained after calling insertMode.

Overrides:
insertRow in class View
Throws:
java.sql.SQLException
See Also:
com.zentense.step2.model.ResultSetModel#insertMode(RequestRuntime)

updateRow

public final void updateRow()
                     throws java.sql.SQLException
Updates current row into database. This only will work if this ResultSetView was obtained after calling updateMode.

Overrides:
updateRow in class View
Throws:
java.sql.SQLException
See Also:
com.zentense.step2.model.ResultSetModel#insertMode(RequestRuntime)

finalize

public void finalize()
              throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

 

© Zentense 2008