| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.command.ddl; |
| 7 |
|
| 8 |
import org.h2.api.ErrorCode; |
| 9 |
import org.h2.command.CommandInterface; |
| 10 |
import org.h2.engine.Database; |
| 11 |
import org.h2.engine.SessionLocal; |
| 12 |
import org.h2.message.DbException; |
| 13 |
import org.h2.schema.Schema; |
| 14 |
import org.h2.schema.UserAggregate; |
| 15 |
|
| 16 |
/** |
| 17 |
* This class represents the statement |
| 18 |
* DROP AGGREGATE |
| 19 |
*/ |
| 20 |
public class DropAggregate extends SchemaOwnerCommand { |
| 21 |
|
| 22 |
private String name; |
| 23 |
private boolean ifExists; |
| 24 |
|
| 25 |
public DropAggregate(SessionLocal session, Schema schema) { |
| 26 |
super(session, schema); |
| 27 |
} |
| 28 |
|
| 29 |
@Override |
| 30 |
long update(Schema schema) { |
| 31 |
Database db = getDatabase(); |
| 32 |
UserAggregate aggregate = schema.findAggregate(name); |
| 33 |
if (aggregate == null) { |
| 34 |
if (!ifExists) { |
| 35 |
throw DbException.get(ErrorCode.AGGREGATE_NOT_FOUND_1, name); |
| 36 |
} |
| 37 |
} else { |
| 38 |
db.removeSchemaObject(session, aggregate); |
| 39 |
} |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
public void setName(String name) { |
| 44 |
this.name = name; |
| 45 |
} |
| 46 |
|
| 47 |
public void setIfExists(boolean ifExists) { |
| 48 |
this.ifExists = ifExists; |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public int getType() { |
| 53 |
return CommandInterface.DROP_AGGREGATE; |
| 54 |
} |
| 55 |
|
| 56 |
} |