package com.ngMAT.Samples.EZScott; import java.sql.*; import java.util.*; import com.ngMAT.Common.*; public class EZEmp extends ngmDBObject { //{{ class constant definitions //}} //{{ class variable definitions /** * 従業員番号 */ public short empno = 0; /** * 従業員名 */ public String ename = null; /** * お仕事 */ public String job = null; /** * 親分従業員番号 */ public short mgr = 0; /** * 雇用日付 */ public java.sql.Date hiredate = null; /** * 給料 */ public double sal = 0; /** * nanikore */ public double comm = 0; /** * 部署番号 */ public short deptno = 0; //}} //emp SELECTALL public static Vector selectAll (EZScottContext context, String Options) { String sql = "select " + "empno," + "ename," + "job," + "mgr," + "hiredate," + "sal," + "comm," + "deptno" + " from emp " + Options; Connection con = context.con; try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery ( sql ); Vector v = new Vector(); while (rs.next()) { v.addElement (fetch (rs)); } return v; } catch (SQLException e) { throw new LowLevelException (e.getMessage() + " : " + sql); } } //emp SELECT public static EZEmp select (EZScottContext context, short empno ) { Connection con = context.con; String sql = "select " + "empno," + "ename," + "job," + "mgr," + "hiredate," + "sal," + "comm," + "deptno" + " from emp" + "\r\nwhere empno = " + empno; try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery ( sql ); EZEmp res = null; if (rs.next()) { res = fetch(rs); } rs.close(); stmt.close(); return res; } catch (SQLException e) { throw new LowLevelException (e.getMessage() + " : " + sql); } } //emp FETCH public static EZEmp fetch (ResultSet rs) { EZEmp d=new EZEmp(); try { d.empno = rs.getShort("empno"); d.ename = rs.getString("ename"); d.job = rs.getString("job"); d.mgr = rs.getShort("mgr"); d.hiredate = rs.getDate("hiredate"); d.sal = rs.getDouble("sal"); d.comm = rs.getDouble("comm"); d.deptno = rs.getShort("deptno"); } catch (SQLException e) { throw new LowLevelException (e); } return d; } //emp UPDATE public void update( Connection con ) { String sql = "update emp set " + "empno = " + empno + "," + "ename = " + ngmDBObject.getQuotedDBString (ename) + "," + "job = " + ngmDBObject.getQuotedDBString (job) + "," + "mgr = " + mgr + "," + "hiredate = " + getDBDateString (hiredate) + "," + "sal = " + sal + "," + "comm = " + comm + "," + "deptno = " + deptno + "," + getDBControlDataStringForUpdate (this.getClass().getName()) + "\r\nwhere empno = " + empno; try { Statement stmt = con.createStatement(); int numOfUpdated = stmt.executeUpdate ( sql ); stmt.close(); } catch (SQLException e) { throw new LowLevelException (e.getMessage() + " : " + sql); } } //emp INSERT public void insert( Connection con ) { String sql = "insert into emp values (" + empno + "," + ngmDBObject.getQuotedDBString (ename) + "," + ngmDBObject.getQuotedDBString (job) + "," + mgr + "," + getDBDateString (hiredate) + "," + sal + "," + comm + "," + deptno + "," + getDBControlDataString (this.getClass().getName()) + ",null,null,null,null)"; try { Statement stmt = con.createStatement(); int numOfUpdated = stmt.executeUpdate ( sql ); stmt.close(); } catch (SQLException e) { throw new LowLevelException (e.getMessage() + " : " + sql); } } //emp DELETE public void delete( Connection con ) { String sql = "delete from emp" + "\r\nwhere empno = " + empno; try { Statement stmt = con.createStatement(); int numOfUpdated = stmt.executeUpdate ( sql ); stmt.close(); } catch (SQLException e) { throw new LowLevelException (e.getMessage() + " : " + sql); } } //emp CLONE SET public Object clone () { EZEmp d = (EZEmp)super.clone(); d.empno = empno; d.ename = ename; d.job = job; d.mgr = mgr; d.hiredate = new java.sql.Date (hiredate.getTime()); d.sal = sal; d.comm = comm; d.deptno = deptno; return d; } //emp Equals public boolean equals (EZEmp d) { if (d.empno != empno) return false; if (! equals_n (ename, ename)) return false; if (! equals_n (job, job)) return false; if (d.mgr != mgr) return false; if (! equals_n (hiredate, hiredate)) return false; if (d.sal != sal) return false; if (d.comm != comm) return false; if (d.deptno != deptno) return false; return true; } }