001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/db/TKMarkupDefinitionDBData.java,v 1.7 2001/06/11 09:14:10 alex Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups.db;
006:
007: import java.sql.*;
008: import java.util.Enumeration;
009:
010: import com.teamkonzept.db.*;
011: import com.teamkonzept.lib.*;
012: import com.teamkonzept.publishing.markups.*;
013: import org.apache.log4j.Category;
014:
015: public class TKMarkupDefinitionDBData extends TKDBVectorData {
016: private static final Category cat = Category
017: .getInstance(TKMarkupDefinitionDBData.class);
018:
019: public TKMarkupDefinition markup;
020: public TKVector params = new TKVector(); // of TKMarkupParamCallTableData
021:
022: public TKMarkupDefinitionDBData() {
023:
024: this .markup = null;
025: }
026:
027: public TKMarkupDefinitionDBData(TKMarkupDefinition markup,
028: StringBuffer diagnostics) {
029:
030: this .markup = markup;
031:
032: Enumeration e = markup.allParams();
033: while ((e != null) && e.hasMoreElements()) {
034:
035: TKMarkupParamCall param = (TKMarkupParamCall) e
036: .nextElement();
037: if (param == null)
038: continue;
039:
040: if ((param.param.id < 0) && (diagnostics != null)) {
041:
042: if (diagnostics.length() != 0)
043: diagnostics.append("; ");
044: diagnostics.append("Wrong id =" + param.param.id
045: + " for param-call: " + param);
046: }
047:
048: TKMarkupParamCallTableData paramData = new TKMarkupParamCallTableData(
049: markup.id, param);
050: params.addElement(paramData);
051: }
052: }
053:
054: public void completeGet() {
055:
056: Enumeration e = params.elements();
057: while ((e != null) && e.hasMoreElements()) {
058:
059: TKMarkupParamCallTableData paramData = (TKMarkupParamCallTableData) e
060: .nextElement();
061: if (paramData != null)
062: markup.defineParam(paramData.param);
063: }
064: }
065:
066: public void completeNew() {
067:
068: Enumeration e = params.elements();
069: while ((e != null) && e.hasMoreElements()) {
070:
071: TKMarkupParamCallTableData paramData = (TKMarkupParamCallTableData) e
072: .nextElement();
073: if (paramData != null)
074: paramData.markupId = markup.id;
075:
076: if (paramData != null)
077: markup.defineParam(paramData.param);
078: }
079: }
080:
081: public void insertPrimaryIntoQuery(TKQuery query)
082: throws SQLException {
083:
084: query.setQueryParams("ATTRIBUTE_ID", new Integer(markup.id));
085: }
086:
087: public void insertInitialIntoQuery(TKQuery query)
088: throws SQLException {
089:
090: query.setQueryParams("NAME", markup.name);
091: query.setQueryParams("INFO", markup.info);
092: query.setQueryParams("IS_ATOM", new Integer(markup.isAtom ? 1
093: : 0));
094: query.setQueryParams("VALIDATION_ID", null);
095:
096: if ((markup.idPar == null) || (markup.idPar.param.id < 0))
097: query.setQueryParams("ID_PARAMETER_ID", null);
098: else
099: query.setQueryParams("ID_PARAMETER_ID", new Integer(
100: markup.idPar.param.id));
101: }
102:
103: public void insertIntoQuery(TKQuery query) throws SQLException {
104:
105: insertPrimaryIntoQuery(query);
106: insertInitialIntoQuery(query);
107: }
108:
109: public static TKMarkupDefinition newMarkupFromResultSet(ResultSet r) {
110:
111: try {
112: int id = r.getInt("ATTRIBUTE_ID");
113: String name = r.getString("NAME");
114: String info = r.getString("INFO");
115: boolean isAtom = r.getBoolean("IS_ATOM");
116: int validationId = r.getInt("VALIDATION_ID");
117: int idParameterId = r.getInt("ID_PARAMETER_ID");
118:
119: return new TKMarkupDefinition(id, name, idParameterId,
120: isAtom, info);
121:
122: } catch (Exception ex) {
123: cat
124: .error(
125: "TKMarkupDefinitionDBData.newMarkupFromResultSet() failed",
126: ex);
127: return null;
128: }
129: }
130:
131: public void fill(ResultSet r) throws SQLException {
132:
133: markup = newMarkupFromResultSet(r);
134: }
135:
136: public TKVector getVector(String table) {
137:
138: if (table.equals("TEXT_ATTRIBUTE_SYNTAX"))
139: return params;
140: else
141: return null;
142: }
143:
144: public TKDBTableData getProtoType(String table) {
145:
146: if (table.equals("TEXT_ATTRIBUTE_SYNTAX"))
147: return new TKMarkupParamCallTableData();
148: else
149: return null;
150: }
151:
152: public String toString() {
153:
154: return "(MARKUP_DEFINITION :=" + markup + ")";
155: }
156: }
|