I have database execute method returning a resultMap with a key as rd and value as list of custom object Employee data.
Map<String,Object> resultMap=getEmpBatchDB.execute(paramMap) currently doing below operation emp=resultMap.get("rd")).findFirst().get(); It is only giving one object which is first record of emp only. Returning one causing defect.
Instead of returning one how to return all records. I wish there is method like findAll() similar to findFirst() on stream API but not there.
sai rama krishna wrote:I have database execute method returning a resultMap with a key as rd and value as list of custom object Employee data.
If in fact the value were a list of data, you'd already be done, right? But apparently not...
sai rama krishna wrote:emp=resultMap.get("rd")).findFirst().get()
It looks like you've got an extra ")" in there, or a missing "(". But, is it possible the thing returned by resultMap.get("rd") is a Stream of some sort, rather than a List? In that case, you have a few options. Given:
EmployeeData empData; //i am declaring at top of this dao class method called getEmpDataBatchDB
i have to return empData to calling service class
I am doing below 3 lines later on in same dao class method
i tried filter() and collect() as above.
Challenge is i have to return empData to calling service class method not ist<EmployeeData>. Please advise
sai rama krishna wrote:Challenge is i have to return empData to calling service class method not ist<EmployeeData>. Please advise
But that means you have to return ONE EmployeeData object. So writing code which produces more than one of them, even if that's what is needed in real life, isn't going to compile. You would have to change the method's return type if that's what is needed.
Can you show us some code that will compile? I see several errors in parentheses still that make it hard to be sure what you're trying to say.
sai rama krishna wrote:
Are you casting to List<Employee>? That would look like this:
sai rama krishna wrote:
Sooo... what's happening here? What class is get("rd") returning? I thought you were casting it to List<Employee>, but List doesn't have a findFirst() method. So what class are you working with now? A List, a Stream, or something else? Are you trying to cast it to something?
I also agree with Paul Clapham's question. Do you want to return one employee (or EmployeeData or whatever), or a list/collection/array of many employees? Can you change the return type of your method to a List<EmployeeData> or something similar?
sai rama krishna wrote:Looks like i cannot change method signature so method still has to return EmployeeData object not List<EmployeeData>
I guess my question would be: "How constrained are you in the implementation?" you say you must return an EmployeeData, but why? do you have this with hundreds or even thousands of calls throughout your project? is this a legacy project or a system that is outside of your rewrite authorization? i guess: what is the reason that you are constrained to only return an EmployeeData record and not the List or some other data structure?
I have had some truly bitch of rewrites throughout my career, but I have always been given god rights in making any changes that I deem necessary to implement the desired features.
If you are truly constrained to return only 1 record, then you are constrained to return only 1 record (this is what you are telling us) ... any thought otherwise is nothing more than a fools errand because you are not authorized to do so by those that do have god powers.
If you do have the god power to change things as you need, then by all means--change it. I've told this to more than one developer in my time: grow some stones and get the implementation done. Even if it is a new feature and not a override of the existing call, make the requested changes to the project.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Agree. Most of the collection courses an YouTube videos i see they teach adding string value to collection object and retrieving and deleting etc simple things. Real world projects has these types of complex scenarios with agile methodologies people giving few hours and judging the performance. Any good courses or YouTube videos or books(not much time for reading these days) where these type of complex scenarios covered like map has list as value and that list is having other filed which is list type which has again string as empNumber string field to set and return that object. My mind some times goes blank and unable to wrap around these type of things to implement. Please advise
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop