/*

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

*/

/*

* Q02bQ022DV02.java

*

* Created on 13/03/09 12:31:39

*/

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 Q02bTablaBDQ022DS01V02 extends q02b.exe.tablasBD.Q02bTablaBDQ022DS01V02 {

    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 Q022DS01V02 */

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

    private Q02bTablaBDQ022DS01V02() {

        super();

        this.idConexion="oracle";

    }



    /** Creates new Q022DS01V02 */

    public Q02bTablaBDQ022DS01V02(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("Q022BT00_ID_GRUPO, Q022DT00_ID_CUES, Q022DT00_IDEN_LICEN, Q022DT00_FEC_ENT, Q022DT00_ESTADO_LICEN, Q022DT00_CAUSA_BAJA, Q022DT00_ENTI, Q022DT00_TVIA, Q022DT00_CALLE, Q022DT00_POR_CL_POR, Q022DT00_BLOQ, Q022DT00_NUME, Q022DT00_BIS, Q022DT00_CDIR, Q022DT00_RS_PROMO, Q022DT00_CIF_DNI, Q022DT00_MUN_PROV, Q022DT00_MUN_MUNI, Q022DT00_ENTI_PRO, Q022DT00_TVIA_PRO, Q022DT00_CALLE_PRO, Q022DT00_POR_CL_POR_PRO, Q022DT00_BLOQ_PRO, Q022DT00_NUME_PRO, Q022DT00_BIS_PRO, Q022DT00_CDIR_PRO, Q022DT00_TLF, Q022DT00_MAIL, Q022DT00_FAX, Q022DT00_WEB, Q022DT00_PRESUPUESTO, Q022DT00_F_INI, Q022DT00_F_FIN, Q022DT00_TIPO_OBRA, Q022DT00_USO_RES, Q022DT00_ACTIVIDAD, Q022DT00_NVN, Q022DT00_NVR, Q022DT00_NVL, Q022DT00_NVVPO, Q022DT00_NVVS, Q022DT00_NVPOT, Q022DT00_NVALDOT, Q022DT00_NVREAL, Q022DT00_NVVTMG, Q022DT00_NVVTME, Q022DT00_NTOT, Q022DT00_NSP45, Q022DT00_NSP75, Q022DT00_NSP90, Q022DT00_NSP120, Q022DT00_NSPT, Q022DT00_PRINC_USO, Q022DT00_PU_ESPECIF, Q022DT00_PRECIO_MED, Q022DT00_OBS, Q022DT00_NORA_T17_LOCALIZACION 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 (Q022BT00_ID_GRUPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022BT00_ID_GRUPO=?");

            queryLog2.append("Q022DS01V02.Q022BT00_ID_GRUPO=").append(Q022BT00_ID_GRUPO_WHERE);

            and = true;

        }

        if (Q022DT00_ID_CUES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ID_CUES=?");

            queryLog2.append("Q022DS01V02.Q022DT00_ID_CUES=").append(Q022DT00_ID_CUES_WHERE);

            and = true;

        }

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_IDEN_LICEN=?");

            queryLog2.append("Q022DS01V02.Q022DT00_IDEN_LICEN='" + Q022DT00_IDEN_LICEN_WHERE+"'");

            and = true;

        }

        if (Q022DT00_FEC_ENT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_FEC_ENT=?");

            queryLog2.append("Q022DS01V02.Q022DT00_FEC_ENT='" + Q022DT00_FEC_ENT_WHERE+"'");

            and = true;

        }

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ESTADO_LICEN=?");

            queryLog2.append("Q022DS01V02.Q022DT00_ESTADO_LICEN='" + Q022DT00_ESTADO_LICEN_WHERE+"'");

            and = true;

        }

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CAUSA_BAJA=?");

            queryLog2.append("Q022DS01V02.Q022DT00_CAUSA_BAJA='" + Q022DT00_CAUSA_BAJA_WHERE+"'");

            and = true;

        }

        if (Q022DT00_ENTI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ENTI=?");

            queryLog2.append("Q022DS01V02.Q022DT00_ENTI=").append(Q022DT00_ENTI_WHERE);

            and = true;

        }

        if (Q022DT00_TVIA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TVIA=?");

            queryLog2.append("Q022DS01V02.Q022DT00_TVIA='" + Q022DT00_TVIA_WHERE+"'");

            and = true;

        }

        if (Q022DT00_CALLE_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CALLE=?");

            queryLog2.append("Q022DS01V02.Q022DT00_CALLE=").append(Q022DT00_CALLE_WHERE);

            and = true;

        }

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_POR_CL_POR=?");

            queryLog2.append("Q022DS01V02.Q022DT00_POR_CL_POR=").append(Q022DT00_POR_CL_POR_WHERE);

            and = true;

        }

        if (Q022DT00_BLOQ_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BLOQ=?");

            queryLog2.append("Q022DS01V02.Q022DT00_BLOQ='" + Q022DT00_BLOQ_WHERE+"'");

            and = true;

        }

        if (Q022DT00_NUME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NUME=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NUME=").append(Q022DT00_NUME_WHERE);

            and = true;

        }

        if (Q022DT00_BIS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BIS=?");

            queryLog2.append("Q022DS01V02.Q022DT00_BIS='" + Q022DT00_BIS_WHERE+"'");

            and = true;

        }

        if (Q022DT00_CDIR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CDIR=?");

            queryLog2.append("Q022DS01V02.Q022DT00_CDIR='" + Q022DT00_CDIR_WHERE+"'");

            and = true;

        }

        if (Q022DT00_RS_PROMO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_RS_PROMO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_RS_PROMO='" + Q022DT00_RS_PROMO_WHERE+"'");

            and = true;

        }

        if (Q022DT00_CIF_DNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CIF_DNI=?");

            queryLog2.append("Q022DS01V02.Q022DT00_CIF_DNI='" + Q022DT00_CIF_DNI_WHERE+"'");

            and = true;

        }

        if (Q022DT00_MUN_PROV_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_MUN_PROV=?");

            queryLog2.append("Q022DS01V02.Q022DT00_MUN_PROV='" + Q022DT00_MUN_PROV_WHERE+"'");

            and = true;

        }

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_MUN_MUNI=?");

            queryLog2.append("Q022DS01V02.Q022DT00_MUN_MUNI='" + Q022DT00_MUN_MUNI_WHERE+"'");

            and = true;

        }

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ENTI_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_ENTI_PRO=").append(Q022DT00_ENTI_PRO_WHERE);

            and = true;

        }

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TVIA_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_TVIA_PRO='" + Q022DT00_TVIA_PRO_WHERE+"'");

            and = true;

        }

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CALLE_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_CALLE_PRO=").append(Q022DT00_CALLE_PRO_WHERE);

            and = true;

        }

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_POR_CL_POR_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_POR_CL_POR_PRO=").append(Q022DT00_POR_CL_POR_PRO_WHERE);

            and = true;

        }

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BLOQ_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_BLOQ_PRO='" + Q022DT00_BLOQ_PRO_WHERE+"'");

            and = true;

        }

        if (Q022DT00_NUME_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NUME_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NUME_PRO=").append(Q022DT00_NUME_PRO_WHERE);

            and = true;

        }

        if (Q022DT00_BIS_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BIS_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_BIS_PRO='" + Q022DT00_BIS_PRO_WHERE+"'");

            and = true;

        }

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CDIR_PRO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_CDIR_PRO='" + Q022DT00_CDIR_PRO_WHERE+"'");

            and = true;

        }

        if (Q022DT00_TLF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TLF=?");

            queryLog2.append("Q022DS01V02.Q022DT00_TLF='" + Q022DT00_TLF_WHERE+"'");

            and = true;

        }

        if (Q022DT00_MAIL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_MAIL=?");

            queryLog2.append("Q022DS01V02.Q022DT00_MAIL='" + Q022DT00_MAIL_WHERE+"'");

            and = true;

        }

        if (Q022DT00_FAX_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_FAX=?");

            queryLog2.append("Q022DS01V02.Q022DT00_FAX='" + Q022DT00_FAX_WHERE+"'");

            and = true;

        }

        if (Q022DT00_WEB_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_WEB=?");

            queryLog2.append("Q022DS01V02.Q022DT00_WEB='" + Q022DT00_WEB_WHERE+"'");

            and = true;

        }

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PRESUPUESTO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_PRESUPUESTO=").append(Q022DT00_PRESUPUESTO_WHERE);

            and = true;

        }

        if (Q022DT00_F_INI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_F_INI=?");

            queryLog2.append("Q022DS01V02.Q022DT00_F_INI='" + Q022DT00_F_INI_WHERE+"'");

            and = true;

        }

        if (Q022DT00_F_FIN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_F_FIN=?");

            queryLog2.append("Q022DS01V02.Q022DT00_F_FIN='" + Q022DT00_F_FIN_WHERE+"'");

            and = true;

        }

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TIPO_OBRA=?");

            queryLog2.append("Q022DS01V02.Q022DT00_TIPO_OBRA='" + Q022DT00_TIPO_OBRA_WHERE+"'");

            and = true;

        }

        if (Q022DT00_USO_RES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_USO_RES=?");

            queryLog2.append("Q022DS01V02.Q022DT00_USO_RES='" + Q022DT00_USO_RES_WHERE+"'");

            and = true;

        }

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ACTIVIDAD=?");

            queryLog2.append("Q022DS01V02.Q022DT00_ACTIVIDAD='" + Q022DT00_ACTIVIDAD_WHERE+"'");

            and = true;

        }

        if (Q022DT00_NVN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVN=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVN=").append(Q022DT00_NVN_WHERE);

            and = true;

        }

        if (Q022DT00_NVR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVR=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVR=").append(Q022DT00_NVR_WHERE);

            and = true;

        }

        if (Q022DT00_NVL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVL=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVL=").append(Q022DT00_NVL_WHERE);

            and = true;

        }

        if (Q022DT00_NVVPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVPO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVVPO=").append(Q022DT00_NVVPO_WHERE);

            and = true;

        }

        if (Q022DT00_NVVS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVS=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVVS=").append(Q022DT00_NVVS_WHERE);

            and = true;

        }

        if (Q022DT00_NVPOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVPOT=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVPOT=").append(Q022DT00_NVPOT_WHERE);

            and = true;

        }

        if (Q022DT00_NVALDOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVALDOT=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVALDOT=").append(Q022DT00_NVALDOT_WHERE);

            and = true;

        }

        if (Q022DT00_NVREAL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVREAL=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVREAL=").append(Q022DT00_NVREAL_WHERE);

            and = true;

        }

        if (Q022DT00_NVVTMG_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVTMG=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVVTMG=").append(Q022DT00_NVVTMG_WHERE);

            and = true;

        }

        if (Q022DT00_NVVTME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVTME=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NVVTME=").append(Q022DT00_NVVTME_WHERE);

            and = true;

        }

        if (Q022DT00_NTOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NTOT=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NTOT=").append(Q022DT00_NTOT_WHERE);

            and = true;

        }

        if (Q022DT00_NSP45_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP45=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NSP45=").append(Q022DT00_NSP45_WHERE);

            and = true;

        }

        if (Q022DT00_NSP75_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP75=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NSP75=").append(Q022DT00_NSP75_WHERE);

            and = true;

        }

        if (Q022DT00_NSP90_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP90=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NSP90=").append(Q022DT00_NSP90_WHERE);

            and = true;

        }

        if (Q022DT00_NSP120_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP120=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NSP120=").append(Q022DT00_NSP120_WHERE);

            and = true;

        }

        if (Q022DT00_NSPT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSPT=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NSPT=").append(Q022DT00_NSPT_WHERE);

            and = true;

        }

        if (Q022DT00_PRINC_USO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PRINC_USO=?");

            queryLog2.append("Q022DS01V02.Q022DT00_PRINC_USO='" + Q022DT00_PRINC_USO_WHERE+"'");

            and = true;

        }

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PU_ESPECIF=?");

            queryLog2.append("Q022DS01V02.Q022DT00_PU_ESPECIF='" + Q022DT00_PU_ESPECIF_WHERE+"'");

            and = true;

        }

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PRECIO_MED=?");

            queryLog2.append("Q022DS01V02.Q022DT00_PRECIO_MED=").append(Q022DT00_PRECIO_MED_WHERE);

            and = true;

        }

        if (Q022DT00_OBS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_OBS=?");

            queryLog2.append("Q022DS01V02.Q022DT00_OBS='" + Q022DT00_OBS_WHERE+"'");

            and = true;

        }

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

                queryLog2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NORA_T17_LOCALIZACION=?");

            queryLog2.append("Q022DS01V02.Q022DT00_NORA_T17_LOCALIZACION='" + Q022DT00_NORA_T17_LOCALIZACION_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 (Q022BT00_ID_GRUPO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022BT00_ID_GRUPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=2;

        if (Q022DT00_ID_CUES_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=3;

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_IDEN_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=4;

        if (Q022DT00_FEC_ENT_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_FEC_ENT_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=5;

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_ESTADO_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=6;

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CAUSA_BAJA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=7;

        if (Q022DT00_ENTI_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=8;

        if (Q022DT00_TVIA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=9;

        if (Q022DT00_CALLE_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=10;

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=11;

        if (Q022DT00_BLOQ_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=12;

        if (Q022DT00_NUME_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=13;

        if (Q022DT00_BIS_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=14;

        if (Q022DT00_CDIR_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=15;

        if (Q022DT00_RS_PROMO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_RS_PROMO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=16;

        if (Q022DT00_CIF_DNI_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CIF_DNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=17;

        if (Q022DT00_MUN_PROV_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_PROV_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=18;

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_MUNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=19;

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=20;

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=21;

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=22;

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=23;

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=24;

        if (Q022DT00_NUME_PRO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_PRO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=25;

        if (Q022DT00_BIS_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=26;

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=27;

        if (Q022DT00_TLF_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TLF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=28;

        if (Q022DT00_MAIL_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MAIL_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=29;

        if (Q022DT00_FAX_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_FAX_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=30;

        if (Q022DT00_WEB_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_WEB_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=31;

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRESUPUESTO_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=32;

        if (Q022DT00_F_INI_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_INI_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=33;

        if (Q022DT00_F_FIN_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_FIN_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=34;

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TIPO_OBRA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=35;

        if (Q022DT00_USO_RES_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_USO_RES_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=36;

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_ACTIVIDAD_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=37;

        if (Q022DT00_NVN_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVN_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=38;

        if (Q022DT00_NVR_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVR_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=39;

        if (Q022DT00_NVL_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=40;

        if (Q022DT00_NVVPO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=41;

        if (Q022DT00_NVVS_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVS_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=42;

        if (Q022DT00_NVPOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVPOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=43;

        if (Q022DT00_NVALDOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVALDOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=44;

        if (Q022DT00_NVREAL_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVREAL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=45;

        if (Q022DT00_NVVTMG_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTMG_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=46;

        if (Q022DT00_NVVTME_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=47;

        if (Q022DT00_NTOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NTOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=48;

        if (Q022DT00_NSP45_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP45_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=49;

        if (Q022DT00_NSP75_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP75_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=50;

        if (Q022DT00_NSP90_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP90_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=51;

        if (Q022DT00_NSP120_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP120_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=52;

        if (Q022DT00_NSPT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSPT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=53;

        if (Q022DT00_PRINC_USO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_PRINC_USO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=54;

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_PU_ESPECIF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=55;

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRECIO_MED_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=56;

        if (Q022DT00_OBS_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_OBS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=57;

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_NORA_T17_LOCALIZACION_WHERE,pos);

            }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 (Q022BT00_ID_GRUPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022BT00_ID_GRUPO=?");

            and = true;

        }

        if (Q022DT00_ID_CUES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ID_CUES=?");

            and = true;

        }

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_IDEN_LICEN=?");

            and = true;

        }

        if (Q022DT00_FEC_ENT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_FEC_ENT=?");

            and = true;

        }

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ESTADO_LICEN=?");

            and = true;

        }

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CAUSA_BAJA=?");

            and = true;

        }

        if (Q022DT00_ENTI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ENTI=?");

            and = true;

        }

        if (Q022DT00_TVIA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TVIA=?");

            and = true;

        }

        if (Q022DT00_CALLE_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CALLE=?");

            and = true;

        }

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_POR_CL_POR=?");

            and = true;

        }

        if (Q022DT00_BLOQ_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BLOQ=?");

            and = true;

        }

        if (Q022DT00_NUME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NUME=?");

            and = true;

        }

        if (Q022DT00_BIS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BIS=?");

            and = true;

        }

        if (Q022DT00_CDIR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CDIR=?");

            and = true;

        }

        if (Q022DT00_RS_PROMO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_RS_PROMO=?");

            and = true;

        }

        if (Q022DT00_CIF_DNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CIF_DNI=?");

            and = true;

        }

        if (Q022DT00_MUN_PROV_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_MUN_PROV=?");

            and = true;

        }

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_MUN_MUNI=?");

            and = true;

        }

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ENTI_PRO=?");

            and = true;

        }

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TVIA_PRO=?");

            and = true;

        }

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CALLE_PRO=?");

            and = true;

        }

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_POR_CL_POR_PRO=?");

            and = true;

        }

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BLOQ_PRO=?");

            and = true;

        }

        if (Q022DT00_NUME_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NUME_PRO=?");

            and = true;

        }

        if (Q022DT00_BIS_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_BIS_PRO=?");

            and = true;

        }

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_CDIR_PRO=?");

            and = true;

        }

        if (Q022DT00_TLF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TLF=?");

            and = true;

        }

        if (Q022DT00_MAIL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_MAIL=?");

            and = true;

        }

        if (Q022DT00_FAX_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_FAX=?");

            and = true;

        }

        if (Q022DT00_WEB_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_WEB=?");

            and = true;

        }

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PRESUPUESTO=?");

            and = true;

        }

        if (Q022DT00_F_INI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_F_INI=?");

            and = true;

        }

        if (Q022DT00_F_FIN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_F_FIN=?");

            and = true;

        }

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_TIPO_OBRA=?");

            and = true;

        }

        if (Q022DT00_USO_RES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_USO_RES=?");

            and = true;

        }

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_ACTIVIDAD=?");

            and = true;

        }

        if (Q022DT00_NVN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVN=?");

            and = true;

        }

        if (Q022DT00_NVR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVR=?");

            and = true;

        }

        if (Q022DT00_NVL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVL=?");

            and = true;

        }

        if (Q022DT00_NVVPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVPO=?");

            and = true;

        }

        if (Q022DT00_NVVS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVS=?");

            and = true;

        }

        if (Q022DT00_NVPOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVPOT=?");

            and = true;

        }

        if (Q022DT00_NVALDOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVALDOT=?");

            and = true;

        }

        if (Q022DT00_NVREAL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVREAL=?");

            and = true;

        }

        if (Q022DT00_NVVTMG_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVTMG=?");

            and = true;

        }

        if (Q022DT00_NVVTME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NVVTME=?");

            and = true;

        }

        if (Q022DT00_NTOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NTOT=?");

            and = true;

        }

        if (Q022DT00_NSP45_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP45=?");

            and = true;

        }

        if (Q022DT00_NSP75_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP75=?");

            and = true;

        }

        if (Q022DT00_NSP90_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP90=?");

            and = true;

        }

        if (Q022DT00_NSP120_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSP120=?");

            and = true;

        }

        if (Q022DT00_NSPT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NSPT=?");

            and = true;

        }

        if (Q022DT00_PRINC_USO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PRINC_USO=?");

            and = true;

        }

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PU_ESPECIF=?");

            and = true;

        }

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_PRECIO_MED=?");

            and = true;

        }

        if (Q022DT00_OBS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_OBS=?");

            and = true;

        }

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DS01V02.Q022DT00_NORA_T17_LOCALIZACION=?");

            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 (Q022BT00_ID_GRUPO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022BT00_ID_GRUPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=2;

        if (Q022DT00_ID_CUES_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=3;

        if (Q022DT00_IDEN_LICEN_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_IDEN_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=4;

        if (Q022DT00_FEC_ENT_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_FEC_ENT_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=5;

        if (Q022DT00_ESTADO_LICEN_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_ESTADO_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=6;

        if (Q022DT00_CAUSA_BAJA_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_CAUSA_BAJA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=7;

        if (Q022DT00_ENTI_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=8;

        if (Q022DT00_TVIA_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=9;

        if (Q022DT00_CALLE_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=10;

        if (Q022DT00_POR_CL_POR_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=11;

        if (Q022DT00_BLOQ_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=12;

        if (Q022DT00_NUME_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=13;

        if (Q022DT00_BIS_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=14;

        if (Q022DT00_CDIR_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=15;

        if (Q022DT00_RS_PROMO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_RS_PROMO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=16;

        if (Q022DT00_CIF_DNI_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_CIF_DNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=17;

        if (Q022DT00_MUN_PROV_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_PROV_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=18;

        if (Q022DT00_MUN_MUNI_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_MUNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=19;

        if (Q022DT00_ENTI_PRO_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=20;

        if (Q022DT00_TVIA_PRO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=21;

        if (Q022DT00_CALLE_PRO_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=22;

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null &&  pkCompletada==false) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=23;

        if (Q022DT00_BLOQ_PRO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=24;

        if (Q022DT00_NUME_PRO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_PRO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=25;

        if (Q022DT00_BIS_PRO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=26;

        if (Q022DT00_CDIR_PRO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=27;

        if (Q022DT00_TLF_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_TLF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=28;

        if (Q022DT00_MAIL_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_MAIL_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=29;

        if (Q022DT00_FAX_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_FAX_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=30;

        if (Q022DT00_WEB_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_WEB_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=31;

        if (Q022DT00_PRESUPUESTO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRESUPUESTO_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=32;

        if (Q022DT00_F_INI_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_INI_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=33;

        if (Q022DT00_F_FIN_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_FIN_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=34;

        if (Q022DT00_TIPO_OBRA_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_TIPO_OBRA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=35;

        if (Q022DT00_USO_RES_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_USO_RES_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=36;

        if (Q022DT00_ACTIVIDAD_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_ACTIVIDAD_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=37;

        if (Q022DT00_NVN_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVN_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=38;

        if (Q022DT00_NVR_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVR_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=39;

        if (Q022DT00_NVL_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=40;

        if (Q022DT00_NVVPO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=41;

        if (Q022DT00_NVVS_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVS_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=42;

        if (Q022DT00_NVPOT_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVPOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=43;

        if (Q022DT00_NVALDOT_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVALDOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=44;

        if (Q022DT00_NVREAL_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVREAL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=45;

        if (Q022DT00_NVVTMG_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTMG_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=46;

        if (Q022DT00_NVVTME_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=47;

        if (Q022DT00_NTOT_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NTOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=48;

        if (Q022DT00_NSP45_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP45_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=49;

        if (Q022DT00_NSP75_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP75_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=50;

        if (Q022DT00_NSP90_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP90_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=51;

        if (Q022DT00_NSP120_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP120_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=52;

        if (Q022DT00_NSPT_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setInt(index,Q022DT00_NSPT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=53;

        if (Q022DT00_PRINC_USO_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_PRINC_USO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=54;

        if (Q022DT00_PU_ESPECIF_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_PU_ESPECIF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=55;

        if (Q022DT00_PRECIO_MED_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRECIO_MED_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=56;

        if (Q022DT00_OBS_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_OBS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

            pos=57;

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null &&  pkCompletada==false) {

            try{

            prepStmt.setString(index,Q022DT00_NORA_T17_LOCALIZACION_WHERE,pos);

            }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(" 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("Q022BT00_ID_GRUPO, Q022DT00_ID_CUES, Q022DT00_IDEN_LICEN, Q022DT00_FEC_ENT, Q022DT00_ESTADO_LICEN, Q022DT00_CAUSA_BAJA, Q022DT00_ENTI, Q022DT00_TVIA, Q022DT00_CALLE, Q022DT00_POR_CL_POR, Q022DT00_BLOQ, Q022DT00_NUME, Q022DT00_BIS, Q022DT00_CDIR, Q022DT00_RS_PROMO, Q022DT00_CIF_DNI, Q022DT00_MUN_PROV, Q022DT00_MUN_MUNI, Q022DT00_ENTI_PRO, Q022DT00_TVIA_PRO, Q022DT00_CALLE_PRO, Q022DT00_POR_CL_POR_PRO, Q022DT00_BLOQ_PRO, Q022DT00_NUME_PRO, Q022DT00_BIS_PRO, Q022DT00_CDIR_PRO, Q022DT00_TLF, Q022DT00_MAIL, Q022DT00_FAX, Q022DT00_WEB, Q022DT00_PRESUPUESTO, Q022DT00_F_INI, Q022DT00_F_FIN, Q022DT00_TIPO_OBRA, Q022DT00_USO_RES, Q022DT00_ACTIVIDAD, Q022DT00_NVN, Q022DT00_NVR, Q022DT00_NVL, Q022DT00_NVVPO, Q022DT00_NVVS, Q022DT00_NVPOT, Q022DT00_NVALDOT, Q022DT00_NVREAL, Q022DT00_NVVTMG, Q022DT00_NVVTME, Q022DT00_NTOT, Q022DT00_NSP45, Q022DT00_NSP75, Q022DT00_NSP90, Q022DT00_NSP120, Q022DT00_NSPT, Q022DT00_PRINC_USO, Q022DT00_PU_ESPECIF, Q022DT00_PRECIO_MED, Q022DT00_OBS, Q022DT00_NORA_T17_LOCALIZACION from ").append(this.getTableFrom());
        }
        boolean and = false;

        if (Q022BT00_ID_GRUPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022BT00_ID_GRUPO=?");

            and = true;

        }

        if (Q022DT00_ID_CUES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ID_CUES=?");

            and = true;

        }

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_IDEN_LICEN=?");

            and = true;

        }

        if (Q022DT00_FEC_ENT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_FEC_ENT=?");

            and = true;

        }

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ESTADO_LICEN=?");

            and = true;

        }

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CAUSA_BAJA=?");

            and = true;

        }

        if (Q022DT00_ENTI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ENTI=?");

            and = true;

        }

        if (Q022DT00_TVIA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TVIA=?");

            and = true;

        }

        if (Q022DT00_CALLE_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CALLE=?");

            and = true;

        }

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_POR_CL_POR=?");

            and = true;

        }

        if (Q022DT00_BLOQ_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BLOQ=?");

            and = true;

        }

        if (Q022DT00_NUME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NUME=?");

            and = true;

        }

        if (Q022DT00_BIS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BIS=?");

            and = true;

        }

        if (Q022DT00_CDIR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CDIR=?");

            and = true;

        }

        if (Q022DT00_RS_PROMO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_RS_PROMO=?");

            and = true;

        }

        if (Q022DT00_CIF_DNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CIF_DNI=?");

            and = true;

        }

        if (Q022DT00_MUN_PROV_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_MUN_PROV=?");

            and = true;

        }

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_MUN_MUNI=?");

            and = true;

        }

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ENTI_PRO=?");

            and = true;

        }

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TVIA_PRO=?");

            and = true;

        }

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CALLE_PRO=?");

            and = true;

        }

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_POR_CL_POR_PRO=?");

            and = true;

        }

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BLOQ_PRO=?");

            and = true;

        }

        if (Q022DT00_NUME_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NUME_PRO=?");

            and = true;

        }

        if (Q022DT00_BIS_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BIS_PRO=?");

            and = true;

        }

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CDIR_PRO=?");

            and = true;

        }

        if (Q022DT00_TLF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TLF=?");

            and = true;

        }

        if (Q022DT00_MAIL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_MAIL=?");

            and = true;

        }

        if (Q022DT00_FAX_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_FAX=?");

            and = true;

        }

        if (Q022DT00_WEB_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_WEB=?");

            and = true;

        }

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PRESUPUESTO=?");

            and = true;

        }

        if (Q022DT00_F_INI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_F_INI=?");

            and = true;

        }

        if (Q022DT00_F_FIN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_F_FIN=?");

            and = true;

        }

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TIPO_OBRA=?");

            and = true;

        }

        if (Q022DT00_USO_RES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_USO_RES=?");

            and = true;

        }

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ACTIVIDAD=?");

            and = true;

        }

        if (Q022DT00_NVN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVN=?");

            and = true;

        }

        if (Q022DT00_NVR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVR=?");

            and = true;

        }

        if (Q022DT00_NVL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVL=?");

            and = true;

        }

        if (Q022DT00_NVVPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVPO=?");

            and = true;

        }

        if (Q022DT00_NVVS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVS=?");

            and = true;

        }

        if (Q022DT00_NVPOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVPOT=?");

            and = true;

        }

        if (Q022DT00_NVALDOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVALDOT=?");

            and = true;

        }

        if (Q022DT00_NVREAL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVREAL=?");

            and = true;

        }

        if (Q022DT00_NVVTMG_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVTMG=?");

            and = true;

        }

        if (Q022DT00_NVVTME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVTME=?");

            and = true;

        }

        if (Q022DT00_NTOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NTOT=?");

            and = true;

        }

        if (Q022DT00_NSP45_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP45=?");

            and = true;

        }

        if (Q022DT00_NSP75_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP75=?");

            and = true;

        }

        if (Q022DT00_NSP90_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP90=?");

            and = true;

        }

        if (Q022DT00_NSP120_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP120=?");

            and = true;

        }

        if (Q022DT00_NSPT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSPT=?");

            and = true;

        }

        if (Q022DT00_PRINC_USO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PRINC_USO=?");

            and = true;

        }

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PU_ESPECIF=?");

            and = true;

        }

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PRECIO_MED=?");

            and = true;

        }

        if (Q022DT00_OBS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_OBS=?");

            and = true;

        }

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NORA_T17_LOCALIZACION=?");

            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("Q022BT00_ID_GRUPO, Q022DT00_ID_CUES, Q022DT00_IDEN_LICEN, Q022DT00_FEC_ENT, Q022DT00_ESTADO_LICEN, Q022DT00_CAUSA_BAJA, Q022DT00_ENTI, Q022DT00_TVIA, Q022DT00_CALLE, Q022DT00_POR_CL_POR, Q022DT00_BLOQ, Q022DT00_NUME, Q022DT00_BIS, Q022DT00_CDIR, Q022DT00_RS_PROMO, Q022DT00_CIF_DNI, Q022DT00_MUN_PROV, Q022DT00_MUN_MUNI, Q022DT00_ENTI_PRO, Q022DT00_TVIA_PRO, Q022DT00_CALLE_PRO, Q022DT00_POR_CL_POR_PRO, Q022DT00_BLOQ_PRO, Q022DT00_NUME_PRO, Q022DT00_BIS_PRO, Q022DT00_CDIR_PRO, Q022DT00_TLF, Q022DT00_MAIL, Q022DT00_FAX, Q022DT00_WEB, Q022DT00_PRESUPUESTO, Q022DT00_F_INI, Q022DT00_F_FIN, Q022DT00_TIPO_OBRA, Q022DT00_USO_RES, Q022DT00_ACTIVIDAD, Q022DT00_NVN, Q022DT00_NVR, Q022DT00_NVL, Q022DT00_NVVPO, Q022DT00_NVVS, Q022DT00_NVPOT, Q022DT00_NVALDOT, Q022DT00_NVREAL, Q022DT00_NVVTMG, Q022DT00_NVVTME, Q022DT00_NTOT, Q022DT00_NSP45, Q022DT00_NSP75, Q022DT00_NSP90, Q022DT00_NSP120, Q022DT00_NSPT, Q022DT00_PRINC_USO, Q022DT00_PU_ESPECIF, Q022DT00_PRECIO_MED, Q022DT00_OBS, Q022DT00_NORA_T17_LOCALIZACION");

            }

            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 (Q022BT00_ID_GRUPO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022BT00_ID_GRUPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=2;

        if (Q022DT00_ID_CUES_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=3;

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_IDEN_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=4;

        if (Q022DT00_FEC_ENT_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_FEC_ENT_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=5;

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_ESTADO_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=6;

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CAUSA_BAJA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=7;

        if (Q022DT00_ENTI_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=8;

        if (Q022DT00_TVIA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=9;

        if (Q022DT00_CALLE_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=10;

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=11;

        if (Q022DT00_BLOQ_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=12;

        if (Q022DT00_NUME_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=13;

        if (Q022DT00_BIS_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=14;

        if (Q022DT00_CDIR_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=15;

        if (Q022DT00_RS_PROMO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_RS_PROMO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=16;

        if (Q022DT00_CIF_DNI_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CIF_DNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=17;

        if (Q022DT00_MUN_PROV_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_PROV_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=18;

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_MUNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=19;

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=20;

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=21;

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=22;

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=23;

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=24;

        if (Q022DT00_NUME_PRO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_PRO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=25;

        if (Q022DT00_BIS_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=26;

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=27;

        if (Q022DT00_TLF_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TLF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=28;

        if (Q022DT00_MAIL_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MAIL_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=29;

        if (Q022DT00_FAX_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_FAX_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=30;

        if (Q022DT00_WEB_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_WEB_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=31;

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRESUPUESTO_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=32;

        if (Q022DT00_F_INI_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_INI_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=33;

        if (Q022DT00_F_FIN_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_FIN_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=34;

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TIPO_OBRA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=35;

        if (Q022DT00_USO_RES_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_USO_RES_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=36;

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_ACTIVIDAD_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=37;

        if (Q022DT00_NVN_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVN_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=38;

        if (Q022DT00_NVR_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVR_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=39;

        if (Q022DT00_NVL_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=40;

        if (Q022DT00_NVVPO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=41;

        if (Q022DT00_NVVS_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVS_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=42;

        if (Q022DT00_NVPOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVPOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=43;

        if (Q022DT00_NVALDOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVALDOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=44;

        if (Q022DT00_NVREAL_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVREAL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=45;

        if (Q022DT00_NVVTMG_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTMG_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=46;

        if (Q022DT00_NVVTME_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=47;

        if (Q022DT00_NTOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NTOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=48;

        if (Q022DT00_NSP45_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP45_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=49;

        if (Q022DT00_NSP75_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP75_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=50;

        if (Q022DT00_NSP90_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP90_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=51;

        if (Q022DT00_NSP120_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP120_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=52;

        if (Q022DT00_NSPT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSPT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=53;

        if (Q022DT00_PRINC_USO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_PRINC_USO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=54;

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_PU_ESPECIF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=55;

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRECIO_MED_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=56;

        if (Q022DT00_OBS_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_OBS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=57;

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_NORA_T17_LOCALIZACION_WHERE,pos);

            }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 (Q022BT00_ID_GRUPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022BT00_ID_GRUPO=?");

            and = true;

        }

        if (Q022DT00_ID_CUES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ID_CUES=?");

            and = true;

        }

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_IDEN_LICEN=?");

            and = true;

        }

        if (Q022DT00_FEC_ENT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_FEC_ENT=?");

            and = true;

        }

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ESTADO_LICEN=?");

            and = true;

        }

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CAUSA_BAJA=?");

            and = true;

        }

        if (Q022DT00_ENTI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ENTI=?");

            and = true;

        }

        if (Q022DT00_TVIA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TVIA=?");

            and = true;

        }

        if (Q022DT00_CALLE_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CALLE=?");

            and = true;

        }

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_POR_CL_POR=?");

            and = true;

        }

        if (Q022DT00_BLOQ_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BLOQ=?");

            and = true;

        }

        if (Q022DT00_NUME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NUME=?");

            and = true;

        }

        if (Q022DT00_BIS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BIS=?");

            and = true;

        }

        if (Q022DT00_CDIR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CDIR=?");

            and = true;

        }

        if (Q022DT00_RS_PROMO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_RS_PROMO=?");

            and = true;

        }

        if (Q022DT00_CIF_DNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CIF_DNI=?");

            and = true;

        }

        if (Q022DT00_MUN_PROV_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_MUN_PROV=?");

            and = true;

        }

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_MUN_MUNI=?");

            and = true;

        }

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ENTI_PRO=?");

            and = true;

        }

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TVIA_PRO=?");

            and = true;

        }

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CALLE_PRO=?");

            and = true;

        }

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_POR_CL_POR_PRO=?");

            and = true;

        }

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BLOQ_PRO=?");

            and = true;

        }

        if (Q022DT00_NUME_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NUME_PRO=?");

            and = true;

        }

        if (Q022DT00_BIS_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_BIS_PRO=?");

            and = true;

        }

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_CDIR_PRO=?");

            and = true;

        }

        if (Q022DT00_TLF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TLF=?");

            and = true;

        }

        if (Q022DT00_MAIL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_MAIL=?");

            and = true;

        }

        if (Q022DT00_FAX_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_FAX=?");

            and = true;

        }

        if (Q022DT00_WEB_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_WEB=?");

            and = true;

        }

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PRESUPUESTO=?");

            and = true;

        }

        if (Q022DT00_F_INI_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_F_INI=?");

            and = true;

        }

        if (Q022DT00_F_FIN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_F_FIN=?");

            and = true;

        }

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_TIPO_OBRA=?");

            and = true;

        }

        if (Q022DT00_USO_RES_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_USO_RES=?");

            and = true;

        }

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_ACTIVIDAD=?");

            and = true;

        }

        if (Q022DT00_NVN_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVN=?");

            and = true;

        }

        if (Q022DT00_NVR_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVR=?");

            and = true;

        }

        if (Q022DT00_NVL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVL=?");

            and = true;

        }

        if (Q022DT00_NVVPO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVPO=?");

            and = true;

        }

        if (Q022DT00_NVVS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVS=?");

            and = true;

        }

        if (Q022DT00_NVPOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVPOT=?");

            and = true;

        }

        if (Q022DT00_NVALDOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVALDOT=?");

            and = true;

        }

        if (Q022DT00_NVREAL_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVREAL=?");

            and = true;

        }

        if (Q022DT00_NVVTMG_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVTMG=?");

            and = true;

        }

        if (Q022DT00_NVVTME_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NVVTME=?");

            and = true;

        }

        if (Q022DT00_NTOT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NTOT=?");

            and = true;

        }

        if (Q022DT00_NSP45_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP45=?");

            and = true;

        }

        if (Q022DT00_NSP75_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP75=?");

            and = true;

        }

        if (Q022DT00_NSP90_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP90=?");

            and = true;

        }

        if (Q022DT00_NSP120_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSP120=?");

            and = true;

        }

        if (Q022DT00_NSPT_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NSPT=?");

            and = true;

        }

        if (Q022DT00_PRINC_USO_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PRINC_USO=?");

            and = true;

        }

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PU_ESPECIF=?");

            and = true;

        }

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_PRECIO_MED=?");

            and = true;

        }

        if (Q022DT00_OBS_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_OBS=?");

            and = true;

        }

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            if (and) {

                subquery2.append(" AND ");

            }

            subquery2.append("Q022DT00_NORA_T17_LOCALIZACION=?");

            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 (Q022BT00_ID_GRUPO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022BT00_ID_GRUPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=2;

        if (Q022DT00_ID_CUES_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=3;

        if (Q022DT00_IDEN_LICEN_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_IDEN_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=4;

        if (Q022DT00_FEC_ENT_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_FEC_ENT_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=5;

        if (Q022DT00_ESTADO_LICEN_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_ESTADO_LICEN_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=6;

        if (Q022DT00_CAUSA_BAJA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CAUSA_BAJA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=7;

        if (Q022DT00_ENTI_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=8;

        if (Q022DT00_TVIA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=9;

        if (Q022DT00_CALLE_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=10;

        if (Q022DT00_POR_CL_POR_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=11;

        if (Q022DT00_BLOQ_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=12;

        if (Q022DT00_NUME_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=13;

        if (Q022DT00_BIS_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=14;

        if (Q022DT00_CDIR_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=15;

        if (Q022DT00_RS_PROMO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_RS_PROMO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=16;

        if (Q022DT00_CIF_DNI_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CIF_DNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=17;

        if (Q022DT00_MUN_PROV_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_PROV_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=18;

        if (Q022DT00_MUN_MUNI_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MUN_MUNI_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=19;

        if (Q022DT00_ENTI_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=20;

        if (Q022DT00_TVIA_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TVIA_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=21;

        if (Q022DT00_CALLE_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=22;

        if (Q022DT00_POR_CL_POR_PRO_WHERE != null) {

            try{

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

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=23;

        if (Q022DT00_BLOQ_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BLOQ_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=24;

        if (Q022DT00_NUME_PRO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NUME_PRO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=25;

        if (Q022DT00_BIS_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_BIS_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=26;

        if (Q022DT00_CDIR_PRO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_CDIR_PRO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=27;

        if (Q022DT00_TLF_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TLF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=28;

        if (Q022DT00_MAIL_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_MAIL_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=29;

        if (Q022DT00_FAX_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_FAX_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=30;

        if (Q022DT00_WEB_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_WEB_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=31;

        if (Q022DT00_PRESUPUESTO_WHERE != null) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRESUPUESTO_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=32;

        if (Q022DT00_F_INI_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_INI_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=33;

        if (Q022DT00_F_FIN_WHERE != null) {

            try{

            prepStmt.setTimestamp(index,new java.sql.Timestamp(Q022DT00_F_FIN_WHERE.getTime()));

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=34;

        if (Q022DT00_TIPO_OBRA_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_TIPO_OBRA_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=35;

        if (Q022DT00_USO_RES_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_USO_RES_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=36;

        if (Q022DT00_ACTIVIDAD_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_ACTIVIDAD_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=37;

        if (Q022DT00_NVN_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVN_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=38;

        if (Q022DT00_NVR_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVR_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=39;

        if (Q022DT00_NVL_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=40;

        if (Q022DT00_NVVPO_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVPO_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=41;

        if (Q022DT00_NVVS_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVS_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=42;

        if (Q022DT00_NVPOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVPOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=43;

        if (Q022DT00_NVALDOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVALDOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=44;

        if (Q022DT00_NVREAL_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVREAL_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=45;

        if (Q022DT00_NVVTMG_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTMG_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=46;

        if (Q022DT00_NVVTME_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NVVTME_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=47;

        if (Q022DT00_NTOT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NTOT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=48;

        if (Q022DT00_NSP45_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP45_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=49;

        if (Q022DT00_NSP75_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP75_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=50;

        if (Q022DT00_NSP90_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP90_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=51;

        if (Q022DT00_NSP120_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSP120_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=52;

        if (Q022DT00_NSPT_WHERE != null) {

            try{

            prepStmt.setInt(index,Q022DT00_NSPT_WHERE.intValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=53;

        if (Q022DT00_PRINC_USO_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_PRINC_USO_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=54;

        if (Q022DT00_PU_ESPECIF_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_PU_ESPECIF_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=55;

        if (Q022DT00_PRECIO_MED_WHERE != null) {

            try{

            prepStmt.setDouble(index,Q022DT00_PRECIO_MED_WHERE.doubleValue());

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=56;

        if (Q022DT00_OBS_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_OBS_WHERE,pos);

            }catch (java.sql.SQLException e){

                e.printStackTrace();

            }

            index=index+1;

        }

        pos=57;

        if (Q022DT00_NORA_T17_LOCALIZACION_WHERE != null) {

            try{

            prepStmt.setString(index,Q022DT00_NORA_T17_LOCALIZACION_WHERE,pos);

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

    }











    /** 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 = "Q022BT00_ID_GRUPO, Q022DT00_ID_CUES, Q022DT00_IDEN_LICEN, Q022DT00_FEC_ENT, Q022DT00_ESTADO_LICEN, Q022DT00_CAUSA_BAJA, Q022DT00_ENTI, Q022DT00_TVIA, Q022DT00_CALLE, Q022DT00_POR_CL_POR, Q022DT00_BLOQ, Q022DT00_NUME, Q022DT00_BIS, Q022DT00_CDIR, Q022DT00_RS_PROMO, Q022DT00_CIF_DNI, Q022DT00_MUN_PROV, Q022DT00_MUN_MUNI, Q022DT00_ENTI_PRO, Q022DT00_TVIA_PRO, Q022DT00_CALLE_PRO, Q022DT00_POR_CL_POR_PRO, Q022DT00_BLOQ_PRO, Q022DT00_NUME_PRO, Q022DT00_BIS_PRO, Q022DT00_CDIR_PRO, Q022DT00_TLF, Q022DT00_MAIL, Q022DT00_FAX, Q022DT00_WEB, Q022DT00_PRESUPUESTO, Q022DT00_F_INI, Q022DT00_F_FIN, Q022DT00_TIPO_OBRA, Q022DT00_USO_RES, Q022DT00_ACTIVIDAD, Q022DT00_NVN, Q022DT00_NVR, Q022DT00_NVL, Q022DT00_NVVPO, Q022DT00_NVVS, Q022DT00_NVPOT, Q022DT00_NVALDOT, Q022DT00_NVREAL, Q022DT00_NVVTMG, Q022DT00_NVVTME, Q022DT00_NTOT, Q022DT00_NSP45, Q022DT00_NSP75, Q022DT00_NSP90, Q022DT00_NSP120, Q022DT00_NSPT, Q022DT00_PRINC_USO, Q022DT00_PU_ESPECIF, Q022DT00_PRECIO_MED, Q022DT00_OBS, Q022DT00_NORA_T17_LOCALIZACION";

        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 = "Q022BT00_ID_GRUPO \"Q022BT00_ID_GRUPO\", Q022DT00_ID_CUES \"Q022DT00_ID_CUES\", Q022DT00_IDEN_LICEN \"Q022DT00_IDEN_LICEN\", Q022DT00_FEC_ENT \"Q022DT00_FEC_ENT\", Q022DT00_ESTADO_LICEN \"Q022DT00_ESTADO_LICEN\", Q022DT00_CAUSA_BAJA \"Q022DT00_CAUSA_BAJA\", Q022DT00_ENTI \"Q022DT00_ENTI\", Q022DT00_TVIA \"Q022DT00_TVIA\", Q022DT00_CALLE \"Q022DT00_CALLE\", Q022DT00_POR_CL_POR \"Q022DT00_POR_CL_POR\", Q022DT00_BLOQ \"Q022DT00_BLOQ\", Q022DT00_NUME \"Q022DT00_NUME\", Q022DT00_BIS \"Q022DT00_BIS\", Q022DT00_CDIR \"Q022DT00_CDIR\", Q022DT00_RS_PROMO \"Q022DT00_RS_PROMO\", Q022DT00_CIF_DNI \"Q022DT00_CIF_DNI\", Q022DT00_MUN_PROV \"Q022DT00_MUN_PROV\", Q022DT00_MUN_MUNI \"Q022DT00_MUN_MUNI\", Q022DT00_ENTI_PRO \"Q022DT00_ENTI_PRO\", Q022DT00_TVIA_PRO \"Q022DT00_TVIA_PRO\", Q022DT00_CALLE_PRO \"Q022DT00_CALLE_PRO\", Q022DT00_POR_CL_POR_PRO \"Q022DT00_POR_CL_POR_PRO\", Q022DT00_BLOQ_PRO \"Q022DT00_BLOQ_PRO\", Q022DT00_NUME_PRO \"Q022DT00_NUME_PRO\", Q022DT00_BIS_PRO \"Q022DT00_BIS_PRO\", Q022DT00_CDIR_PRO \"Q022DT00_CDIR_PRO\", Q022DT00_TLF \"Q022DT00_TLF\", Q022DT00_MAIL \"Q022DT00_MAIL\", Q022DT00_FAX \"Q022DT00_FAX\", Q022DT00_WEB \"Q022DT00_WEB\", Q022DT00_PRESUPUESTO \"Q022DT00_PRESUPUESTO\", Q022DT00_F_INI \"Q022DT00_F_INI\", Q022DT00_F_FIN \"Q022DT00_F_FIN\", Q022DT00_TIPO_OBRA \"Q022DT00_TIPO_OBRA\", Q022DT00_USO_RES \"Q022DT00_USO_RES\", Q022DT00_ACTIVIDAD \"Q022DT00_ACTIVIDAD\", Q022DT00_NVN \"Q022DT00_NVN\", Q022DT00_NVR \"Q022DT00_NVR\", Q022DT00_NVL \"Q022DT00_NVL\", Q022DT00_NVVPO \"Q022DT00_NVVPO\", Q022DT00_NVVS \"Q022DT00_NVVS\", Q022DT00_NVPOT \"Q022DT00_NVPOT\", Q022DT00_NVALDOT \"Q022DT00_NVALDOT\", Q022DT00_NVREAL \"Q022DT00_NVREAL\", Q022DT00_NVVTMG \"Q022DT00_NVVTMG\", Q022DT00_NVVTME \"Q022DT00_NVVTME\", Q022DT00_NTOT \"Q022DT00_NTOT\", Q022DT00_NSP45 \"Q022DT00_NSP45\", Q022DT00_NSP75 \"Q022DT00_NSP75\", Q022DT00_NSP90 \"Q022DT00_NSP90\", Q022DT00_NSP120 \"Q022DT00_NSP120\", Q022DT00_NSPT \"Q022DT00_NSPT\", Q022DT00_PRINC_USO \"Q022DT00_PRINC_USO\", Q022DT00_PU_ESPECIF \"Q022DT00_PU_ESPECIF\", Q022DT00_PRECIO_MED \"Q022DT00_PRECIO_MED\", Q022DT00_OBS \"Q022DT00_OBS\", Q022DT00_NORA_T17_LOCALIZACION \"Q022DT00_NORA_T17_LOCALIZACION\"";

        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 = " \"Q022BT00_ID_GRUPO\", \"Q022DT00_ID_CUES\", \"Q022DT00_IDEN_LICEN\", \"Q022DT00_FEC_ENT\", \"Q022DT00_ESTADO_LICEN\", \"Q022DT00_CAUSA_BAJA\", \"Q022DT00_ENTI\", \"Q022DT00_TVIA\", \"Q022DT00_CALLE\", \"Q022DT00_POR_CL_POR\", \"Q022DT00_BLOQ\", \"Q022DT00_NUME\", \"Q022DT00_BIS\", \"Q022DT00_CDIR\", \"Q022DT00_RS_PROMO\", \"Q022DT00_CIF_DNI\", \"Q022DT00_MUN_PROV\", \"Q022DT00_MUN_MUNI\", \"Q022DT00_ENTI_PRO\", \"Q022DT00_TVIA_PRO\", \"Q022DT00_CALLE_PRO\", \"Q022DT00_POR_CL_POR_PRO\", \"Q022DT00_BLOQ_PRO\", \"Q022DT00_NUME_PRO\", \"Q022DT00_BIS_PRO\", \"Q022DT00_CDIR_PRO\", \"Q022DT00_TLF\", \"Q022DT00_MAIL\", \"Q022DT00_FAX\", \"Q022DT00_WEB\", \"Q022DT00_PRESUPUESTO\", \"Q022DT00_F_INI\", \"Q022DT00_F_FIN\", \"Q022DT00_TIPO_OBRA\", \"Q022DT00_USO_RES\", \"Q022DT00_ACTIVIDAD\", \"Q022DT00_NVN\", \"Q022DT00_NVR\", \"Q022DT00_NVL\", \"Q022DT00_NVVPO\", \"Q022DT00_NVVS\", \"Q022DT00_NVPOT\", \"Q022DT00_NVALDOT\", \"Q022DT00_NVREAL\", \"Q022DT00_NVVTMG\", \"Q022DT00_NVVTME\", \"Q022DT00_NTOT\", \"Q022DT00_NSP45\", \"Q022DT00_NSP75\", \"Q022DT00_NSP90\", \"Q022DT00_NSP120\", \"Q022DT00_NSPT\", \"Q022DT00_PRINC_USO\", \"Q022DT00_PU_ESPECIF\", \"Q022DT00_PRECIO_MED\", \"Q022DT00_OBS\", \"Q022DT00_NORA_T17_LOCALIZACION\"";

        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="Q022DS01V02" + "," + listaTablas;
        }
        else{

             this.tableFrom="Q022DS01V02";
        }
    }



    /** 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;

    }





}

