@Override protected boolean checkClosed() { if (super.checkClosed()) { // if the session was re-connected, re-prepare the statement ArrayList<? extends ParameterInterface> oldParams = command.getParameters(); command = conn.prepareCommand(sqlStatement, fetchSize); ArrayList<? extends ParameterInterface> newParams = command.getParameters(); for (int i = 0, size = oldParams.size(); i < size; i++) { ParameterInterface old = oldParams.get(i); Value value = old.getParamValue(); if (value != null) { ParameterInterface n = newParams.get(i); n.setValue(value, false); } } return true; } return false; }
/** * Checks if this is nullable parameter. * Returns ResultSetMetaData.columnNullableUnknown.. * * @param param the column index (1,2,...) * @return ResultSetMetaData.columnNullableUnknown */ @Override public int isNullable(int param) throws SQLException { try { debugCodeCall("isNullable", param); return getParameter(param).getNullable(); } catch (Exception e) { throw logAndConvert(e); } }
private void registerOutParameter(int parameterIndex) throws SQLException { try { checkClosed(); if (outParameters == null) { maxOutParameters = Math.min( getParameterMetaData().getParameterCount(), getCheckedMetaData().getColumnCount()); outParameters = new BitField(); } checkIndexBounds(parameterIndex); ParameterInterface param = command.getParameters().get(--parameterIndex); if (!param.isValueSet()) { param.setValue(ValueNull.INSTANCE, false); } outParameters.set(parameterIndex); } catch (Exception e) { throw logAndConvert(e); } }
/** * Format the parameter list. * * @param parameters the parameter list * @return the formatted text */ public static String formatParams( ArrayList<? extends ParameterInterface> parameters) { if (parameters.size() == 0) { return ""; } StatementBuilder buff = new StatementBuilder(); int i = 0; boolean params = false; for (ParameterInterface p : parameters) { if (p.isValueSet()) { if (!params) { buff.append(" {"); params = true; } buff.appendExceptFirst(", "); Value v = p.getParamValue(); buff.append(++i).append(": ").append(v.getTraceSQL()); } } if (params) { buff.append('}'); } return buff.toString(); }
/** * The command is now re-used, therefore reset the canReuse flag, and the * parameter values. */ public void reuse() { canReuse = false; ArrayList<? extends ParameterInterface> parameters = getParameters(); for (int i = 0, size = parameters.size(); i < size; i++) { ParameterInterface param = parameters.get(i); param.setValue(null, true); } }
/** * Adds the current settings to the batch. */ @Override public void addBatch() throws SQLException { try { debugCodeCall("addBatch"); checkClosed(); try { ArrayList<? extends ParameterInterface> parameters = command.getParameters(); int size = parameters.size(); Value[] set = new Value[size]; for (int i = 0; i < size; i++) { ParameterInterface param = parameters.get(i); Value value = param.getParamValue(); set[i] = value; } if (batchParameters == null) { batchParameters = New.arrayList(); } batchParameters.add(set); } finally { afterWriting(); } } catch (Exception e) { throw logAndConvert(e); } }
/** * Returns the parameter type. * java.sql.Types.VARCHAR is returned if the data type is not known. * * @param param the column index (1,2,...) * @return the data type */ @Override public int getParameterType(int param) throws SQLException { try { debugCodeCall("getParameterType", param); ParameterInterface p = getParameter(param); int type = p.getType(); if (type == Value.UNKNOWN) { type = Value.STRING; } return DataType.getDataType(type).sqlType; } catch (Exception e) { throw logAndConvert(e); } }
/** * Returns the parameter scale. * The value 0 is returned if the scale is not known. * * @param param the column index (1,2,...) * @return the scale */ @Override public int getScale(int param) throws SQLException { try { debugCodeCall("getScale", param); ParameterInterface p = getParameter(param); return p.getScale(); } catch (Exception e) { throw logAndConvert(e); } }
/** * Returns the parameter precision. * The value 0 is returned if the precision is not known. * * @param param the column index (1,2,...) * @return the precision */ @Override public int getPrecision(int param) throws SQLException { try { debugCodeCall("getPrecision", param); ParameterInterface p = getParameter(param); return MathUtils.convertLongToInt(p.getPrecision()); } catch (Exception e) { throw logAndConvert(e); } }
private void setParameter(int parameterIndex, Value value) { checkClosed(); parameterIndex--; ArrayList<? extends ParameterInterface> parameters = command.getParameters(); if (parameterIndex < 0 || parameterIndex >= parameters.size()) { throw DbException.getInvalidValueException("parameterIndex", parameterIndex + 1); } ParameterInterface param = parameters.get(parameterIndex); // can only delete old temp files if they are not in the batch param.setValue(value, batchParameters == null); }
/** * Returns the Java class name of the parameter. * "java.lang.String" is returned if the type is not known. * * @param param the column index (1,2,...) * @return the Java class name */ @Override public String getParameterClassName(int param) throws SQLException { try { debugCodeCall("getParameterClassName", param); ParameterInterface p = getParameter(param); int type = p.getType(); if (type == Value.UNKNOWN) { type = Value.STRING; } return DataType.getTypeClassName(type); } catch (Exception e) { throw logAndConvert(e); } }
/** * Clears all parameters. * * @throws SQLException if this object is closed or invalid */ @Override public void clearParameters() throws SQLException { try { debugCodeCall("clearParameters"); checkClosed(); ArrayList<? extends ParameterInterface> parameters = command.getParameters(); for (int i = 0, size = parameters.size(); i < size; i++) { ParameterInterface param = parameters.get(i); // can only delete old temp files if they are not in the batch param.setValue(null, batchParameters == null); } } catch (Exception e) { throw logAndConvert(e); } }
/** * Returns the parameter type name. * "VARCHAR" is returned if the type is not known. * * @param param the column index (1,2,...) * @return the type name */ @Override public String getParameterTypeName(int param) throws SQLException { try { debugCodeCall("getParameterTypeName", param); ParameterInterface p = getParameter(param); int type = p.getType(); if (type == Value.UNKNOWN) { type = Value.STRING; } return DataType.getDataType(type).name; } catch (Exception e) { throw logAndConvert(e); } }
Value value = set[j]; ParameterInterface param = parameters.get(j); param.setValue(value, false);