How to fetch data from database on scroll? - java

I am using CachedRowSet in the java application to pull data from database. Suppose, if a query return 10,000 rows, my app will hang till i got all the rows.
Instead of that, i need to show the complete result only on scrolling. Please help me to solve this problem.

You may choose to implement your own lazy loading List which will load values page by page as accessed. There are many tutorials on this on internet check this one : http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/

Related

how to avoid waiting too long for the server's data when using recyclerview

I managed to set up a recyclerview that displays server's data regarding some articles ( total 328 ).
The problem is the waiting time.
I have to wait about 40 seconds for the recyclerview to display completely.
Is there a way to display a small portion of this data directly without having to retrieve all the data ?
For instance, displaying data for the top 10 articles , scrolling down to the bottom , loading the next 10 articles and so on ..
ANy recommendations ?
First of all, backend api should be able to provide results in a paginated way. So, when you load screen, you load first page. When you scroll down, you show a spinner and request the next page.
You can find a sample here
Another point would be store articles in local database.
If you are using Room library as database, you can use the pagination library
If you use another database, you have to implement your own solution.

Fetching user data with pagination

I have a user table & a child table Post containing user's posts. A user has a large number of posts just like twitter posts.
I need to fetch user posts on the UI, load more posts as the user scrolls down the page just like facebook/twitter do. I am using hibernate as the ORM framework & MySql as db. I looked into pagination found two primary ways of achieving that
1. setFirstResult();
setMaxResults();
2. ScrollableResults
I have two questions
A. Which way of pagination would be more appropriate & efficient to achieve this? I've read that ScrollableResults is more efficient than setFirstResult but it keeps the connection open for the entire pagination process.
B. As the user's profile page is loaded ajax call is fired to display the user's posts everytime, it's like a certain default content in the page. So do I need to implement a second level cache in order to avoid db hits every time the page loads?
If the dataset is large then choosing ScrollableResults will be
better.
If the users will be accessing your application with low bandwidth
and mostly will be retrieving only first or specific page say from page1 to page2
then go with setFirstResult() and setMaxResults().

Find out who deleted the row in the DB

We have a Oracle DB with around 4K tables in it. And around 30 different applications accessing the data. We have an issue where one of the application is deleting a row in one of our tables. We do not know which app and why. I'm trying to figure out, but, first thought I got is to use Triggers when ever something is deleted and log it, but, is there a way to find out which application has deleted it in oracle?
Thanks
If you didnt want to go down the autiting or logging route and the application is not distinct from v$session as it stands, you could set the name of the application by calling
dbms_application_info.set_client_info('my_application');
This sets v$session.client_info for the session, which you can read via
dbms_application_info.read_client_info(client_info out varchar2);.
You could then use triggers and to record this value.

ZK - how to show 1Million rows in a table / grid

So far I've seen examples that use the following logic:
Create a table / grid object
Set its data source (Collection such as array list/ set)
The table shows the entries on the client side!
Problem is, we have millions of rows to display, (on a side note I tried to load the container with all the entries, it took tons of time, and the client side performance were lacking)
So that raises the question:
How do you show huge amount of data on the zk tables \ grids? Wishful
thinking points me to think that instead of an array list data source
i could set a DB connection or something instead, and that will manage
the results on demand with paging.
Any ideas?
Why loading data when you are not displaying all the rows at a time.
Retieve only those data that should be displayed and load the other data on demand not while the page is initially loading.
if you try to fetch 1 million rows and try to bind it to a control, it will hugely effect your application performance and increases the time for your page to load.
So, my adivce should be fetch only those rows that needs to be displayed. if the request comes from the user for the next set of pages then load that data and bind.
you can make ajax calls to avoid every time entire page refershing
hope this helps..
ZK give BigListbox to show huge record

Do I need to normalize this MySQL db?

I have a classifieds website which uses SOLR to search for whatever ads the user wants to search for... SOLR then returns the ID:s of all the matches found. I then use the ID:s to fetch and display the ads from a MySQL table.
currently I have one huge table containing everything in MySQL.
Sometimes some of the fields are empty because for instance an apartment has no "model" but a car does.
Is this a problem for me if I use SOLR like I do?
Thanks
Ask yourself these questions:
Is your current implementation slow or prone to error?
Are you adding a lot of "hacks" in order to display content or fetch data correctly due to the de-normalization of your database?
In the long run, will you benefit from normalizing the table?
Hope that helps. It all depends on your situation! Personally, I build databases normalized and then de-normalize as needed to keep things speedy.
If you are using SOLR, why don't you just serve complete ad from solr instead of MySQL to save DB time?
One huge table usually is not goog option at all.

Categories

Resources