1 36 37 package com.bluecubs.xinco.core.server; 38 39 import java.sql.*; 40 import java.util.Vector ; 41 import java.io.File ; 42 import com.bluecubs.xinco.core.*; 43 import com.bluecubs.xinco.add.*; 44 import com.bluecubs.xinco.add.server.*; 45 46 public class XincoCoreDataServer extends XincoCoreData { 47 48 public XincoCoreDataServer(int attrID, XincoDBManager DBM) throws XincoException { 50 51 try { 52 53 Statement stmt = DBM.con.createStatement(); 54 ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_data WHERE id=" + attrID); 55 56 int RowCount = 0; 58 while (rs.next()) { 59 RowCount++; 60 setId(rs.getInt("id")); 61 setXinco_core_node_id(rs.getInt("xinco_core_node_id")); 62 setXinco_core_language(new XincoCoreLanguageServer(rs.getInt("xinco_core_language_id"), DBM)); 63 setXinco_core_data_type(new XincoCoreDataTypeServer(rs.getInt("xinco_core_data_type_id"), DBM)); 64 setXinco_core_logs(XincoCoreLogServer.getXincoCoreLogs(rs.getInt("id"), DBM)); 66 setXinco_add_attributes(XincoAddAttributeServer.getXincoAddAttributes(rs.getInt("id"), DBM)); 68 setDesignation(rs.getString("designation")); 69 setStatus_number(rs.getInt("status_number")); 70 setXinco_core_acl(XincoCoreACEServer.getXincoCoreACL(rs.getInt("id"), "xinco_core_data_id", DBM)); 72 } 73 if (RowCount < 1) { 74 throw new XincoException(); 75 } 76 77 stmt.close(); 78 79 } catch (Exception e) { 80 getXinco_core_acl().removeAllElements(); 81 throw new XincoException(); 82 } 83 84 } 85 86 public XincoCoreDataServer(int attrID, int attrCNID, int attrLID, int attrDTID, String attrD, int attrSN, XincoDBManager DBM) throws XincoException { 88 89 setId(attrID); 90 setXinco_core_node_id(attrCNID); 91 setXinco_core_language(new XincoCoreLanguageServer(attrLID, DBM)); 92 setXinco_core_data_type(new XincoCoreDataTypeServer(attrDTID, DBM)); 93 setXinco_core_logs(XincoCoreLogServer.getXincoCoreLogs(attrID, DBM)); 95 setXinco_add_attributes(new Vector ()); 99 setDesignation(attrD); 100 setStatus_number(attrSN); 101 setXinco_core_acl(XincoCoreACEServer.getXincoCoreACL(getId(), "xinco_core_data_id", DBM)); 103 104 } 105 106 public int write2DB(XincoDBManager DBM) throws XincoException { 108 109 int i = 0; 110 111 try { 112 113 Statement stmt; 114 115 if (getId() > 0) { 116 stmt = DBM.con.createStatement(); 117 stmt.executeUpdate("UPDATE xinco_core_data SET xinco_core_node_id=" + getXinco_core_node_id() + ", xinco_core_language_id=" + getXinco_core_language().getId() + ", xinco_core_data_type_id=" + getXinco_core_data_type().getId() + ", designation='" + getDesignation().replaceAll("'","\\\\'") + "', status_number=" + getStatus_number() + " WHERE id =" + getId()); 118 stmt.close(); 119 120 } else { 121 setId(DBM.getNewID("xinco_core_data")); 122 123 stmt = DBM.con.createStatement(); 124 stmt.executeUpdate("INSERT INTO xinco_core_data VALUES (" + getId() + ", " + getXinco_core_node_id() + ", " + getXinco_core_language().getId() + ", " + getXinco_core_data_type().getId() + ", '" + getDesignation().replaceAll("'","\\\\'") + "', " + getStatus_number() + ")"); 125 stmt.close(); 126 127 } 128 129 stmt = DBM.con.createStatement(); 131 stmt.executeUpdate("DELETE FROM xinco_add_attribute WHERE xinco_core_data_id=" + getId()); 132 stmt.close(); 133 XincoAddAttributeServer xaas; 134 for (i=0;i<getXinco_add_attributes().size();i++) { 135 ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).setXinco_core_data_id(getId()); 136 xaas = new XincoAddAttributeServer(((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getXinco_core_data_id(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttribute_id(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttrib_int(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttrib_unsignedint(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttrib_double(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttrib_varchar(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttrib_text(), ((XincoAddAttribute)getXinco_add_attributes().elementAt(i)).getAttrib_datetime()); 138 xaas.write2DB(DBM); 139 } 141 142 DBM.con.commit(); 143 144 } catch (Exception e) { 145 try { 146 DBM.con.rollback(); 147 } catch (Exception erollback) { 148 } 149 throw new XincoException(); 150 } 151 152 return getId(); 153 154 } 155 156 public void deleteFromDB(XincoDBManager DBM) throws XincoException { 158 159 int i=0; 160 161 try { 162 163 Statement stmt; 164 165 stmt = DBM.con.createStatement(); 166 stmt.executeUpdate("DELETE FROM xinco_core_log WHERE xinco_core_data_id=" + getId()); 167 stmt.close(); 168 stmt = DBM.con.createStatement(); 169 stmt.executeUpdate("DELETE FROM xinco_core_ace WHERE xinco_core_data_id=" + getId()); 170 stmt.close(); 171 stmt = DBM.con.createStatement(); 172 stmt.executeUpdate("DELETE FROM xinco_add_attribute WHERE xinco_core_data_id=" + getId()); 173 stmt.close(); 174 if (getXinco_core_data_type().getId() == 1) { 176 try { 177 (new File (DBM.config.FileRepositoryPath + getId())).delete(); 178 } catch (Exception dfe) { 179 } 181 for (i=0;i<this.getXinco_core_logs().size();i++) { 183 if ((((XincoCoreLog)getXinco_core_logs().elementAt(i)).getOp_code() == 1) || (((XincoCoreLog)getXinco_core_logs().elementAt(i)).getOp_code() == 5)) 184 try { 185 (new File (DBM.config.FileRepositoryPath + getId() + "-" + ((XincoCoreLog)getXinco_core_logs().elementAt(i)).getId())).delete(); 186 } catch (Exception drfe) { 187 } 189 } 190 } 191 stmt = DBM.con.createStatement(); 192 stmt.executeUpdate("DELETE FROM xinco_core_data WHERE id=" + getId()); 193 stmt.close(); 194 DBM.con.commit(); 195 } catch (Exception e) { 196 try { 197 DBM.con.rollback(); 198 } catch (Exception erollback) { 199 } 200 throw new XincoException(); 201 } 202 203 } 204 205 public static byte[] loadBinaryData(XincoCoreData attrCD) { 206 207 byte[] binary_data = null; 208 209 return binary_data; 210 211 } 212 213 public static int saveBinaryData(XincoCoreData attrCD, byte[] attrBD) { 214 215 return 0; 216 217 } 218 219 public static Vector findXincoCoreData(String attrS, int attrLID, boolean attrSA, boolean attrSFD, XincoDBManager DBM) { 220 221 Vector data = new Vector (); 222 223 try { 224 225 Statement stmt = DBM.con.createStatement(); 226 ResultSet rs; 227 String lang = ""; 228 if (attrLID != 0) { 229 lang = "AND (xinco_core_language_id = " + attrLID + ")"; 230 } 231 if (attrSA) { 232 rs = stmt.executeQuery("SELECT DISTINCT xinco_core_data.* FROM xinco_core_data, xinco_add_attribute WHERE (xinco_core_data.id = xinco_add_attribute.xinco_core_data_id) AND (xinco_core_data.designation LIKE '" + attrS + "%' OR xinco_add_attribute.attrib_varchar LIKE '" + attrS + "' OR xinco_add_attribute.attrib_text LIKE '" + attrS + "') " + lang + " ORDER BY xinco_core_data.designation, xinco_core_data.xinco_core_language_id"); 233 } else { 234 rs = stmt.executeQuery("SELECT DISTINCT xinco_core_data.* FROM xinco_core_data WHERE designation LIKE '" + attrS + "' " + lang + " ORDER BY designation, xinco_core_language_id"); 235 } 236 237 int i = 0; 238 while (rs.next()) { 239 data.addElement(new XincoCoreDataServer(rs.getInt("id"), DBM)); 241 i++; 242 if (i >= DBM.config.MaxSearchResult) { 243 break; 244 } 245 } 246 247 stmt.close(); 248 249 } catch (Exception e) { 250 data.removeAllElements(); 251 } 252 253 return data; 254 255 } 256 257 } 258 | Popular Tags |