package com.gamvan.sql;
import java.sql.*;
public class PageableResultSet2 implements Pageable {
protected java.sql.ResultSet rs=null;
protected int rowsCount;
protected int pageSize ;
protected int curPage;
protected String command = "" ;
public PageableResultSet2(java.sql.ResultSet rs) throws java.sql.SQLException {
if(rs==null) throw new SQLException("given ResultSet is NULL","user");
rs.last();
rowsCount=rs.getRow();
rs.beforeFirst();
this.rs=rs;
}
public PageableResultSet2(java.sql.ResultSet rs, String command) throws java.sql.SQLException {
if(rs==null) throw new SQLException("given ResultSet is NULL","user");
rs.last();
rowsCount=rs.getRow();
rs.beforeFirst();
this.rs=rs;
this.command = command;
}
public int getCurPage() {
return curPage;
}
//////////////////////////
public java.net.URL getURL(String columnName) throws SQLException{
return rs.getURL(columnName);
}
public java.net.URL getURL(int columnName) throws SQLException{
return rs.getURL(columnName);
}
/////////////////////////////////
public int getPageCount() {
if(rowsCount==0) return 0;
if(pageSize==0) return 1;
//calculate PageCount
double tmpD=(double)rowsCount/pageSize;
int tmpI=(int)tmpD;
if(tmpD>tmpI) tmpI++;
return tmpI;
}
public int getPageRowsCount() {
if(pageSize==0) return rowsCount;
if(getRowsCount()==0) return 0;
if(curPage!=getPageCount()) return pageSize;
return rowsCount-(getPageCount()-1)*pageSize;
}
public int getPageSize() {
return pageSize;
}
public int getRowsCount() {
return rowsCount;
}
public void gotoPage(int page) {
if (rs == null)
return;
if (page < 1)
page = 1;
if (page > getPageCount())
page = getPageCount();
int row = (page - 1) * pageSize + 1;
try {
rs.absolute(row);
curPage = page;
}
catch (java.sql.SQLException e) {
}
}
public void pageFirst() throws java.sql.SQLException {
int row=(curPage-1)*pageSize+1;
rs.absolute(row);
}
public void pageLast() throws java.sql.SQLException {
int row=(curPage-1)*pageSize+getPageRowsCount();
rs.absolute(row);
}
public void setPageSize(int pageSize) {
if(pageSize>=0){
this.pageSize=pageSize;
curPage=1;
}
}
//============================================================================
public boolean absolute(int row) throws SQLException {
return rs.absolute(row);
}
public void afterLast() throws SQLException {
rs.afterLast();
}
public void beforeFirst() throws SQLException {
rs.beforeFirst();
}
public void cancelRowUpdates() throws SQLException {
rs.cancelRowUpdates();
}
public void clearWarnings() throws SQLException {
rs.clearWarnings();
}
public void close() throws SQLException {
rs.close();
}
public void deleteRow() throws SQLException {
rs.deleteRow();
}
public int findColumn(String columnName) throws SQLException { try
{
return rs.findColumn(columnName);
}
catch (SQLException e)
{
throw new SQLException(e.toString()+ "/"+columnName + "/"+this.getCommand());
}
}
public boolean first() throws SQLException {
return rs.first();
}
public Array getArray(int i) throws SQLException {
try
{
return rs.getArray(i);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+i
+"\r\nSQL="+this.getCommand());
}
}
public Array getArray(String colName) throws SQLException {
try
{
return rs.getArray(colName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+colName
+"\r\nSQL="+this.getCommand());
}
}
public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException {
try
{
return rs.getAsciiStream(columnIndex);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+columnIndex
+"\r\nSQL="+this.getCommand());
}
}
public java.io.InputStream getAsciiStream(String columnName) throws SQLException{
try
{
return rs.getAsciiStream(columnName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+columnName
+"\r\nSQL="+this.getCommand());
}
}
public java.math.BigDecimal getBigDecimal(int columnIndex) throws SQLException {
try
{
return rs.getBigDecimal(columnIndex);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+columnIndex
+"\r\nSQL="+this.getCommand());
}
}
public java.math.BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
throw new SQLException("Deprecated Method, Don't Call it!","user");
}
public java.math.BigDecimal getBigDecimal(String columnName) throws SQLException {
try
{
return rs.getBigDecimal(columnName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+columnName
+"\r\nSQL="+this.getCommand());
}
}
public java.math.BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
throw new SQLException("Deprecated Method, Don't Call it!","user");
}
public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException{
try
{
return rs.getBinaryStream(columnIndex);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+columnIndex
+"\r\nSQL="+this.getCommand());
}
}
public java.io.InputStream getBinaryStream(String columnName) throws SQLException {
try
{
return rs.getBinaryStream(columnName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+columnName
+"\r\nSQL="+this.getCommand());
}
}
public Blob getBlob(int columnIndex) throws SQLException {
try
{
return rs.getBlob(columnIndex);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+columnIndex
+"\r\nSQL="+this.getCommand());
}
}
public Blob getBlob(String colName) throws SQLException{
try
{
return rs.getBlob(colName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+colName
+"\r\nSQL="+this.getCommand());
}
}
public boolean getBoolean(int columnIndex) throws SQLException {
try
{
return rs.getBoolean(columnIndex);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+columnIndex
+"\r\nSQL="+this.getCommand());
}
}
public boolean getBoolean(String columnName) throws SQLException {
try
{
return rs.getBoolean(columnName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+columnName
+"\r\nSQL="+this.getCommand());
}
}
public byte getByte(int columnIndex) throws SQLException {
try
{
return rs.getByte(columnIndex);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" column Index="+columnIndex
+"\r\nSQL="+this.getCommand());
}
}
public byte getByte(String columnName) throws SQLException{
try
{
return rs.getByte(columnName);
}
catch (SQLException e)
{
throw new SQLException (e.getMessage()+" columnName="+columnName
+"\r\nSQL="+this.getCommand());
}
}
public byte[] getBytes(int columnIndex) throws SQLException {