DbSeller.java :  » ERP-CRM-Financial » Evaristo-4.0 » com » m16e » mpbiz » tables » Java Open Source

Java Open Source » ERP CRM Financial » Evaristo 4.0 
Evaristo 4.0 » com » m16e » mpbiz » tables » DbSeller.java
/*
 * $Log$
 *
 * DO NOT CHANGE THIS FILE or CHANGE IT WITH CARE!!!
 * FILE GENERATED BY Gaud ( version 1.4 - build (build 376)
 *
 * on Wed Apr 14 18:19:19 WEST 2010
 *
 *
 *
 */

package com.m16e.mpbiz.tables;

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

import com.m16e.tools.*;
import com.m16e.tools.db.*;
import com.m16e.tools.xgm.*;
import com.m16e.tools.xml.*;
import java.math.BigDecimal;
import org.apache.log4j.Logger;


////////////////////////////////////////////////////////////
public class DbSeller
extends DbTab
implements DbTableInterface
{
  static Logger logger = Logger.getLogger( DbSeller.class );

  public final static String XGM_FORM_SELLER =
    "xgm-form-seller.xml";
  public final static String XGM_FORM_SELLER_FRAME =
    "form-seller-frame";
  public final static String XGM_LIST_SELLER =
    "xgm-list-seller.xml";
  public final static String XGM_LIST_SELLER_FRAME =
    "list-seller-frame";

  public final static String T_NAME = "seller";

  public final static String[] FIELDS = 
    {  "seller_id",
      "ent_id",
      "name" };

  public final static int SELLER_ID = 0;
  public final static int ENT_ID = 1;
  public final static int NAME = 2;

  public final static String FN_SELLER_ID = "seller_id";
  public final static String FN_ENT_ID = "ent_id";
  public final static String FN_NAME = "name";

  XmlTreeNode xtnTabLayout = null;
  XmlTreeNode xtnFormLayout = null;

  ////////////////////////////////////////////////////////////
  public DbSeller()

    throws SQLException
  {
    super( T_NAME );
    setDataModel( getDataModel() );
  }

  ////////////////////////////////////////////////////////////
  public DbSeller( ResultSet rs )
    throws SQLException
  {
    this();
    setTuple( rs );
  }

  ////////////////////////////////////////////////////////////
  public DbSeller( Tuple t )
    throws SQLException
  {
    this();
    setTuple( t );
  }

  ////////////////////////////////////////////////////////////
  public static DbSeller getTable( Object... pkey )
  throws SQLException, MpToolsException
  {
    DbSeller table = new DbSeller();
    java.util.List<Integer> lstPK = table.getPrimaryKey();
    int i = 0;
    for( Object o : pkey )
    {
      table.setValue( lstPK.get( i++ ), o );
    }
    if( !table.getById() )
    {
      table = null;
    }
    return table;
  }

  ////////////////////////////////////////////////////////////
  public static DbSeller getSingleRecord(
    String where, Object... args )
  throws SQLException, DatabaseException
  {
    DbSeller obj = new DbSeller();
    StringBuffer select = new StringBuffer();
    select.append( "select * from " + DbSeller.T_NAME );
    if( where != null && where.trim().length() > 0 )
    {
      select.append( " where " + where );
    }
    int i = 1;
    PreparedStatement ps =
      MpAppContext.getInstance().getDatabase().getPreparedStatement( select.toString() );
    for( Object arg : args )
    {
      ps.setObject( i++, arg );
    }
    if( logger.isTraceEnabled() )
    {
      logger.trace( "query: \n" + ps.toString() );
    }
    ResultSet rs = ps.executeQuery();
    if( rs.next() )
      obj = new DbSeller( rs );
    else
      obj = null;
    rs.close();
    ps.close();
    return obj;
  }

  ////////////////////////////////////////////////////////////
  public static java.util.List<DbSeller> getList(
    String where, String order, Object... args )
  throws SQLException, DatabaseException
  {
    DbSeller obj = new DbSeller();
    java.util.List<Tuple> lst =
      obj.selectWithArgs( false, where, order, args );
    java.util.List<DbSeller> lstObj = new Vector<DbSeller>( DbWorkingTable.ARR_INIT_CAP, DbWorkingTable.ARR_CAP_INCR );
    for( Tuple t : lst )
    {
      obj = new DbSeller();
      obj.setTuple( t );
      lstObj.add( obj );
    }
    return lstObj;
  }

  ////////////////////////////////////////////////////////////
  public static java.util.List<DbSeller> getList(
    boolean validateMaxRows, String where, String order, Object... args )
  throws SQLException, DatabaseException
  {
    DbSeller obj = new DbSeller();
    java.util.List<Tuple> lst =
      obj.selectWithArgs( validateMaxRows, where, order, args );
    java.util.List<DbSeller> lstObj = new Vector<DbSeller>( DbWorkingTable.ARR_INIT_CAP, DbWorkingTable.ARR_CAP_INCR );
    for( Tuple t : lst )
    {
      obj = new DbSeller();
      obj.setTuple( t );
      lstObj.add( obj );
    }
    return lstObj;
  }

  ////////////////////////////////////////////////////////////
  public TupleDataModel getDataModel()
  {
    java.util.List<TupleColDataModel> tcdm = new Vector<TupleColDataModel>( 10, 10 );
    for( int f = 0; f < FIELDS.length; f++ )
    {
      DbField dbField = super.getField( f );
      int len = dbField.getTotalLen();
      switch( dbField.getDbFieldType() )
      {
        case INT:
          len = 8;
          break;
        case DOUBLE:
          len = 15;
          break;
        default:
          if( len > 40 )
            len = 40;
          break;
      }
      tcdm.add( new TupleColDataModel( dbField ) );
    }
    TupleDataModel tdm =
      new TupleDataModel( getDbTable(), "DbSeller.class", tcdm );
    return tdm;
  }
  ////////////////////////////////////////////////////////////
  public DbTableInterface createTab(  String tableName, ResultSet rs)
    throws SQLException
  {
    DbSeller dbSeller = new DbSeller( rs );
    return dbSeller;
  }

  ////////////////////////////////////////////////////////////
  public XmlTreeNode getTabLayout()
  throws XgmException
  {
    if( xtnTabLayout == null )
    {
      try
      {
        String s = XgmFactory.getInstance().readLayout( XGM_FORM_SELLER );
        xtnFormLayout = new XmlTreeNode();
        xtnFormLayout.fromXml( s );
        s = XgmFactory.getInstance().readLayout( XGM_LIST_SELLER );
        xtnTabLayout = new XmlTreeNode();
        xtnTabLayout.fromXml( s );
      }
      catch( Exception e )
      {
        String msg = e.getLocalizedMessage();
        logger.error( e.getMessage(), e );
        throw new XgmException( XgmException.IO_ERROR, e.getMessage() );
      }
    }
    return xtnTabLayout;
  }

  ////////////////////////////////////////////////////////////
  public XmlTreeNode getFormLayout()
  throws XgmException
  {
    if( xtnFormLayout == null )
    {
      try
      {
        String s = XgmFactory.getInstance().readLayout( XGM_FORM_SELLER );
        xtnFormLayout = new XmlTreeNode();
        xtnFormLayout.fromXml( s );
        s = XgmFactory.getInstance().readLayout( XGM_FORM_SELLER );
        xtnFormLayout = new XmlTreeNode();
        xtnFormLayout.fromXml( s );
      }
      catch( Exception e )
      {
        String msg = e.getLocalizedMessage();
        logger.error( e.getMessage(), e );
        throw new XgmException( XgmException.IO_ERROR, e.getMessage() );
      }
    }
    return xtnFormLayout;
  }

  ////////////////////////////////////////////////////////////
  public String getTabLayoutFilename()
  {
    return XGM_LIST_SELLER;
  }

  ////////////////////////////////////////////////////////////
  public String getFormLayoutFilename()
  {
    return XGM_FORM_SELLER;
  }

  ////////////////////////////////////////////////////////////
  public boolean getById()
  throws SQLException
  {
    Database db = MpAppContext.getInstance().getDatabase();
    Tuple tuple = getTuple();
    java.util.List<Integer> kFields = getPrimaryKey();
    int nCols = getFieldCount();
    PreparedStatement ps =
      db.getPreparedStatement(
        "select * from seller where seller_id = ?" );
    ps.setObject( 1, tuple.get( kFields.get( 0 ) ) );
    if( logger.isTraceEnabled() )
    {
      logger.trace( "query: \n" + ps.toString() );
    }
    boolean found = false;
    ResultSet rs = ps.executeQuery();
    if ( rs.next() )
    {
      found = true;
      for( int f = 0; f < nCols; f++ )
      {
        Object o = rs.getObject( f + 1 );
        if( o instanceof String )
          o = ((String) o).trim();
        tuple.setAll( f, o );
      }
    }
    rs.close();
    ps.close();
    return found;
  }

  ////////////////////////////////////////////////////////////
  public static DbSeller getById(
    Integer sellerId )
  throws SQLException, DatabaseException
  {
    return
      DbSeller.getSingleRecord(
        DbSeller.FN_SELLER_ID + " = ?",
        sellerId );
  }

  ////////////////////////////////////////////////////////////
  public boolean fetchNext()
  throws SQLException
  {
    Database db = MpAppContext.getInstance().getDatabase();
    Tuple tuple = getTuple();
    java.util.List<Integer> kFields = getPrimaryKey();
    int nCols = getFieldCount();
    PreparedStatement ps =
      db.getPreparedStatement(
        "select * from seller where (seller_id > ?) order by  seller_id limit 1" );
    ps.setObject( 1, tuple.get( kFields.get( 0 ) ) );
    if( logger.isTraceEnabled() )
    {
      logger.trace( "query: \n" + ps.toString() );
    }
    boolean fetched = false;
    ResultSet rs = ps.executeQuery();
    if ( rs.next() )
    {
      fetched = true;
      setTuple( rs );
    }
    rs.close();
    ps.close();
    return fetched;
  }
  ////////////////////////////////////////////////////////////
  public boolean fetchPrev()
  throws SQLException
  {
    Database database = MpAppContext.getInstance().getDatabase();
    Tuple tuple = getTuple();
    java.util.List<Integer> kFields = getPrimaryKey();
    int nCols = getFieldCount();
    PreparedStatement ps =
      database.getPreparedStatement(
        "select * from seller where (seller_id < ?) order by  seller_id desc limit 1" );
    ps.setObject( 1, tuple.get( kFields.get( 0 ) ) );
    if( logger.isTraceEnabled() )
    {
      logger.trace( "query: \n" + ps.toString() );
    }
    boolean fetched = false;
    ResultSet rs = ps.executeQuery();
    if ( rs.next() )
    {
      fetched = true;
      setTuple( rs );
    }
    rs.close();
    ps.close();
    return fetched;
  }
  ////////////////////////////////////////////////////////////
  // Get/Set methods: BEGIN
  ////////////////////////////////////////////////////////////

  ////////////////////////////////////////////////////////////
  public Integer getSellerId()
  {
    return getSellerId( getTuple() );
  }

  ////////////////////////////////////////////////////////////
  public static Integer getSellerId( Tuple tuple )
  {
    Integer value = (Integer) tuple.get( SELLER_ID );
    return value;
  }

  ////////////////////////////////////////////////////////////
  public void setSellerId( Integer value )
  {
    setSellerId( getTuple(), value );
  }

  ////////////////////////////////////////////////////////////
  public void setSellerId( Integer value, boolean changed )
  {
    setSellerId( getTuple(), value );
    setChangedField( SELLER_ID, changed );
  }

  ////////////////////////////////////////////////////////////
  public static void setSellerId( Tuple tuple, Integer value )
  {
    setValue( tuple, SELLER_ID, value );
  }

  ////////////////////////////////////////////////////////////
  public Integer getEntId()
  {
    return getEntId( getTuple() );
  }

  ////////////////////////////////////////////////////////////
  public static Integer getEntId( Tuple tuple )
  {
    Integer value = (Integer) tuple.get( ENT_ID );
    return value;
  }

  ////////////////////////////////////////////////////////////
  public void setEntId( Integer value )
  {
    setEntId( getTuple(), value );
  }

  ////////////////////////////////////////////////////////////
  public void setEntId( Integer value, boolean changed )
  {
    setEntId( getTuple(), value );
    setChangedField( ENT_ID, changed );
  }

  ////////////////////////////////////////////////////////////
  public static void setEntId( Tuple tuple, Integer value )
  {
    setValue( tuple, ENT_ID, value );
  }

  ////////////////////////////////////////////////////////////
  public String getName()
  {
    return getName( getTuple() );
  }

  ////////////////////////////////////////////////////////////
  public static String getName( Tuple tuple )
  {
    String value = (String) tuple.get( NAME );
    return value;
  }

  ////////////////////////////////////////////////////////////
  public void setName( String value )
  {
    setName( getTuple(), value );
  }

  ////////////////////////////////////////////////////////////
  public void setName( String value, boolean changed )
  {
    setName( getTuple(), value );
    setChangedField( NAME, changed );
  }

  ////////////////////////////////////////////////////////////
  public static void setName( Tuple tuple, String value )
  {
    setValue( tuple, NAME, value );
  }

  ////////////////////////////////////////////////////////////
  // Get/Set methods: END
  ////////////////////////////////////////////////////////////


}
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.