001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/field/db/TKFormDBData.java,v 1.10 2001/10/05 13:51:40 markus Exp $
003: *
004: */
005: package com.teamkonzept.field.db;
006:
007: import java.sql.*;
008:
009: import com.teamkonzept.db.*;
010: import com.teamkonzept.lib.*;
011: import com.teamkonzept.field.*;
012: import com.teamkonzept.field.db.queries.*;
013: import com.teamkonzept.webman.mainint.DatabaseDefaults;
014:
015: /**
016: *
017: * @author
018: * @version
019: */
020: public class TKFormDBData extends TKDBVectorData implements
021: DatabaseDefaults {
022:
023: public int form_id;
024: public int form_type;
025:
026: public TKVector field = new TKVector(); // of TKFieldTableData, order by field_id
027: public TKVector sub_field = new TKVector(); // of TKSubFieldTableData
028: public TKVector field_attribute = new TKVector(); // of TKFieldAttributeTableData
029:
030: public TKFormDBData() {
031: this .form_id = 0;
032: this .form_type = TKQuery.DBFORM_IDENT;
033: }
034:
035: public TKFormDBData(int id) {
036: this .form_id = id;
037: this .form_type = TKQuery.DBFORM_IDENT;
038: }
039:
040: public TKFormDBData(int id, int type) {
041: this .form_id = id;
042: this .form_type = type;
043: }
044:
045: public boolean isRemoveable() throws SQLException {
046: TKQuery query;
047: if (form_type == CONTENT_FORM_TYPE) {
048: query = TKDBManager.newQuery(TKDBFormIsRemoveable.class);
049: query.setQueryParams("FORM_ID", new Integer(form_id));
050: } else if (form_type == STRUCTURE_FORM_TYPE) {
051: query = TKDBManager
052: .newQuery(TKDBStructureFormIsRemoveable.class);
053: query.setQueryParams("FORM_ID", new Integer(form_id));
054:
055: } else {
056: query = TKDBManager
057: .newQuery(TKDBFragmentFormIsRemoveable.class);
058: query.setQueryParams("FORM_ID", Integer.toString(form_id));
059: }
060: query.execute();
061: ResultSet rs = query.fetchResultSet();
062: return !rs.next();
063: }
064:
065: public void fill(ResultSet rs) throws SQLException {
066: this .form_id = rs.getInt("FORM_ID");
067: this .form_type = rs.getInt("FORM_TYPE");
068: }
069:
070: public void insertIntoQuery(TKQuery query) throws SQLException {
071: insertPrimaryIntoQuery(query);
072: insertInitialIntoQuery(query);
073: }
074:
075: public void insertInitialIntoQuery(TKQuery query)
076: throws SQLException {
077: query.setQueryParams("FORM_TYPE", new Integer(form_type));
078: }
079:
080: public void insertPrimaryIntoQuery(TKQuery query)
081: throws SQLException {
082: query.setQueryParams("FORM_ID", new Integer(form_id));
083: }
084:
085: public TKVector getVector(String table) {
086: if (table.equals("FIELD")) {
087: return field;
088: } else if (table.equals("SUB_FIELD")) {
089: return sub_field;
090: } else if (table.equals("FIELD_ATTRIBUTE")) {
091: return field_attribute;
092: }
093: return null;
094: }
095:
096: public TKDBTableData getProtoType(String table) {
097: if (table.equals("FIELD")) {
098: return new TKFieldTableData();
099: } else if (table.equals("SUB_FIELD")) {
100: return new TKSubFieldTableData();
101: } else if (table.equals("FIELD_ATTRIBUTE")) {
102: return new TKFieldAttributeTableData();
103: }
104: return null;
105: }
106:
107: public String toString() {
108: return "( FORM := " + "( FORM_ID=" + String.valueOf(form_id)
109: + ", FORM_TYPE=" + String.valueOf(form_type) + ")"
110: + System.getProperty("line.separator") + ","
111: + System.getProperty("line.separator") + "FIELD := "
112: + field.toString() + ","
113: + System.getProperty("line.separator")
114: + "SUB_FIELD := " + sub_field.toString() + ","
115: + System.getProperty("line.separator")
116: + "FIELD_ATTRIBUTE := " + field_attribute.toString()
117: + ")" + System.getProperty("line.separator");
118: }
119:
120: }
|