File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\CreateAggregate.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.constant.ErrorCode;
11 import org.h2.engine.Database;
12 import org.h2.engine.Session;
13 import org.h2.engine.UserAggregate;
14 import org.h2.message.DbException;
15 import org.h2.schema.Schema;
16
17 /**
18 * This class represents the statement
19 * CREATE AGGREGATE
20 */
21 public class CreateAggregate extends DefineCommand {
22
23 private Schema schema;
24 private String name;
25 private String javaClassMethod;
26 private boolean ifNotExists;
27 private boolean force;
28
29 public CreateAggregate(Session session) {
30 super(session);
31 }
32
33 public int update() {
34 session.commit(true);
35 session.getUser().checkAdmin();
36 Database db = session.getDatabase();
37 if (db.findAggregate(name) != null || schema.findFunction(name) != null) {
38 if (!ifNotExists) {
39 throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
40 }
41 } else {
42 int id = getObjectId();
43 UserAggregate aggregate = new UserAggregate(db, id, name, javaClassMethod, force);
44 db.addDatabaseObject(session, aggregate);
45 }
46 return 0;
47 }
48
49 public void setSchema(Schema schema) {
50 this.schema = schema;
51 }
52
53 public void setName(String name) {
54 this.name = name;
55 }
56
57 public void setJavaClassMethod(String string) {
58 this.javaClassMethod = string;
59 }
60
61 public void setIfNotExists(boolean ifNotExists) {
62 this.ifNotExists = ifNotExists;
63 }
64
65 public void setForce(boolean force) {
66 this.force = force;
67 }
68
69 public int getType() {
70 return CommandInterface.CREATE_AGGREGATE;
71 }
72
73 }
74