File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\CreateTrigger.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.message.DbException;
14 import org.h2.schema.Schema;
15 import org.h2.schema.TriggerObject;
16 import org.h2.table.Table;
17
18 /**
19 * This class represents the statement
20 * CREATE TRIGGER
21 */
22 public class CreateTrigger extends SchemaCommand {
23
24 private String triggerName;
25 private boolean ifNotExists;
26
27 private boolean insteadOf;
28 private boolean before;
29 private int typeMask;
30 private boolean rowBased;
31 private int queueSize = TriggerObject.DEFAULT_QUEUE_SIZE;
32 private boolean noWait;
33 private String tableName;
34 private String triggerClassName;
35 private boolean force;
36 private boolean onRollback;
37
38 public CreateTrigger(Session session, Schema schema) {
39 super(session, schema);
40 }
41
42 public void setInsteadOf(boolean insteadOf) {
43 this.insteadOf = insteadOf;
44 }
45
46 public void setBefore(boolean before) {
47 this.before = before;
48 }
49
50 public void setTriggerClassName(String triggerClassName) {
51 this.triggerClassName = triggerClassName;
52 }
53
54 public void setTypeMask(int typeMask) {
55 this.typeMask = typeMask;
56 }
57
58 public void setRowBased(boolean rowBased) {
59 this.rowBased = rowBased;
60 }
61
62 public void setQueueSize(int size) {
63 this.queueSize = size;
64 }
65
66 public void setNoWait(boolean noWait) {
67 this.noWait = noWait;
68 }
69
70 public void setTableName(String tableName) {
71 this.tableName = tableName;
72 }
73
74 public void setTriggerName(String name) {
75 this.triggerName = name;
76 }
77
78 public void setIfNotExists(boolean ifNotExists) {
79 this.ifNotExists = ifNotExists;
80 }
81
82 public int update() {
83 session.commit(true);
84 Database db = session.getDatabase();
85 if (getSchema().findTrigger(triggerName) != null) {
86 if (ifNotExists) {
87 return 0;
88 }
89 throw DbException.get(ErrorCode.TRIGGER_ALREADY_EXISTS_1, triggerName);
90 }
91 int id = getObjectId();
92 Table table = getSchema().getTableOrView(session, tableName);
93 TriggerObject trigger = new TriggerObject(getSchema(), id, triggerName, table);
94 trigger.setInsteadOf(insteadOf);
95 trigger.setBefore(before);
96 trigger.setNoWait(noWait);
97 trigger.setQueueSize(queueSize);
98 trigger.setRowBased(rowBased);
99 trigger.setTypeMask(typeMask);
100 trigger.setOnRollback(onRollback);
101 trigger.setTriggerClassName(triggerClassName, force);
102 db.addSchemaObject(session, trigger);
103 table.addTrigger(trigger);
104 return 0;
105 }
106
107 public void setForce(boolean force) {
108 this.force = force;
109 }
110
111 public void setOnRollback(boolean onRollback) {
112 this.onRollback = onRollback;
113 }
114
115 public int getType() {
116 return CommandInterface.CREATE_TRIGGER;
117 }
118
119 }
120