/* This class was generated by Cartographer
 * Licensing info here.
 */

package dbobjects;

import java.io.*;
import java.sql.*;
import java.math.*;

public abstract class DBObject
{

  //
  // Constants
  //


  //
  // Class Methods
  //

  /**
   * Gets a connection to the connection pool.
   * @return Connection to the database
   */
  protected static Connection getConnection()
  {
    Connection con = null;
    try
    {
      boolean autoCommitStatus = true;
      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","alee","T3st3r");
      con.setAutoCommit(autoCommitStatus);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    return  con;
  }// end getConnection()

  /**
   *
   */
  protected static void log(String msg)
  {
    System.out.println(new java.util.Date(System.currentTimeMillis()) + "\t" + msg);
    //System.out.println(msg);
  }// end log(String)

  protected void psSetObject(PreparedStatement ps, int fieldNum, DBField field)
    throws SQLException
  {
    if( field.isNull() ) { ps.setNull(fieldNum, field.getType()); }
    else { ps.setObject(fieldNum, field.getValue()); }
  }


  protected abstract class DBField extends DBObject
  {
    protected abstract boolean isNull();
    protected abstract Object getValue();
    protected abstract void setValue(Object o);
    protected abstract int getType();
  }

  protected class DBChar extends DBField
  {
    private String s;
    private static final int TYPE = java.sql.Types.CHAR;

    protected DBChar() {}
    protected DBChar(String s) { setValue(s); }

    protected boolean isNull() { return s == null ? true : false; }
    protected Object getValue() { return s; }
    protected void setValue(Object s) { this.s = (String)s; }
    protected int getType() { return TYPE; }
  }

  protected class DBVarChar extends DBField
  {
    private String s;
    private static final int TYPE = java.sql.Types.VARCHAR;

    protected DBVarChar() {}
    protected DBVarChar(String s) { setValue(s); }

    protected boolean isNull() { return s == null ? true : false; }
    protected Object getValue() { return s; }
    protected void setValue(Object s) { this.s = (String)s; }
    protected int getType() { return TYPE; }
  }

  protected class DBLongVarChar extends DBField
  {
    private String s;
    private static final int TYPE = java.sql.Types.LONGVARCHAR;

    protected DBLongVarChar() {}
    protected DBLongVarChar(String s) { setValue(s); }

    protected boolean isNull() { return s == null ? true : false; }
    protected Object getValue() { return s; }
    protected void setValue(Object s) { this.s = (String)s; }
    protected int getType() { return TYPE; }
  }

  protected class DBNumeric extends DBField
  {
    private Integer i;
    private static final int TYPE = java.sql.Types.NUMERIC;

    protected DBNumeric() {}
    protected DBNumeric(Integer i) { setValue(i); }

    protected boolean isNull() { return i == null ? true : false; }
    protected Object getValue() { return i; }
    protected void setValue(Object i) { this.i = (Integer)i; }
    protected int getType() { return TYPE; }
  }

  protected class DBSmallInt extends DBField
  {
    private Integer i;
    private static final int TYPE = java.sql.Types.SMALLINT;

    protected DBSmallInt() {}
    protected DBSmallInt(Integer i) { setValue(i); }

    protected boolean isNull() { return i == null ? true : false; }
    protected Object getValue() { return i; }
    protected void setValue(Object i) { this.i = (Integer)i; }
    protected int getType() { return TYPE; }
  }

  protected class DBTinyInt extends DBField
  {
    private Integer i;
    private static final int TYPE = java.sql.Types.TINYINT;

    protected DBTinyInt() {}
    protected DBTinyInt(Integer i) { setValue(i); }

    protected boolean isNull() { return i == null ? true : false; }
    protected Object getValue() { return i; }
    protected void setValue(Object i) { this.i = (Integer)i; }
    protected int getType() { return TYPE; }
  }

  protected class DBInteger extends DBField
  {
    private Integer i;
    private static final int TYPE = java.sql.Types.INTEGER;

    protected DBInteger() {}
    protected DBInteger(Integer i) { setValue(i); }

    protected boolean isNull() { return i == null ? true : false; }
    protected Object getValue() { return i; }
    protected void setValue(Object i) { this.i = (Integer)i; }
    protected int getType() { return TYPE; }
  }

  protected class DBBigInteger extends DBField
  {
    private BigInteger i;
    private static final int TYPE = java.sql.Types.BIGINT;

    protected DBBigInteger() {}
    protected DBBigInteger(BigInteger i) { setValue(i); }

    protected boolean isNull() { return i == null ? true : false; }
    protected Object getValue() { return i; }
    protected void setValue(Object i) { this.i = (BigInteger)i; }
    protected int getType() { return TYPE; }
  }

  protected class DBFloat extends DBField
  {
    private Double d;
    private static final int TYPE = java.sql.Types.FLOAT;

    protected DBFloat() {}
    protected DBFloat(Double d) { setValue(d); }

    protected boolean isNull() { return d == null ? true : false; }
    protected Object getValue() { return d; }
    protected void setValue(Object d) { this.d = (Double)d; }
    protected int getType() { return TYPE; }
  }

  protected class DBDouble extends DBField
  {
    private Double d;
    private static final int TYPE = java.sql.Types.DOUBLE;

    protected DBDouble() {}
    protected DBDouble(Double d) { setValue(d); }

    protected boolean isNull() { return d == null ? true : false; }
    protected Object getValue() { return d; }
    protected void setValue(Object d) { this.d = (Double)d; }
    protected int getType() { return TYPE; }
  }

  protected class DBReal extends DBField
  {
    private BigDecimal d;
    private static final int TYPE = java.sql.Types.REAL;

    protected DBReal() {}
    protected DBReal(BigDecimal d) { setValue(d); }

    protected boolean isNull() { return d == null ? true : false; }
    protected Object getValue() { return d; }
    protected void setValue(Object d) { this.d = (BigDecimal)d; }
    protected int getType() { return TYPE; }
  }

  protected class DBDecimal extends DBField
  {
    private BigDecimal d;
    private static final int TYPE = java.sql.Types.DECIMAL;

    protected DBDecimal() {}
    protected DBDecimal(BigDecimal d) { setValue(d); }

    protected boolean isNull() { return d == null ? true : false; }
    protected Object getValue() { return d; }
    protected void setValue(Object d) { this.d = (BigDecimal)d; }
    protected int getType() { return TYPE; }
  }

  protected class DBTimestamp extends DBField
  {
    private Timestamp t;
    private static final int TYPE = java.sql.Types.TIMESTAMP;

    protected DBTimestamp() {}
    protected DBTimestamp(Timestamp t) { setValue(t); }

    protected boolean isNull() { return t == null ? true : false; }
    protected Object getValue() { return t; }
    protected void setValue(Object t) { this.t = (Timestamp)t; }
    protected int getType() { return TYPE; }
  }

  protected class DBDate extends DBField
  {
    private Date d;
    private static final int TYPE = java.sql.Types.DATE;

    protected DBDate() {}
    protected DBDate(Date d) { setValue(d); }

    protected boolean isNull() { return d == null ? true : false; }
    protected Object getValue() { return d; }
    protected void setValue(Object d) { this.d = (Date)d; }
    protected int getType() { return TYPE; }
  }

  protected class DBTime extends DBField
  {
    private Time t;
    private static final int TYPE = java.sql.Types.TIME;

    protected DBTime() {}
    protected DBTime(Time t) { setValue(t); }

    protected boolean isNull() { return t == null ? true : false; }
    protected Object getValue() { return t; }
    protected void setValue(Object t) { this.t = (Time)t; }
    protected int getType() { return TYPE; }
  }

  protected class DBNoType extends DBField
  {
    private Object o;
    private static final int TYPE = 0;

    protected DBNoType() {}
    protected DBNoType(Object o) { setValue(o); }

    protected boolean isNull() { return false; }
    protected Object getValue() { return o; }
    protected void setValue(Object o) { this.o = (Object)o; }
    protected int getType() { return TYPE; }
  }

}// end abstract class DBObject{}