1 36 37 package com.bluecubs.xinco.core.server; 38 39 import java.util.Vector ; 40 import java.util.Calendar ; 41 import java.util.GregorianCalendar ; 42 import java.sql.*; 43 44 import com.bluecubs.xinco.core.*; 45 46 public class XincoCoreLogServer extends XincoCoreLog { 47 48 public XincoCoreLogServer(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_log WHERE id=" + attrID); 55 56 int RowCount = 0; 58 while (rs.next()) { 59 RowCount++; 60 setId(rs.getInt("id")); 61 setXinco_core_data_id(rs.getInt("xinco_core_data_id")); 62 setXinco_core_user_id(rs.getInt("xinco_core_user_id")); 63 setOp_code(rs.getInt("op_code")); 64 setOp_datetime(new GregorianCalendar ()); 65 getOp_datetime().setTime(rs.getDate("op_datetime")); 66 setOp_description(rs.getString("op_description")); 67 setVersion(new XincoVersion()); 68 getVersion().setVersion_high(rs.getInt("version_high")); 69 getVersion().setVersion_mid(rs.getInt("version_mid")); 70 getVersion().setVersion_low(rs.getInt("version_low")); 71 getVersion().setVersion_postfix(rs.getString("version_postfix")); 72 } 73 if (RowCount < 1) { 74 throw new XincoException(); 75 } 76 77 stmt.close(); 78 79 } catch (Exception e) { 80 throw new XincoException(); 81 } 82 83 } 84 85 public XincoCoreLogServer(int attrID, int attrCDID, int attrUID, int attrOC, Calendar attrODT, String attrOD, int attrVH, int attrVM, int attrVL, String attrVP) throws XincoException { 87 88 setId(attrID); 89 setXinco_core_data_id(attrCDID); 90 setXinco_core_user_id(attrUID); 91 setOp_code(attrOC); 92 setOp_datetime(attrODT); 93 setOp_description(attrOD); 94 setVersion(new XincoVersion()); 95 getVersion().setVersion_high(attrVH); 96 getVersion().setVersion_mid(attrVM); 97 getVersion().setVersion_low(attrVL); 98 getVersion().setVersion_postfix(attrVP); 99 100 } 101 102 public int write2DB(XincoDBManager DBM) throws XincoException { 104 105 try { 106 107 if (getId() > 0) { 108 Statement stmt = DBM.con.createStatement(); 109 stmt.executeUpdate("UPDATE xinco_core_log SET xinco_core_data_id=" + getXinco_core_data_id() + ", xinco_core_user_id=" + getXinco_core_user_id() + ", op_code=" + getOp_code() + ", op_datetime=now(), op_description='" + getOp_description().replaceAll("'","\\\\'") + "', version_high=" + getVersion().getVersion_high() + ", version_mid=" + getVersion().getVersion_mid() + ", version_low=" + getVersion().getVersion_low() + ", version_postfix='" + getVersion().getVersion_postfix().replaceAll("'","\\\\'") + "' WHERE id=" + getId()); 110 stmt.close(); 111 } else { 112 setId(DBM.getNewID("xinco_core_log")); 113 114 Statement stmt = DBM.con.createStatement(); 115 stmt.executeUpdate("INSERT INTO xinco_core_log VALUES (" + getId() + ", " + getXinco_core_data_id() + ", " + getXinco_core_user_id() + ", " + getOp_code() + ", now(), '" + getOp_description().replaceAll("'","\\\\'") + "', " + getVersion().getVersion_high() + ", " + getVersion().getVersion_mid() + ", " + getVersion().getVersion_low() + ", '" + getVersion().getVersion_postfix().replaceAll("'","\\\\'") + "')"); 116 stmt.close(); 117 } 118 119 DBM.con.commit(); 120 121 } catch (Exception e) { 122 try { 123 DBM.con.rollback(); 124 } catch (Exception erollback) { 125 } 126 throw new XincoException(); 127 } 128 129 return getId(); 130 131 } 132 133 public static Vector getXincoCoreLogs(int attrID, XincoDBManager DBM) { 135 136 Vector core_log = new Vector (); 137 GregorianCalendar cal = new GregorianCalendar (); 138 139 try { 140 Statement stmt = DBM.con.createStatement(); 141 ResultSet rs = stmt.executeQuery("SELECT * FROM xinco_core_log WHERE xinco_core_data_id=" + attrID); 142 143 while (rs.next()) { 144 cal = new GregorianCalendar (); 145 cal.setTime( rs.getDate("op_datetime")); 146 core_log.addElement(new XincoCoreLogServer(rs.getInt("id"), rs.getInt("xinco_core_data_id"), rs.getInt("xinco_core_user_id"), rs.getInt("op_code"), cal, rs.getString("op_description"), rs.getInt("version_high"), rs.getInt("version_mid"), rs.getInt("version_low"), rs.getString("version_postfix"))); 147 } 148 149 stmt.close(); 150 } catch (Exception e) { 151 core_log.removeAllElements(); 152 } 153 154 return core_log; 155 } 156 157 } 158 | Popular Tags |