1 22 23 package org.xquark.extractor.sql; 24 25 import java.sql.SQLException ; 26 import java.sql.Statement ; 27 import java.util.List ; 28 29 public class SqlCreateTable extends SqlExpression 30 { 31 32 private static final String RCSRevision = "$Revision: 1.6 $"; 33 private static final String RCSName = "$Name: $"; 34 35 private String _tableName; 36 private SqlExpression _query; 37 38 42 public SqlCreateTable(String tableName, SqlExpression query) 43 { 44 setTableName(tableName); 45 setQuery(query); 46 } 47 48 public SqlCreateTable() {} 49 50 54 public SqlExpression getQuery() 55 { 56 return _query; 57 } 58 59 64 public void setQuery(SqlExpression aQuery) 65 { 66 _query = aQuery; 67 } 68 69 public void setTableName(String tableName) 70 { 71 _tableName = tableName; 72 } 73 74 75 public String toSql(Context context) 76 { 77 StringBuffer sb = new StringBuffer (); 78 sb.append(" CREATE GLOBAL TEMPORARY TABLE "); 79 sb.append(_tableName); 80 sb.append("AS "); 81 sb.append(_query.toSql(context)); 82 return sb.toString() ; 83 } 84 85 public void clean(Statement statement) throws SQLException 86 { 87 statement.executeQuery ( "DROP TABLE " + _tableName ) ; 88 } 89 90 protected List getResetStatementList(List stmts) 91 { 92 stmts.add(new StatementInfo("TRUNCATE TABLE " + _tableName)); 93 return stmts; 94 } 95 } 96 | Popular Tags |