• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Reading files

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic