Can we create Array of different kinds of primitives ??
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Pappu_Kumar
Posted On:   Saturday, November 8, 2003 08:22 AM

I have a JDBCWrapper class which has a executeStoredProc(String procName,Object[] arguments) method. When i need to call a stored procedure...i call this method and pass all my arguments as an Object array. Ex. If i need to call a Stored Proc that adds two integer numbers (AddNum) , i would do the following. executeStoredProc(AddNum,new Object[]{new Integer(5),new Integer(10)}). The method would prepare the required callable statment with the required number of '?' and depending on the Object[] element types would do a setInt or setString,setFloat etc etc. Now my problem is that somestimes i have 20 arguments , so i am creating 20 objects (and creating new instance is always expensive). Is there any other    More>>

I have a JDBCWrapper class which has a executeStoredProc(String procName,Object[] arguments) method.
When i need to call a stored procedure...i call this method and pass all my arguments as an Object array. Ex. If i need to call a Stored Proc that adds two integer numbers (AddNum) , i would do the following.

executeStoredProc(AddNum,new Object[]{new Integer(5),new Integer(10)}).

The method would prepare the required callable statment with the required number of '?' and depending on the Object[] element types would do a setInt or setString,setFloat etc etc.

Now my problem is that somestimes i have 20 arguments , so i am creating 20 objects (and creating new instance is always expensive).

Is there any other way i could pass my arguments as an array and find out their type inside the method. I regularly use String,int,float.
Basically can we store primitives,String objects in the same Array kind of implementation ? Please suggest

   <<Less

Re: Can we create Array of different kinds of primitives ??

Posted By:   Ori_Kushnir  
Posted On:   Tuesday, November 11, 2003 09:32 AM

You could create a structure that contains arrays of the different primitive types:



class MultiArray {

int [] intData;

float [] floatData;

...

...

}




And supports mapping from the global array index to
primitive array indices (array instantiation should be
lazy). If you have 20 instances of, say, 4 types,
you'll need to create 5 arrays (4 for the types and one for
the index mapping) instead of 20, not to mention
savings on casting. Of course, it does add its own

indirection.



About | Sitemap | Contact