JAXB - Multiple values to the same element - java

My use case is something like this, I get an object with multiple properties which I need to map to 2 elements in my XML using Jaxb.
Eg:
Employee Object has emp id, emp name, salary
This need to be mapped to
<customProperties>
<customPropName> EmpId </customPropName>
<customPropId> 123456 </customPropId>
<customPropName> EmpName </customPropName>
<customPropId> John Doe </customPropId>
<customPropName> Salary </customPropName>
<customPropId> 1029 </customPropId>
<customProperties>
How do I achieve this?

Related

SQL or Spring JDBC return object of objects

Is it possible for postgres-sql or Spring JDBC to return data with the following shape:
{
id: 1
profit: 200
sales_rep: {
name: 'bob',
age: 9,
gender: male
}
where name, age, and gender are inside the key 'sales_rep' before it reaches the repository layer? Or do I have to retrieve flat data and then put it into the shape I want in repository layer using java.
Please assume we are using two tables 'earnings' and 'sales_rep' with foreign key being 'sales_rep_id' for the sake of argument.
In Postgres SQL, you can do this easily with json functions:
select jsonb_build_object(
'id', e.id,
'profit', e.profit
'sales_rep', jsonb_build_object(
'name', sr.name,
'age', sr.age,
'gender', sr.gender
)
) js
from earnings e
inner join sales_rep sr on sr.sales_rep_id = e.sales_rep_id
This gives you a resultset with one row per earning and a single colum, that contains a jsonb payload with the structure that you asked for.

How to display Max using groovy expression in adf

I need to find max salary and displaying in new attribute.
Employee table has following columns:
Id,
Name,
Salary
I have added new add transient variable with groovy expression using Edit Expression Editor :
max(Salary)
to display max salary which exists in whole table.
I have tried this example in 11g.
Table : Emp :
E_ID EMP_NAME E_SAL
2 emp2 5000000
4 e5 100000
5 emp2 300000
6 emp3 250000
7 emp3 100000
8 emp3 100000
3 eee 250000
1 emp 100000
In which E_ID - 2 has max salary as 5000000.
Now coming back to ADF:
I have created EMP table EO and VO both.
EMPEO
EMPVO - EmpView
Now in EmpView has all the attributes as Eid, EmpName, Esal.
Created a ViewAccessor of Same VO (EmpView) in EmpView
- Click on EmpView.
- Go to View Accessor. Click on Green plus symbol. Add the EmpView from left to right. It will be named as EmpView1.
Create a transient variable named as maxSal. Give a groovy expression
to it in a Expression component.
EmpView1.max("Esal")
Now,create a jsff page and add EmpView as Form or table (as per your
requirement) with newly created transient variable. Run the
application. It's working in my case.
Hope this may help.

ehcache search API - in case of joining two tables

i am trying to new cache configuration with new DB tables. following are sample table structure and sample Data.
TABLE_DEPT:
Dept Id Detp Name Dept Dtls
111 SALES A1
112 MARKET A2
TABLE_EMP:
Emp Id Emp Name DeptId Working Started Working ended
1 ABEmp 111 01-01-2017 02-02-2017
2 CDEmp 112 01-01-2017 03-12-2017
3 EFEmp 113 01-01-2017 03-12-2017
1 ABEmp 115 03-02-2017 03-12-2017
if i want to add load the data in cache by using Dept Id, i will have unique dept Id with list of emp Id - details.
if i want to search by dept id in ehcache configuration, i can simply give search attribute is "dept id".
but, if i want to search by emp id, i should get list of dept under employee worked.
what should be my ehcache design?
my Java bean/POJO looks like below.
Class DeptDtls{
int deptId;
String deptName;
List<Integer> empIdList;
//Setter & getters
}
cache - i want to put key as deptId & value is whole DeptDtls.
in this case, how can i allow search operation based on empId?
Ehcache can provide in memory data storage only but in your case search also required on top cache.I got the same scenario and used elasticsearch for caching the data and search on stored data.elastic search has inbuilt support for search and we can index the stored data .elasticsearch can be configured for cache.

hibernate returning same instance for same foreign keys

I have two tables -
PersonType Person
---------------------- ------------------
ID type pid pid name
1 Teacher 1 1 Smith
2 Driver 1 2 David
3 Waiter 2
pid is foreign key of Person. With the hibernate, mapped these two table with many to one.
For java classes -
PersonType
{
String id;
String type;
Person p;
}
Person
{
String pid;
String name;
}
From java code, all PersonTypes were retrieved. After retrieving, changed "Driver" as Smith by calling personType.p.pid= 2.
But, both of PersonType ID 1 and 2 are updated. Since PersonType ID 1 and 2 have pid 1, hibernate return the same instance and
any changes to one of them is reflecting on both. Please anyone can suggest how to overcome this. Thanks.
I think the way you have modeled this, you should not be doing this:
personType.p.pid=2
As you're changing referential data on the hibernate managed models, I think you would want to do this:
personType.p=smith
Where smith is a reference to the Person object with ID 1
personType.p.pid= 2 this code does not change the Driver to Smith. It changes Smith's id from 1 to 2. What you need to do is what #Alex suggested.

Building a datastructure in Java

I am trying to construct a DTO object to ferry the data from data layer to view layer.
The data is as follows:
There are 7 days(dates can be used as a key in Map or any other datastructure)
The individual dates will contain multiple records.
Each record contains contact details obtained from multiple tables.
One record needs to be constructed from 3 rows in the result table. ie:
A record may return three rows with same values for all columns except for the user details; which contains details like id,name and designation.
When I display, I need to show their name as Manager and assistant manager in the same row.
Data Layer
T01 25/12/2012 ABC XYZ Manager
T01 25/12/2012 ABC IJK Asst.manager
Display:
Date 1
TaskID Taskdeadline TaskGivenBy Task assigned to Manager Task Assigned toAsst.Manager
T01 25/12/2012 ABC XYZ IJK
T02 1/1/2013 BCE WUV MNO
Solution I tried:
Map<Date,Map<Position,Object>>
Map<25/12/2012,Map<(Manager,Object details),(Asst Manager,Object details)>
and then repeat it. But I guess I am storing duplicate data. I don't think this is an ideal solution

Categories

Resources