public static String utf8Decode(byte[] bytes, int offset, int length) { try { return new String(bytes, offset, length, Constants.UTF8); } catch (UnsupportedEncodingException e) { throw Message.convertToInternal(e); } }
public static String utf8Decode(byte[] utf8) { try { return new String(utf8, Constants.UTF8); } catch (UnsupportedEncodingException e) { throw Message.convertToInternal(e); } }
public boolean equals(Object other) { try { return other instanceof ValueLob && compareSecure((Value) other, null) == 0; } catch (SQLException e) { throw Message.convertToInternal(e); } }
public int compare(Object o1, Object o2) { Row r1 = (Row) o1; Row r2 = (Row) o2; try { return idx.compareRows(r1, r2); } catch (SQLException e) { throw Message.convertToInternal(e); } } });
private ValueDecimal(BigDecimal value) { if (value == null) { throw new IllegalArgumentException(); } else if (!SysProperties.ALLOW_BIG_DECIMAL_EXTENSIONS && !value.getClass().equals(BigDecimal.class)) { SQLException e = Message.getSQLException(ErrorCode.INVALID_CLASS_2, new String[] { BigDecimal.class.getName(), value.getClass().getName() }); throw Message.convertToInternal(e); } this.value = value; }
public Reader getReader() { try { return IOUtils.getReader(getInputStream()); } catch (SQLException e) { throw Message.convertToInternal(e); } }
public Object getObject() { if (type == Value.CLOB) { return getReader(); } else { try { return getInputStream(); } catch (SQLException e) { throw Message.convertToInternal(e); } } }
public String getString() { try { StringBuffer buff = new StringBuffer(); buff.append("("); result.beforeFirst(); ResultSetMetaData meta = result.getMetaData(); int columnCount = meta.getColumnCount(); for (int i = 0; result.next(); i++) { if (i > 0) { buff.append(", "); } buff.append('('); for (int j = 0; j < columnCount; j++) { if (j > 0) { buff.append(", "); } int t = DataType.convertSQLTypeToValueType(meta.getColumnType(j + 1)); Value v = DataType.readValue(null, result, j+1, t); buff.append(v.getString()); } buff.append(')'); } buff.append(")"); result.beforeFirst(); return buff.toString(); } catch (SQLException e) { throw Message.convertToInternal(e); } }
public int hashCode() { if (hash == 0) { if (precision > 4096) { // TODO: should calculate the hash code when saving, and store // it in the data file return (int) (precision ^ (precision >> 32)); } try { hash = ByteUtils.getByteArrayHash(getBytes()); } catch (SQLException e) { throw Message.convertToInternal(e); } } return hash; }
public static synchronized FileSystem getInstance(String url) { int idx = url.indexOf('/'); if (idx > 0) { url = url.substring(0, idx); } FileSystemDatabase fs = (FileSystemDatabase) INSTANCES.get(url); if (fs != null) { return fs; } Connection conn; try { if (url.startsWith("jdbc:h2:")) { // avoid using DriverManager if possible conn = Driver.load().connect(url, new Properties()); } else { conn = JdbcUtils.getConnection(null, url, new Properties()); } boolean log = url.toUpperCase().indexOf("TRACE_") >= 0; fs = new FileSystemDatabase(url, conn, log); INSTANCES.put(url, fs); return fs; } catch (SQLException e) { throw Message.convertToInternal(e); } }
public int compare(Object o1, Object o2) { try { Value[] a1 = ((ValueArray) o1).getList(); Value[] a2 = ((ValueArray) o2).getList(); return sort.compare(a1, a2); } catch (SQLException e) { throw Message.convertToInternal(e); } } });
public String getSQL() { try { String s; if (type == Value.CLOB) { s = getString(); return StringUtils.quoteStringSQL(s); } else { byte[] buff = getBytes(); s = ByteUtils.convertBytesToString(buff); return "X'" + s + "'"; } } catch (SQLException e) { throw Message.convertToInternal(e); } }
public String getString() { int len = precision > Integer.MAX_VALUE || precision == 0 ? Integer.MAX_VALUE : (int) precision; try { if (type == Value.CLOB) { if (small != null) { return StringUtils.utf8Decode(small); } return IOUtils.readStringAndClose(getReader(), len); } else { byte[] buff; if (small != null) { buff = small; } else { buff = IOUtils.readBytesAndClose(getInputStream(), len); } return ByteUtils.convertBytesToString(buff); } } catch (IOException e) { throw Message.convertToInternal(Message.convertIOException(e, fileName)); } catch (SQLException e) { throw Message.convertToInternal(e); } }
public void close() { try { if (table != null) { index.remove(session); ObjectArray indexes = table.getIndexes(); indexes.remove(indexes.indexOf(index)); table.removeChildrenAndResources(session); } } catch (SQLException e) { throw Message.convertToInternal(e); } finally { table = null; } }