Skip to content

Commit

Permalink
Add IF EXISTS option to DROP CLASS
Browse files Browse the repository at this point in the history
Related to: #3597
  • Loading branch information
luigidellaquila committed Nov 9, 2016
1 parent 9588453 commit 10c8bb2
Show file tree
Hide file tree
Showing 7 changed files with 1,664 additions and 1,554 deletions.
1 change: 1 addition & 0 deletions core/src/main/grammar/OrientSQL.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -3955,6 +3955,7 @@ ODropClassStatement DropClassStatement():
{
<DROP> <CLASS>
jjtThis.name = Identifier()
[ <IF> <EXISTS> { jjtThis.ifExists = true; } ]
[ <UNSAFE> { jjtThis.unsafe = true; } ]
{ return jjtThis; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class OCommandExecutorSQLDropClass extends OCommandExecutorSQLAbstract im
public static final String KEYWORD_UNSAFE = "UNSAFE";

private String className;
private boolean ifExists;
private boolean unsafe;

public OCommandExecutorSQLDropClass parse(final OCommandRequest iRequest) {
Expand All @@ -57,6 +58,7 @@ public OCommandExecutorSQLDropClass parse(final OCommandRequest iRequest) {
final boolean strict = getDatabase().getStorage().getConfiguration().isStrictSql();
if (strict) {
this.className = ((ODropClassStatement) this.preParsedStatement).name.getStringValue();
this.ifExists = ((ODropClassStatement) this.preParsedStatement).ifExists;
this.unsafe = ((ODropClassStatement) this.preParsedStatement).unsafe;
} else {
oldParsing((OCommandRequestText) iRequest);
Expand Down Expand Up @@ -162,7 +164,7 @@ public Object execute(final Map<Object, Object> iArgs) {

@Override
public String getSyntax() {
return "DROP CLASS <class> [UNSAFE]";
return "DROP CLASS <class> [IF EXISTS] [UNSAFE]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
public class ODropClassStatement extends ODDLStatement {

public OIdentifier name;
public boolean unsafe = false;
public boolean ifExists = false;
public boolean unsafe = false;

public ODropClassStatement(int id) {
super(id);
Expand All @@ -29,6 +30,9 @@ public ODropClassStatement(OrientSql p, int id) {
OSchema schema = ctx.getDatabase().getMetadata().getSchema();
OClass clazz = schema.getClass(name.getStringValue());
if (clazz == null) {
if (ifExists) {
return new OInternalResultSet();
}
throw new OCommandExecutionException("Class " + name.getStringValue() + " does not exist");
}

Expand Down Expand Up @@ -57,6 +61,9 @@ public ODropClassStatement(OrientSql p, int id) {
@Override public void toString(Map<Object, Object> params, StringBuilder builder) {
builder.append("DROP CLASS ");
name.toString(params, builder);
if (ifExists) {
builder.append(" IF EXISTS");
}
if (unsafe) {
builder.append(" UNSAFE");
}
Expand All @@ -65,6 +72,7 @@ public ODropClassStatement(OrientSql p, int id) {
@Override public ODropClassStatement copy() {
ODropClassStatement result = new ODropClassStatement(-1);
result.name = name == null ? null : name.copy();
result.ifExists = ifExists;
result.unsafe = unsafe;
return result;
}
Expand All @@ -79,6 +87,8 @@ public ODropClassStatement(OrientSql p, int id) {

if (unsafe != that.unsafe)
return false;
if(ifExists != that.ifExists)
return false;
if (name != null ? !name.equals(that.name) : that.name != null)
return false;

Expand Down
Loading

0 comments on commit 10c8bb2

Please sign in to comment.