KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > api > dataxs > OwxcategoryManager


1 package com.raptus.owxv3.api.dataxs;
2
3 import java.util.Vector JavaDoc;
4 import java.sql.*;
5 import com.raptus.owxv3.*;
6
7
8 /******************SQL2JAVA_IMPORT_BEGIN******************/
9
10 /******************SQL2JAVA_IMPORT_END********************/
11
12
13 public class OwxcategoryManager extends SQLDatabaseManager
14 /******************SQL2JAVA_EXTENDS_BEGIN******************/
15
16 /******************SQL2JAVA_EXTENDS_END********************/
17
18 {
19
20 /******************SQL2JAVA_CLASS_BEGIN******************/
21
22 /******************SQL2JAVA_CLASS_END********************/
23
24
25     protected static final String JavaDoc tableNamebase = "owxcategory";
26
27     public OwxcategoryManager()
28     {
29         tableID = tableNamebase;
30         initialize();
31     }
32
33     public OwxcategoryManager(String JavaDoc tableNamespace)
34     {
35         this.tableNamespace = tableNamespace;
36         if(tableNamespace != null && tableNamespace.length() > 0)
37             tableID = tableNamebase + tableNamespace;
38         else
39             tableID = tableNamebase;
40         initialize();
41     }
42
43     public static final int ROWID = 0;
44     public static final int ID = 1;
45     public static final int OWNER = 2;
46     public static final int PARENT = 3;
47     public static final int USAGECTR = 4;
48     public static final int LEVEL = 5;
49     public static final int STATIC = 6;
50
51     protected void initialize()
52     {
53         ALL_FIELDS = "\"rowid\""
54                             + ",\"id\""
55                             + ",\"owner\""
56                             + ",\"parent\""
57                             + ",\"usagectr\""
58                             + ",\"level\""
59                             + ",\"static\"";
60         S2J_FIELD_NAMES = new String JavaDoc[]
61         {
62         tableID + ".\"rowid\"",
63         tableID + ".\"id\"",
64         tableID + ".\"owner\"",
65         tableID + ".\"parent\"",
66         tableID + ".\"usagectr\"",
67         tableID + ".\"level\"",
68         tableID + ".\"static\""
69         };
70     }
71
72     public Owxcategory loadByKey(int _rowid) throws SQLException {
73         Connection _conn = null;
74         try {
75             _conn = openConnection();
76             Owxcategory _val = loadByKey(_rowid, _conn);
77             closeConnection(_conn);
78             return _val;
79         }
80         catch(SQLException e) {
81             if(_conn != null) try { closeConnection(_conn); } catch(SQLException e2) { }
82             throw e;
83         }
84     }
85
86     public Owxcategory loadByKey(int _rowid, Connection _conn) throws SQLException {
87         PreparedStatement _pstmt = null;
88         try {
89             _pstmt = _conn.prepareStatement("SELECT " + ALL_FIELDS + " FROM " + tableID + " WHERE \"rowid\"=?");
90             _pstmt.setLong(1, _rowid);
91             Owxcategory _list[] = loadByPreparedStatement(_pstmt);
92             _pstmt.close();
93             if(_list.length < 1) return null;
94             else return _list[0];
95         }
96         catch(SQLException e) {
97             if(_pstmt != null) try { _pstmt.close(); } catch(SQLException e2) { }
98             throw e;
99         }
100     }
101
102     public Owxcategory[] loadAll() throws SQLException {
103         Connection _conn = null;
104         try {
105             _conn = openConnection();
106             Owxcategory _list[] = loadAll(_conn);
107             closeConnection(_conn);
108             return _list;
109         }
110         catch(SQLException e) {
111             if(_conn != null) try { closeConnection(_conn); } catch(SQLException e2) { }
112             throw e;
113         }
114     }
115
116     public Owxcategory[] loadAll(Connection _conn) throws SQLException {
117         PreparedStatement _pstmt = null;
118         try {
119             _pstmt = _conn.prepareStatement("SELECT " + ALL_FIELDS + " FROM " + tableID );
120             Owxcategory _list[] = loadByPreparedStatement(_pstmt);
121             _pstmt.close();
122             return _list;
123         }
124         catch(SQLException e) {
125             if(_pstmt != null) try { _pstmt.close(); } catch(SQLException e2) { }
126             throw e;
127         }
128     }
129
130     public Owxcategory[] loadByPreparedStatement(PreparedStatement pstmt) throws SQLException {
131         return loadByPreparedStatement(pstmt, null, 0);
132     }
133
134     public Owxcategory[] loadByPreparedStatement(PreparedStatement pstmt, int maxRows) throws SQLException {
135         return loadByPreparedStatement(pstmt, null, maxRows);
136     }
137
138     public Owxcategory[] loadByPreparedStatement(PreparedStatement pstmt, int[] fieldList) throws SQLException {
139         return loadByPreparedStatement(pstmt, fieldList, 0);
140     }
141
142     public Owxcategory[] loadByPreparedStatement(PreparedStatement pstmt, int[] fieldList, int maxRows) throws SQLException {
143         ResultSet rs = null;
144         try {
145             rs = pstmt.executeQuery();
146             java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
147             while(rs.next() && (maxRows == 0 || v.size() < maxRows)) {
148                 if(fieldList == null) v.addElement(decodeRow(rs));
149                 else v.addElement(decodeRow(rs, fieldList));
150             }
151             rs.close();
152             Owxcategory list[] = new Owxcategory[v.size()];
153             v.copyInto(list);
154             return list;
155         }
156         catch(SQLException e) {
157             if(rs!=null) try { rs.close();} catch(Exception JavaDoc e2) {}
158             throw e;
159         }
160     }
161
162     public Owxcategory[] loadByWhere(String JavaDoc where) throws SQLException {
163         return loadByWhere(where, (int[])null, 0, (String JavaDoc)null);
164     }
165     public Owxcategory[] loadByWhere(String JavaDoc where, int maxRows) throws SQLException {
166         return loadByWhere(where, (int[])null, maxRows, (String JavaDoc)null);
167     }
168     public Owxcategory[] loadByWhere(String JavaDoc where, String JavaDoc orderby, int maxRows) throws SQLException {
169         return loadByWhere(where, (int[])null, maxRows, orderby);
170     }
171     public Owxcategory[] loadByWhere(String JavaDoc where, int[] fieldList) throws SQLException {
172         return loadByWhere(where, fieldList, 0, (String JavaDoc)null);
173     }
174     public Owxcategory[] loadByWhere(String JavaDoc where, int[] fieldList, int maxRows, String JavaDoc orderby) throws SQLException {
175         Connection conn = null;
176         try {
177             conn = openConnection();
178             Owxcategory _list[] = loadByWhere(where, conn, fieldList, maxRows, orderby);
179             closeConnection(conn);
180             return _list;
181         }
182         catch(SQLException e) {
183             if(conn!=null) try { closeConnection(conn);} catch(Exception JavaDoc e2) {}
184             throw e;
185         }
186     }
187
188     public Owxcategory[] loadByWhere(String JavaDoc where, Connection conn) throws SQLException {
189         return loadByWhere(where, conn, (int[])null, 0, (String JavaDoc)null);
190     }
191
192     public Owxcategory[] loadByWhere(String JavaDoc where, Connection conn, int[] fieldList) throws SQLException {
193         return loadByWhere(where, conn, fieldList, 0, (String JavaDoc)null);
194     }
195
196     public Owxcategory[] loadByWhere(String JavaDoc where, Connection conn, int[] fieldList, int maxRows, String JavaDoc orderby)
197                 throws SQLException {
198         String JavaDoc sql = null;
199         if(fieldList == null)
200         {
201             sql = "select " + ALL_FIELDS + " from " + tableID + " where (" + where + ")";
202             if(orderby != null) sql += " order by " + orderby;
203         }
204         else
205         {
206             StringBuffer JavaDoc buff = new StringBuffer JavaDoc(128);
207             buff.append("select ");
208             for(int i = 0; i < fieldList.length; i++)
209             {
210                 if(i != 0) buff.append(",");
211                     buff.append(S2J_FIELD_NAMES[fieldList[i]]);
212             }
213             buff.append(" from " + tableID + " ");
214             buff.append(" where (" + where + ")");
215             if(orderby != null)
216                 buff.append(" order by " + orderby);
217             sql = buff.toString();
218         }
219         Statement stmt = null;
220         ResultSet rs = null;
221         try {
222             stmt = conn.createStatement();
223             rs = stmt.executeQuery(sql);
224             java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
225             while(rs.next() && (maxRows == 0 || v.size() < maxRows)) {
226                 if(fieldList == null) v.addElement(decodeRow(rs));
227                 else v.addElement(decodeRow(rs, fieldList));
228             }
229             rs.close();
230             stmt.close();
231
232             Owxcategory _list[] = new Owxcategory[v.size()];
233             v.copyInto(_list);
234             return _list;
235         }
236         catch(SQLException e) {
237             if(rs!=null) try { rs.close();} catch(Exception JavaDoc e2) {}
238             if(stmt!=null) try { stmt.close();} catch(Exception JavaDoc e2) {}
239             throw e;
240         }
241     }
242
243     public int deleteByKey(int _rowid) throws SQLException {
244         Connection _conn = null;
245         try {
246             _conn = openConnection();
247             int _rows = deleteByKey(_rowid, _conn);
248             closeConnection(_conn);
249             return _rows;
250         }
251         catch(SQLException e) {
252             if(_conn!=null) try { closeConnection(_conn);} catch(Exception JavaDoc e2) {}
253             throw e;
254         }
255     }
256
257     public int deleteByKey(int _rowid, Connection _conn) throws SQLException {
258         PreparedStatement _pstmt = null;
259         try {
260             _pstmt = _conn.prepareStatement("DELETE from " + tableID + " WHERE \"rowid\"=?");
261             _pstmt.setLong(1, _rowid);
262             int _rows = _pstmt.executeUpdate();
263             _pstmt.close();
264             return _rows;
265         }
266         catch(SQLException e) {
267             if(_pstmt!=null) try { _pstmt.close();} catch(Exception JavaDoc e2) {}
268             throw e;
269         }
270     }
271
272     public void save(Owxcategory obj) throws SQLException {
273         if(!obj.isModifiedS2J()) return;
274         Connection _conn = null;
275         try {
276             _conn = openConnection();
277             save(obj, _conn);
278             closeConnection(_conn);
279         }
280         catch(SQLException e) {
281             if(_conn!=null) try { closeConnection(_conn);} catch(Exception JavaDoc e2) {}
282             throw e;
283         }
284     }
285
286     public void save(Owxcategory obj, Connection _conn) throws SQLException {
287         PreparedStatement _pstmt = null;
288         try {
289             if(obj.isNew()) {
290                 int _dirtyCount = 0;
291                 StringBuffer JavaDoc _sql = new StringBuffer JavaDoc("INSERT into " + tableID + " (");
292                 if(obj.rowidIsModifiedS2j()) { _sql.append("\"rowid\"").append(","); _dirtyCount++; }
293                 if(obj.idIsModifiedS2j()) { _sql.append("\"id\"").append(","); _dirtyCount++; }
294                 if(obj.ownerIsModifiedS2j()) { _sql.append("\"owner\"").append(","); _dirtyCount++; }
295                 if(obj.parentIsModifiedS2j()) { _sql.append("\"parent\"").append(","); _dirtyCount++; }
296                 if(obj.usagectrIsModifiedS2j()) { _sql.append("\"usagectr\"").append(","); _dirtyCount++; }
297                 if(obj.levelIsModifiedS2j()) { _sql.append("\"level\"").append(","); _dirtyCount++; }
298                 if(obj.staticIsModifiedS2j()) { _sql.append("\"static\"").append(","); _dirtyCount++; }
299                 _sql.setLength(_sql.length() - 1);
300                 _sql.append(") values (");
301                 for(int i = 0; i < _dirtyCount; i++) _sql.append("?,");
302                 _sql.setLength(_sql.length() - 1);
303                 _sql.append(")");
304
305                 _pstmt = _conn.prepareStatement(_sql.toString());
306                 _dirtyCount = 0;
307                 if(obj.rowidIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getRowid()); }
308                 if(obj.idIsModifiedS2j()) { _pstmt.setString(++_dirtyCount, obj.getId()); }
309                 if(obj.ownerIsModifiedS2j()) { _pstmt.setString(++_dirtyCount, obj.getOwner()); }
310                 if(obj.parentIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getParent()); }
311                 if(obj.usagectrIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getUsagectr()); }
312                 if(obj.levelIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getLevel()); }
313                 if(obj.staticIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getStatic()); }
314                 _pstmt.executeUpdate();
315                 _pstmt.close();
316                 _pstmt = _conn.prepareStatement("SELECT currval('" + tableID + "_ROWID_seq')");
317                 ResultSet _rs = _pstmt.executeQuery();
318                 if(_rs.next()) obj.setRowid(_rs.getInt(1));
319                 _rs.close();
320                 obj.setIsNew(false);
321                 obj.resetIsModifiedS2J();
322             }
323             else {
324                 StringBuffer JavaDoc _sql = new StringBuffer JavaDoc("UPDATE " + tableID + " SET ");
325                 if(obj.rowidIsModifiedS2j()) { _sql.append("\"rowid\"").append("=?,"); }
326                 if(obj.idIsModifiedS2j()) { _sql.append("\"id\"").append("=?,"); }
327                 if(obj.ownerIsModifiedS2j()) { _sql.append("\"owner\"").append("=?,"); }
328                 if(obj.parentIsModifiedS2j()) { _sql.append("\"parent\"").append("=?,"); }
329                 if(obj.usagectrIsModifiedS2j()) { _sql.append("\"usagectr\"").append("=?,"); }
330                 if(obj.levelIsModifiedS2j()) { _sql.append("\"level\"").append("=?,"); }
331                 if(obj.staticIsModifiedS2j()) { _sql.append("\"static\"").append("=?,"); }
332                 _sql.setLength(_sql.length() - 1);
333                 _sql.append(" WHERE ");
334                 _sql.append("\"rowid\"=?");
335                 _pstmt = _conn.prepareStatement(_sql.toString());
336                 int _dirtyCount = 0;
337                 if(obj.rowidIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getRowid()); }
338                 if(obj.idIsModifiedS2j()) { _pstmt.setString(++_dirtyCount, obj.getId()); }
339                 if(obj.ownerIsModifiedS2j()) { _pstmt.setString(++_dirtyCount, obj.getOwner()); }
340                 if(obj.parentIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getParent()); }
341                 if(obj.usagectrIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getUsagectr()); }
342                 if(obj.levelIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getLevel()); }
343                 if(obj.staticIsModifiedS2j()) { _pstmt.setLong(++_dirtyCount, obj.getStatic()); }
344                 _pstmt.setLong(++_dirtyCount, obj.getRowid());
345                 _pstmt.executeUpdate();
346                 obj.resetIsModifiedS2J();
347             }
348             _pstmt.close();
349         }
350         catch(SQLException e) {
351             if(_pstmt!=null) try { _pstmt.close();} catch(Exception JavaDoc e2) {}
352             throw e;
353         }
354     }
355
356     private Owxcategory decodeRow(ResultSet rs) throws SQLException {
357         Owxcategory obj = new Owxcategory();
358         obj.setRowid(rs.getInt(1));
359         obj.setId(rs.getString(2));
360         obj.setOwner(rs.getString(3));
361         obj.setParent(rs.getInt(4));
362         obj.setUsagectr(rs.getInt(5));
363         obj.setLevel(rs.getInt(6));
364         obj.setStatic(rs.getInt(7));
365         obj.setIsNew(false);
366         obj.resetIsModifiedS2J();
367
368         return obj;
369     }
370
371     private Owxcategory decodeRow(ResultSet rs, int[] fieldList) throws SQLException {
372         Owxcategory obj = new Owxcategory();
373         int pos = 0;
374         for(int i = 0; i < fieldList.length; i++) {
375             switch(fieldList[i]) {
376                 case ROWID: obj.setRowid(rs.getInt(++pos));
377                     break;
378                 case ID: obj.setId(rs.getString(++pos));
379                     break;
380                 case OWNER: obj.setOwner(rs.getString(++pos));
381                     break;
382                 case PARENT: obj.setParent(rs.getInt(++pos));
383                     break;
384                 case USAGECTR: obj.setUsagectr(rs.getInt(++pos));
385                     break;
386                 case LEVEL: obj.setLevel(rs.getInt(++pos));
387                     break;
388                 case STATIC: obj.setStatic(rs.getInt(++pos));
389                     break;
390             }
391         }
392         obj.setIsNew(false);
393         obj.resetIsModifiedS2J();
394
395         return obj;
396     }
397
398 }
399
Popular Tags