private DocumentList query(String sql, Object... args) { activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(args); return DocumentList.wrap(results.iterator()); }
private void executeCommand(String query, Object... args) { activateOnCurrentThread(); db.command(new OCommandSQL(query)).execute(args); }
/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
public boolean execute(final ODatabaseDocumentTx db, final Object... values) { checkNotNull(db); checkArgument(values.length > 0); int records = db.command(new OCommandSQL(query)) .execute(values); return records == 1; }
@Nullable public T execute(final ODatabaseDocumentTx db, final Object... values) { checkNotNull(db); checkArgument(values.length > 0); List<ODocument> results = db.command(new OSQLSynchQuery<>(query)) .execute(values); if (results.isEmpty()) { return null; } return adapter.readEntity(results.get(0)); }
public boolean exists(final ODatabaseDocumentTx db, final String name, final Bucket bucket) { Map<String, Object> params = ImmutableMap.of( P_NAME, checkNotNull(name), P_BUCKET, recordIdentity(id(checkNotNull(bucket))) ); return !isEmpty(db.command(EXISTS_QUERY).<Iterable<ODocument>>execute(params)); }
private Iterable<ODocument> buildAndRunQuery(final ODatabaseDocumentTx db, final String whereClause, final Map<String, String> parameters) { StringBuilder query = new StringBuilder("SELECT FROM " + DB_CLASS + whereClause); log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters); return db.command(new OCommandSQL(query.toString())).execute(parameters); }
T findByProperty(final ODatabaseDocumentTx db, final String propName, final Object propValue) { checkNotNull(propName); checkNotNull(propValue); Map<String, Object> parameters = ImmutableMap.of("propValue", propValue); String query = String.format("select from %s where %s = :propValue", getTypeName(), propName); Iterable<ODocument> docs = db.command(new OCommandSQL(query)).execute(parameters); ODocument first = Iterables.getFirst(docs, null); return first != null ? readEntity(first) : null; }
private List<ODocument> execute(final ODatabaseDocumentTx db, // NOSONAR final String query, final Map<String, Object> parameters) { return db.command(new OCommandSQL(query)).execute(parameters); } }
public Iterable<T> execute(final ODatabaseDocumentTx db, final Object... values) { checkNotNull(db); checkArgument(values.length > 0); Iterable<ODocument> results = db.command(new OSQLSynchQuery<>(query)) .execute(values); return adapter.transform(results); }
/** * Executes commands against the graph. Commands are executed outside * transaction. * * @param iCommand * Command request between SQL, GREMLIN and SCRIPT commands */ public OCommandRequest command(final OCommandRequest iCommand) { return new OrientGraphCommand(this, getRawGraph().command(iCommand)); }
/** * @since 3.2 */ public void clear(final ODatabaseDocumentTx db) { db.command(new OCommandSQL(DELETE_ALL)).execute(); } }
/** * @since 3.6 */ public SelectorConfiguration getByName(final ODatabaseDocumentTx db, final String name) { Map<String, Object> parameters = ImmutableMap.of(P_NAME, name); Iterable<ODocument> docs = db.command(new OCommandSQL(FIND_BY_NAME)).execute(parameters); return this.readEntity(Iterables.getFirst(docs, null)); }
public long getCount(final ODatabaseDocumentTx db, final String repositoryName, final String assetName) { checkNotNull(db); checkNotNull(repositoryName); checkNotNull(assetName); Map<String, Object> parameters = buildQueryParameters(repositoryName, assetName, DateType.DAY, null, null); Iterable<ODocument> docs = db.command(new OCommandSQL(TOTAL_COUNT_QUERY)).execute(parameters); ODocument result = Iterables.getFirst(docs, null); if (result != null) { return result.field("sum", OType.LONG); } return 0; }
public long[] getCounts(final ODatabaseDocumentTx db, final String repositoryName, final DateType dateType) { checkNotNull(db); checkNotNull(repositoryName); checkNotNull(dateType); Map<String, Object> parameters = buildQueryParameters(repositoryName, "", dateType, null, null); Iterable<ODocument> docs = db.command(new OCommandSQL(REPO_TOTAL_FOR_DATE_TYPE_QUERY)).execute(parameters); return getCounts(docs, dateType); }
private boolean exists(final String path) { try (ODatabaseDocumentTx db = openDb()) { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>( "SELECT FROM " + RawBinaryEntityAdapter.DB_CLASS + " WHERE path = ?"); final List<ODocument> results = db.command(query).execute(path); return !results.isEmpty(); } }
/** * Executes commands against the graph. Commands are executed outside transaction. * * @param iCommand Command request between SQL, GREMLIN and SCRIPT commands */ public OCommandRequest command(final OCommandRequest iCommand) { makeActive(); return new OrientGraphCommand(this, getRawGraph().command(iCommand)); }
public Iterable<ODocument> documents(final ODatabaseDocumentTx db, final Iterable<EntityId> ids) { Set<ORID> rids = stream(ids).map(id -> { if (id instanceof AttachedEntityId) { return ((AttachedEntityId) id).getIdentity(); } return getRecordIdObfuscator().decode(getSchemaType(), id.getValue()); }).collect(toSet()); return db.command(new OCommandSQL("select from :rids")).execute(singletonMap("rids", rids)); }
private void renameAssetLastAccessedField() { try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) { OClass assetClass = getAssetDbClass(db); if (assetClass.existsProperty(P_LAST_ACCESSED)) { db.command(new OCommandSQL(ALTER_ASSET_LAST_ACCESSED)).execute(); } } }
@Override @Timed public boolean test(final BlobStore blobStore, final BlobId blobId, final String blobName) { BlobRef blobRef = new BlobRef(ANY_NODE, blobStore.getBlobStoreConfiguration().getName(), blobId.asUniqueString()); try (ODatabaseDocumentTx tx = txSupplier.get()) { tx.begin(); List<ODocument> results = tx.command(assetBlobRefQuery).execute(blobName, blobRef.toString()); return !results.isEmpty(); } } }