1 22 23 package org.xquark.extractor.sybase.sql; 24 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 import java.sql.Statement ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.xquark.extractor.sql.Context; 32 import org.xquark.extractor.sql.SqlExpression; 33 34 public class SqlCreateTable extends org.xquark.extractor.sql.SqlExpression { 35 private static final String RCSRevision = "$Revision: 1.5 $"; 36 private static final String RCSName = "$Name: $"; 37 38 private org.xquark.extractor.sql.SqlTable _tableName; 39 protected List _attrDefList; 40 41 public SqlCreateTable() { 42 43 } 44 45 public org.xquark.extractor.sql.SqlTable getTableName() { 46 return _tableName; 47 } 48 49 public void setTableName(org.xquark.extractor.sql.SqlTable tableName) { 50 _tableName = tableName; 51 } 52 53 public List getAttrDefList() { 54 return _attrDefList; 55 } 56 57 public void setAttrDefList(List attrDefList) { 58 _attrDefList = attrDefList; 59 } 60 61 public void addAttributeDefination(SqlAttributeDefinition attrDef) { 62 63 } 64 65 public ResultSet Execute(Statement statement) throws SQLException { 66 ResultSet retResultSet = null; 67 List prcedents = getPrecedents(); 68 if (null != prcedents) { 69 Iterator iter = prcedents.iterator(); 70 while (iter.hasNext()) { 71 ((SqlExpression) iter.next()).Execute(statement); 72 } 73 } 74 String query = this.toSql(new Context()); 75 try { 76 statement.executeUpdate(query); 77 } catch (SQLException ex) { 78 if (true 79 ) { 80 clean(statement); 81 statement.executeUpdate(query); 82 } 83 } 84 85 return retResultSet; 86 } 87 88 public String toSql(Context context) { 89 StringBuffer retVal = new StringBuffer (); 90 91 retVal.append("CREATE TABLE "); 92 retVal.append(getTableName().toSql(context)); 93 retVal.append(" ("); 94 95 SqlAttributeDefinition attrDef = null; 96 for (int i = 0; i < getAttrDefList().size(); i++) { 97 attrDef = (SqlAttributeDefinition) getAttrDefList().get(i); 98 retVal.append(attrDef.toSql(context)); 99 if (i != getAttrDefList().size() - 1) { 100 retVal.append(" , "); 101 } 102 } 103 retVal.append(")"); 104 105 return retVal.toString(); 106 } 107 108 protected void clean(Statement statement) throws SQLException { 109 statement.execute("DROP TABLE " + getTableName().toSql()); 110 } 111 } 112 | Popular Tags |