담당계.java :  » Game » galatichero » net » narusas » aceauction » model » Java Open Source

Java Open Source » Game » galatichero 
galatichero » net » narusas » aceauction » model » 담당계.java
package net.narusas.aceauction.model;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.narusas.aceauction.data.DB;

public class  {

  static Logger logger = Logger.getLogger("log");

  private  court;

  private long no;

  private List<> sagun;

  private String time;

  private String ;
  private int ;

  private Date ;

  private String ;

  private Date _;

  private Date _;

  private String ;

  public ( court, int charge_code, String name, Date fixed_date, Date start_date, Date end_date,
      String location, String method, String time, long no) {
    this.court = court;
     = charge_code;
     = name;
     = fixed_date;
    _ = start_date;
    _ = end_date;
     = location;
     = method;
    this.time = time;
    this.no = no;
  }

  public ( court, String , String , String , String name) {
    this.court = court;
    this. = DB.toDate();
    if ( != null) {
      _ = DB.toDate(DB.token(, "~", 0));
      _ = DB.toDate(DB.token(, "~", 1));

    }
    this. = DB.toInt();
    this. = name;
     = _ == null ? "" : "";
  }

  public long getNo() {
    return no;
  }

  public List<> getSagun() {
    return sagun;
  }

  public String get() {
    return ;
  }

  public int get() {
    return ;
  }

  public Date get() {
    return ;
  }

  public String get() {
    return ;
  }

  public String get() {
    return time;
  }

  public  get() {
    return court;
  }

  public Date get_() {
    return _;
  }

  public Date get_() {
    return _;
  }

  public String get() {
    return ;
  }

  public void insert() throws Exception {
    logger.info("  . :" + this);
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      stmt = DB.prepareStatement("INSERT INTO ac_charge " + "(" + //
          "charge_code, " + //
          "court_code, " + //
          "name, " + //
          "fixed_date, " + //
          "start_date, " + //
          "end_date, " + //
          "location, " + //
          "method, " + //
          "time" + //
          ") " + "VALUES (?,?,?,?,?,?,?,?,?);");
      stmt.setInt(1, this.get());
      stmt.setInt(2, DB.toInt(this.get().getCode()));
      stmt.setString(3, get());
      stmt.setDate(4, get());
      stmt.setDate(5, get_());
      stmt.setDate(6, get_());
      stmt.setString(7, get());
      stmt.setString(8, get());
      stmt.setString(9, get());
      stmt.execute();
      rs = stmt.getGeneratedKeys();
      rs.next();
      int no = rs.getInt(1);
      rs.close();
      this.setNo(no);
      Registry.add(this);
    } finally {
      DB.cleanup(rs, stmt);
    }
  }

  public boolean isInScoop(java.util.Date startD, java.util.Date endD) {
    Date d = get();
    return d.compareTo(startD) >= 0 && d.compareTo(endD) <= 0;
  }

  public void setNo(long l) {
    this.no = l;
  }

  public void setSagun(List<> sagun) {
    this.sagun = sagun;
  }

  public void set(String time) {
    this.time = time;
  }

  public void set(List<> sagun) {
    this.sagun = sagun;
  }

  public void set(String ) {
    this. = ;
  }

  @Override
  public String toString() {
    if (_ == null) {
      return  + ":" + ;
    }
    return  + ":" +  + "(" + _ + "~" + _ + ")";

  }

  public void update() {
    try {
      DB.dbConnect();
       charge = .findByMemoryObject(this);
      if (updateNo() == false) {
        insert();
      } else {
        update();
      }
    } catch (RuntimeException e) {
      logger.log(Level.INFO, "Reconnection failed", e);
      e.printStackTrace();
    } catch (Exception e) {
      logger.log(Level.INFO, "Reconnection failed", e);
      e.printStackTrace();
    }
  }

  private boolean updateNo() throws Exception {
     ch = findByMemoryObject(this);
    if (ch != null) {
      this.setNo(ch.getNo());
      this. = ch.;
      this.time = ch.time;
      Registry.add(this);
      return true;
    }
    return false;
  }

  private void update() throws Exception {
    logger.info("    . :" + this);
    PreparedStatement stmt = null;
    try {
      stmt = DB.prepareStatement("UPDATE ac_charge " + //
          "SET  " //
          + "name=?, " // 
          + "start_date=?, "//
          + "end_date=?, " //
          + "location=?, " //
          + "method=? "//
          + "WHERE "//
          + "charge_code=? AND  " //
          + "court_code=? AND " //
          + "fixed_date=?;");

      stmt.setString(1, get());
      stmt.setDate(2, get_());
      stmt.setDate(3, get_());
      stmt.setString(4, get());
      stmt.setString(5, get());
      stmt.setInt(6, get());
      stmt.setString(7, get().getCode());
      stmt.setDate(8, get());
      stmt.execute();
    } finally {
      DB.cleanup(stmt);
    }
  }

  public static  find(int charge_code, int court_code, Date date) throws Exception {
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      stmt = DB.prepareStatement("SELECT * " + //
          "FROM ac_charge " + //
          "WHERE charge_code=? AND  court_code=? AND fixed_date=?;");
      stmt.setInt(1, charge_code);
      stmt.setInt(2, court_code);
      stmt.setDate(3, date);
      stmt.execute();
      rs = stmt.getResultSet();
      return checkResultSet(rs);
    } finally {
      DB.cleanup(rs, stmt);
    }
  }

  public static  findByMemoryObject( charge) throws Exception {
    PreparedStatement stmt = DB
        .prepareStatement("SELECT * FROM ac_charge WHERE charge_code=? AND  court_code=? AND fixed_date=?;");
    stmt.setInt(1, charge.get());
    stmt.setInt(2, DB.toInt(charge.get().getCode()));
    stmt.setDate(3, charge.get());
    stmt.execute();
    ResultSet rs = stmt.getResultSet();
    if (rs.next()) {
      return .load(rs);
    }
    return null;
  }

  public static  findByNo(long no) throws Exception {
     charge = Registry.get(no);
    if (charge != null) {
      return charge;
    }

    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      stmt = DB.prepareStatement("SELECT * " + //
          "FROM ac_charge " + //
          "WHERE no=?;");
      stmt.setLong(1, no);
      stmt.execute();
      rs = stmt.getResultSet();
      return checkResultSet(rs);
    } finally {
      DB.cleanup(rs, stmt);
    }
  }

  private static  checkResultSet(ResultSet rs) throws SQLException {
    if (rs.next()) {
       loaded = .load(rs);
      Registry.add(loaded);
      return loaded;
    }
    return null;
  }

  private static  load(ResultSet rs) throws SQLException {
    int charge_code = rs.getInt("charge_code");
    int court_code = rs.getInt("court_code");
    String name = rs.getString("name");
    Date fixed_date = rs.getDate("fixed_date");
    Date start_date = rs.getDate("start_date");
    Date end_date = rs.getDate("end_date");
    String location = rs.getString("location");
    String method = rs.getString("method");
    String time = rs.getString("time");
    long no = rs.getLong("no");

     charge = new (.findByCode(court_code), charge_code, name, fixed_date, start_date, end_date, location,
        method, time, no);

    return charge;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.