KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > command > ddl > TruncateTable


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.command.ddl;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.engine.Right;
10 import org.h2.engine.Session;
11 import org.h2.message.Message;
12 import org.h2.schema.Schema;
13 import org.h2.table.Table;
14
15 public class TruncateTable extends SchemaCommand {
16
17     private String JavaDoc tableName;
18
19     public TruncateTable(Session session, Schema schema) {
20         super(session, schema);
21     }
22     
23     public void setTableName(String JavaDoc tableName) {
24         this.tableName = tableName;
25     }
26     
27     public int update() throws SQLException JavaDoc {
28         session.commit();
29         Table table = getSchema().getTableOrView(session, tableName);
30         if(!table.canTruncate()) {
31             throw Message.getSQLException(Message.CANT_TRUNCATE_1, tableName);
32         } else {
33             session.getUser().checkRight(table, Right.DELETE);
34             table.lock(session, true);
35             table.truncate(session);
36         }
37         return 0;
38     }
39
40 }
41
Popular Tags