ehcache search API - in case of joining two tables - java

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.

Related

Simple SQL query on highest ID

I unsuccessfully attempted to leverage Java's DerivedQueries but cannot accomplish the required result so I have to manually write a SELECT Statement.
I want to display one single record in my UI. This should be the most recently generated record (which means it has the highest ID Number) associated with a category that we call "ASMS". In other words, look through all the rows that have ASMS#123, find the one that has the highest ID and then return the contents of one column cell.
ASMS: Entries are classified by 11 specific ASMS numbers.
ID: AutoGenerated
PPRECORD: New entries being inserted each day
I hope the image makes more sense.
//RETURN ONLY THE LATEST RECORD
//https://besterdev-api.apps.pcfepg3mi.gm.com/api/v1/pprecords/latest/{asmsnumber}
#RequestMapping("/pprecords/latest/{asmsNumber}")
public List<Optional<PriorityProgressEntity>> getLatestRecord(#PathVariable(value = "asmsNumber") String asmsNumber) {
List<Optional<PriorityProgressEntity>> asms_number = priorityprogressrepo.findFirst1ByAsmsNumber(asmsNumber);
return asms_number;}
The ReactJS FE makes an AXIOS.get and I can retrieve all the records associated with the ASMS, but I do not have the skill to display only JSON object that has the highest ID value. I'm happy to do this in the FE also.
I tried Derived Queries. .findFirst1ByAsmsNumber(asmsNumber) does not consider the highest ID number.
Try this:
SELECT pprecord FROM YourTable WHERE id =
(SELECT MAX(id) FROM YourTable WHERE asms = '188660')
Explanation:
First line select pprecord, second line select the id
I'll improve the answer if any additional question. Upvotes and acceptions are appreciated~

display data based on LOV selection in adf

I have adf view Object called SalesVO that I need to save to database, in that View object I have a foreign key (CustomerId) that is associated with another View Object called CustmersVO
I dragged salesVO in jspx page, The user should enter information in the sales information in the page then click save (commit).
the problem is when while the user is filling the sales info he should select customer from LOV once he select customer the page should display Customer info (like address, phone, ..etc) automatically from CustomersVO
how can I display these read only info of the selected customer?
the structure is as follow:
SalesVO : saleId, SaleDate, CustomerId ..... etc
CustomerVO: CustomerId, CustomerName, Phone, Address....etc
Are you saying you want to basically join the Sales info with Customer info and allow user to select the Customer based on Customer ID in Sales VO and then when that customer is selected, display the retrieved customer data along with the sales VO, but only the Sales VO info is saved?
If so this is a simple, basic thing to do in ADF BC. have you looked at the many tutorials available online here? Have you read the docs on how to create an LOV or Reference entity usage or seen this or this?
The SalesVO is based on the Sales EO and is updatable, then add the CustVO as a non-updatable reference only data and then make the Cust ID in the Sales VO the basis for the LOV. The selected Customer data will appear in the LOV and the selected Customer ID will be saved as the foreign key to the Sales VO, with the extra customer data providing non-updatable reference values. The steps to do this are widely available in many blog posts - Google is your friend here. Also consider reading the ADF BC docs, on LOVS, and reference entities and joins of VOs.

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

Hibernate query by example (from Spring 3)

I've made my entity classes Adress, Road and County. A Road is in a County and an Adress in on a Road. I would like to list all the Adresses in a County. Therefore, in my AdressService I say:
public List<Adress> AllAdresses(County county) {
Adress adress = new Adress();
Road road = new Road();
road.setCounty(county);
adress.setRoad(road);
Example example = Example.create(adress);
return (List<Adress>) adressDAO.query(Adress.class, example);
}
In my AdressDAO I have query():
public List query(Class<?> c, Example example) {
return getSession().createCriteria(c).add(example).setMaxResults(100).list();
}
This executes the following query on my database server:
select this_.AdressId as AdressId2_0_,
this_.Description as Descript3_2_0_,
this_.DescriptionShort as Descript4_2_0_,
this_.HouseLetter as HouseLetter2_0_,
this_.HouseNr as HouseNr2_0_,
this_.RoadId as RoadId2_0_
from tblAdress this_
where (this_.HouseNr=0)
limit 100
I had expected it to at least include SOME information about my entity County, and an inner join with tblRoad. tblRoad has a primary key roadId, so I expected this_.roadId to be joined with tblRoad.roadId, and I expected tblRoad.countyId to be set to the primary key of County, that is countyId.
Why is the query in this example not built correctly when I use my own entity types? If I only use integers and strings, they work fine, but not entities. How do I make joins like this work with my own entities?
From the Hibernate docs:
Version properties, identifiers and
associations are ignored
And that, as they say, is that.

Categories

Resources