• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Reading files

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have an xls file which has few records in it. There is a link which requests all the records in the file. I am planning to write a repository class which reads and loads the xls file. A service layer which sorts the list. In the controller I want to annotate a method with @PostConstruct which will make the service call and the service will call the repository to load and read the entire file. Whenever a request comes to the controller the list is returned. I will cache the method in the controller also. Is this a good approach?

Or should I load and read the file on the first request to the controller and then cache the result?

Can anyone please tell me how to proceed?

Thank you, good day.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I injected a resource like thisIn my repository class I used thisIs this a right approach to load a resource?

However I am not going to use a @PostConstruct because if there is some problem reading the file I will get errors during the server startup which might make the application unavailable (404 error).
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your not going to get an exception until you try and access the resource in some way. Wherever you do this you can choose to catch and handle the exceptions.

After looking at this again you can probably just do something like below. It still uses the resource abstraction to read the file in but there is probably not anything to be gained by @Autowiring in the Resource, since you are most likely going to want to access it in some special format (you are probably using some library for reading an XLS)

In this example I am just using a String but gives you the idea.

 
No, tomorrow we rule the world! With this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic