public void deleteRow() throws SQLException { result.toElement().delete(); }
public Object command(final String iText, final Object... iParameters) { try (OResultSet rs = database.command(iText, iParameters)) { return rs.stream().map(x -> x.toElement()).toArray(size -> new OIdentifiable[size]); } }
public String getString(String columnLabel) throws SQLException { if ("@rid".equals(columnLabel) || "rid".equals(columnLabel)) { return result.toElement().getIdentity().toString(); } if ("@class".equals(columnLabel) || "class".equals(columnLabel)) { return result.toElement().getSchemaType().map(c -> c.getName()).orElse("NOCLASS"); } try { String r = Optional.ofNullable(result.getProperty(columnLabel)).map(v -> "" + v).orElse(null); lastReadWasNull = r == null; return r; } catch (Exception e) { throw new SQLException("An error occurred during the retrieval of the string value at column '" + columnLabel + "'", e); } }
public Collection<ODocument> getEntries(final Collection<?> iKeys) { final StringBuilder params = new StringBuilder(128); if (!iKeys.isEmpty()) { params.append("?"); for (int i = 1; i < iKeys.size(); i++) { params.append(", ?"); } } try (OResultSet rs = getDatabase().indexQuery(getName(), String.format(QUERY_GET_ENTRIES, name, params.toString()), iKeys.toArray())) { return rs.stream().map((res) -> (ODocument) res.toElement()).collect(Collectors.toList()); } }
public OIdentifiable[] query(final String iText, final Object... iParameters) { try (OResultSet rs = database.query(iText, iParameters)) { return rs.stream().map(x -> x.toElement()).toArray(size -> new OIdentifiable[size]); } }
@SuppressWarnings("boxing") public boolean getBoolean(String columnLabel) throws SQLException { try { Boolean r = result.getProperty(columnLabel); lastReadWasNull = r == null; return Boolean.TRUE.equals(r); } catch (Exception e) { throw new SQLException( "An error occurred during the retrieval of the boolean value at column '" + columnLabel + "' ---> " + result.toElement() .toJSON(), e); } }
public int getInt(String columnLabel) throws SQLException { if ("@version".equals(columnLabel)) return result.toElement().getVersion(); try { final Integer r = result.getProperty(columnLabel); lastReadWasNull = r == null; return r != null ? r : 0; } catch (Exception e) { throw new SQLException("An error occurred during the retrieval of the integer value at column '" + columnLabel + "'", e); } }
private Object convertToElement(Object property) { if (property instanceof OResult) { return ((OResult) property).toElement(); } if (property instanceof List) { return ((List) property).stream().map(x -> convertToElement(x)).collect(Collectors.toList()); } if (property instanceof Set) { return ((Set) property).stream().map(x -> convertToElement(x)).collect(Collectors.toSet()); } if (property instanceof Map) { Map<Object, Object> result = new HashMap<>(); Map<Object, Object> prop = ((Map) property); for (Map.Entry<Object, Object> o : prop.entrySet()) { result.put(o.getKey(), convertToElement(o.getValue())); } } return property; }
public RowId getRowId(final int columnIndex) throws SQLException { try { lastReadWasNull = false; return new OrientRowId(result.toElement().getIdentity()); } catch (Exception e) { throw new SQLException("An error occurred during the retrieval of the rowid for record '" + result + "'", e); } }
public static Object convertResultToDocument(Object value) { if (value instanceof OResult) { return ((OResult) value).toElement(); } if (value instanceof OIdentifiable) { return value; } if (value instanceof List && containsOResult((Collection) value)) { return ((List) value).stream().map(x -> convertResultToDocument(x)).collect(Collectors.toList()); } if (value instanceof Set && containsOResult((Collection) value)) { return ((Set) value).stream().map(x -> convertResultToDocument(x)).collect(Collectors.toSet()); } return value; }
protected OProperty getProperty(final int column) throws SQLException { String fieldName = getColumnName(column); return getCurrentRecord().toElement().getSchemaType() .map(st -> st.getProperty(fieldName)) .orElse(null); }
@Override public String getColumnTypeName(final int column) throws SQLException { final OResult currentRecord = getCurrentRecord(); String columnLabel = fieldNames[column - 1]; return currentRecord.toElement().getSchemaType() .map(st -> st.getProperty(columnLabel)) .map(p -> p.getType()) .map(t -> t.toString()) .orElse(null); }
public boolean isSigned(final int column) throws SQLException { final OResult currentRecord = getCurrentRecord(); OType otype = currentRecord.toElement().getSchemaType() .map(st -> st.getProperty(fieldNames[column - 1]).getType()) .orElse(null); return this.isANumericColumn(otype); }
public String getSchemaName(final int column) throws SQLException { final OResult currentRecord = getCurrentRecord(); if (currentRecord == null) return ""; else return currentRecord.toElement().getDatabase().getName(); }
@ConsoleCommand(splitInWords = false, description = "Traverse records and display the results", onlineHelp = "SQL-Traverse") public void traverse(@ConsoleParameter(name = "query-text", description = "The traverse to execute") String iQueryText) { final int limit; if (iQueryText.toLowerCase(Locale.ENGLISH).contains(" limit ")) { // RESET CONSOLE FLAG limit = -1; } else { limit = Integer.parseInt(properties.get("limit")); } long start = System.currentTimeMillis(); OResultSet rs = currentDatabase.command("traverse " + iQueryText); setResultset(rs.stream().map(x -> x.toElement()).collect(Collectors.toList())); rs.close(); float elapsedSeconds = getElapsedSecs(start); dumpResultSet(limit); message("\n\n" + currentResultSet.size() + " item(s) found. Traverse executed in " + elapsedSeconds + " sec(s)."); }
@ConsoleCommand(splitInWords = false, description = "Create a new edge into the database", onlineHelp = "SQL-Create-Edge") public void createEdge( @ConsoleParameter(name = "command-text", description = "The command text to execute") String iCommandText) { String command = "create " + iCommandText; resetResultSet(); final long start = System.currentTimeMillis(); OResultSet rs = currentDatabase.command(command); final List<OIdentifiable> result = rs.stream().map(x -> x.toElement()).collect(Collectors.toList()); rs.close(); float elapsedSeconds = getElapsedSecs(start); setResultset((List<OIdentifiable>) result); int displayLimit = Integer.parseInt(properties.get("limit")); dumpResultSet(displayLimit); message("\nCreated '%s' edges in %f sec(s).\n", ((List<OIdentifiable>) result).size(), elapsedSeconds); }
protected void executeServerSideScript(final String iLanguage, final String iText) { if (iText == null) return; resetResultSet(); long start = System.currentTimeMillis(); OResultSet rs = currentDatabase.execute(iLanguage, iText); currentResult = rs.stream().map(x -> x.toElement()).collect(Collectors.toList()); rs.close(); float elapsedSeconds = getElapsedSecs(start); parseResult(); if (currentResultSet != null) { dumpResultSet(-1); message("\nServer side script executed in %f sec(s). Returned %d records", elapsedSeconds, currentResultSet.size()); } else { String lineFeed = currentResult instanceof Map<?, ?> ? "\n" : ""; message("\nServer side script executed in %f sec(s). Value returned is: %s%s", elapsedSeconds, lineFeed, currentResult); } }
public Array getArray(String columnLabel) throws SQLException { OType columnType = result.toElement().getSchemaType().map(t -> t.getProperty(columnLabel).getType()).orElse(OType.EMBEDDEDLIST); assert columnType.isEmbedded() && columnType.isMultiValue(); // System.out.println("columnType.name() = " + columnType.getDefaultJavaType()); Array array = new OrientJdbcArray(result.getProperty(columnLabel)); lastReadWasNull = array == null; return array; }
static DocumentEntity convert(OResult row) { OElement element = row.toElement(); String name = element.getSchemaType() .map(OClass::getName) .orElseThrow(() -> new IllegalArgumentException("SchemaType is required in a row")); DocumentEntity entity = DocumentEntity.of(name); for (String propertyName : element.getPropertyNames()) { Object property = element.getProperty(propertyName); entity.add(propertyName, convert(property)); } ORID identity = element.getIdentity(); int clusterId = identity.getClusterId(); long clusterPosition = identity.getClusterPosition(); entity.add(VERSION_FIELD, element.getVersion()); entity.add(RID_FIELD, "#" + clusterId + ":" + clusterPosition); return entity; }
@Override public void delete(DocumentDeleteQuery query) { requireNonNull(query, "query is required"); DocumentQuery selectQuery = new OrientDBDocumentQuery(query); QueryOSQLFactory.QueryResult orientQuery = QueryOSQLFactory.to(selectQuery); try (ODatabaseSession tx = pool.acquire(); OResultSet resultSet = tx.command(orientQuery.getQuery(), orientQuery.getParams())) { while (resultSet.hasNext()) { OResult next = resultSet.next(); tx.delete(next.toElement().getIdentity()); } } }