access result set of jdbcbatchitemwriter spring batch - spring

I am trying to read an excel sheet using itemreader and pass it to writer where i need to query for record existence. I am not sure how to access result set of jdbcbatchitemwriter so that i can validate whether query results. can any one please guide

It can actually be done in ItemProcessor. To filter a record, one simply returns "null" from the ItemProcessor.(Ref : here)
This post explains how to drop the duplicates in ItemProcessor. As per this example, you can maintain the list of previousItems from database to drop out the records.

Related

Spring Boot CRUD findall without orderBy: is the order predictable?

Does the list returned by a CRUD repository method such as the following have a predictable order?
List<UserProfile> findAllByGroupKey (String groupKey);
The database is MySQL 5 and Spring Boot version is 2.2.7. I'd like the order of the items in the list to be the same as they were stored in the database, but I'm not sure if it's enough to omit `orderBy' to achieve this result. I couldn't find any documentation on this.
I did some testing with the specified configuration (MySQL 5 and Spring Boot 2.2.7). The answer is definitely "no", at least if the index is not a progressive number (in my case it is an UUID).
The order is in no way predictable based on how the data was entered.
The only way to get the rows in the same order as they were entered into the database is to add an additional sort variable (such as a sequence number or a timestamp) and explicitly sort the rows with "orderBy" based on that variable.

Spring Data JPA and NULL filter, if Double field value is null nothing is returned

I have a data JPA entity where it contains a "price" type Double. Now, the users need to able to filter the records based on that field (Between min and max). Now the problem is, the value in the DB can be null for some records. My data JPA repository uses a native query like "price BETWEEN :priceFrom AND :priceTo". Now, if the user does not specify anything in the filter conditions, all record including the ones where prices is null should be returned. However, this query does not return those record. I know, I can create a new method with query "price IS NULL" and check the filter values in my service layer and call the null version if nothing is specified. But, I have multiple fields with the same requirement then it results in a lot of duplicate methods to maintain. Is there a better approach to handle that situation?
It seems to me, that you can specify
(:priceFrom is null and :priceTo is null and price is null)
OR price between :priceFrom and :priceTo
if priceFrom and priceTo are entered, second part of OR will be used, otherwise it selects records where price is null
Since you are using Spring Data JPA - Specifications should solve this for you. This is a JPA Criteria based solution.
For any complex-enough API – searching/filtering your resources by very simple fields is simply not enough. A query language is more flexible and allows you to filter down to exactly the resources you need. Hence you should easily be able to program for NULL (in the scenario that you currently need) and anything else that you might need.
This is scalable for multiple fields and easy to code/configure. There are a few links which will give you more insight into it
Spring Blog
Tutorial 1
Tutorial 2
Hopefully, this is helpful.

Is a result set required to retrieve only single row queries results?

I know only one record fetching form sql query in jdbc example, do I need to use result set interface to store that only one row, or is there any way to store results from single result queries?

Does Parse now support more than 1 geopoint per object?

It used to be, and the documentation still says: Each PFObject class may only have one key with a PFGeoPoint object.
But in my tests today, I created an object with 2 GeoPoint columns, was able to query on either GeoPoint, and was able to modify and save either GeoPoint. Previously, this would lead to an error like: only 1 ParseGeoPoint object can be stored in a class.
Is this really supported now?
Some additional info: I first have to create the 2 geoPoint columns in the data browser. If they don't exist and my iPhone code tries to save an object with 2 geoPoints, then I get the "only one GeoPoint field may exist in an object". But as long as the 2 columns exist, my client code appears to be able to use both.
As of July 2015, Parse still does not support more than one GeoPoint column on a class. They have, however, fixed the Data Browser to prevent users from creating two GeoPoint columns.
Got this response from Parse (in the Google Group forum):
Hmm, that sounds like a problem with the data browser's mechanism of altering the schema. Could you report a bug? I would not recommend using objects created in this way - the underlying data store can only index one geopoint field per object, so whichever field gets indexed second just will have the index fail and you won't be able to run queries against it.
The solution is to put the second GeoPoint (which you will not be able to search on) into a singleton array.

Unique Query Creation result in Spring-Data

I'm using Spring-Data's Query Creation as described here.
I have an ID to Person, and also a secId which is also a unique Id.
I want to be able to write
Person findBySecId(long secId);
Because I know that I will get only one result.
Right now as I've seen, I can only write
List<Person> findBySecId(long secId);
and then I have to extract the first element.
Is there any known way to do what I want?

Resources