1 16 17 package org.apache.cocoon.components.language.markup.xsp; 18 19 import java.sql.PreparedStatement ; 20 import java.sql.SQLException ; 21 import java.sql.ResultSet ; 22 import java.sql.CallableStatement ; 23 import java.sql.Connection ; 24 25 35 final public class JdbcEsqlQuery extends AbstractEsqlQuery { 36 37 public JdbcEsqlQuery(Connection connection, String query) { 38 super(connection, query); 39 } 40 41 45 private JdbcEsqlQuery(final ResultSet resultSet) { 46 super(resultSet); 47 } 48 49 53 public AbstractEsqlQuery newInstance(final ResultSet resultSet) { 54 return(new JdbcEsqlQuery(resultSet)); 55 } 56 57 public PreparedStatement prepareStatement() throws SQLException { 58 return ( 59 setPreparedStatement( 60 getConnection().prepareStatement( 61 getQueryString(), 62 ResultSet.TYPE_SCROLL_INSENSITIVE, 63 ResultSet.CONCUR_READ_ONLY) 64 )); 65 } 66 67 public CallableStatement prepareCall() throws SQLException { 68 return ( 69 (CallableStatement ) setPreparedStatement( 70 getConnection().prepareCall( 71 getQueryString(), 72 ResultSet.TYPE_SCROLL_INSENSITIVE, 73 ResultSet.CONCUR_READ_ONLY 74 ) 75 ) 76 ); 77 } 78 79 86 87 public int getRowCount() throws SQLException { 88 ResultSet rs = getResultSet(); 89 synchronized (rs) { 90 int currentRow = rs.getRow(); 91 rs.last(); 92 int count = rs.getRow(); 93 if (currentRow > 0) { 94 rs.absolute(currentRow); 95 } 96 else { 97 rs.first(); 98 rs.relative(-1); 99 } 100 return (count); 101 } 102 } 103 104 public void getResultRows() throws SQLException { 105 final int skip = getSkipRows(); 106 if (skip > 0) { 107 getResultSet().absolute(skip); 108 } 109 setPosition(skip); 110 } 111 112 } 113 | Popular Tags |