use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLAlterSequence method execute.
@Override
public Object execute(Map<Object, Object> iArgs) {
if (this.sequenceName == null) {
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
}
final ODatabaseDocument database = getDatabase();
OSequence sequence = database.getMetadata().getSequenceLibrary().getSequence(this.sequenceName);
boolean result = sequence.updateParams(this.params);
sequence.reset();
return result;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLDelete method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLDelete parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
queryText = preParse(queryText, iRequest);
textRequest.setText(queryText);
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
query = null;
recordCount = 0;
if (parserTextUpperCase.endsWith(KEYWORD_UNSAFE)) {
unsafe = true;
parserText = parserText.substring(0, parserText.length() - KEYWORD_UNSAFE.length() - 1);
parserTextUpperCase = parserTextUpperCase.substring(0, parserTextUpperCase.length() - KEYWORD_UNSAFE.length() - 1);
}
parserRequiredKeyword(OCommandExecutorSQLDelete.KEYWORD_DELETE);
parserRequiredKeyword(OCommandExecutorSQLDelete.KEYWORD_FROM);
String subjectName = parserRequiredWord(false, "Syntax error", " =><,\r\n", true);
if (subjectName == null)
throwSyntaxErrorException("Invalid subject name. Expected cluster, class, index or sub-query");
if (OStringParser.startsWithIgnoreCase(subjectName, OCommandExecutorSQLAbstract.INDEX_PREFIX)) {
// INDEX
indexName = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_PREFIX.length());
if (!parserIsEnded()) {
while (!parserIsEnded()) {
final String word = parserGetLastWord();
if (word.equals(KEYWORD_LOCK))
lockStrategy = parseLock();
else if (word.equals(KEYWORD_RETURN))
returning = parseReturn();
else if (word.equals(KEYWORD_UNSAFE))
unsafe = true;
else if (word.equalsIgnoreCase(KEYWORD_WHERE))
compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition()), getContext(), KEYWORD_WHERE);
parserNextWord(true);
}
} else
parserSetCurrentPosition(-1);
} else if (subjectName.startsWith("(")) {
subjectName = subjectName.trim();
query = database.command(new OSQLAsynchQuery<ODocument>(subjectName.substring(1, subjectName.length() - 1), this));
parserNextWord(true);
if (!parserIsEnded()) {
while (!parserIsEnded()) {
final String word = parserGetLastWord();
if (word.equals(KEYWORD_LOCK))
lockStrategy = parseLock();
else if (word.equals(KEYWORD_RETURN))
returning = parseReturn();
else if (word.equals(KEYWORD_UNSAFE))
unsafe = true;
else if (word.equalsIgnoreCase(KEYWORD_WHERE))
compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition()), getContext(), KEYWORD_WHERE);
parserNextWord(true);
}
}
} else {
parserNextWord(true);
while (!parserIsEnded()) {
final String word = parserGetLastWord();
if (word.equals(KEYWORD_LOCK))
lockStrategy = parseLock();
else if (word.equals(KEYWORD_RETURN))
returning = parseReturn();
else {
parserGoBack();
break;
}
parserNextWord(true);
}
final String condition = parserGetCurrentPosition() > -1 ? " " + parserText.substring(parserGetCurrentPosition()) : "";
query = database.command(new OSQLAsynchQuery<ODocument>("select from " + getSelectTarget(subjectName) + condition, this));
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropClass method execute.
/**
* Execute the DROP CLASS.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (className == null) {
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
}
final ODatabaseDocument database = getDatabase();
if (ifExists && !database.getMetadata().getSchema().existsClass(className)) {
return true;
}
final OClass cls = database.getMetadata().getSchema().getClass(className);
if (cls == null) {
return null;
}
final long records = cls.count(true);
if (records > 0 && !unsafe) {
// NOT EMPTY, CHECK IF CLASS IS OF VERTEX OR EDGES
if (cls.isSubClassOf("V")) {
// FOUND VERTEX CLASS
throw new OCommandExecutionException("'DROP CLASS' command cannot drop class '" + className + "' because it contains Vertices. Use 'DELETE VERTEX' command first to avoid broken edges in a database, or apply the 'UNSAFE' keyword to force it");
} else if (cls.isSubClassOf("E")) {
// FOUND EDGE CLASS
throw new OCommandExecutionException("'DROP CLASS' command cannot drop class '" + className + "' because it contains Edges. Use 'DELETE EDGE' command first to avoid broken vertices in a database, or apply the 'UNSAFE' keyword to force it");
}
}
database.getMetadata().getSchema().dropClass(className);
if (records > 0 && unsafe) {
// NOT EMPTY, CHECK IF CLASS IS OF VERTEX OR EDGES
if (cls.isSubClassOf("V")) {
// FOUND VERTICES
if (unsafe)
OLogManager.instance().warn(this, "Dropped class '%s' containing %d vertices using UNSAFE mode. Database could contain broken edges", className, records);
} else if (cls.isSubClassOf("E")) {
// FOUND EDGES
OLogManager.instance().warn(this, "Dropped class '%s' containing %d edges using UNSAFE mode. Database could contain broken vertices", className, records);
}
}
return true;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropProperty method execute.
/**
* Execute the CREATE PROPERTY.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (fieldName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not yet been parsed");
final ODatabaseDocument database = getDatabase();
final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
if (sourceClass == null)
throw new OCommandExecutionException("Source class '" + className + "' not found");
if (ifExists && !sourceClass.existsProperty(fieldName)) {
return null;
}
final List<OIndex<?>> indexes = relatedIndexes(fieldName);
if (!indexes.isEmpty()) {
if (force) {
dropRelatedIndexes(indexes);
} else {
final StringBuilder indexNames = new StringBuilder();
boolean first = true;
for (final OIndex<?> index : sourceClass.getClassInvolvedIndexes(fieldName)) {
if (!first) {
indexNames.append(", ");
} else {
first = false;
}
indexNames.append(index.getName());
}
throw new OCommandExecutionException("Property used in indexes (" + indexNames.toString() + "). Please drop these indexes before removing property or use FORCE parameter.");
}
}
// REMOVE THE PROPERTY
sourceClass.dropProperty(fieldName);
return null;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropProperty method relatedIndexes.
private List<OIndex<?>> relatedIndexes(final String fieldName) {
final List<OIndex<?>> result = new ArrayList<OIndex<?>>();
final ODatabaseDocument database = getDatabase();
for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className)) {
if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) {
result.add(oIndex);
}
}
return result;
}
Aggregations