KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > field > db > TKContentValueTableData


1 package com.teamkonzept.field.db;
2
3 import com.teamkonzept.db.*;
4 import de.webman.util.legacy.Legacy;
5
6 import java.sql.*;
7
8 /**
9  * Reads/writes content from/to the database (table CONTENT_VALUE).
10  * Note, that it is distinguished between oracle/sybase (clob behavior) and
11  * webman 1.2/greater than 1.2 (empty string behavior), respectively, at certain points.
12  *
13  * @author $Author: ralf $
14  * @version $Revision: 1.12 $
15  */

16 public class TKContentValueTableData extends TKDBTableData{
17
18     /**
19      * content_id
20      */

21     public int content_id;
22
23     /**
24      * content_node_id
25      */

26     public int content_node_id;
27     public int idx;
28     public String JavaDoc value;
29     public Integer JavaDoc mediaID;
30
31
32     public TKContentValueTableData( )
33     {
34     }
35     
36     public TKContentValueTableData( int content_id, int content_node_id, int idx, String JavaDoc value)
37     {
38         this(content_id, content_node_id, idx, value, null);
39     }
40
41     public TKContentValueTableData( int content_id, int content_node_id, int idx, String JavaDoc value, Integer JavaDoc mediaID)
42     {
43         this.content_id = content_id;
44         this.content_node_id = content_node_id;
45         this.idx = idx;
46         this.value = value;
47         this.mediaID = mediaID;
48     }
49
50     public TKContentValueTableData ( ResultSet r )
51         throws SQLException
52     {
53         this.content_id = r.getInt("CONTENT_ID");
54         this.content_node_id = r.getInt("CONTENT_NODE_ID");
55         this.idx = r.getInt("IDX");
56
57         // NOTE: the current jdbc driver for sybase does not implement the
58
// jdbc 2.0 specification. we distinguish between oracle and
59
// other database vendors at the point.
60
// TO BE FIXED SOON
61
if( TKDBManager.getDBVendor() == QueryConstants.ORACLE) {
62             Clob clob = r.getClob("VALUE"); // see comments below!
63
if (clob != null)
64             {
65                 this.value = clob.getSubString(1, (int) clob.length());
66             }
67         }
68         else {
69                 this.value = r.getString("VALUE");
70         }
71           //if( this.value.equals(" ") ) this.value = "";
72
// BUGFIX: leere Strings in TEXT-Spalten werden als String mit einem Leerzeichen abgelegt!
73
// ...yes and Oracle does not allow to insert empty strings if the column is restricted to
74
// "not null" values (this applies to VARCHAR as well as CLOB (Sybase: TEXT)). -ralf
75
// There is another problem with "value": column VALUE is definded as CLOB and, at least,
76
// Oracle's JDBC driver returns null if ResultSet.getString("VALUE") is called. Solution:
77
// call ResultSet.getClob("VALUE") and convert it to a string object.
78
// It looks like as if this works with Sybase as well. -ralf
79
if (Legacy.getInstance().isEmptyStringEnabled())
80           {
81               if (this.value == null || this.value.equals(" "))
82               {
83                 this.value = ""; // see comments above!
84
}
85           }
86           else
87           {
88               if (this.value == null || this.value.equals(QueryConstants.EMPTY_STRING_VALUE))
89               {
90                 this.value = ""; // see comments above!
91
}
92           }
93           
94           int id = r.getInt(MEDIA_ID);
95           if(!r.wasNull()){
96             this.mediaID = new Integer JavaDoc(id);
97           }
98
99     }
100
101     public void updatePrimary (TKDBVectorData dbData) {
102
103         TKContentDBData cdata = (TKContentDBData) dbData;
104         content_id = cdata.content_id;
105     }
106
107     public void insertIntoQuery(TKQuery query)
108         throws SQLException
109     {
110         query.setQueryParams("CONTENT_ID", new Integer JavaDoc(content_id));
111         query.setQueryParams("CONTENT_NODE_ID", new Integer JavaDoc(content_node_id));
112         query.setQueryParams("IDX", new Integer JavaDoc(idx));
113          // if (value != null) { // -ralf
114
// query.setQueryParams("VALUE", value);
115
// NOTE: value "can't" be null (that is, value is obviously *expected* to differ
116
// from null), otherwise the database would report a contraint violation because
117
// column "VALUE" is restricted to "not null"-values (see table CONTENT_VALUE).
118
// Also note, that Oracle supports neither null-values (as expected), nor string
119
// objects of length 0 (empty string) to be inserted into a "not null" restricted
120
// column of type clob (sybase: text) and varchar, respectively!
121
// The solution to this problem is - at this moment - to insert a string
122
// consisting of exactly one blank or changing the definition of the particular
123
// table.
124
if (Legacy.getInstance().isEmptyStringEnabled())
125          {
126             query.setQueryParams("VALUE", (value.length() == 0 ? " " : value)); // -ralf
127
}
128          else
129          {
130             query.setQueryParams("VALUE", (value.length() == 0 ? QueryConstants.EMPTY_STRING_VALUE : value)); // -ralf
131
}
132          // }
133
query.setQueryParams(MEDIA_ID, mediaID);
134     }
135
136     public TKDBTableData newFromResultSet( ResultSet r )
137         throws SQLException
138     {
139         return new TKContentValueTableData( r );
140     }
141
142     public String JavaDoc toString()
143     {
144         return "( CONTENT_ID="+String.valueOf( content_id )
145             + ", CONTENT_NODE_ID="+String.valueOf( content_node_id )
146             + ", IDX="+String.valueOf( idx )
147             + ", VALUE="+value
148             + ", MEDIA_ID=" + mediaID
149             + ")<BR>";
150     }
151
152     //{{DECLARE_CONTROLS
153
//}}
154
}
155
Popular Tags