01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.command.ddl;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.constant.ErrorCode;
11: import org.h2.engine.UserAggregate;
12: import org.h2.engine.Database;
13: import org.h2.engine.Session;
14: import org.h2.message.Message;
15:
16: /**
17: * This class represents the statement
18: * CREATE AGGREGATE
19: */
20: public class CreateAggregate extends DefineCommand {
21:
22: private String name;
23: private String javaClassMethod;
24: private boolean ifNotExists;
25: private boolean force;
26:
27: public CreateAggregate(Session session) {
28: super (session);
29: }
30:
31: public int update() throws SQLException {
32: session.commit(true);
33: session.getUser().checkAdmin();
34: Database db = session.getDatabase();
35: if (db.findAggregate(name) != null
36: || db.findFunctionAlias(name) != null) {
37: if (!ifNotExists) {
38: throw Message
39: .getSQLException(
40: ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1,
41: name);
42: }
43: } else {
44: int id = getObjectId(false, true);
45: UserAggregate aggregate = new UserAggregate(db, id, name,
46: javaClassMethod, force);
47: db.addDatabaseObject(session, aggregate);
48: }
49: return 0;
50: }
51:
52: public void setName(String name) {
53: this .name = name;
54: }
55:
56: public void setJavaClassMethod(String string) {
57: this .javaClassMethod = string;
58: }
59:
60: public void setIfNotExists(boolean ifNotExists) {
61: this .ifNotExists = ifNotExists;
62: }
63:
64: public void setForce(boolean force) {
65: this.force = force;
66: }
67:
68: }
|