private static void checkParamLength(int expected, int got) { if (expected != got) { throw DbException.getInvalidValueException("paramLen", got); } }
private static void checkHoldability(int resultSetHoldability) { // TODO compatibility / correctness: DBPool uses // ResultSet.HOLD_CURSORS_OVER_COMMIT if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT && resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) { throw DbException.getInvalidValueException("resultSetHoldability", resultSetHoldability); } }
private static void rangeCheckUnknown(long zeroBasedOffset, long length) { if (zeroBasedOffset < 0) { throw DbException.getInvalidValueException("offset", zeroBasedOffset + 1); } if (length < 0) { throw DbException.getInvalidValueException("length", length); } }
/** * Check the range of the parameters. * * @param zeroBasedOffset the offset (0 meaning no offset) * @param length the length of the target * @param dataSize the length of the source */ static void rangeCheck(long zeroBasedOffset, long length, long dataSize) { if ((zeroBasedOffset | length) < 0 || length > dataSize - zeroBasedOffset) { if (zeroBasedOffset < 0 || zeroBasedOffset > dataSize) { throw DbException.getInvalidValueException("offset", zeroBasedOffset + 1); } throw DbException.getInvalidValueException("length", length); } }
/** * Set the scale of a BigDecimal value. * * @param bd the BigDecimal value * @param scale the new scale * @return the scaled value */ public static BigDecimal setScale(BigDecimal bd, int scale) { if (scale > BIG_DECIMAL_SCALE_MAX || scale < -BIG_DECIMAL_SCALE_MAX) { throw DbException.getInvalidValueException("scale", scale); } return bd.setScale(scale, BigDecimal.ROUND_HALF_UP); }
private Object[] get(long index, int count) { Object[] array = get(); if (count < 0 || count > array.length) { throw DbException.getInvalidValueException("count (1.." + array.length + ")", count); } if (index < 1 || index > array.length) { throw DbException.getInvalidValueException("index (1.." + array.length + ")", index); } int offset = (int) (index - 1); return Arrays.copyOfRange(array, offset, offset + count); }
private void checkIndexBounds(int parameterIndex) { checkClosed(); if (parameterIndex < 1 || parameterIndex > maxOutParameters) { throw DbException.getInvalidValueException("parameterIndex", parameterIndex); } }
private void checkColumnIndex(int columnIndex) { checkClosed(); if (columnIndex < 1 || columnIndex > columnCount) { throw DbException.getInvalidValueException("columnIndex", columnIndex); } }
private static byte[] getHash(String algorithm, byte[] bytes, int iterations) { if (!"SHA256".equalsIgnoreCase(algorithm)) { throw DbException.getInvalidValueException("algorithm", algorithm); } for (int i = 0; i < iterations; i++) { bytes = SHA256.getHash(bytes, false); } return bytes; }
public void setMaxIdentiferLength(int maxIdentiferLength) { this.maxIdentiferLength = Math.max(30, maxIdentiferLength); if (maxIdentiferLength != getMaxIdentiferLength()) { throw DbException.getInvalidValueException("Illegal value (<30) in SET COLUMN_NAME_RULES", "MAX_IDENTIFIER_LENGTH=" + maxIdentiferLength); } }
private void checkColumnIndex(int columnIndex) { checkClosed(); if (columnIndex < 1 || columnIndex > columnCount) { throw DbException.getInvalidValueException("columnIndex", columnIndex); } }
private static int getDatePart(String part) { Integer p = DATE_PART.get(StringUtils.toUpperEnglish(part)); if (p == null) { throw DbException.getInvalidValueException("date part", part); } return p.intValue(); }
private int readPositiveInt() { int v = readInt(); if (v < 0) { throw DbException.getInvalidValueException("positive integer", v); } return v; }
private void checkColumnIndex(int columnIndex) throws SQLException { if (columnIndex < 1 || columnIndex > columns.size()) { throw DbException.getInvalidValueException( "columnIndex", columnIndex).getSQLException(); } }
private ParameterInterface getParameter(int param) { checkClosed(); if (param < 1 || param > paramCount) { throw DbException.getInvalidValueException("param", param); } return parameters.get(param - 1); }
/** * Convert the time using the specified calendar. * * @param x the time * @param calendar the calendar * @return the time */ public static ValueTime convertTime(Time x, Calendar calendar) { if (calendar == null) { throw DbException.getInvalidValueException("calendar", null); } Calendar cal = (Calendar) calendar.clone(); cal.setTimeInMillis(x.getTime()); long nanos = nanosFromCalendar(cal); return ValueTime.fromNanos(nanos); }
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); }
/** * Return an object of this class if possible. * * @param iface the class * @return this */ @Override @SuppressWarnings("unchecked") public <T> T unwrap(Class<T> iface) throws SQLException { try { if (isWrapperFor(iface)) { return (T) this; } throw DbException.getInvalidValueException("iface", iface); } catch (Exception e) { throw logAndConvert(e); } }
private void checkRegistered(int parameterIndex) throws SQLException { try { checkIndexBounds(parameterIndex); if (!outParameters.get(parameterIndex - 1)) { throw DbException.getInvalidValueException("parameterIndex", parameterIndex); } } catch (Exception e) { throw logAndConvert(e); } }
private Set parseSetBinaryCollation() { Set command = new Set(session, SetTypes.BINARY_COLLATION); String name = readAliasIdentifier(); command.setString(name); if (equalsToken(name, CompareMode.UNSIGNED) || equalsToken(name, CompareMode.SIGNED)) { return command; } throw DbException.getInvalidValueException("BINARY_COLLATION", name); }