/*

* Copyright 2009 by GRUPO IE, Inc.

* 

* Private and Confidential

* Code contained in this document is the property of GRUPO IE. 

* It is for the exclusive use of designated employees 

* and not for distribution without prior written

* authorization.

*/

/*

* Q02bQ021LT00.java

*

* Created on 12/05/09 04:40:49

*/

package q02b.exe.tablasBD.jdbc.oracle;

import java.sql.SQLException;

import java.sql.ResultSet;

import java.sql.Connection;

import java.sql.PreparedStatement;

import q02b.exe.arquitectura.dataobjects.Q02bDAOException;

import q02b.exe.arquitectura.utils.tablasBD.*;

import q02b.exe.arquitectura.utils.tablasBD.helpers.*;

import javax.naming.NamingException;

import es.ejie.frmk.infraestructura.traza.Q70TraceLevel;

import es.ejie.frmk.infraestructura.traza.Q70Traza;

import es.ejie.frmk.conectores.conectorJDBC.Q70ConectorJDBC;

import es.ejie.frmk.listeners.base.Q70ListenerUtils;



/*

*

* @author automatic generated

* @version 1.0

*/

public class Q02bTablaBDQ021LS00 extends q02b.exe.tablasBD.Q02bTablaBDQ021LS00 {

    private static final long serialVersionUID =1L;

    /** Obtenemos una referencia del componente gestor de trazas de Geremua */

    private static Q70Traza tr = Q70Traza.getSingleton();

    /** Obtenemos el nombre del DataSource de nuestra aplicación */

    private String Q02B_JNDI_DATASOURCE = Q70ListenerUtils.getApplicationProperty(this.getClass().getName(),null,"Q02B_JNDI_DATASOURCE");

    /** Nombre del componente */

    private String COMPONENTE = "TABLAS_BD";

    /** Creates new Q021LS00 */

    /** Está declarado como private para que se utilice el constructor con argumentos */

    private Q02bTablaBDQ021LS00() {

        super();

        this.idConexion="oracle";

    }



    /** Creates new Q021LS00 */

    public Q02bTablaBDQ021LS00(Connection con) {

        this();

        connection=con;

    }



    /** Method select(where) 

    * @param where New value of property WHERE.

    * @return Value of the resultSet.

    */

    public ResultSet select(String where)throws SQLException,Q02bDAOException  {

        Connection con=null;

        String[] aliasNom={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        con=this.getConnection();

        StringBuffer query = new StringBuffer();

        ResultSet rs = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" select ");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        StringBuffer tablesdb2 = new StringBuffer(this.getTableFrom());

        String[] artablesdb2 = q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.split(tablesdb2.toString(),",");

        StringBuffer columnsdb2 = new StringBuffer(this.getColumnsSelectTotal());

        String text2=null;

        for (int i=0;i<artablesdb2.length ;i++ )

        {

        	String tableReplace = artablesdb2[i];

        	if (tableReplace.indexOf(" ")!=-1)

        	{

        		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

        	}

        	text2=tableReplace+".";

            columnsdb2 = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(columnsdb2.toString(),text2,aliasNom[i]+"."));

            if (i==0)

            {

                tablesdb2 = new StringBuffer(artablesdb2[i]+ " " + aliasNom[i]);

            }else{

                tablesdb2.append(",").append(artablesdb2[i]).append(" ").append(aliasNom[i]);

            }

        	}

        query.append("SELECT ");

        query.append(columnsdb2);

        query.append(" from ").append(tablesdb2);

        if ((this.getInitialWhere() != null) && (!this.getInitialWhere().equals(""))) {

             query.append( this.getInitialWhere());

             queryLog.append( this.getInitialWhere());

        }

        if ((this.getFixedWhere() != null) && (!this.getFixedWhere().equals(""))) {

             query.append( this.getFixedWhere());

             queryLog.append( this.getFixedWhere());

        }

        if ((where != null) && (!where.equals(""))) {

            if ((this.getInitialWhere() == null || this.getInitialWhere().equals("")) && (this.getFixedWhere() == null || this.getFixedWhere().equals("")) )

            {

                query.append(" where ");

            }else{

                query.append(" and ");

            }

            query.append( where );

        }

        if ((where.indexOf("group by")==-1) &&(where.indexOf("GROUP BY")==-1)){

        if ((this.getGroupBy() != null) && (!this.getGroupBy().equals(""))) {

            query.append(" GROUP BY ");

            query.append( this.getGroupBy());

        }

        }

        if ((where.indexOf("order by")==-1) &&(where.indexOf("ORDER BY")==-1)){

        if ((this.getOrderBy() != null) && (!this.getOrderBy().equals("")) && (!this.getOrderBy().equals("null"))) {

            query.append(" ORDER BY ");

            query.append( this.getOrderBy());

        }

        }

        if (this.getNumMaxRegistros()>0){

           if (this.getLimitRows()){

                this.setLimitRows(false);

                this.setNumInicio(0);

                this.setNumFinal(this.getNumMaxRegistros());

           }

            StringBuffer queryAux = new StringBuffer(query.toString());

            queryAux.insert(0," (");

            queryAux.append(") ");

            queryAux.append(") ");

                 if (this.getNumMaxRegistros()>0){

                     queryAux.insert(0," FROM ");
                 }
                 if (this.getNumMaxRegistros()>0){

                     queryAux.insert(0," ,rownum num ");
                 }
            queryAux.insert(0,this.getColumnsSelectComitas());

            queryAux.insert(0,"SELECT ");

            queryAux.insert(0," (");

            queryAux.insert(0," FROM ");

            queryAux.insert(0,this.getColumnsSelectComitas());

            queryAux.insert(0,"SELECT ");

            queryAux.append(" WHERE NUM>");

            queryAux.append(this.getNumInicio());

            queryAux.append(" AND NUM<=");

            queryAux.append(this.getNumFinal());

            query = queryAux;

        }

            if (this.getForUpdate()==true){

            	query.append(" FOR UPDATE ");
            }
            StringBuffer queryAux = query;

            for (int i=0;i<artablesdb2.length ;i++ )

            {

            	String tableReplace = artablesdb2[i];

            	if (tableReplace.indexOf(" ")!=-1)

            	{

            		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

            	}

            	String aux1=tableReplace+".";

            	String aux2=aliasNom[i]+".";

                queryAux = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(queryAux.toString(),aux1,aux2));

            }

            query = queryAux;

            tr.trace(COMPONENTE,Q70TraceLevel.INFO,"0:" + query.toString());

        PreparedStatement prepStmt = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement spaPrepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt);

        addStatement(prepStmt);

        rs = spaPrepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" select");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method selectCount(where) 

    * @param where New value of property WHERE.

    * @return Value of the resultSet.

    */

    public ResultSet selectCount(String where)throws SQLException  {

        String[] aliasNom={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        Connection con=this.getConnection();

        StringBuffer query = new StringBuffer();

        ResultSet rs = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" selectCount ");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        StringBuffer tablesdb2 = new StringBuffer(this.getTableFrom());

        String[] artablesdb2 = q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.split(tablesdb2.toString(),",");

        StringBuffer columnsdb2 = new StringBuffer(this.getColumnsSelectTotal());

        String text2=null;

        for (int i=0;i<artablesdb2.length ;i++ )

        {

        	String tableReplace = artablesdb2[i];

        	if (tableReplace.indexOf(" ")!=-1)

        	{

        		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

        	}

        	text2=tableReplace+".";

            columnsdb2 = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(columnsdb2.toString(),text2,aliasNom[i]+"."));

            if (i==0)

            {

                tablesdb2 = new StringBuffer(artablesdb2[i]+ " " + aliasNom[i]);

            }else{

                tablesdb2.append(",").append(artablesdb2[i]).append(" ").append(aliasNom[i]);

            }

        	}

        query.append("SELECT COUNT(");

        if  ((this.getDistinct()!=null) && (!this.getDistinct().equals(""))) {

             query.append("DISTINCT ("+this.getDistinct()+")");

        }else {

              query.append("*");

        }

        query.append(") from ").append(tablesdb2);

        if ((this.getInitialWhere() != null) && (!this.getInitialWhere().equals(""))) {

             query.append( this.getInitialWhere());

             queryLog.append( this.getInitialWhere());

        }

        if ((this.getFixedWhere() != null) && (!this.getFixedWhere().equals(""))) {

             query.append( this.getFixedWhere());

             queryLog.append( this.getFixedWhere());

        }

        if ((where != null) && (!where.equals(""))) {

        if (where.indexOf("order by")!=-1)

        {

        where= where.substring(0,where.indexOf("order by"));

        }

        if (where.indexOf("ORDER BY")!=-1)

        {

        where= where.substring(0,where.indexOf("ORDER BY"));

        }

            if ((this.getInitialWhere() == null || this.getInitialWhere().equals("")) && (this.getFixedWhere() == null || this.getFixedWhere().equals("")) )

            {

                query.append(" where ");

            }else{

                query.append(" and ");

            }

            query.append("(");

            query.append( where);

            query.append(")");

        if ((where.indexOf("group by")==-1) &&(where.indexOf("GROUP BY")==-1)){

        if ((this.getGroupBy() != null) && (!this.getGroupBy().equals(""))) {

            query.append(" GROUP BY ");

            query.append( this.getGroupBy());

        }

        }

        if ((where.indexOf("order by")==-1) &&(where.indexOf("ORDER BY")==-1)){

        if ((this.getOrderBy() != null) && (!this.getOrderBy().equals("")) && (!this.getOrderBy().equals("null"))) {

            query.append(" ORDER BY ");

            query.append( this.getOrderBy());

        }

        }

            if (this.getForUpdate()==true){

            	query.append(" FOR UPDATE ");
            }
            StringBuffer queryAux = query;

            for (int i=0;i<artablesdb2.length ;i++ )

            {

            	String tableReplace = artablesdb2[i];

            	if (tableReplace.indexOf(" ")!=-1)

            	{

            		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

            	}

            	String aux1=tableReplace+".";

            	String aux2=aliasNom[i]+".";

                queryAux = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(queryAux.toString(),aux1,aux2));

            }

            query = queryAux;

            tr.trace(COMPONENTE,Q70TraceLevel.INFO,"0:" + query.toString());

        }

        PreparedStatement prepStmt = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement spaPrepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt);

        addStatement(prepStmt);

        rs = spaPrepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" selectCount");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method selectDistinct(where) 

    * @param where New value of property WHERE.

    * @return Value of the resultSet.

    */

    public ResultSet selectDistinct(String where)throws SQLException  {

        Connection con=this.getConnection();

        StringBuffer query = new StringBuffer();

        ResultSet rs = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" selectDistinct ");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        query.append("SELECT DISTINCT ");

        if ((this.getDistinct() != null) && (!this.getDistinct().equals(""))){

            query.append(this.getDistinct()).append(" from ").append(this.getTableFrom());
        }
        else{

            query.append("Q021GT00_NI, Q021FT00_NI from ").append(this.getTableFrom());
        }
        if ((where != null) && (!where.equals(""))) {

            query.append(" where ");

            query.append( where);

        }

        if ((where.indexOf("group by")==-1) &&(where.indexOf("GROUP BY")==-1)){

        if ((this.getGroupBy() != null) && (!this.getGroupBy().equals(""))) {

            query.append(" GROUP BY ");

            query.append( this.getGroupBy());

        }

        }

        if ((where.indexOf("order by")==-1) &&(where.indexOf("ORDER BY")==-1)){

        if ((this.getOrderBy() != null) && (!this.getOrderBy().equals("")) && (!this.getOrderBy().equals("null"))) {

            query.append(" ORDER BY ");

            query.append( this.getOrderBy());

        }

        }

        if (this.getNumMaxRegistros()>0){

           if (this.getLimitRows()){

                this.setLimitRows(false);

                this.setNumInicio(0);

                this.setNumFinal(this.getNumMaxRegistros());

           }

            StringBuffer queryAux = new StringBuffer(query.toString());

            queryAux.insert(0,",rownum num FROM (");

            queryAux.insert(0,this.getDistinct());

            queryAux.insert(0," FROM ( SELECT ");

            queryAux.insert(0,this.getDistinct());

            queryAux.insert(0,"SELECT ");

            queryAux.append(")) WHERE NUM>");

            queryAux.append(this.getNumInicio());

            queryAux.append("AND NUM<=");

            queryAux.append(this.getNumFinal());

            query = queryAux;

        }

            if (this.getForUpdate()==true){

            	query.append(" FOR UPDATE ");
            }
            tr.trace(COMPONENTE,Q70TraceLevel.INFO,"0:" + query.toString());

        PreparedStatement prepStmt = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement spaPrepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt);

        addStatement(prepStmt);

        rs = spaPrepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" select");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method selectMax(where) 

    * @param where New value of property WHERE.

    * @return Value of the resultSet.

    */

    public ResultSet selectMax(String where)throws SQLException  {

        Connection con=this.getConnection();

        StringBuffer query = new StringBuffer();

        ResultSet rs = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" selectMax ");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        query.append("SELECT MAX (");

        if (this.getMax() != null){

            query.append(this.getMax() + ") from " + this.getTableFrom() );
        }
        else{

            throw new NullPointerException();

        }

        if ((where != null) && (!where.equals(""))) {

            query.append(" where ");

            query.append( where);

        }

        if ((where.indexOf("group by")==-1) &&(where.indexOf("GROUP BY")==-1)){

        if ((this.getGroupBy() != null) && (!this.getGroupBy().equals(""))) {

            query.append(" GROUP BY ");

            query.append( this.getGroupBy());

        }

        }

        if ((where.indexOf("order by")==-1) &&(where.indexOf("ORDER BY")==-1)){

        if ((this.getOrderBy() != null) && (!this.getOrderBy().equals("")) && (!this.getOrderBy().equals("null"))) {

            query.append(" ORDER BY ");

            query.append( this.getOrderBy());

        }

        }

        if (this.getNumMaxRegistros()>0){

           if (this.getLimitRows()){

                this.setLimitRows(false);

                this.setNumInicio(0);

                this.setNumFinal(this.getNumMaxRegistros());

           }

            StringBuffer queryAux = new StringBuffer(query.toString());

            queryAux.insert(0,",rownum num FROM (");

            queryAux.insert(0,this.getMax());

            queryAux.insert(0," FROM ( SELECT ");

            queryAux.insert(0,this.getMax());

            queryAux.insert(0,"SELECT ");

            queryAux.append(")) WHERE NUM>");

            queryAux.append(this.getNumInicio());

            queryAux.append("AND NUM<=");

            queryAux.append(this.getNumFinal());

            query = queryAux;

        }

            if (this.getForUpdate()==true){

            	query.append(" FOR UPDATE ");
            }
            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + query.toString());

        PreparedStatement prepStmt = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement spaPrepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt);

        addStatement(prepStmt);

        rs = spaPrepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" select");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method select() 

    * @return Value of the resultSet.

    */

    public ResultSet select()throws SQLException,Q02bDAOException  {

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" select");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        String[] aliasNom={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        Connection con=null;

        con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery2 = new StringBuffer();

        StringBuffer queryLog = new StringBuffer();

        StringBuffer queryLog2 = new StringBuffer();

        ResultSet rs = null;

        StringBuffer tablesdb2 = new StringBuffer(this.getTableFrom());

        String[] artablesdb2 = q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.split(tablesdb2.toString(),",");

        StringBuffer columnsdb2 = new StringBuffer(this.getColumnsSelectTotal());

        String text2=null;

        for (int i=0;i<artablesdb2.length ;i++ )

        {

        	String tableReplace = artablesdb2[i];

        	if (tableReplace.indexOf(" ")!=-1)

        	{

        		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

        	}

        	text2=tableReplace+".";

            columnsdb2 = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(columnsdb2.toString(),text2,aliasNom[i]+"."));

            if (i==0)

            {

                tablesdb2 = new StringBuffer(artablesdb2[i]+ " " + aliasNom[i]);

            }else{

                tablesdb2.append(",").append(artablesdb2[i]).append(" ").append(aliasNom[i]);

            }

        	}

        query.append("SELECT ");

        query.append(columnsdb2);

        query.append(" from ").append(tablesdb2);

        queryLog=new StringBuffer(query.toString());

        boolean and = false;

        if (Q021GT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q021LS00.Q021GT00_NI=?");

            queryLog2.append("Q021LS00.Q021GT00_NI=").append(Q021GT00_NI_WHERE);

            and = true;

        }

        if (Q021FT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q021LS00.Q021FT00_NI=?");

            queryLog2.append("Q021LS00.Q021FT00_NI=").append(Q021FT00_NI_WHERE);

            and = true;

        }

        if ((this.getInitialWhere() != null) && (!this.getInitialWhere().equals(""))) {

             query.append( this.getInitialWhere());

             queryLog.append( this.getInitialWhere());

        }

        if ((this.getFixedWhere() != null) && (!this.getFixedWhere().equals(""))) {

             query.append( this.getFixedWhere());

             queryLog.append( this.getFixedWhere());

        }

            if (subquery2 == null || (subquery2 != null && subquery2.toString().equals("") )) {

        		subquery2 = new StringBuffer(" 1=1 ");

        }

        if (subquery2 != null && !subquery2.toString().equals("") ) {

            if ((this.getInitialWhere() == null || this.getInitialWhere().equals("")) && (this.getFixedWhere() == null || this.getFixedWhere().equals("")) )

        	{

        		query.append(" where ");

        		queryLog.append(" where ");

        	}else{

        		query.append(" and ");

        		queryLog.append(" and ");

        			}

            query.append("(");

            queryLog.append("(");

            queryLog.append(queryLog2.toString());

            query.append(subquery2.toString());

            query.append(") ");

            queryLog.append(") ");

        }

        if ((this.getAditionalWhere() != null) && (!this.getAditionalWhere().equals(""))) {

            query.append( this.getAditionalWhere());

            queryLog.append( this.getAditionalWhere());

        }

        if ((this.getGroupBy() != null) && (!this.getGroupBy().equals(""))) {

            query.append(" GROUP BY ");

            queryLog.append(" GROUP BY ");

            query.append( this.getGroupBy());

            queryLog.append( this.getGroupBy());

        }

        if ((this.getOrderBy() != null) && (!this.getOrderBy().equals("")) && (!this.getOrderBy().equals("null"))) {

            query.append(" ORDER BY ");

            queryLog.append(" ORDER BY ");

            query.append( this.getOrderBy());

            queryLog.append( this.getOrderBy());

        }

        if (this.getNumMaxRegistros()>0){

           if (this.getLimitRows()){

                this.setLimitRows(false);

                this.setNumInicio(0);

                this.setNumFinal(this.getNumMaxRegistros());

           }

            //prepStmt.setMaxRows(this.getNumMaxRegistros());

            StringBuffer queryAux = new StringBuffer(query.toString());

            StringBuffer queryAuxLog = new StringBuffer(queryLog.toString());

            queryAux.insert(0," (");

            queryAux.append(") ");

            queryAux.append(") ");

            queryAuxLog.insert(0," (");

            queryAuxLog.append(") ");

            queryAuxLog.append(") ");

            queryAux.insert(0," FROM ");

            queryAuxLog.insert(0," FROM ");

        if (this.getNumMaxRegistros()>0){

            queryAux.insert(0," ,rownum num ");
        }
            queryAux.insert(0,this.getColumnsSelectComitas());

            queryAux.insert(0,"SELECT ");

            queryAuxLog.insert(0," ,rownum num ");

            queryAuxLog.insert(0,this.getColumnsSelectComitas());

            queryAuxLog.insert(0,"SELECT ");

            queryAux.insert(0," (");

            queryAux.insert(0," FROM ");

            queryAux.insert(0,this.getColumnsSelectComitas());

            queryAux.insert(0,"SELECT ");

            queryAuxLog.insert(0," (");

            queryAuxLog.insert(0," FROM ");

            queryAuxLog.insert(0,this.getColumnsSelectComitas());

            queryAuxLog.insert(0,"SELECT ");

            queryAux.append(" WHERE NUM>");

            queryAux.append(this.getNumInicio());

            queryAux.append(" AND NUM<=");

            queryAux.append(this.getNumFinal());

            query = queryAux;

            queryAuxLog.append(" WHERE NUM>");

            queryAuxLog.append(this.getNumInicio());

            queryAuxLog.append(" AND NUM<=");

            queryAuxLog.append(this.getNumFinal());

            queryLog = queryAuxLog;

        }

            if (this.getForUpdate()==true){

            	query.append(" FOR UPDATE ");

            	queryLog.append(" FOR UPDATE ");

        }

            StringBuffer queryAux = query;

            StringBuffer queryLogAux = queryLog;

            for (int i=0;i<artablesdb2.length ;i++ )

            {

            	String tableReplace = artablesdb2[i];

            	if (tableReplace.indexOf(" ")!=-1)

            	{

            		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

            	}

            	String aux1=tableReplace+".";

            	String aux2=aliasNom[i]+".";

                queryAux = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(queryAux.toString(),aux1,aux2));

            	queryLogAux = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(queryLogAux.toString(),aux1,aux2));

            }

            query = queryAux;

            queryLog = queryLogAux;

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + queryLog.toString());

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement prepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt1);

        int index=1;

        //int pos=1;

            //pos=1;

        if (Q021GT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021GT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            //pos=2;

        if (Q021FT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021FT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        addStatement(prepStmt);

        addStatement(prepStmt1);

        rs = prepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" select");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method selectCount() 

    * @return Value of the resultSet.

    */

    public ResultSet selectCount()throws SQLException  {

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" selectCount");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        String[] aliasNom={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        Connection con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery2 = new StringBuffer();

        ResultSet rs = null;

        StringBuffer tablesdb2 = new StringBuffer(this.getTableFrom());

        String[] artablesdb2 = q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.split(tablesdb2.toString(),",");

        StringBuffer columnsdb2 = new StringBuffer(this.getColumnsSelectTotal());

        String text2=null;

        for (int i=0;i<artablesdb2.length ;i++ )

        {

        	String tableReplace = artablesdb2[i];

        	if (tableReplace.indexOf(" ")!=-1)

        	{

        		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

        	}

        	text2=tableReplace+".";

            columnsdb2 = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(columnsdb2.toString(),text2,aliasNom[i]+"."));

            if (i==0)

            {

                tablesdb2 = new StringBuffer(artablesdb2[i]+ " " + aliasNom[i]);

            }else{

                tablesdb2.append(",").append(artablesdb2[i]).append(" ").append(aliasNom[i]);

            }

        	}

        query.append("SELECT COUNT(");

        if  ((this.getDistinct()!=null) && (!this.getDistinct().equals(""))) {

             query.append("DISTINCT ("+this.getDistinct()+")");

        }else {

              query.append("*");

        }

        query.append(") from ").append(tablesdb2);

        //boolean pkCompletada=false;

        boolean and = false;

        if (Q021GT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021LS00.Q021GT00_NI=?");

            and = true;

        }

        if (Q021FT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021LS00.Q021FT00_NI=?");

            and = true;

        }

        if ((this.getInitialWhere() != null) && (!this.getInitialWhere().equals(""))) {

             query.append( this.getInitialWhere());

             queryLog.append( this.getInitialWhere());

        }

        if ((this.getFixedWhere() != null) && (!this.getFixedWhere().equals(""))) {

             query.append( this.getFixedWhere());

             queryLog.append( this.getFixedWhere());

        }

            if (subquery2 == null || (subquery2 != null && subquery2.toString().equals("") )) {

        		subquery2 = new StringBuffer(" 1=1 ");

        			}

        if (subquery2 != null && !subquery2.toString().equals("") ) {

            if ((this.getInitialWhere() == null || this.getInitialWhere().equals("")) && (this.getFixedWhere() == null || this.getFixedWhere().equals("")) )

            {

                query.append(" where ");

            }

            else{

                query.append(" and ");

            }

            query.append("(");

            query.append(subquery2.toString());

            query.append(") ");

        if ((this.getAditionalWhere() != null) && (!this.getAditionalWhere().equals(""))) {

            query.append( this.getAditionalWhere());

            queryLog.append( this.getAditionalWhere());

        }

        }

            StringBuffer queryAux = query;

            for (int i=0;i<artablesdb2.length ;i++ )

            {

            	String tableReplace = artablesdb2[i];

            	if (tableReplace.indexOf(" ")!=-1)

            	{

            		tableReplace=tableReplace.substring(0,tableReplace.indexOf(" "));

            	}

            	String aux1=tableReplace+".";

            	String aux2=aliasNom[i]+".";

                queryAux = new StringBuffer(q02b.exe.arquitectura.webCommon.utils.Q02bCommonUtils.replaceAll(queryAux.toString(),aux1,aux2));

            }

            query = queryAux;

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + query.toString());

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement prepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt1);

        int index=1;

        //int pos=1;

            //pos=1;

        if (Q021GT00_NI_WHERE != null) {

            //pkCompletada=true;

            try{

            prepStmt.setLong(index,Q021GT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //else{

            //pkCompletada=false;

        //}

            //pos=2;

        if (Q021FT00_NI_WHERE != null) {

            //pkCompletada=true;

            try{

            prepStmt.setLong(index,Q021FT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //else{

            //pkCompletada=false;

        //}

        addStatement(prepStmt);

        addStatement(prepStmt1);

        rs = prepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" selectCount");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method selectDistinct() 

    * @return Value of the resultSet.

    */

    public ResultSet selectDistinct()throws SQLException  {

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" selectDistinct");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        Connection con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery2 = new StringBuffer();

        ResultSet rs = null;

        query.append("SELECT DISTINCT ");

        if ((this.getDistinct() != null) && (!this.getDistinct().equals(""))){

            query.append(this.getDistinct()).append(" from  ").append(this.getTableFrom());
        }
        else{

            query.append("Q021GT00_NI, Q021FT00_NI from ").append(this.getTableFrom());
        }
        boolean and = false;

        if (Q021GT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021GT00_NI=?");

            and = true;

        }

        if (Q021FT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021FT00_NI=?");

            and = true;

        }

        if (subquery2 != null&& !subquery2.toString().equals("")) {

            query.append(" where ");

            query.append(subquery2.toString());

        }else{query.append(" where (1=1)");}

        if ((this.getAditionalWhere() != null) && (!this.getAditionalWhere().equals(""))) {

            query.append( this.getAditionalWhere());

            queryLog.append( this.getAditionalWhere());

        }

        if (this.getNumMaxRegistros()>0){

           if (this.getLimitRows()){

                this.setLimitRows(false);

                this.setNumInicio(0);

                this.setNumFinal(this.getNumMaxRegistros());

           }

            if (this.getDistinct()==null || this.getDistinct().equals("")){

                this.setDistinct("Q021GT00_NI, Q021FT00_NI");

            }

            StringBuffer queryAux = new StringBuffer(query.toString());

            queryAux.insert(0,",rownum num FROM (");

            queryAux.insert(0,this.getDistinct());

            queryAux.insert(0," FROM ( SELECT ");

            queryAux.insert(0,this.getDistinct());

            queryAux.insert(0,"SELECT ");

            queryAux.append(")) WHERE NUM>");

            queryAux.append(this.getNumInicio());

            queryAux.append(" AND NUM<=");

            queryAux.append(this.getNumFinal());

            query = queryAux;

        }

            if (this.getForUpdate()==true){

            	query.append(" FOR UPDATE ");
            }
            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + query.toString());

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement prepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt1);

        int index=1;

        //int pos=1;

        //pos=1;

        if (Q021GT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021GT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //pos=2;

        if (Q021FT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021FT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        addStatement(prepStmt);

        addStatement(prepStmt1);

        rs = prepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" selectDistinct");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method selectMax() 

    * @return Value of the resultSet.

    */

    public ResultSet selectMax()throws SQLException  {

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" selectMax");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        Connection con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery2 = new StringBuffer();

        ResultSet rs = null;

        query.append("SELECT MAX (");

        if (this.getMax() != null){

        query.append(this.getMax() + ") from  " + this.getTableFrom() );
        }
        else{

            throw new NullPointerException();

        }

        boolean and = false;

        if (Q021GT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021GT00_NI=?");

            and = true;

        }

        if (Q021FT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021FT00_NI=?");

            and = true;

        }

        if (subquery2 != null) {

            query.append(" where ");

            query.append(subquery2.toString());

        }

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + query.toString());

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement prepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt1);

        int index=1;

        //int pos=1;

        //pos=1;

        if (Q021GT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021GT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //pos=2;

        if (Q021FT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021FT00_NI_WHERE.longValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        addStatement(prepStmt);

        addStatement(prepStmt1);

        rs = prepStmt.executeQuery();

        addResultSet(rs);

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" selectMax");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        return rs;

    }



    /** Method update() */

    public void update()throws SQLException  {

    Connection con = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" update");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

         con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery1 = new StringBuffer();

        StringBuffer subquery2 = new StringBuffer();

         queryLog = new StringBuffer();

        query.append("UPDATE Q021LS00 ");

        queryLog.append("UPDATE Q021LS00 SET ");

        boolean and = false;

            if (Q021GT00_NI != null || this.Q021GT00_NI_MODIF==true) {

            if (and) {

            subquery1.append(" ,");

            }

            subquery1.append("Q021GT00_NI=?");

            and = true;

        }

            if (Q021FT00_NI != null || this.Q021FT00_NI_MODIF==true) {

            if (and) {

            subquery1.append(" ,");

            }

            subquery1.append("Q021FT00_NI=?");

            and = true;

        }

        if (subquery1 != null) {

            query.append(" set ");

            query.append(subquery1.toString());

        }

        and = false;

        //boolean pkCompletada=false;

        if (Q021GT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021GT00_NI=?");

            and = true;

        }

        //else{

            //pkCompletada=false;

        //}

        if (Q021FT00_NI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021FT00_NI=?");

            and = true;

        }

        //else{

            //pkCompletada=false;

        //}

        if (subquery2 != null) {

            query.append(" where ");

            query.append(subquery2.toString());

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,query.toString());

        }

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement prepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt1);

        int index=1;

        //int pos=1;

        //pos=1;

        if (Q021GT00_NI != null|| Q021GT00_NI_MODIF == true) {

            try{

        if (Q021GT00_NI != null){

            prepStmt.setLong(index,Q021GT00_NI.longValue());

            queryLog.append("Q021GT00_NI" + "=" +Q021GT00_NI.longValue()+ ",");

        }else{

            prepStmt.setNull(index,java.sql.Types.INTEGER);

            queryLog.append("Q021GT00_NI" + "=" + null + ",");

            }}catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //pos=2;

        if (Q021FT00_NI != null|| Q021FT00_NI_MODIF == true) {

            try{

        if (Q021FT00_NI != null){

            prepStmt.setLong(index,Q021FT00_NI.longValue());

            queryLog.append("Q021FT00_NI" + "=" +Q021FT00_NI.longValue()+ ",");

        }else{

            prepStmt.setNull(index,java.sql.Types.INTEGER);

            queryLog.append("Q021FT00_NI" + "=" + null + ",");

            }}catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        queryLog.deleteCharAt(queryLog.toString().length()-1);

        queryLog.append(" where (");

        //pkCompletada=true;

        //pos=1;

        //pos=1;

        //pos=1;

        if (Q021GT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021GT00_NI_WHERE.longValue());

            queryLog.append("Q021GT00_NI" + "=" +Q021GT00_NI_WHERE.longValue()+ " AND ");

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //else{

            //pkCompletada=false;

        //}

        //pos=2;

        //pos=2;

        if (Q021FT00_NI_WHERE != null) {

            try{

            prepStmt.setLong(index,Q021FT00_NI_WHERE.longValue());

            queryLog.append("Q021FT00_NI" + "=" +Q021FT00_NI_WHERE.longValue()+ " AND ");

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //else{

            //pkCompletada=false;

        //}

        if (queryLog.toString().endsWith("AND ")){

        	queryLog.delete(queryLog.toString().length()-4,queryLog.toString().length());
        }
        if ((this.getAditionalWhere() != null) && (!this.getAditionalWhere().equals(""))) {

        if (subquery2!=null && !subquery2.toString().equals("")){

            query.append(" where ");

            queryLog.append(" where ");

        }else{

            query.append(" and ");

            queryLog.append(" and ");

        }

            query.append( this.getAditionalWhere());

            queryLog.append( this.getAditionalWhere());

        }

        queryLog.append(")");

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + queryLog.toString());

        this.regModif=prepStmt.executeUpdate();

        prepStmt.close();

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" update");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

    }



    /** Method update(where) 

    * @param where New value of property WHERE.

    */

    public void update(String  where )throws SQLException  {

    Connection con = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        queryLog = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" update");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery1 = new StringBuffer();

        query.append("UPDATE Q021LS00 ");

        boolean and = false;

            if (Q021GT00_NI != null || this.Q021GT00_NI_MODIF==true) {

            if (and) {

            subquery1.append(" ,");

            }

            subquery1.append("Q021GT00_NI=?");

            and = true;

        }

            if (Q021FT00_NI != null || this.Q021FT00_NI_MODIF==true) {

            if (and) {

            subquery1.append(" ,");

            }

            subquery1.append("Q021FT00_NI=?");

            and = true;

        }

        if (subquery1 != null) {

            query.append(" set ");

            query.append(subquery1.toString());

        }

        if ((where != null) && (!where.equals(""))) {

            query.append("where ");

            query.append(where);

            queryLog=query;

            tr.trace(COMPONENTE,Q70TraceLevel.INFO,query.toString());

        }

        PreparedStatement prepStmt = con.prepareStatement(query.toString());

        int index=1;

        if (Q021GT00_NI != null|| Q021GT00_NI_MODIF == true) {

            try{

        if (Q021GT00_NI != null){

            prepStmt.setLong(index,Q021GT00_NI.longValue());

        }else{

            prepStmt.setNull(index,java.sql.Types.INTEGER);
        }
            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        if (Q021FT00_NI != null|| Q021FT00_NI_MODIF == true) {

            try{

        if (Q021FT00_NI != null){

            prepStmt.setLong(index,Q021FT00_NI.longValue());

        }else{

            prepStmt.setNull(index,java.sql.Types.INTEGER);
        }
            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        if ((this.getAditionalWhere() != null) && (!this.getAditionalWhere().equals(""))) {

        if (where!=null && !where.equals("")){

            query.append(" where ");

            queryLog.append(" where ");

        }else{

            query.append(" and ");

            queryLog.append(" and ");

        }

            query.append( this.getAditionalWhere());

            queryLog.append( this.getAditionalWhere());

        }

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + queryLog.toString());

        this.regModif=prepStmt.executeUpdate();

        prepStmt.close();

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" update");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

    }



    /** Method delete(where) 

    * @param where New value of property WHERE.

    */

    public void delete(String where)throws SQLException  {

    Connection con = null;

        String name = (this.getClass()).getName();

        queryLog = new StringBuffer();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" delete");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        con=this.getConnection();

        StringBuffer query = new StringBuffer();

        query.append("DELETE  from Q021LS00 ");

        if ((where != null) && (!where.equals(""))) {

            query.append("where ");

            query.append(where);

            queryLog=query;

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + queryLog.toString());

        }

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        this.regModif=prepStmt1.executeUpdate();

        prepStmt1.close();

        if (tr.isTraceActive()) {

        mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" delete");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

    }



    /** Method delete */

    public void delete()throws SQLException  {

    Connection con = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" delete");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        con=this.getConnection();

        StringBuffer query = new StringBuffer();

        StringBuffer subquery2 = new StringBuffer();

         queryLog = new StringBuffer();

        query.append("DELETE from Q021LS00 ");

        queryLog.append("DELETE from Q021LS00 ");

        //boolean pkCompletada=false;

        boolean and = false;

        if (Q021GT00_NI_WHERE != null) {

            //pkCompletada=true;

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021GT00_NI=?");

            and = true;

        }

        //else{

            //pkCompletada=false;

        //}

        if (Q021FT00_NI_WHERE != null) {

            //pkCompletada=true;

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q021FT00_NI=?");

            and = true;

        }

        //else{

            //pkCompletada=false;

        //}

        if (subquery2 != null) {

            query.append("where ");

            queryLog.append("where ");

            query.append(subquery2.toString());

            tr.trace(COMPONENTE,Q70TraceLevel.INFO,query.toString());

        }

        PreparedStatement prepStmt1 = con.prepareStatement(query.toString());

        Q02bSpacePreparedStatement prepStmt = new Q02bSpacePreparedStatement(tipos,longitudes,prepStmt1);

        int index=1;

        //int pos=1;

        //pos=1;

        if (Q021GT00_NI_WHERE != null) {

            //pkCompletada=true;

            try{

            prepStmt.setLong(index,Q021GT00_NI_WHERE.longValue());

            queryLog.append("Q021GT00_NI" + "=" +Q021GT00_NI_WHERE.longValue()+  " AND ");

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //else{

            //pkCompletada=false;

        //}

        //pos=2;

        if (Q021FT00_NI_WHERE != null) {

            //pkCompletada=true;

            try{

            prepStmt.setLong(index,Q021FT00_NI_WHERE.longValue());

            queryLog.append("Q021FT00_NI" + "=" +Q021FT00_NI_WHERE.longValue()+  " AND ");

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        //else{

            //pkCompletada=false;

        //}

        queryLog.delete(queryLog.toString().length()-4,queryLog.toString().length());

        queryLog.append(")");

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + queryLog.toString());

        this.regModif=prepStmt.executeUpdate();

        prepStmt.close();

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" delete");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

    }



    /** Method insert */

    public void insert()throws SQLException  {

    Connection con = null;

        String name = (this.getClass()).getName();

        StringBuffer mensaje = new StringBuffer();

        //long user = 0;

        if (tr.isTraceActive()) {

            mensaje.append(name);

            mensaje.append(" Beginning:");

            mensaje.append(" insert");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

        con=this.getConnection();

        StringBuffer query = new StringBuffer();

        //variable para la sentencia de log

        queryLog = new StringBuffer();

        String commentInsertQ021GT00_NI = null;

        if (Q021GT00_NI == null && commentInsertQ021GT00_NI == null ) {

        NullPointerException e = new NullPointerException();

        String msgError = e.getMessage();

        name = (this.getClass()).getName();

        mensaje = new StringBuffer();

        mensaje.append(name);

        mensaje.append("Q021GT00_NI ");

        mensaje.append(msgError);

        mensaje.append(" Failed:");

        mensaje.append(" insert");

        tr.trace(COMPONENTE,Q70TraceLevel.ERROR,mensaje.toString());

        throw new NullPointerException();

        }

        String commentInsertQ021FT00_NI = null;

        if (Q021FT00_NI == null && commentInsertQ021FT00_NI == null ) {

        NullPointerException e = new NullPointerException();

        String msgError = e.getMessage();

        name = (this.getClass()).getName();

        mensaje = new StringBuffer();

        mensaje.append(name);

        mensaje.append("Q021FT00_NI ");

        mensaje.append(msgError);

        mensaje.append(" Failed:");

        mensaje.append(" insert");

        tr.trace(COMPONENTE,Q70TraceLevel.ERROR,mensaje.toString());

        throw new NullPointerException();

        }

        query.append("INSERT into Q021LS00 (Q021GT00_NI,Q021FT00_NI) values (?,?)");

        queryLog.append("INSERT into Q021LS00 (Q021GT00_NI,Q021FT00_NI) values (");

        PreparedStatement prepStmt = con.prepareStatement(query.toString());

        int index=1;

            try{

        if (Q021GT00_NI != null){

            prepStmt.setLong(index,Q021GT00_NI.longValue());

            queryLog.append(Q021GT00_NI.longValue()+ ",");

        }else{

            prepStmt.setNull(index,java.sql.Types.INTEGER);

            queryLog.append("null"+ ",");

            }}catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

            try{

        if (Q021FT00_NI != null){

            prepStmt.setLong(index,Q021FT00_NI.longValue());

            queryLog.append(Q021FT00_NI.longValue()+ ",");

        }else{

            prepStmt.setNull(index,java.sql.Types.INTEGER);

            queryLog.append("null"+ ",");

            }}catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        queryLog.deleteCharAt(queryLog.toString().length()-1);

        queryLog.append(")");

            tr.trace(COMPONENTE,Q70TraceLevel.INFO, "0:" + queryLog.toString());

        this.regModif=prepStmt.executeUpdate();

        prepStmt.close();

        if (tr.isTraceActive()) {

            mensaje = new StringBuffer();

            mensaje.append(name);

            mensaje.append(" Ending:");

            mensaje.append(" insert");

            tr.trace(COMPONENTE,Q70TraceLevel.DEBUG,mensaje.toString());

        }

    }

    /** Getter for property idConexion.

    * @return Value of property idConexion.

    */

    public String getIdConexion() {

           return idConexion;

    }



    /** Getter for property Conexion.

    * @return Value of property Conexion.

    */

    public Connection getConn() {

           return connection;

    }



    /** Method addColumnSelect(nombreColumna) 

    * @param nombreColumna New value of property columnasSelect.

    * Este método añade una nueva columna a mostrar en el resultado de la select

    * Añadir las columnas usando las constantes de la tabla

    */

    public void addColumnSelect(String nombreColumna) {

        while (nombreColumna.endsWith(" ")) {

            nombreColumna = nombreColumna.substring(0, nombreColumna.length()-1);

          }

        while (nombreColumna.startsWith(" ")) {

            nombreColumna = nombreColumna.substring(1, nombreColumna.length());

          }

        if (nombreColumna.lastIndexOf(" ")!=-1){

            this.alias.add(nombreColumna.substring(nombreColumna.lastIndexOf(" ")+1).trim());

            this.columnasSelect.add(nombreColumna.substring(0,nombreColumna.lastIndexOf(" ")).trim());

        }else{

            this.columnasSelect.add(nombreColumna.trim());

        }

    }



    /** Method clearColumnsSelect() 

    * Este método vacia el ArrayList con los nombres de las columnas sobre los q hacer la select

    */

    public void clearColumnsSelect() {

        this.columnasSelect.clear();

    }



    /** Method setColumnsSelect(listaColumnas) 

    * Este método da valor al ArrayList con los nombres de las columnas sobre los q hacer la select

    */

    public void setColumnsSelect(String listaColumnas) {

        this.clearColumnsSelect();

        java.util.StringTokenizer token1 = new java.util.StringTokenizer(listaColumnas,",");

        String columna=token1.nextToken();

        while (columna.endsWith(" ")) {

            columna = columna.substring(0, columna.length()-1);

          }

        while (columna.startsWith(" ")) {

            columna = columna.substring(1, columna.length());

          }

        if (columna.lastIndexOf(" ")!=-1){

            this.alias.add(columna.substring(columna.lastIndexOf(" ")).trim());

            this.columnasSelect.add(columna.substring(0,columna.lastIndexOf(" ")).trim());

        }else{

            this.columnasSelect.add(columna);

        }

        while (token1.hasMoreTokens()){

          columna=token1.nextToken();

        while (columna.endsWith(" ")) {

            columna = columna.substring(0, columna.length()-1);

          }

        while (columna.startsWith(" ")) {

            columna = columna.substring(1, columna.length());

          }

          if (columna.lastIndexOf(" ")!=-1){

            this.alias.add(columna.substring(columna.lastIndexOf(" ")+1).trim());

            this.columnasSelect.add(columna.substring(0,columna.lastIndexOf(" ")).trim());

          }else{

            this.columnasSelect.add(columna.trim());

          }

    }

    }



    /** Method getColumnsSelect() 

    * Este método devuelve un String con los nombres de las columnas sobres las q hacer la

    * select separadas por comas.

    */

    public String getColumnsSelect() {

        sbColumnasSelect = new StringBuffer();

        String columnasTotal = "Q021GT00_NI, Q021FT00_NI";

        if (columnasSelect!=null){

        for(int i=0; i<columnasSelect.size();i++){

            sbColumnasSelect.append( (String)this.columnasSelect.get(i));

            sbColumnasSelect.append(",");

            }

            }

        if (sbColumnasSelect!=null && !sbColumnasSelect.toString().equals("")){

            sbColumnasSelect.setLength(sbColumnasSelect.length()-1);

            return sbColumnasSelect.toString();

            }

        else{

            return columnasTotal;

        }

    }



    /** Method getColumnsSelectTotal() 

    * Este método devuelve un String con los nombres de las columnas sobres las q hacer la

    * select separadas por comas.

    */

    public String getColumnsSelectTotal() {

        sbColumnasSelect = new StringBuffer();

        String columnasTotal = "Q021GT00_NI \"Q021GT00_NI\", Q021FT00_NI \"Q021FT00_NI\"";

        if (columnasSelect!=null){

        for(int i=0; i<columnasSelect.size();i++){

            sbColumnasSelect.append( (String)this.columnasSelect.get(i));

            if (alias.size()>0 && i<alias.size()){

               sbColumnasSelect.append(" \"" + (String)this.alias.get(i)+ "\"");

            }else{

               sbColumnasSelect.append(" \"" + (String)this.columnasSelect.get(i)+ "\"");

            }

            sbColumnasSelect.append(",");

            }

            }

        if (sbColumnasSelect!=null && !sbColumnasSelect.toString().equals("")){

            sbColumnasSelect.setLength(sbColumnasSelect.length()-1);

            return sbColumnasSelect.toString();

            }

        else{

            return columnasTotal;

        }

    }



    /** Method getColumnsSelectComitas() 

    * Este método devuelve un String con los nombres de las columnas sobres las q hacer la

    * select separadas por comas.

    */

    public String getColumnsSelectComitas() {

        sbColumnasSelect = new StringBuffer();

        String columnasTotal = " \"Q021GT00_NI\", \"Q021FT00_NI\"";

        if (alias.size()>0){

        for(int i=0; i<alias.size();i++){

            sbColumnasSelect.append(" \"" + (String)this.alias.get(i)+ "\"");

            sbColumnasSelect.append(",");

            }

            }

        else if (columnasSelect!=null){

        for(int i=0; i<columnasSelect.size();i++){

            sbColumnasSelect.append(" \"" + (String)this.columnasSelect.get(i)+ "\"");

            sbColumnasSelect.append(",");

            }

            }

        if (sbColumnasSelect!=null && !sbColumnasSelect.toString().equals("")){

            sbColumnasSelect.setLength(sbColumnasSelect.length()-1);

            return sbColumnasSelect.toString();

            }

        else{

            return columnasTotal;

        }

    }



    /** Method setTableFrom(listaTablas) 

    * @param listaTablas New value of property tableFrom.

    * Este método añade la lista de tablas pasadas por parametro a la from .

    * Cada tabla de la lista debe ir separada por comas

    */

    public void setTableFrom(String listaTablas) {

        if (listaTablas!=null){

             this.tableFrom="Q021LS00" + "," + listaTablas;
        }
        else{

             this.tableFrom="Q021LS00";
        }
    }



    /** Method getTableFrom() 

    * Este método devuelve un String con los nombres de las tablas sobres las q hacer la

    * from separadas por comas.

    */

    public String getTableFrom() {

        return this.tableFrom;

    }



    /** Method getRegModif() 

    * Este método devuelve un int con el nº de registros modifcados.

    */

    public int getRegModif() {

        return this.regModif;

    }



    /** Method setUncommittedRead() 

    * Este método es válido SOLO EN DB2. Permite 'lecturas sucias' si se establece a true

    */

    public void setUncommittedRead(boolean ur) {

        this.uncommittedRead=ur;

    }



    /** Method getUncommittedRead() 

    * Este método es válido SOLO EN DB2.Devuelve el valor de UncommittedRead

    */

    public boolean getUncommittedRead() {

        return this.uncommittedRead;

    }



    /** Method setForUpdate() 

    * Este método permite añadir la clausula FOR UPDATE si se establece a true

    */

    public void setForUpdate(boolean fu) {

        this.forUpdate=fu;

    }



    /** Method getForUpdate() 

    * Este método devuelve el valor de forUpdate

    */

    public boolean getForUpdate() {

        return this.forUpdate;

    }



    /** Method setMax(columnName) 

    * @param columnName New value of property max.

    * Este método da valor a la var. max .

    */

    public void setMax(String columnName) {

        if (columnName!=null){

             this.max=columnName;
        }
    }



    /** Method getMax() 

    * Este método devuelve un String con el nombre de la columna sobre la q hacer la

    * clausula max.

    */

    public String getMax() {

        return this.max;

    }



    /** Method setDistinct(columnName) 

    * @param columnName New value of property distinct.

    * Este método da valor a la var. distinct .

    */

    public void setDistinct(String columnName) {

        if (columnName!=null){

             this.distinct=columnName;
        }
    }



    /** Method getDistinct() 

    * Este método devuelve un String con el nombre de la columna sobre la q hacer la

    * clausula distinct.

    */

    public String getDistinct() {

        return this.distinct;

    }



    /** Method setGroupBy(listaColumnas) 

    * @param listaColumnas New value of property groupBy.

    * Este método da el valor de la lista de columnas pasadas por parametro a la groupby .

    * Cada columna de la lista debe ir separada por comas

    */

    public void setGroupBy(String listaColumnas) {

             this.groupBy=listaColumnas;

    }



    /** Method getGroupBy() 

    * Este método devuelve un String con los nombres de las columnas sobres las q hacer la

    * groupBy separadas por comas.

    */

    public String getGroupBy() {

        return this.groupBy;

    }



    /** Method setOrderBy(valor) 

    * @param listaColumnas New value of property orderBy.

    * Este método da el valor de la lista de columnas pasadas por parametro a la orderBy .

    * Cada columna de la lista debe ir separada por comas

    */

    public void setOrderBy(String listaColumnas) {

             this.orderBy=listaColumnas;

    }



    /** Method getOrderBy() 

    * Este método devuelve un String con los nombres de las columnas sobres las q hacer la

    * orderBy separadas por comas.

    */

    public String getOrderBy() {

        return this.orderBy;

    }



    /** Method setLimitRows(valor) 

    * @param listaColumnas New value of property limitRows.

    * Este método da el valor pasado por parametro a la limitRows .

    */

    public void setLimitRows(boolean valor) {

             this.limitRows=valor;

    }



    /** Method getLimitRows() 

    * Este método devuelve un boolean el valor de limitRows

    */

    public boolean getLimitRows() {

        return this.limitRows;

    }



    /** Method setAditionalWhere(valor) 

    * @param valor New value of property aditionalWhere.

    * Este método da el valor pasado por parametro a la aditionalWhere .

    */

    public void setAditionalWhere(String valor) {

             this.aditionalWhere=valor;

    }



    /** Method getAditionalWhere() 

    * Este método devuelve un String con el valor de la aditionalWhere.

    */

    public String getAditionalWhere() {

        return this.aditionalWhere;

    }



    /** Method setInitialWhere(valor) 

    * @param valor New value of property initialWhere.

    * Este método da el valor pasado por parametro a la initialWhere .

    */

    public void setInitialWhere(String valor) {

             this.initialWhere=valor;

    }



    /** Method getInitialWhere() 

    * Este método devuelve un String con el valor de la initialWhere.

    */

    public String getInitialWhere() {

        return this.initialWhere;

    }



    /** Method setFixedWhere(valor) 

    * @param valor New value of property fixedWhere.

    * Este método da el valor pasado por parametro a la fixedWhere .

    */

    public void setFixedWhere(String valor) {

             this.fixedWhere=valor;

    }



    /** Method getFixedWhere() 

    * Este método devuelve un String con el valor de la fixedWhere.

    */

    public String getFixedWhere() {

        return this.fixedWhere;

    }



    /** Method getConnection() 

    * Este método devuelve un objeto connection.

    */

    public java.sql.Connection getConnection() {

        	try{

        		if (this.connection==null || this.connection.isClosed()){

           		this.connection = Q70ConectorJDBC.getSingleton().getConnection(Q02B_JNDI_DATASOURCE);

           	}

        	}catch (NamingException nex){

           		nex.printStackTrace();

         }catch (SQLException sqlex){

           		sqlex.printStackTrace();

         }

        return this.connection;

    }





}

