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.Right;
12: import org.h2.engine.Session;
13: import org.h2.message.Message;
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() throws SQLException {
33: session.commit(true);
34: if (!table.canTruncate()) {
35: throw Message.getSQLException(ErrorCode.CANNOT_TRUNCATE_1,
36: table.getSQL());
37: } else {
38: session.getUser().checkRight(table, Right.DELETE);
39: table.lock(session, true, true);
40: table.truncate(session);
41: }
42: return 0;
43: }
44:
45: }
|