KickJava   Java API By Example, From Geeks To Geeks.

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


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: XincoCoreDataTypeAttributeServer
23  *
24  * Description: data type attribute
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 XincoCoreDataTypeAttributeServer extends XincoCoreDataTypeAttribute {
45     
46     //create data type attribute object for data structures
47
public XincoCoreDataTypeAttributeServer(int attrID1, int attrID2, XincoDBManager DBM) throws XincoException {
48         
49         try {
50             Statement stmt = DBM.con.createStatement();
51             ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_data_type_attribute WHERE xinco_core_data_type_id=" + attrID1 + " AND attribute_id=" + attrID2);
52
53             //throw exception if no result found
54
int RowCount = 0;
55             while (rs.next()) {
56                 RowCount++;
57                 setXinco_core_data_type_id(rs.getInt("xinco_core_data_type_id"));
58                 setAttribute_id(rs.getInt("attribute_id"));
59                 setDesignation(rs.getString("designation"));
60                 setData_type(rs.getString("data_type"));
61                 setSize(rs.getInt("size"));
62             }
63             if (RowCount < 1) {
64                 throw new XincoException();
65             }
66
67             stmt.close();
68         } catch (Exception JavaDoc e) {
69             throw new XincoException();
70         }
71         
72     }
73
74     //create data type attribute object for data structures
75
public XincoCoreDataTypeAttributeServer(int attrID1, int attrID2, String JavaDoc attrD, String JavaDoc attrDT, int attrS) throws XincoException {
76         
77         setXinco_core_data_type_id(attrID1);
78         setAttribute_id(attrID2);
79         setDesignation(attrD);
80         setData_type(attrDT);
81         setSize(attrS);
82         
83     }
84     
85     //write to db
86
public int write2DB(XincoDBManager DBM) throws XincoException {
87
88         try {
89             
90             Statement stmt = null;
91             
92             stmt = DBM.con.createStatement();
93             stmt.executeUpdate("INSERT INTO xinco_core_data_type_attribute VALUES (" + getXinco_core_data_type_id() + ", " + getAttribute_id() + ", '" + getDesignation() + "', '" + getData_type() + "', " + getSize() + ")");
94             stmt.close();
95
96             stmt = DBM.con.createStatement();
97             stmt.executeUpdate("INSERT INTO xinco_add_attribute SELECT id, " + getAttribute_id() + ", 0, 0, 0, '', '', now() FROM xinco_core_data WHERE xinco_core_data_type_id = " + getXinco_core_data_type_id());
98             stmt.close();
99
100             DBM.con.commit();
101             
102         } catch (Exception JavaDoc e) {
103             try {
104                 DBM.con.rollback();
105             } catch (Exception JavaDoc erollback) {
106             }
107             throw new XincoException();
108         }
109         
110         return 0;
111             
112     }
113     
114     //delete from db
115
public static int deleteFromDB(XincoCoreDataTypeAttribute attrCDTA, XincoDBManager DBM) throws XincoException {
116
117         try {
118             
119             Statement stmt = null;
120             
121             stmt = DBM.con.createStatement();
122             stmt.executeUpdate("DELETE FROM xinco_add_attribute WHERE xinco_add_attribute.attribute_id=" + attrCDTA.getAttribute_id() + " AND xinco_add_attribute.xinco_core_data_id IN (SELECT id FROM xinco_core_data WHERE xinco_core_data.xinco_core_data_type_id=" + attrCDTA.getXinco_core_data_type_id() + ")");
123             stmt.close();
124             
125             stmt = DBM.con.createStatement();
126             stmt.executeUpdate("DELETE FROM xinco_core_data_type_attribute WHERE xinco_core_data_type_id=" + attrCDTA.getXinco_core_data_type_id() + " AND attribute_id=" + attrCDTA.getAttribute_id());
127             stmt.close();
128
129             DBM.con.commit();
130             
131         } catch (Exception JavaDoc e) {
132             try {
133                 DBM.con.rollback();
134             } catch (Exception JavaDoc erollback) {
135             }
136             throw new XincoException();
137         }
138         
139         return 0;
140             
141     }
142     
143     //create complete list of data type attributes
144
public static Vector JavaDoc getXincoCoreDataTypeAttributes(int attrID, XincoDBManager DBM) {
145         
146         Vector JavaDoc coreDataTypeAttributes = new Vector JavaDoc();
147         
148         try {
149             Statement stmt = DBM.con.createStatement();
150             ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_data_type_attribute WHERE xinco_core_data_type_id =" + attrID + " ORDER BY attribute_id");
151
152             while (rs.next()) {
153                 coreDataTypeAttributes.addElement(new XincoCoreDataTypeAttributeServer(rs.getInt("xinco_core_data_type_id"), rs.getInt("attribute_id"), rs.getString("designation"), rs.getString("data_type"), rs.getInt("size")));
154             }
155
156             stmt.close();
157         } catch (Exception JavaDoc e) {
158             coreDataTypeAttributes.removeAllElements();
159         }
160
161         return coreDataTypeAttributes;
162     }
163
164 }
165
Popular Tags