1 16 17 package org.apache.cocoon.components.language.markup.xsp; 18 19 import java.sql.SQLException ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 import java.sql.CallableStatement ; 23 import java.sql.Connection ; 24 25 30 final public class SybaseEsqlQuery extends AbstractEsqlQuery { 31 32 public SybaseEsqlQuery(Connection connection, String query) { 33 super(connection, query); 34 } 35 36 40 private SybaseEsqlQuery(final ResultSet resultSet) { 41 super(resultSet); 42 } 43 44 48 public AbstractEsqlQuery newInstance(ResultSet resultSet) { 49 return(new SybaseEsqlQuery(resultSet)); 50 } 51 52 public String getQueryString() throws SQLException { 53 if (getMaxRows() > -1) { 54 String original = super.getQueryString().trim(); 55 int command = original.indexOf(' '); 56 return (new StringBuffer () 57 .append(original.substring(0,command)) 58 .append(" TOP ").append(getMaxRows()+1 + getSkipRows()) 59 .append(original.substring(command)) 60 .toString()); 61 } 62 else { 63 return (super.getQueryString()); 64 } 65 } 66 67 public PreparedStatement prepareStatement() throws SQLException { 68 return ( 69 setPreparedStatement( 70 getConnection().prepareStatement( 71 getQueryString(), 72 ResultSet.TYPE_SCROLL_INSENSITIVE, 73 ResultSet.CONCUR_READ_ONLY) 74 )); 75 } 76 77 public CallableStatement prepareCall() throws SQLException { 78 return ( 79 (CallableStatement ) setPreparedStatement( 80 getConnection().prepareCall( 81 getQueryString(), 82 ResultSet.TYPE_SCROLL_INSENSITIVE, 83 ResultSet.CONCUR_READ_ONLY 84 ) 85 ) 86 ); 87 } 88 89 public void getResultRows() throws SQLException { 90 final int skip = getSkipRows(); 91 if (skip > 0) { 92 getResultSet().absolute(skip); 93 } 94 setPosition(skip); 95 } 96 97 } 98 | Popular Tags |