1 36 37 package com.bluecubs.xinco.core.server; 38 39 import java.util.Vector ; 40 import java.sql.*; 41 42 import com.bluecubs.xinco.core.*; 43 44 public class XincoCoreDataTypeAttributeServer extends XincoCoreDataTypeAttribute { 45 46 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 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 e) { 69 throw new XincoException(); 70 } 71 72 } 73 74 public XincoCoreDataTypeAttributeServer(int attrID1, int attrID2, String attrD, String 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 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 e) { 103 try { 104 DBM.con.rollback(); 105 } catch (Exception erollback) { 106 } 107 throw new XincoException(); 108 } 109 110 return 0; 111 112 } 113 114 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 e) { 132 try { 133 DBM.con.rollback(); 134 } catch (Exception erollback) { 135 } 136 throw new XincoException(); 137 } 138 139 return 0; 140 141 } 142 143 public static Vector getXincoCoreDataTypeAttributes(int attrID, XincoDBManager DBM) { 145 146 Vector coreDataTypeAttributes = new Vector (); 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 e) { 158 coreDataTypeAttributes.removeAllElements(); 159 } 160 161 return coreDataTypeAttributes; 162 } 163 164 } 165 | Popular Tags |