KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bluecubs > xinco > core > server > XincoCoreGroupServer


1 /**
2  *Copyright 2004 blueCubs.com
3  *
4  *Licensed under the Apache License, Version 2.0 (the "License");
5  *you may not use this file except in compliance with the License.
6  *You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *Unless required by applicable law or agreed to in writing, software
11  *distributed under the License is distributed on an "AS IS" BASIS,
12  *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *See the License for the specific language governing permissions and
14  *limitations under the License.
15  *
16  *************************************************************
17  * This project supports the blueCubs vision of giving back
18  * to the community in exchange for free software!
19  * More information on: http://www.bluecubs.org
20  *************************************************************
21  *
22  * Name: XincoCoreGroupServer
23  *
24  * Description: group
25  *
26  * Original Author: Alexander Manes
27  * Date: 2004
28  *
29  * Modifications:
30  *
31  * Who? When? What?
32  * - - -
33  *
34  *************************************************************
35  */

36
37 package com.bluecubs.xinco.core.server;
38
39 import java.util.Vector JavaDoc;
40 import java.sql.*;
41
42 import com.bluecubs.xinco.core.*;
43
44 public class XincoCoreGroupServer extends XincoCoreGroup {
45     
46     //create group object for data structures
47
public XincoCoreGroupServer(int attrID, XincoDBManager DBM) throws XincoException {
48         
49         try {
50             
51             Statement stmt = DBM.con.createStatement();
52             ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_group WHERE id=" + attrID);
53
54             //throw exception if no result found
55
int RowCount = 0;
56             while (rs.next()) {
57                 RowCount++;
58                 setId(rs.getInt("id"));
59                 setDesignation(rs.getString("designation"));
60                 setStatus_number(rs.getInt("status_number"));
61             }
62             if (RowCount < 1) {
63                 throw new XincoException();
64             }
65
66             stmt.close();
67             
68         } catch (Exception JavaDoc e) {
69             throw new XincoException();
70         }
71         
72     }
73     
74     //create group object for data structures
75
public XincoCoreGroupServer(int attrID, String JavaDoc attrD, int attrSN) throws XincoException {
76         
77         setId(attrID);
78         setDesignation(attrD);
79         setStatus_number(attrSN);
80         
81     }
82     
83     //write to db
84
public int write2DB(XincoDBManager DBM) throws XincoException{
85
86         try {
87
88             Statement stmt;
89             
90             if (getId() > 0) {
91                 stmt = DBM.con.createStatement();
92                 stmt.executeUpdate("UPDATE xinco_core_group SET designation='" + getDesignation().replaceAll("'","\\\\'") + "', status_number=" + getStatus_number() + " WHERE id=" + getId());
93                 stmt.close();
94             } else {
95                 setId(DBM.getNewID("xinco_core_group"));
96
97                 stmt = DBM.con.createStatement();
98                 stmt.executeUpdate("INSERT INTO xinco_core_group VALUES (" + getId() + ", '" + getDesignation().replaceAll("'","\\\\'") + "', " + getStatus_number() + ")");
99                 stmt.close();
100             }
101             
102             DBM.con.commit();
103             
104         } catch (Exception JavaDoc e) {
105             try {
106                 DBM.con.rollback();
107             } catch (Exception JavaDoc erollback) {
108             }
109             throw new XincoException();
110         }
111         
112         return getId();
113
114     }
115     
116     //create complete list of groups
117
public static Vector JavaDoc getXincoCoreGroups(XincoDBManager DBM) {
118         
119         Vector JavaDoc coreGroups = new Vector JavaDoc();
120         
121         try {
122             
123             Statement stmt = DBM.con.createStatement();
124             ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_group ORDER BY designation");
125
126             while (rs.next()) {
127                 coreGroups.addElement(new XincoCoreGroupServer(rs.getInt("id"), rs.getString("designation"), rs.getInt("status_number")));
128             }
129
130             stmt.close();
131             
132         } catch (Exception JavaDoc e) {
133             coreGroups.removeAllElements();
134         }
135
136         return coreGroups;
137     }
138
139 }
140
Popular Tags