Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display info that belongs to logged in user and not all users

 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a tough time finding any example that shows me how to display files that a user has uploaded.

When i log in, it shows info from all user files.

ArrayList<UploadClass> list = user1.getFiles();
for (UploadClass files: list) {
System.out.println(files);
}

What can I do to my arrayList to only show the files for the current logged in user?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That very much depends upon how the getFiles() method is implemented.
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the hibernate method for this

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so it's just reading a list from the DB?

If so, is there no tracking of which user uploaded the file in the first place? If not, how would it be possible to know?
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my apologies I am new to this site and new to coding.

my problem is i don't know how I would be able to set the parameter username in the array list correctly
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the list contains UploadClass items. Does that class contain any information regarding the uploading user? If not, you can't just add something to it. If so, then why would you need to add anything?

How are you expecting to know which items from the DB "belong" to the user or not?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Your method should be declared as:



Code to interfaces, not implementations.

And remove the cast from your return statement. The fact that you needed to put that in is a clue that there's a problem.
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the list is being populated with the username and the filename that was uploaded.

My question is how do I only show the files the current user has uploaded opposed to showing all of the uploaded files
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the username is a column of the DB table, and therefore a member of class UploadClass?

In that case, you'd modify the DB query to only fetch the list of items whose username match the one you are looking for,
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand but is my query "FROM uploadClass where username = (:username)"; ?

but how would i link the parameter?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure myself -- it's been many years since I've used raw Hibernate (as opposed to JPA).

As this is a Hibernate rather than servlets question, I've moved it to the ORM forum where the Hibernate-savvy will have a better chance of seeing your question.
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks i appreciate you taking your time
 
Dave Tolls
Ranch Hand
Posts: 2107
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the UploadClass look like?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic