Passing data to a prepared statement



  •  Ran across this today in a application.  It's used to pass parameters that are later built into a prepared statement.  There might some genius in this but I don't see it.

     

     /* * Generates the conMap the GeneralPurposeDataAccess.addToConMap uses.
    *
    * */
    public static Map < String, Map < SQLComparator, Map < List < Object >, Integer >>> conMap () {

        Map < String, Map < SQLComparator, Map < List < Object >, Integer >>> conMap =

              new LinkedHashMap < String, Map<SQLComparator,Map<List<Object>,Integer>> >();

        return conMap;

    } // end of method conMap



  • I'm not quite sure, but that might be a cheap way to create a map that takes a tuple key, if you don't want to create an extra class just for this single function.

    Why you'd need to index something with respect to (String, SQLComparator, List<Object>) keys is still beyond me, though.



  •  I like how he's using generics to create the list of type Object.



  • @amischiefr said:

    I like how he's using generics to create the list of type Object.

    Assuming this is Java, the compiler would complain without it.



  •  Yes, this this from Java...  He uses more constructed objects like this throughout the code for this app.  I'm trying to get them to chunk the who thing and re-write from scratch with a standard framework like Spring.



  • Without seeing the sort of stuff that's going into these calls it's hard to tell what's going on. A Weblogic SQLComparator is used when you're using a sorted rowset (I'm guessing that this data is displayed somehow and a user can re-sort the data). 

     It looks like this method might be being used to cache setup for statements? Without knowing what he puts in the Object list and Integer it's hard to know. I can see that if you've got a GUI with tabs perhaps you could use this to map the tab name to the comparator, then the comparator to some kind of display controls? 

     I have to say that in my old age I'm not a fan of ripping out and starting over a lot of the time.. Every job I've been in the business has prioritised new functionality over making old functionality neater - and whilst it's frustrating for a coder who wants it perfect, a lot of the time it's the right decision for profit making.

     

    Plus, while frameworks certainly have their place, trying to retrofit them is always a nightmare..



  • @brhurley said:

     Yes, this this from Java...  He uses more constructed objects like this throughout the code for this app.  I'm trying to get them to chunk the who thing and re-write from scratch with a standard framework like Spring.

     

    Ah, I see. You're shooting for the "Please hold me personally 100% responsible for the total failure of a working product due to an unwarranted complete rewrite because of a bit of code I didn't like" angle.



  • @smxlong said:

    Ah, I see. You're shooting for the "Please hold me personally 100% responsible for the total failure of a working product due to an unwarranted complete rewrite because of a bit of code I didn't like" angle.

     

    Well that would be more fun but no.  I wish that I could show you the entire code base as there is a WTF as some level in each class.   Just belive me this code will be redone at some point it's just a matter of when...  I will say this the cyclomatic complexity average is over 12 with the highest method being 84.   We have a 3% code coverage with unit tests.



  • @Buff said:

    Without seeing the sort of stuff that's going into these calls it's hard to tell what's going on. A Weblogic SQLComparator is used when you're using a sorted rowset (I'm guessing that this data is displayed somehow and a user can re-sort the data). 

     It looks like this method might be being used to cache setup for statements? Without knowing what he puts in the Object list and Integer it's hard to know. I can see that if you've got a GUI with tabs perhaps you could use this to map the tab name to the comparator, then the comparator to some kind of display controls? 

     

     

    It's simpler than that.  He is just using this contruct to pass data to a class that abstracts the database connection and execution part.  He takes this map and builds the select values or the where clause.  

     

     



  • That's odd.. why on earth does he need an SQL Comparator then...

    Heh, probably a case of over-doing it ready for imagined future needs


Log in to reply