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 void scanOperation(final ODatabase database) { final String query = String.format("SELECT count(*) FROM %s WHERE notexistent is null", CLASS_NAME); final List<ODocument> result = database.command(new OSQLSynchQuery<ODocument>(query)).execute(); if (result.size() != 1) { throw new RuntimeException(String.format("The query [%s] result size is %d. Expected size is 1.", query, result.size())); } }
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; }
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; }
@Override public void sql(String query, Consumer<List<DocumentEntity>> callBack, Object... params) throws NullPointerException { requireNonNull(query, "query is required"); requireNonNull(callBack, "callBack is required"); ODatabaseSession tx = pool.acquire(); QueryOSQLFactory.QueryResultAsync orientQuery = toAsync(query, l -> callBack.accept(l.stream() .map(OrientDBConverter::convert) .collect(toList())), params); tx.command(orientQuery.getQuery()).execute(orientQuery.getParams()); }
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); }
/** * @since 3.2 */ public void clear(final ODatabaseDocumentTx db) { db.command(new OCommandSQL(DELETE_ALL)).execute(); } }
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(); } }
@Override public void notFilter(String type, String value) { try (ODatabaseDocumentTx db = docDb()) { db.command(new OCommandSQL(String.format("delete from Filter where type=\"%s\" and value=\"%s\"", type, value))).execute(); } }
public ORole getRole(final String iRoleName) { if (iRoleName == null) return null; final List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select from ORole where name = ? limit 1")).execute(iRoleName); if (result != null && !result.isEmpty()) return new ORole(result.get(0)); return null; }
public ORID getRoleRID(final String iRoleName) { if (iRoleName == null) return null; final List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select rid from index:ORole.name where key = ? limit 1")).execute(iRoleName); if (result != null && !result.isEmpty()) return result.get(0).rawField("rid"); return null; }
@Override public IPictogram findByTitle(String title) { if (title == null) return null; initDb(); // execute query OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>("select * from Pictogram where title LIKE ?"); List<ODocument> result = db.command(query).execute(title); // no pic found? if (result.isEmpty()) return null; // get first entity return convertToEntity(result.get(0)); }
@Override public OUser getUser(final String iUserName) { List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select from OUser where name = ? limit 1").setFetchPlan("roles:1")).execute(iUserName); if (result != null && !result.isEmpty()) return new OUser(result.get(0)); return null; }
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(); } } }
private Object extractValue(ODocument record, OPair<String, Object> entry) { Object value = entry.getValue(); if (value instanceof OSQLFilterItem) value = ((OSQLFilterItem) value).getValue(record, null, context); else if (value instanceof OCommandRequest) value = ((OCommandRequest) value).execute(record, null, context); if (value instanceof OIdentifiable && ((OIdentifiable) value).getIdentity().isPersistent()) // USE ONLY THE RID TO AVOID CONCURRENCY PROBLEM WITH OLD VERSIONS value = ((OIdentifiable) value).getIdentity(); return value; }
@Statement public void deleteProcessDefinitionsByDeploymentId(OPersistenceSession session, String deploymentId) { session.getDatabase().command(new OCommandSQL("delete from "+getSchemaClass()+" where deployment.id = ?")) .execute(deploymentId); }
@Override public void delete(T entity, OPersistenceSession session) { ODatabaseDocument db = session.getDatabase(); String id = entity.getId(); String oid = (String) convertValueFromEntity("id", id); OIdentifiable oIdentifiable = session.lookupOIdentifiableForIdInCache(oid); if(oIdentifiable!=null) { db.delete(oIdentifiable.getIdentity()); } else { db.command(new OCommandSQL("delete from "+getSchemaClass()+" where "+getPkField()+" = ?")).execute(oid); } }
private void distributedDropIndex(final String iName) { String dropIndexDDL = "DROP INDEX `" + iName + "`"; //noinspection deprecation getDatabase().command(new OCommandSQL(dropIndexDDL)).execute(); ORecordInternal .setIdentity(delegate.getDocument(), new ORecordId(getDatabase().getStorage().getConfiguration().getIndexMgrRecordId())); reload(); }