1 5 package org.h2.command.ddl; 6 7 import java.sql.SQLException ; 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 tableName; 18 19 public TruncateTable(Session session, Schema schema) { 20 super(session, schema); 21 } 22 23 public void setTableName(String tableName) { 24 this.tableName = tableName; 25 } 26 27 public int update() throws SQLException { 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 |