FunctionCursorResultSet(FunctionIndex index, SearchRow first, SearchRow last, Session session, ResultSet result) { super(index, first, last, session); this.result = result; try { this.meta = result.getMetaData(); } catch (SQLException e) { throw DbException.convert(e); } }
/** * Converts a LocalTime to a Value. * * @param localTime the LocalTime to convert, not {@code null} * @return the value */ public static Value localTimeToTimeValue(Object localTime) { try { return ValueTime.fromNanos((Long) LOCAL_TIME_TO_NANO.invoke(localTime)); } catch (IllegalAccessException e) { throw DbException.convert(e); } catch (InvocationTargetException e) { throw DbException.convertInvocation(e, "time conversion failed"); } }
private static Cursor get(Future<Cursor> f) { Cursor c; try { c = f.get(); } catch (Exception e) { throw DbException.convert(e); } return c == null ? EMPTY_CURSOR : c; }
/** * Converts a LocalDate to a Value. * * @param localDate the LocalDate to convert, not {@code null} * @return the value */ public static Value localDateToDateValue(Object localDate) { try { return ValueDate.fromDateValue(dateValueFromLocalDate(localDate)); } catch (IllegalAccessException e) { throw DbException.convert(e); } catch (InvocationTargetException e) { throw DbException.convertInvocation(e, "date conversion failed"); } }
/** * Encode the string as an URL. * * @param s the string to encode * @return the encoded string */ public static String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); } catch (Exception e) { // UnsupportedEncodingException throw DbException.convert(e); } }
private byte[] fetch() { try { prep.setInt(2, seq++); ResultSet rs = prep.executeQuery(); if (rs.next()) { return rs.getBytes(1); } return null; } catch (SQLException e) { throw DbException.convert(e); } }
/** * Convert an exception to a SQL exception using the default mapping. * * @param e the root cause * @return the SQL exception object */ public static SQLException toSQLException(Throwable e) { if (e instanceof SQLException) { return (SQLException) e; } return convert(e).getSQLException(); }
private void open() { try { conn = JdbcUtils.getConnection(driver, url, user, password); } catch (SQLException e) { throw DbException.convert(e); } }
@Override public void uncaughtException(Thread t, Throwable e) { db.setBackgroundException(DbException.convert(e)); }
/** * Kill a currently running query on this thread. */ private synchronized void cancelRequest() { if (activeRequest != null) { try { activeRequest.cancel(); activeRequest = null; } catch (SQLException e) { throw DbException.convert(e); } } }
/** {@inheritDoc} */ @Override public Row get() { try { return cursor.get(); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** * Convert an InvocationTarget exception to a database exception. * * @param te the root cause * @param message the added message or null * @return the database exception object */ public static DbException convertInvocation(InvocationTargetException te, String message) { Throwable t = te.getTargetException(); if (t instanceof SQLException || t instanceof DbException) { return convert(t); } message = message == null ? t.getMessage() : message + ": " + t.getMessage(); return get(ErrorCode.EXCEPTION_IN_FUNCTION_1, t, message); }
public Geometry getGeometryNoCopy() { if (geometry == null) { try { geometry = new WKBReader().read(bytes); } catch (ParseException ex) { throw DbException.convert(ex); } } return geometry; }
/** {@inheritDoc} */ @Override public Row get() { try { return desc.createRow(curr.get()); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** * Get or create a geometry value for the given geometry. * * @param s the WKT representation of the geometry * @return the value */ public static ValueGeometry get(String s) { try { Geometry g = new WKTReader().read(s); return get(g); } catch (ParseException ex) { throw DbException.convert(ex); } }
/** {@inheritDoc} */ @Override public byte[] getBytesNoCopy() { if (obj.cacheObjectType() == CacheObject.TYPE_REGULAR) { // Result must be the same as `marshaller.marshall(obj.value(coctx, false));` try { return obj.valueBytes(valCtx); } catch (IgniteCheckedException e) { throw DbException.convert(e); } } // For user-provided and array types. return JdbcUtils.serialize(obj, null); }
@Override public void removeRow(Session session, Row row) { lastModificationId = database.getNextModificationDataId(); Transaction t = session.getTransaction(); long savepoint = t.setSavepoint(); try { for (int i = indexes.size() - 1; i >= 0; i--) { Index index = indexes.get(i); index.remove(session, row); } } catch (Throwable e) { t.rollbackToSavepoint(savepoint); throw DbException.convert(e); } analyzeIfRequired(session); }
/** {@inheritDoc} */ @Override public long getRowCount(Session ses) { try { int seg = threadLocalSegment(); H2Tree tree = treeForRead(seg); GridH2QueryContext qctx = GridH2QueryContext.get(); return tree.size(filter(qctx)); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }
/** * Get or create a geometry value for the given geometry. * * @param s the WKT representation of the geometry * @param srid the srid of the object * @return the value */ public static ValueGeometry get(String s, int srid) { try { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid); Geometry g = new WKTReader(geometryFactory).read(s); return get(g); } catch (ParseException ex) { throw DbException.convert(ex); } }
/** {@inheritDoc} */ @Override public Cursor findFirstOrLast(Session session, boolean b) { try { H2Tree tree = treeForRead(threadLocalSegment()); GridH2QueryContext qctx = GridH2QueryContext.get(); return new SingleRowCursor(b ? tree.findFirst(filter(qctx)): tree.findLast(filter(qctx))); } catch (IgniteCheckedException e) { throw DbException.convert(e); } }