use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.
the class OIndexMultiValues method remove.
@Override
public boolean remove(Object key, final OIdentifiable value) {
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireExclusiveLock(key);
try {
acquireSharedLock();
try {
Set<OIdentifiable> values = null;
while (true) {
try {
values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
if (values == null) {
return false;
}
final OModifiableBoolean removed = new OModifiableBoolean(false);
final Callable<Object> creator = new EntityRemover(value, removed, values);
while (true) try {
storage.updateIndexEntry(indexId, key, creator);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
return removed.getValue();
} finally {
releaseSharedLock();
}
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.
the class OIndexFullText method remove.
/**
* Splits passed in key on several words and remove records with keys equals to any item of split result and values equals to
* passed in value.
*
* @param key Key to remove.
* @param value Value to remove.
*
* @return <code>true</code> if at least one record is removed.
*/
@Override
public boolean remove(Object key, final OIdentifiable value) {
if (key == null)
return false;
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireExclusiveLock(key);
try {
final Set<String> words = splitIntoWords(key.toString());
final OModifiableBoolean removed = new OModifiableBoolean(false);
for (final String word : words) {
acquireSharedLock();
try {
Set<OIdentifiable> recs;
while (true) {
try {
recs = (Set<OIdentifiable>) storage.getIndexValue(indexId, word);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
if (recs != null && !recs.isEmpty()) {
while (true) {
try {
storage.updateIndexEntry(indexId, word, new EntityRemover(recs, value, removed));
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
}
} finally {
releaseSharedLock();
}
}
return removed.getValue();
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.
the class OServerCommandGetGephi method execute.
@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: gephi/<database>/<language>/<query-text>[/<limit>][/<fetchPlan>].<br>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");
final String language = urlParts[2];
final String text = urlParts[3];
final int limit = urlParts.length > 4 ? Integer.parseInt(urlParts[4]) : 20;
final String fetchPlan = urlParts.length > 5 ? urlParts[5] : null;
iRequest.data.commandInfo = "Gephi";
iRequest.data.commandDetail = text;
final ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getAnyGraph(shutdownFlag);
try {
final Iterable<OrientElement> vertices;
if (language.equals("sql"))
vertices = graph.command(new OSQLSynchQuery<OrientVertex>(text, limit).setFetchPlan(fetchPlan)).execute();
else if (language.equals("gremlin")) {
List<Object> result = new ArrayList<Object>();
OGremlinHelper.execute(graph, text, null, null, result, null, null);
vertices = new ArrayList<OrientElement>(result.size());
for (Object o : result) {
((ArrayList<OrientElement>) vertices).add(graph.getVertex(o));
}
} else
throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");
sendRecordsContent(iRequest, iResponse, vertices, fetchPlan);
} finally {
if (graph != null && shutdownFlag.getValue())
graph.shutdown(false, false);
if (db != null)
db.close();
}
return false;
}
use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.
the class OCommandExecutorSQLDeleteEdge method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLDeleteEdge parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
// System.out.println("NEW PARSER FROM: " + queryText);
queryText = preParse(queryText, iRequest);
// System.out.println("NEW PARSER TO: " + queryText);
textRequest.setText(queryText);
init((OCommandRequestText) iRequest);
parserRequiredKeyword("DELETE");
parserRequiredKeyword("EDGE");
OClass clazz = null;
String where = null;
String temp = parseOptionalWord(true);
String originalTemp = null;
int limit = -1;
if (temp != null && !parserIsEnded())
originalTemp = parserText.substring(parserGetPreviousPosition(), parserGetCurrentPosition()).trim();
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(false, shutdownFlag);
try {
while (temp != null) {
if (temp.equals("FROM")) {
fromExpr = parserRequiredWord(false, "Syntax error", " =><,\r\n");
if (rids != null)
throwSyntaxErrorException("FROM '" + fromExpr + "' is not allowed when specify a RIDs (" + rids + ")");
} else if (temp.equals("TO")) {
toExpr = parserRequiredWord(false, "Syntax error", " =><,\r\n");
if (rids != null)
throwSyntaxErrorException("TO '" + toExpr + "' is not allowed when specify a RID (" + rids + ")");
} else if (temp.startsWith("#")) {
rids = new ArrayList<ORecordId>();
rids.add(new ORecordId(temp));
if (fromExpr != null || toExpr != null)
throwSyntaxErrorException("Specifying the RID " + rids + " is not allowed with FROM/TO");
} else if (temp.startsWith("[") && temp.endsWith("]")) {
temp = temp.substring(1, temp.length() - 1);
rids = new ArrayList<ORecordId>();
for (String rid : temp.split(",")) {
rid = rid.trim();
if (!rid.startsWith("#")) {
throwSyntaxErrorException("Not a valid RID: " + rid);
}
rids.add(new ORecordId(rid));
}
} else if (temp.equals(KEYWORD_WHERE)) {
if (clazz == null)
// ASSIGN DEFAULT CLASS
clazz = graph.getEdgeType(OrientEdgeType.CLASS_NAME);
where = parserGetCurrentPosition() > -1 ? " " + parserText.substring(parserGetCurrentPosition()) : "";
if (this.preParsedStatement != null) {
StringBuilder builder = new StringBuilder();
((ODeleteEdgeStatement) this.preParsedStatement).getWhereClause().toString(parameters, builder);
where = builder.toString();
}
compiledFilter = OSQLEngine.getInstance().parseCondition(where, getContext(), KEYWORD_WHERE);
break;
} else if (temp.equals(KEYWORD_BATCH)) {
temp = parserNextWord(true);
if (temp != null)
batch = Integer.parseInt(temp);
} else if (temp.equals(KEYWORD_LIMIT)) {
temp = parserNextWord(true);
if (temp != null)
limit = Integer.parseInt(temp);
} else if (temp.length() > 0) {
// GET/CHECK CLASS NAME
label = originalTemp;
clazz = graph.getEdgeType(temp);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + temp + "' was not found");
}
temp = parseOptionalWord(true);
if (parserIsEnded())
break;
}
if (where == null)
if (limit > -1) {
where = " LIMIT " + limit;
} else {
where = "";
}
else
where = " WHERE " + where;
if (fromExpr == null && toExpr == null && rids == null)
if (clazz == null)
// DELETE ALL THE EDGES
query = graph.getRawGraph().command(new OSQLAsynchQuery<ODocument>("select from E" + where, this));
else
// DELETE EDGES OF CLASS X
query = graph.getRawGraph().command(new OSQLAsynchQuery<ODocument>("select from " + clazz.getName() + where, this));
return this;
} finally {
if (shutdownFlag.getValue())
graph.shutdown(false, false);
ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
}
} finally {
textRequest.setText(originalQuery);
}
}
use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.
the class OCommandExecutorSQLMoveVertex method execute.
/**
* Executes the command and return the ODocument object created.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (className == null && clusterName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
OModifiableBoolean shutdownGraph = new OModifiableBoolean();
final boolean txAlreadyBegun = getDatabase().getTransaction().isActive();
final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownGraph);
try {
final Set<OIdentifiable> sourceRIDs = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), source, context, iArgs);
// CREATE EDGES
final List<ODocument> result = new ArrayList<ODocument>(sourceRIDs.size());
for (OIdentifiable from : sourceRIDs) {
final OrientVertex fromVertex = graph.getVertex(from);
if (fromVertex == null)
continue;
final ORID oldVertex = fromVertex.getIdentity().copy();
final ORID newVertex = fromVertex.moveTo(className, clusterName);
final ODocument newVertexDoc = newVertex.getRecord();
if (fields != null) {
// EVALUATE FIELDS
for (final OPair<String, Object> f : fields) {
if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context));
}
OSQLHelper.bindParameters(newVertexDoc, fields, new OCommandParameters(iArgs), context);
}
if (merge != null)
newVertexDoc.merge(merge, true, false);
// SAVE CHANGES
newVertexDoc.save();
// PUT THE MOVE INTO THE RESULT
result.add(new ODocument().setTrackingChanges(false).field("old", oldVertex, OType.LINK).field("new", newVertex, OType.LINK));
if (batch > 0 && result.size() % batch == 0) {
graph.commit();
if (!graph.isAutoStartTx())
graph.begin();
}
}
graph.commit();
return result;
} finally {
if (!txAlreadyBegun)
graph.commit();
if (shutdownGraph.getValue())
graph.shutdown(false);
}
}
Aggregations