Current position:  Home > Default > Map access problems

Map access problems

Time:November 30
Advertisement
Hi all,
I am populating a hashmap from data. One set of data is the keys and the rest is put inside an array and becomes the value.
private static final  LookupMap<Double, Integer> getFractionLookupMap(){
          Connection connSpe = null;
         PreparedStatement pstmtModel = null;
         ResultSet rsModel = null;  
         Map<Double, Integer[]> fractionLookupMap = new HashMap<Double, Integer[]>();
         try
              //Open connections
              connSpe = getConnection("", Constants.JNDI_R);
              connSpe.createStatement().execute(SET_LOCK_MODE_WAIT);
              int rowCount = 0;
              pstmtModel = connSpe.prepareStatement(MYSQL.GET_FRACTION_LOOKUP);
              rsModel = pstmtModel.executeQuery();
              if (rsModel != null)
                   Integer[] price = new Integer[2];
                   while (rsModel.next())
                        price[0] = rsModel.getInt("NUM");
                        price[1] = rsModel.getInt("DEN");
                        double value = rsModel.getDouble("VALUE");
                        log.info("Fraction Value : "+value);
                        log.info("Fraction Num : "+price[0]);
                        log.info("Fraction Den : "+price[1]);
                        fractionLookupMap.put(value, price);
                        rowCount++;
                   log.info("Map size : "+fractionLookupMap.size());
                   log.info("Fraction Lookup Rows Retrieved: " + rowCount);
              //close connectionsetc         
         catch(SQLException se)
              log.info("Error in getFractionLookup");
              throw new DatabaseTransactionException(se, "Error communicating with database","","");
         finally
              try
                   //close stuff
              catch(SQLException se)
                   //throw stuff
         return new FractionLookupMap(fractionLookupMap);
     }Inside this method all seems OK with with the correct amount of pairings in the map and the correct data in there.
However when i try to use the data inside it doesn't work as expected. I am iterating through the keys to find the nearest value to the lookup value. This seems fine, with all key values correct, but when i try to get the value pairing for that key (or any in fact) i receive the value of the LAST value pairing put onto the map!
Integer[] price = (Integer[]) GenericDao.getFractionLookupMap().getLookupMapResult(value);where FractionLookupMap().getLookupMapResult(value) is simple a lookup on the hashmap object.
This was working perfectly before but i made a change to how the map was populated and made the method static so i'm assuming it had something to do with this but i cant see what.
Any pointers?
Advertisement
Nevermind - solved it, object reference issue