How to display Max using groovy expression in adf - java

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.

Related

Get all results that contain the largest value in table

Let's say I have a very simple table called test:
ID AGE NAME
1 12 Bob
1 13 Bob
2 13 John
3 9 Michael
3 11 Michael
I want to return all results that have the largest AGE in the table. So for this case, the result would be the entities with the age 13:
ID AGE NAME
1 13 Bob
2 13 John
I would think something like this should exist, my thought process would have been the following (even though I know the syntax would not work):
connection.getSqlQuery()
.from(test)
.max(test.age)
.list(test.id, test.age, test.name);
What would be the proper query for this?
You can create a subquery and use it in your where clause:
// Aggregate to get the maximum age
var subQuery = connection.getSqlQuery()
.select(test.age.max())
.from(test);
connection.getSqlQuery()
.from(test)
.where(test.age.eq(subQuery))
.list(test.id, test.age, test.name);
If you use JPA, you can also use var subQuery = JPAExpressions.select(...

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.

JAXB - Multiple values to the same element

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?

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.

How to select addtion of two columns of a table through hibernate

Suppose i have a table Student
- ID Name Sub1 Sub2
- 1 Deepika 99 89
- 2 Shubham 78 90
I want my hibernate application to provide me the following result
- ID Name Sub1 Sub2 Total
- 1 Deepika 90 80 170
- 2 Shubham 78 90 168
i.e my sql query is
select id name, sub1, sub2, sub1+sub2 as total
from employee
How can i do this in Hibernate? What changes should i make in my hbm.xml file and bean class?
Using addScalar() you can fetch any additional row than the existing information without changing the xml. For more details refer this documentation
Otherwise you need to change the xml and bean class corresponding to the new table structure.

Categories

Resources