File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\TruncateTable.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.Right;
12 import org.h2.engine.Session;
13 import org.h2.message.DbException;
14 import org.h2.table.Table;
15
16 /**
17 * This class represents the statement
18 * TRUNCATE TABLE
19 */
20 public class TruncateTable extends DefineCommand {
21
22 private Table table;
23
24 public TruncateTable(Session session) {
25 super(session);
26 }
27
28 public void setTable(Table table) {
29 this.table = table;
30 }
31
32 public int update() {
33 session.commit(true);
34 if (!table.canTruncate()) {
35 throw DbException.get(ErrorCode.CANNOT_TRUNCATE_1, table.getSQL());
36 }
37 session.getUser().checkRight(table, Right.DELETE);
38 table.lock(session, true, true);
39 table.truncate(session);
40 return 0;
41 }
42
43 public int getType() {
44 return CommandInterface.TRUNCATE_TABLE;
45 }
46
47 }
48