File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\CreateFunctionAlias.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.FunctionAlias;
13 import org.h2.engine.Session;
14 import org.h2.message.DbException;
15 import org.h2.schema.Schema;
16 import org.h2.util.StringUtils;
17
18 /**
19 * This class represents the statement
20 * CREATE ALIAS
21 */
22 public class CreateFunctionAlias extends SchemaCommand {
23
24 private String aliasName;
25 private String javaClassMethod;
26 private boolean deterministic;
27 private boolean ifNotExists;
28 private boolean force;
29 private String source;
30
31 public CreateFunctionAlias(Session session, Schema schema) {
32 super(session, schema);
33 }
34
35 public int update() {
36 session.commit(true);
37 session.getUser().checkAdmin();
38 Database db = session.getDatabase();
39 if (getSchema().findFunction(aliasName) != null) {
40 if (!ifNotExists) {
41 throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
42 }
43 } else {
44 int id = getObjectId();
45 FunctionAlias functionAlias;
46 if (javaClassMethod != null) {
47 functionAlias = FunctionAlias.newInstance(getSchema(), id, aliasName, javaClassMethod, force);
48 } else {
49 functionAlias = FunctionAlias.newInstanceFromSource(getSchema(), id, aliasName, source, force);
50 }
51 functionAlias.setDeterministic(deterministic);
52 db.addSchemaObject(session, functionAlias);
53 }
54 return 0;
55 }
56
57 public void setAliasName(String name) {
58 this.aliasName = name;
59 }
60
61 /**
62 * Set the qualified method name after removing whitespace.
63 *
64 * @param method the qualified method name
65 */
66 public void setJavaClassMethod(String method) {
67 this.javaClassMethod = StringUtils.replaceAll(method, " ", "");
68 }
69
70 public void setIfNotExists(boolean ifNotExists) {
71 this.ifNotExists = ifNotExists;
72 }
73
74 public void setForce(boolean force) {
75 this.force = force;
76 }
77
78 public void setDeterministic(boolean deterministic) {
79 this.deterministic = deterministic;
80 }
81
82 public void setSource(String source) {
83 this.source = source;
84 }
85
86 public int getType() {
87 return CommandInterface.CREATE_ALIAS;
88 }
89
90 }
91