DbUserRoles.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 » DbUserRoles.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 DbUserRoles
extends DbTab
implements DbTableInterface
{
  static Logger logger = Logger.getLogger( DbUserRoles.class );

  public final static String XGM_FORM_USER_ROLES =
    "xgm-form-user-roles.xml";
  public final static String XGM_FORM_USER_ROLES_FRAME =
    "form-user-roles-frame";
  public final static String XGM_LIST_USER_ROLES =
    "xgm-list-user-roles.xml";
  public final static String XGM_LIST_USER_ROLES_FRAME =
    "list-user-roles-frame";

  public final static String T_NAME = "user_roles";

  public final static String[] FIELDS = 
    {  "role_id",
      "tag",
      "name",
      "full_access" };

  public final static int ROLE_ID = 0;
  public final static int TAG = 1;
  public final static int NAME = 2;
  public final static int FULL_ACCESS = 3;

  public final static String FN_ROLE_ID = "role_id";
  public final static String FN_TAG = "tag";
  public final static String FN_NAME = "name";
  public final static String FN_FULL_ACCESS = "full_access";

  XmlTreeNode xtnTabLayout = null;
  XmlTreeNode xtnFormLayout = null;

  ////////////////////////////////////////////////////////////
  public DbUserRoles()

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

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

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

  ////////////////////////////////////////////////////////////
  public static DbUserRoles getTable( Object... pkey )
  throws SQLException, MpToolsException
  {
    DbUserRoles table = new DbUserRoles();
    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 DbUserRoles getSingleRecord(
    String where, Object... args )
  throws SQLException, DatabaseException
  {
    DbUserRoles obj = new DbUserRoles();
    StringBuffer select = new StringBuffer();
    select.append( "select * from " + DbUserRoles.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 DbUserRoles( rs );
    else
      obj = null;
    rs.close();
    ps.close();
    return obj;
  }

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

  ////////////////////////////////////////////////////////////
  public static java.util.List<DbUserRoles> getList(
    boolean validateMaxRows, String where, String order, Object... args )
  throws SQLException, DatabaseException
  {
    DbUserRoles obj = new DbUserRoles();
    java.util.List<Tuple> lst =
      obj.selectWithArgs( validateMaxRows, where, order, args );
    java.util.List<DbUserRoles> lstObj = new Vector<DbUserRoles>( DbWorkingTable.ARR_INIT_CAP, DbWorkingTable.ARR_CAP_INCR );
    for( Tuple t : lst )
    {
      obj = new DbUserRoles();
      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(), "DbUserRoles.class", tcdm );
    return tdm;
  }
  ////////////////////////////////////////////////////////////
  public DbTableInterface createTab(  String tableName, ResultSet rs)
    throws SQLException
  {
    DbUserRoles dbUserRoles = new DbUserRoles( rs );
    return dbUserRoles;
  }

  ////////////////////////////////////////////////////////////
  public XmlTreeNode getTabLayout()
  throws XgmException
  {
    if( xtnTabLayout == null )
    {
      try
      {
        String s = XgmFactory.getInstance().readLayout( XGM_FORM_USER_ROLES );
        xtnFormLayout = new XmlTreeNode();
        xtnFormLayout.fromXml( s );
        s = XgmFactory.getInstance().readLayout( XGM_LIST_USER_ROLES );
        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_USER_ROLES );
        xtnFormLayout = new XmlTreeNode();
        xtnFormLayout.fromXml( s );
        s = XgmFactory.getInstance().readLayout( XGM_FORM_USER_ROLES );
        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_USER_ROLES;
  }

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

  ////////////////////////////////////////////////////////////
  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 user_roles where role_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 DbUserRoles getById(
    Integer roleId )
  throws SQLException, DatabaseException
  {
    return
      DbUserRoles.getSingleRecord(
        DbUserRoles.FN_ROLE_ID + " = ?",
        roleId );
  }

  ////////////////////////////////////////////////////////////
  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 user_roles where (role_id > ?) order by  role_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 user_roles where (role_id < ?) order by  role_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 getRoleId()
  {
    return getRoleId( getTuple() );
  }

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

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

  ////////////////////////////////////////////////////////////
  public void setRoleId( Integer value, boolean changed )
  {
    setRoleId( getTuple(), value );
    setChangedField( ROLE_ID, changed );
  }

  ////////////////////////////////////////////////////////////
  public static void setRoleId( Tuple tuple, Integer value )
  {
    setValue( tuple, ROLE_ID, value );
  }

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

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

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

  ////////////////////////////////////////////////////////////
  public void setTag( String value, boolean changed )
  {
    setTag( getTuple(), value );
    setChangedField( TAG, changed );
  }

  ////////////////////////////////////////////////////////////
  public static void setTag( Tuple tuple, String value )
  {
    setValue( tuple, TAG, 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 );
  }

  ////////////////////////////////////////////////////////////
  public Boolean getFullAccess()
  {
    return getFullAccess( getTuple() );
  }

  ////////////////////////////////////////////////////////////
  public static Boolean getFullAccess( Tuple tuple )
  {
    Boolean value = (Boolean) tuple.get( FULL_ACCESS );
    return value;
  }

  ////////////////////////////////////////////////////////////
  public void setFullAccess( Boolean value )
  {
    setFullAccess( getTuple(), value );
  }

  ////////////////////////////////////////////////////////////
  public void setFullAccess( Boolean value, boolean changed )
  {
    setFullAccess( getTuple(), value );
    setChangedField( FULL_ACCESS, changed );
  }

  ////////////////////////////////////////////////////////////
  public static void setFullAccess( Tuple tuple, Boolean value )
  {
    setValue( tuple, FULL_ACCESS, 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.