1 package com.daffodilwoods.daffodildb.client; 2 3 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents._SelectIterator; 4 import java.util.*; 5 import java.sql.SQLException ; 6 import com.daffodilwoods.daffodildb.server.datadictionarysystem._ColumnCharacteristics; 7 import com.daffodilwoods.daffodildb.server.serversystem.*; 8 import com.daffodilwoods.database.general.*; 9 import com.daffodilwoods.database.resource.*; 10 11 public class ClientStatement implements _ClientStatement { 12 13 private _PreparedStatement preparedStatement; 14 private int parameterCount; 15 private String query; 16 private _ClientUserSession clientUserSesion; 17 private _ColumnCharacteristics columnCharacteristics; 18 public _Connection connection; 19 private _ParameterMetaData parameterMetaData; 20 private boolean browserType ; 21 22 public ClientStatement(String query,_PreparedStatement preparedStatement,_ClientUserSession clientUserSesion) throws DException{ 23 this.query = query; 24 this.preparedStatement = preparedStatement; 25 this.clientUserSesion = clientUserSesion; 26 parameterCount = preparedStatement.getParameterCount(); 27 parameterMetaData = preparedStatement.getParameterMetaData(); 28 } 29 30 public void setClient(_Client client0){ 31 } 32 33 public Object execute(Object [] parameters) throws java.sql.SQLException { 34 try{ 35 return getRequiredObjectOfexecute(preparedStatement.executeForFresh(parameters),query,parameters); 36 }catch (DException ex){ 37 throw ex.getSqlException(null); 38 } 39 } 40 41 public _ColumnCharacteristics getColumnCharacteristics() throws java.sql.SQLException { 42 if(columnCharacteristics == null) 43 execute(parameterCount == 0 ? null : new Object [parameterCount]); 44 return columnCharacteristics; 45 } 46 47 48 public int getParameterCount() throws java.sql.SQLException { 49 return parameterCount; 50 } 51 52 private Object getRequiredObjectOfexecute(Object returnObject,String query,Object [] parameters) throws SQLException ,DException{ 53 try { 54 if(returnObject instanceof _SelectIterator){ 55 _SelectIterator iterator = (_SelectIterator)returnObject; 56 if(columnCharacteristics == null) 57 columnCharacteristics = iterator.getColumnCharacteristics(); 58 boolean type = iterator.isUpdatable(); 59 if(type) { 60 RecordSetBuffer rsb = new RecordSetBuffer(); 61 rsb.setClientUserSession(clientUserSesion); 62 rsb.setSelectIterator(iterator); 63 rsb.setQuery(query); 64 rsb.setParameters(parameters); 65 rsb.setListenerMode(browserType); 66 return rsb; 67 } 68 RecordSet rsb = new RecordSet(); 69 rsb.setQuery(query); 70 rsb.setSelectIterator(iterator); 71 return rsb; 72 } 73 } 74 catch( RuntimeException ex) { 75 throw new SQLException (" query :[" + query + "] parameters : ["+ (parameters == null ? null : Arrays.asList(parameters))+"]" + ex.getMessage()); 76 } 77 return returnObject; 78 } 79 80 81 public String toString() { 82 return " query -> "+ query 83 + " parameter count " + parameterCount; 84 } 85 86 public Object executeWithSameIterator(Object [] parameters) throws java.sql.SQLException { 87 try{ 88 return getRequiredObjectOfexecute(preparedStatement.execute(parameters),query,parameters); 89 }catch (DException ex){ 90 throw ex.getSqlException(null); 91 } 92 } 93 94 public _ParameterMetaData getParameterMetaData() throws DException{ 95 return parameterMetaData; 96 } 97 98 public void setListenerMode(boolean browserType1)throws DException{ 99 browserType = browserType1; 100 } 101 102 } 103 | Popular Tags |