private void checkHoldability(int resultSetHoldability) throws SQLException { // TODO compatibility / correctness: DBPool uses // ResultSet.HOLD_CURSORS_OVER_COMMIT //## Java 1.4 begin ## if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT && resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) { throw Message.getInvalidValueException("" + resultSetHoldability, "resultSetHoldability"); } //## Java 1.4 end ## }
public static BigDecimal setScale(BigDecimal bd, int scale) throws SQLException { if (scale > Constants.BIG_DECIMAL_SCALE_MAX) { throw Message.getInvalidValueException("" + scale, "scale"); } else if (scale < 0) { throw Message.getInvalidValueException("" + scale, "scale"); } return bd.setScale(scale, BigDecimal.ROUND_HALF_UP); }
private Object[] get(long index, int count) throws SQLException { Object[] array = get(); if (count < 0 || count > array.length) { throw Message.getInvalidValueException("" + count, "count (1.." + array.length + ")"); } if (index < 1 || index > array.length) { throw Message.getInvalidValueException("" + index, "index (1.." + array.length + ")"); } Object[] subset = new Object[count]; System.arraycopy(array, (int) (index - 1), subset, 0, count); return subset; }
private static long getLocalTime(java.util.Date x, Calendar target) throws SQLException { if (target == null) { throw Message.getInvalidValueException("calendar", null); } target = (Calendar) target.clone(); Calendar local = Calendar.getInstance(); local.setTime(x); convertTime(local, target); return target.getTime().getTime(); }
void checkParameterIndex(int param) throws SQLException { checkClosed(); if (param < 1 || param > paramCount) { throw Message.getInvalidValueException("" + param, "param"); } }
private void checkColumnIndex(int columnIndex) throws SQLException { checkClosed(); if (columnIndex < 1 || columnIndex > columnCount) { throw Message.getInvalidValueException("" + columnIndex, "columnIndex"); } }
boolean getTextStorage() throws SQLException { String storage = removeProperty("STORAGE", "BINARY"); if ("BINARY".equalsIgnoreCase(storage)) { return false; } else if ("TEXT".equalsIgnoreCase(storage)) { return true; } else { throw Message.getInvalidValueException(storage, "storage"); } }
public static SHA256 getHash(String algorithm) throws SQLException { if ("SHA256".equalsIgnoreCase(algorithm)) { return new SHA256(); } else { throw Message.getInvalidValueException(algorithm, "algorithm"); } }
private static long getUniversalTime(Calendar source, java.util.Date x) throws SQLException { if (source == null) { throw Message.getInvalidValueException("calendar", null); } source = (Calendar) source.clone(); Calendar universal = Calendar.getInstance(); source.setTime(x); convertTime(source, universal); return universal.getTime().getTime(); }
private void checkColumnIndex(int columnIndex) throws SQLException { checkClosed(); if (columnIndex < 1 || columnIndex > columnCount) { throw Message.getInvalidValueException("" + columnIndex, "columnIndex"); } }
private int getPositiveInt() throws SQLException { int v = getInt(); if (v < 0) { throw Message.getInvalidValueException("" + v, "positive integer"); } return v; }
public Value convertScale(boolean onlyToSmallerScale, int targetScale) throws SQLException { if (targetScale < 0 || targetScale > DEFAULT_SCALE) { // TODO convertScale for Timestamps: may throw an exception? throw Message.getInvalidValueException(""+targetScale, "scale"); } int nanos = value.getNanos(); BigDecimal bd = new BigDecimal("" + nanos); bd = bd.movePointLeft(9); bd = MathUtils.setScale(bd, targetScale); bd = bd.movePointRight(9); int n2 = bd.intValue(); if (n2 == nanos) { return this; } long t = value.getTime(); while (n2 >= 1000000000) { t += 1000; n2 -= 1000000000; } Timestamp t2 = new Timestamp(t); t2.setNanos(n2); return ValueTimestamp.getNoCopy(t2); }
public ConnectionInfo(String u, Properties info) throws SQLException { this.originalURL = u; if (!u.startsWith(Constants.START_URL)) { throw Message.getInvalidValueException(u, "url"); } this.url = u; readProperties(info); readSettingsFromURL(); setUserName(removeProperty("USER", "")); readPasswords(); name = url.substring(Constants.START_URL.length()); parseName(); }
/** * Sets the number of rows suggested to read in one step. This value cannot * be higher than the maximum rows (setMaxRows) set by the statement or * prepared statement, otherwise an exception is throws. * * @param rowCount the number of rows */ public void setFetchSize(int rowCount) throws SQLException { try { debugCodeCall("setFetchSize", rowCount); checkClosed(); if (rowCount < 0) { throw Message.getInvalidValueException("" + rowCount, "rowCount"); } if (rowCount > 0) { if (stat != null) { int maxRows = stat.getMaxRows(); if (maxRows > 0 && rowCount > maxRows) { throw Message.getInvalidValueException("" + rowCount, "rowCount"); } } } } catch (Throwable e) { throw logAndConvert(e); } }
/** * Gets the maximum number of rows for a ResultSet. * * @param maxRows the number of rows where 0 means no limit * @throws SQLException if this object is closed */ public void setMaxRows(int maxRows) throws SQLException { try { debugCodeCall("setMaxRows", maxRows); checkClosed(); if (maxRows < 0) { throw Message.getInvalidValueException(""+maxRows, "maxRows"); } this.maxRows = maxRows; } catch (Throwable e) { throw logAndConvert(e); } }
/** * Sets the number of rows suggested to read in one step. * This value cannot be higher than the maximum rows (setMaxRows) * set by the statement or prepared statement, otherwise an exception * is throws. Setting the value to 0 will set the default value. * The default value can be changed using the system property * h2.serverResultSetFetchSize. * * @param rows the number of rows * @throws SQLException if this object is closed */ public void setFetchSize(int rows) throws SQLException { try { debugCodeCall("setFetchSize", rows); checkClosed(); if (rows < 0 || (rows > 0 && maxRows > 0 && rows > maxRows)) { throw Message.getInvalidValueException("" + rows, "rows"); } if (rows == 0) { rows = SysProperties.SERVER_RESULT_SET_FETCH_SIZE; } fetchSize = rows; } catch (Throwable e) { throw logAndConvert(e); } }
/** * Sets the current query timeout in seconds. Calling this method will * commit an open transaction, even if the value is the same as before. * Changing the value will affect all statements of this connection. * * @param seconds the timeout in seconds - 0 means no timeout, values * smaller 0 will throw an exception * @throws SQLException if this object is closed */ public void setQueryTimeout(int seconds) throws SQLException { try { debugCodeCall("setQueryTimeout", seconds); checkClosed(); if (seconds < 0) { throw Message.getInvalidValueException("" + seconds, "seconds"); } conn.setQueryTimeout(seconds); } catch (Throwable e) { throw logAndConvert(e); } }
private void setParameter(int parameterIndex, Value value) throws SQLException { checkClosed(); parameterIndex--; ObjectArray parameters = command.getParameters(); if (parameterIndex < 0 || parameterIndex >= parameters.size()) { throw Message.getInvalidValueException("" + (parameterIndex + 1), "parameterIndex"); } ParameterInterface param = (ParameterInterface) parameters.get(parameterIndex); param.setValue(value); }
/** * Returns the value of the specified column as a String. * * @deprecated * * @param columnIndex (1,2,...) * @return the value * @throws SQLException if the column is not found or if the result set is * closed */ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { try { if (debug()) { debugCode("getBigDecimal(" + columnIndex+", "+scale+");"); } if (scale < 0) { throw Message.getInvalidValueException(""+scale, "scale"); } BigDecimal bd = get(columnIndex).getBigDecimal(); return bd == null ? null : MathUtils.setScale(bd, scale); } catch (Throwable e) { throw logAndConvert(e); } }
/** * Returns the value of the specified column as a String. * * @deprecated * * @param columnName * @return the value * @throws SQLException if the column is not found or if the result set is * closed */ public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { try { if (debug()) { debugCode("getBigDecimal(" + StringUtils.quoteJavaString(columnName)+", "+scale+");"); } if (scale < 0) { throw Message.getInvalidValueException(""+scale, "scale"); } BigDecimal bd = get(columnName).getBigDecimal(); return bd == null ? null : MathUtils.setScale(bd, scale); } catch (Throwable e) { throw logAndConvert(e); } }