001: package com.teamkonzept.field.db;
002:
003: import com.teamkonzept.db.*;
004: import de.webman.util.legacy.Legacy;
005:
006: import java.sql.*;
007:
008: /**
009: * Reads/writes content from/to the database (table CONTENT_VALUE).
010: * Note, that it is distinguished between oracle/sybase (clob behavior) and
011: * webman 1.2/greater than 1.2 (empty string behavior), respectively, at certain points.
012: *
013: * @author $Author: ralf $
014: * @version $Revision: 1.12 $
015: */
016: public class TKContentValueTableData extends TKDBTableData {
017:
018: /**
019: * content_id
020: */
021: public int content_id;
022:
023: /**
024: * content_node_id
025: */
026: public int content_node_id;
027: public int idx;
028: public String value;
029: public Integer mediaID;
030:
031: public TKContentValueTableData() {
032: }
033:
034: public TKContentValueTableData(int content_id, int content_node_id,
035: int idx, String value) {
036: this (content_id, content_node_id, idx, value, null);
037: }
038:
039: public TKContentValueTableData(int content_id, int content_node_id,
040: int idx, String value, Integer mediaID) {
041: this .content_id = content_id;
042: this .content_node_id = content_node_id;
043: this .idx = idx;
044: this .value = value;
045: this .mediaID = mediaID;
046: }
047:
048: public TKContentValueTableData(ResultSet r) throws SQLException {
049: this .content_id = r.getInt("CONTENT_ID");
050: this .content_node_id = r.getInt("CONTENT_NODE_ID");
051: this .idx = r.getInt("IDX");
052:
053: // NOTE: the current jdbc driver for sybase does not implement the
054: // jdbc 2.0 specification. we distinguish between oracle and
055: // other database vendors at the point.
056: // TO BE FIXED SOON
057: if (TKDBManager.getDBVendor() == QueryConstants.ORACLE) {
058: Clob clob = r.getClob("VALUE"); // see comments below!
059: if (clob != null) {
060: this .value = clob.getSubString(1, (int) clob.length());
061: }
062: } else {
063: this .value = r.getString("VALUE");
064: }
065: //if( this.value.equals(" ") ) this.value = "";
066: // BUGFIX: leere Strings in TEXT-Spalten werden als String mit einem Leerzeichen abgelegt!
067: // ...yes and Oracle does not allow to insert empty strings if the column is restricted to
068: // "not null" values (this applies to VARCHAR as well as CLOB (Sybase: TEXT)). -ralf
069: // There is another problem with "value": column VALUE is definded as CLOB and, at least,
070: // Oracle's JDBC driver returns null if ResultSet.getString("VALUE") is called. Solution:
071: // call ResultSet.getClob("VALUE") and convert it to a string object.
072: // It looks like as if this works with Sybase as well. -ralf
073: if (Legacy.getInstance().isEmptyStringEnabled()) {
074: if (this .value == null || this .value.equals(" ")) {
075: this .value = ""; // see comments above!
076: }
077: } else {
078: if (this .value == null
079: || this .value
080: .equals(QueryConstants.EMPTY_STRING_VALUE)) {
081: this .value = ""; // see comments above!
082: }
083: }
084:
085: int id = r.getInt(MEDIA_ID);
086: if (!r.wasNull()) {
087: this .mediaID = new Integer(id);
088: }
089:
090: }
091:
092: public void updatePrimary(TKDBVectorData dbData) {
093:
094: TKContentDBData cdata = (TKContentDBData) dbData;
095: content_id = cdata.content_id;
096: }
097:
098: public void insertIntoQuery(TKQuery query) throws SQLException {
099: query.setQueryParams("CONTENT_ID", new Integer(content_id));
100: query.setQueryParams("CONTENT_NODE_ID", new Integer(
101: content_node_id));
102: query.setQueryParams("IDX", new Integer(idx));
103: // if (value != null) { // -ralf
104: // query.setQueryParams("VALUE", value);
105: // NOTE: value "can't" be null (that is, value is obviously *expected* to differ
106: // from null), otherwise the database would report a contraint violation because
107: // column "VALUE" is restricted to "not null"-values (see table CONTENT_VALUE).
108: // Also note, that Oracle supports neither null-values (as expected), nor string
109: // objects of length 0 (empty string) to be inserted into a "not null" restricted
110: // column of type clob (sybase: text) and varchar, respectively!
111: // The solution to this problem is - at this moment - to insert a string
112: // consisting of exactly one blank or changing the definition of the particular
113: // table.
114: if (Legacy.getInstance().isEmptyStringEnabled()) {
115: query.setQueryParams("VALUE", (value.length() == 0 ? " "
116: : value)); // -ralf
117: } else {
118: query
119: .setQueryParams(
120: "VALUE",
121: (value.length() == 0 ? QueryConstants.EMPTY_STRING_VALUE
122: : value)); // -ralf
123: }
124: // }
125: query.setQueryParams(MEDIA_ID, mediaID);
126: }
127:
128: public TKDBTableData newFromResultSet(ResultSet r)
129: throws SQLException {
130: return new TKContentValueTableData(r);
131: }
132:
133: public String toString() {
134: return "( CONTENT_ID=" + String.valueOf(content_id)
135: + ", CONTENT_NODE_ID="
136: + String.valueOf(content_node_id) + ", IDX="
137: + String.valueOf(idx) + ", VALUE=" + value
138: + ", MEDIA_ID=" + mediaID + ")<BR>";
139: }
140:
141: //{{DECLARE_CONTROLS
142: //}}
143: }
|