1 21 22 package org.apache.derby.impl.jdbc; 23 24 import org.apache.derby.iapi.sql.Activation; 25 import org.apache.derby.iapi.sql.ParameterValueSet; 26 import org.apache.derby.iapi.types.DataTypeDescriptor; 27 import org.apache.derby.iapi.types.DataTypeUtilities; 28 import org.apache.derby.iapi.reference.JDBC30Translation; 29 import org.apache.derby.iapi.reference.SQLState; 30 import org.apache.derby.iapi.jdbc.EngineParameterMetaData; 31 32 import java.sql.SQLException ; 33 import java.sql.Types ; 34 35 47 public class EmbedParameterSetMetaData implements EngineParameterMetaData 48 { 49 50 private final ParameterValueSet pvs; 51 private final DataTypeDescriptor[] types; 52 private final int paramCount; 53 54 protected EmbedParameterSetMetaData(ParameterValueSet pvs, DataTypeDescriptor[] types) { 60 int paramCount; 61 paramCount = pvs.getParameterCount(); 62 this.pvs = pvs; 63 this.paramCount = paramCount; 64 this.types = types; 65 } 66 73 public int getParameterCount() { 74 return paramCount; 75 } 76 77 87 public int isNullable(int param) throws SQLException { 88 checkPosition(param); 89 90 if (types[param - 1].isNullable()) 91 return JDBC30Translation.PARAMETER_NULLABLE; 92 else 93 return JDBC30Translation.PARAMETER_NO_NULLS; 94 } 95 96 104 public boolean isSigned(int param) throws SQLException { 105 checkPosition(param); 106 107 return types[param - 1].getTypeId().isNumericTypeId(); 108 } 109 110 118 public int getPrecision(int param) throws SQLException { 119 checkPosition(param); 120 121 int outparamPrecision = -1; 122 int precision = DataTypeUtilities.getPrecision(types[param - 1]); 123 124 if (((param == 1) && pvs.hasReturnOutputParameter())) 125 { 126 outparamPrecision = pvs.getPrecision(param); 127 } 128 129 return (outparamPrecision == -1) ? precision : outparamPrecision; 130 131 } 132 133 141 public int getScale(int param) throws SQLException { 142 checkPosition(param); 143 144 if (((param == 1) && pvs.hasReturnOutputParameter())) 145 return pvs.getScale(param); 146 return types[param - 1].getScale(); 147 148 } 149 150 158 public int getParameterType(int param) throws SQLException { 159 checkPosition(param); 160 161 return types[param - 1].getTypeId().getJDBCTypeId(); 162 } 163 164 173 public String getParameterTypeName(int param) throws SQLException { 174 checkPosition(param); 175 176 return types[param - 1].getTypeId().getSQLTypeName(); 177 } 178 179 191 public String getParameterClassName(int param) throws SQLException { 192 checkPosition(param); 193 194 return types[param - 1].getTypeId().getResultSetMetaDataTypeName(); 195 } 196 197 207 public int getParameterMode(int param) throws SQLException { 208 checkPosition(param); 209 210 if ((param == 1) && pvs.hasReturnOutputParameter()) return JDBC30Translation.PARAMETER_MODE_OUT; 214 return pvs.getParameterMode(param); 215 } 216 217 218 private void checkPosition(int parameterIndex) throws SQLException { 221 222 if (parameterIndex < 1 || 223 parameterIndex > paramCount) { 224 225 226 throw Util.generateCsSQLException( 227 SQLState.LANG_INVALID_PARAM_POSITION, 228 new Integer (parameterIndex), new Integer (paramCount)); 229 } 230 } 231 } 232 233 | Popular Tags |