01: package com.teamkonzept.field.db.queries.oracle;
02:
03: import com.teamkonzept.db.*;
04: import com.teamkonzept.webman.mainint.db.queries.field.InsertEmptyClob;
05: import com.teamkonzept.webman.mainint.db.queries.field.SelectEmptyClob;
06:
07: import java.sql.*;
08:
09: import oracle.sql.CLOB;
10:
11: import org.apache.log4j.Category;
12:
13: public class TKDBContentValuePut extends TKExtendedPrepQuery {
14:
15: private static Category cat = Category
16: .getInstance(TKDBContentValuePut.class.getName());
17:
18: public final static boolean IS_PREPARED = true;
19:
20: public final static String[] PARAM_ORDER = { "CONTENT_ID",
21: "CONTENT_NODE_ID", "IDX", "VALUE", MEDIA_ID };
22:
23: public final static Object[][] PARAM_TYPES = null;
24:
25: public final static boolean[] SET_RELEVANTS = { false };
26:
27: protected static Class[] queryClasses = { InsertEmptyClob.class, // [0]
28: SelectEmptyClob.class // [1]
29: };
30:
31: public boolean execute() {
32: try {
33: init(queryClasses); // init query objects
34:
35: boolean isNotOpen = aTKDBConnection.isAutoCommit();
36: if (isNotOpen) {
37: TKDBManager.beginTransaction(); // begin transaction
38: }
39:
40: // insert am empty clob locator...
41: // NOTE: the (sub-)query below uses Oracle extensions to JDBC!
42: queries[0].setQueryParams("CONTENT_ID", queryParams
43: .get("CONTENT_ID"));
44: queries[0].setQueryParams("CONTENT_NODE_ID", queryParams
45: .get("CONTENT_NODE_ID"));
46: queries[0].setQueryParams("IDX", queryParams.get("IDX"));
47: queries[0].setQueryParams(MEDIA_ID, queryParams
48: .get(MEDIA_ID));
49: queries[0].execute();
50:
51: // retrieve newly inserted (empty) clob and set "VALUE"
52: queries[1].setQueryParams("CONTENT_ID", queryParams
53: .get("CONTENT_ID"));
54: queries[1].setQueryParams("CONTENT_NODE_ID", queryParams
55: .get("CONTENT_NODE_ID"));
56: queries[1].setQueryParams("IDX", queryParams.get("IDX"));
57: queries[1].execute();
58: ResultSet rs = queries[1].fetchResultSet();
59: if (rs.next()) {
60: CLOB clob = (CLOB) rs.getClob(1);
61: String value = (String) queryParams.get("VALUE");
62: int written = clob.putString(1, value);
63: cat.debug(written + " chars written");
64: }
65:
66: // COMMIT TRANSACTION
67: if (isNotOpen) {
68: aTKDBConnection.commitTransaction(); // commit all changes
69: }
70:
71: } catch (Throwable t) {
72: cat.error("Error while inserting clob data", t);
73: TKDBManager.safeRollbackTransaction(t);
74: }
75: return hasResults();
76: }
77:
78: public void initQuery(Connection con) {
79: super.initQuery(con, IS_PREPARED, PARAM_ORDER, PARAM_TYPES,
80: SET_RELEVANTS, null);
81: }
82: }
|