1 5 package com.teamkonzept.field.db; 6 7 import java.sql.*; 8 9 import com.teamkonzept.db.*; 10 import com.teamkonzept.lib.*; 11 import com.teamkonzept.field.*; 12 import com.teamkonzept.field.db.queries.*; 13 import com.teamkonzept.webman.mainint.DatabaseDefaults; 14 15 20 public class TKFormDBData extends TKDBVectorData implements DatabaseDefaults{ 21 22 public int form_id; 23 public int form_type; 24 25 public TKVector field = new TKVector(); public TKVector sub_field = new TKVector(); public TKVector field_attribute = new TKVector(); 29 public TKFormDBData() 30 { 31 this.form_id = 0; 32 this.form_type = TKQuery.DBFORM_IDENT; 33 } 34 35 public TKFormDBData(int id) 36 { 37 this.form_id = id; 38 this.form_type = TKQuery.DBFORM_IDENT; 39 } 40 41 public TKFormDBData(int id, int type) 42 { 43 this.form_id = id; 44 this.form_type = type; 45 } 46 47 public boolean isRemoveable() 48 throws SQLException 49 { 50 TKQuery query; 51 if (form_type == CONTENT_FORM_TYPE) 52 { 53 query = TKDBManager.newQuery(TKDBFormIsRemoveable.class); 54 query.setQueryParams("FORM_ID", new Integer (form_id)); 55 } 56 else if (form_type == STRUCTURE_FORM_TYPE) 57 { 58 query = TKDBManager.newQuery(TKDBStructureFormIsRemoveable.class); 59 query.setQueryParams("FORM_ID", new Integer (form_id)); 60 61 } 62 else 63 { 64 query = TKDBManager.newQuery(TKDBFragmentFormIsRemoveable.class); 65 query.setQueryParams("FORM_ID", Integer.toString(form_id)); 66 } 67 query.execute(); 68 ResultSet rs = query.fetchResultSet(); 69 return !rs.next(); 70 } 71 72 public void fill(ResultSet rs) 73 throws SQLException 74 { 75 this.form_id = rs.getInt("FORM_ID"); 76 this.form_type = rs.getInt("FORM_TYPE"); 77 } 78 79 public void insertIntoQuery(TKQuery query) 80 throws SQLException 81 { 82 insertPrimaryIntoQuery(query); 83 insertInitialIntoQuery(query); 84 } 85 86 public void insertInitialIntoQuery(TKQuery query) 87 throws SQLException 88 { 89 query.setQueryParams("FORM_TYPE", new Integer (form_type)); 90 } 91 92 public void insertPrimaryIntoQuery(TKQuery query) 93 throws SQLException 94 { 95 query.setQueryParams("FORM_ID", new Integer (form_id)); 96 } 97 98 public TKVector getVector(String table) 99 { 100 if( table.equals("FIELD") ) { 101 return field; 102 } 103 else if ( table.equals("SUB_FIELD") ) { 104 return sub_field; 105 } 106 else if ( table.equals("FIELD_ATTRIBUTE") ) { 107 return field_attribute; 108 } 109 return null; 110 } 111 112 public TKDBTableData getProtoType(String table) { 113 if( table.equals("FIELD") ) { 114 return new TKFieldTableData(); 115 } 116 else if ( table.equals("SUB_FIELD") ) { 117 return new TKSubFieldTableData(); 118 } 119 else if ( table.equals("FIELD_ATTRIBUTE") ) { 120 return new TKFieldAttributeTableData(); 121 } 122 return null; 123 } 124 125 public String toString() 126 { 127 return "( FORM := " + "( FORM_ID="+ String.valueOf( form_id ) 128 + ", FORM_TYPE=" + String.valueOf( form_type ) 129 + ")" + System.getProperty("line.separator") 130 + "," + System.getProperty("line.separator") + "FIELD := " + field.toString() 131 + "," + System.getProperty("line.separator") + "SUB_FIELD := " + sub_field.toString() 132 + "," + System.getProperty("line.separator") + "FIELD_ATTRIBUTE := " + field_attribute.toString() 133 + ")" + System.getProperty("line.separator"); 134 } 135 136 } 137 138 | Popular Tags |