dimanche 31 janvier 2016

execute two insert and select statement as per the return value?

@SuppressWarnings("unchecked")
public TblSeed getSeed(String tableName, String tableName1) {
    Session session = this.sessionFactory.getCurrentSession();

        List<TblSeed> list = new ArrayList<TblSeed>();
        TblSeed tblSeed = null;
        try{
            Query query = session.createQuery("from TblSeed where seedName =:tableName");
        query.setParameter("tableName", tableName);

            list = query.list();
            if(list!=null && list.size()>0){
                tblSeed = list.get(0);
                }

        Query query1 = session
                .createQuery("from TblSeed where seedName =:tableName1");
        query.setParameter("tableName1", tableName1);

        list = query1.list();
        if (list != null && list.size() > 0) {
            tblSeed = list.get(0);
        }

        }catch(Exception ex){
            tblSeed = null;
            logger.error("Exception:",ex);
        }
        return tblSeed;

}



    TblSeed tblSeed = getSeed("TblTransactions",
            "TblTransactionsRepository");
    String format = "%"+(tblSeed.getSeedMaxValue()+"").length()+"s";
    long id= (tblSeed.getSeedCurrentCtr()!=null?tblSeed.getSeedCurrentCtr():tblSeed.getSeedBaseCtr())+tblSeed.getSeedIncrementCtr();


    String tblTransactionsRowName1 = ApplicationProperties
            .getValue("TblTransactionsROWNAMELIST1");
    String qInsertSelect1 = "select "
            + tblTransactionsRowName1
            + " "
            + " from "
            + srcTable
            + "Temp a, "
            + destTable
            + "Temp b "
            + " where  1=1 and a.reconFlag = b.reconFlag  and coalesce( b.reconFlag, 'B' ) = '"
            + autoFlag + "'" + joinQ;
    System.out.println("qInsertSelect1-------->" + qInsertSelect1);

Here, tblSeed returns two tables(i.e TblTransactions and TblTransactionsRepository) as per my source. In below i am getting the max id of that TblTransactions table inserting into it.

Query is- Similarly how can i insert tha same into TblTransactionsRepository as per the return value of tblSeed enter code here.

I am trying to do this like this

    TblSeed tblSeed = getSeed("TblTransactions",
            "TblTransactionsRepository");
    String format = "%"+(tblSeed.getSeedMaxValue()+"").length()+"s";
    long id= (tblSeed.getSeedCurrentCtr()!=null?tblSeed.getSeedCurrentCtr():tblSeed.getSeedBaseCtr())+tblSeed.getSeedIncrementCtr();


    String tblTransactionsRowName1 = ApplicationProperties
            .getValue("TblTransactionsROWNAMELIST1");
    String qInsertSelect1 = "select "
            + tblTransactionsRowName1
            + " "
            + " from "
            + srcTable
            + "Temp a, "
            + destTable
            + "Temp b "
            + " where  1=1 and a.reconFlag = b.reconFlag  and coalesce( b.reconFlag, 'B' ) = '"
            + autoFlag + "'" + joinQ;
    System.out.println("qInsertSelect1-------->" + qInsertSelect1);
    List<Object> objList = null;
    try{
        Query queryInsertSelect1 = this.sessionFactory.getCurrentSession()
                .createQuery(qInsertSelect1);
        // queryInsertSelect.setParameter("reconProcessId",
        // Integer.parseInt(reconProcessId));
        objList = queryInsertSelect1.list();
        Query queryInsertSelect3 = this.sessionFactory.getCurrentSession()
                .createQuery(qInsertSelect3);
        objList = queryInsertSelect1.list();
        logger.debug("objList :"+objList!=null ?objList.size():0);
    }catch(Exception ex){
        logger.error("Exception :",ex);
        ex.printStackTrace();
    }

Aucun commentaire:

Enregistrer un commentaire