com.orientechnologies.orient.core.sql.parser.ODropSequenceStatement Maven / Gradle / Ivy
/* Generated By:JJTree: Do not edit this line. OAlterSequenceStatement.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.metadata.sequence.OSequence;
import com.orientechnologies.orient.core.sql.executor.OInternalResultSet;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import java.util.Map;
public class ODropSequenceStatement extends ODDLStatement {
OIdentifier name;
boolean ifExists = false;
public ODropSequenceStatement(int id) {
super(id);
}
public ODropSequenceStatement(OrientSql p, int id) {
super(p, id);
}
@Override
public OResultSet executeDDL(OCommandContext ctx) {
final ODatabaseSession database = ctx.getDatabase();
OSequence sequence =
database.getMetadata().getSequenceLibrary().getSequence(this.name.getStringValue());
if (sequence == null) {
if (ifExists) {
return new OInternalResultSet();
} else {
throw new OCommandExecutionException("Sequence not found: " + name);
}
}
try {
database.getMetadata().getSequenceLibrary().dropSequence(name.getStringValue());
} catch (ODatabaseException exc) {
String message = "Unable to execute command: " + exc.getMessage();
OLogManager.instance().error(this, message, exc, (Object) null);
throw new OCommandExecutionException(message);
}
OInternalResultSet rs = new OInternalResultSet();
OResultInternal result = new OResultInternal();
result.setProperty("operation", "drop sequence");
result.setProperty("sequenceName", name.getStringValue());
rs.add(result);
return rs;
}
@Override
public void toString(Map